feat(gateway): fetch sealed Apollo session work
Verify Data Plane / gateway (push) Successful in 3m33s
Verify Data Plane / gateway (push) Successful in 3m33s
This commit is contained in:
+30
-8
@@ -44,8 +44,17 @@ func (i ProviderIdentity) Key() string {
|
||||
return i.UniqueID + "#" + i.Fingerprint
|
||||
}
|
||||
|
||||
func providerIdentityFromKey(value string) (ProviderIdentity, bool) {
|
||||
uniqueID, fingerprint, ok := strings.Cut(strings.TrimSpace(value), "#")
|
||||
if !ok || uniqueID == "" || fingerprint == "" || strings.Contains(fingerprint, "#") || len(uniqueID) > 128 || len(fingerprint) > 256 {
|
||||
return ProviderIdentity{}, false
|
||||
}
|
||||
return ProviderIdentity{UniqueID: uniqueID, Fingerprint: fingerprint}, true
|
||||
}
|
||||
|
||||
func (i ProviderIdentity) Validate(now time.Time, expected ProviderIdentity) error {
|
||||
if i.UniqueID == "" || i.Fingerprint == "" || i.UniqueID != expected.UniqueID || i.Fingerprint != expected.Fingerprint {
|
||||
if i.UniqueID == "" || expected.UniqueID == "" || i.UniqueID != expected.UniqueID ||
|
||||
(i.Fingerprint != "" && i.Fingerprint != expected.Fingerprint) {
|
||||
return ErrProviderIdentity
|
||||
}
|
||||
if !i.NotBefore.IsZero() && now.Before(i.NotBefore) {
|
||||
@@ -68,7 +77,8 @@ func ParseManagementXML(data []byte) (ManagementInfo, error) {
|
||||
}
|
||||
var document struct {
|
||||
XMLName xml.Name `xml:"root"`
|
||||
UniqueID string `xml:"unique_id"`
|
||||
UniqueID string `xml:"uniqueid"`
|
||||
LegacyID string `xml:"unique_id"`
|
||||
Fingerprint string `xml:"fingerprint"`
|
||||
NotBefore string `xml:"not_before"`
|
||||
NotAfter string `xml:"not_after"`
|
||||
@@ -79,6 +89,9 @@ func ParseManagementXML(data []byte) (ManagementInfo, error) {
|
||||
if err := decoder.Decode(&document); err != nil {
|
||||
return ManagementInfo{}, fmt.Errorf("%w: %v", ErrProviderMalformed, err)
|
||||
}
|
||||
if document.UniqueID == "" {
|
||||
document.UniqueID = document.LegacyID
|
||||
}
|
||||
identity := ProviderIdentity{UniqueID: document.UniqueID, Fingerprint: document.Fingerprint}
|
||||
var err error
|
||||
if document.NotBefore != "" {
|
||||
@@ -93,7 +106,7 @@ func ParseManagementXML(data []byte) (ManagementInfo, error) {
|
||||
return ManagementInfo{}, ErrProviderMalformed
|
||||
}
|
||||
}
|
||||
if identity.UniqueID == "" || len(identity.UniqueID) > 128 || identity.Fingerprint == "" || len(identity.Fingerprint) > 256 {
|
||||
if identity.UniqueID == "" || len(identity.UniqueID) > 128 || len(identity.Fingerprint) > 256 {
|
||||
return ManagementInfo{}, ErrProviderMalformed
|
||||
}
|
||||
return ManagementInfo{Identity: identity, Name: document.Name}, nil
|
||||
@@ -181,6 +194,7 @@ type LaunchRequest struct {
|
||||
Capabilities protocol.CapabilityProfile
|
||||
ProviderProfile string
|
||||
ProviderIdentity string
|
||||
ProviderWork protocol.ProviderSessionWork
|
||||
}
|
||||
|
||||
type InputEvent struct {
|
||||
@@ -213,7 +227,7 @@ type ProviderSession interface {
|
||||
}
|
||||
|
||||
type ApolloBackend interface {
|
||||
Management(context.Context) ([]byte, error)
|
||||
Management(context.Context, LaunchRequest) ([]byte, error)
|
||||
Setup(context.Context, LaunchRequest) ([]byte, error)
|
||||
Open(context.Context, LaunchRequest, RTSPResponse) (ProviderSession, error)
|
||||
}
|
||||
@@ -233,7 +247,7 @@ func (a *ApolloAdapter) Start(ctx context.Context, request LaunchRequest) (Provi
|
||||
if a == nil || a.backend == nil || request.ProviderProfile != ProviderProfileApollo {
|
||||
return nil, ErrProviderIdentity
|
||||
}
|
||||
management, err := a.backend.Management(ctx)
|
||||
management, err := a.backend.Management(ctx, request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -241,10 +255,18 @@ func (a *ApolloAdapter) Start(ctx context.Context, request LaunchRequest) (Provi
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := info.Identity.Validate(a.now(), a.expected); err != nil {
|
||||
expected := a.expected
|
||||
if request.ProviderWork.ProviderIdentity != "" {
|
||||
parsed, ok := providerIdentityFromKey(request.ProviderWork.ProviderIdentity)
|
||||
if !ok {
|
||||
return nil, ErrProviderIdentity
|
||||
}
|
||||
expected = parsed
|
||||
}
|
||||
if err := info.Identity.Validate(a.now(), expected); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if request.ProviderIdentity != "" && request.ProviderIdentity != info.Identity.Key() {
|
||||
if request.ProviderIdentity != "" && info.Identity.UniqueID != expected.UniqueID {
|
||||
return nil, ErrProviderIdentity
|
||||
}
|
||||
rawRTSP, err := a.backend.Setup(ctx, request)
|
||||
@@ -320,7 +342,7 @@ func NewFakeApollo(config FakeApolloConfig) *FakeApollo {
|
||||
return &FakeApollo{config: config}
|
||||
}
|
||||
|
||||
func (f *FakeApollo) Management(context.Context) ([]byte, error) {
|
||||
func (f *FakeApollo) Management(context.Context, LaunchRequest) ([]byte, error) {
|
||||
if f.config.Failure == FakeFailureMalformed {
|
||||
return []byte("<root>"), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user