feat(protocol): negotiate registered gateway profiles
Verify Protocol / verify (push) Canceled after 0s
Verify Protocol / module (push) Successful in 2m29s

This commit is contained in:
sechmachine
2026-07-30 04:47:52 +07:00
parent d26f8b60f8
commit e58f1c7c48
17 changed files with 227 additions and 67 deletions
+42 -14
View File
@@ -13,7 +13,7 @@ import (
"time"
)
const SchemaSHA256 = "fe4d6be69665f09f04e2cd89273ebc5d2dddf4cde98b94a9d8c4f726504ffe1b"
const SchemaSHA256 = "3aec8dd72bdbb6b9657c8df3160252c93034c7c1032d471e01eae2ef91e47716"
const ProtocolVersion = "1.0.0"
const CurrentWireVersion = "1"
const NMinus1WireVersion = "0"
@@ -68,12 +68,12 @@ type BrokerSession struct {
}
type CapabilityProfile struct {
Transport string `json:"transport"`
Framing string `json:"framing"`
Media string `json:"media"`
Audio string `json:"audio"`
SourceRateControl string `json:"source_rate_control"`
ClientDecode string `json:"client_decode"`
Transport string `json:"transport"`
Framing string `json:"framing"`
Media string `json:"media"`
Audio string `json:"audio"`
SourceRateControl string `json:"source_rate_control"`
ClientDecode []string `json:"client_decode"`
}
type ChannelFrame struct {
@@ -884,14 +884,26 @@ func (v CapabilityProfile) Validate() error {
if len(v.SourceRateControl) > 64 {
violations = append(violations, FieldViolation{Field: "source_rate_control", Code: "max_length"})
}
if v.ClientDecode == "" {
if v.ClientDecode == nil {
violations = append(violations, FieldViolation{Field: "client_decode", Code: "required"})
}
if len(v.ClientDecode) < 1 && v.ClientDecode != "" {
violations = append(violations, FieldViolation{Field: "client_decode", Code: "min_length"})
if len(v.ClientDecode) < 1 {
violations = append(violations, FieldViolation{Field: "client_decode", Code: "min_items"})
}
if len(v.ClientDecode) > 64 {
violations = append(violations, FieldViolation{Field: "client_decode", Code: "max_length"})
if len(v.ClientDecode) > 2 {
violations = append(violations, FieldViolation{Field: "client_decode", Code: "max_items"})
}
for _, item := range v.ClientDecode {
if !(item == "h264-opus" || item == "hevc-opus") {
violations = append(violations, FieldViolation{Field: "client_decode", Code: "invalid_item"})
}
}
for index, item := range v.ClientDecode {
for prior := 0; prior < index; prior++ {
if item == v.ClientDecode[prior] {
violations = append(violations, FieldViolation{Field: "client_decode", Code: "duplicate_item"})
}
}
}
if len(violations) > 0 {
return ValidationError{Violations: violations}
@@ -4990,16 +5002,32 @@ func IntersectCapabilityProfiles(profiles ...CapabilityProfile) (CapabilityProfi
if err := selected.Validate(); err != nil {
return CapabilityProfile{}, ErrNoCapabilityOverlap
}
common := append([]string(nil), selected.ClientDecode...)
for _, profile := range profiles[1:] {
if err := profile.Validate(); err != nil || profile != selected {
if err := profile.Validate(); err != nil || profile.Transport != selected.Transport || profile.Framing != selected.Framing || profile.Media != selected.Media || profile.Audio != selected.Audio || profile.SourceRateControl != selected.SourceRateControl {
return CapabilityProfile{}, ErrNoCapabilityOverlap
}
next := common[:0]
for _, candidate := range common {
for _, offered := range profile.ClientDecode {
if candidate == offered {
next = append(next, candidate)
break
}
}
}
common = next
if len(common) == 0 {
return CapabilityProfile{}, ErrNoCapabilityOverlap
}
}
selected.ClientDecode = common
return selected, nil
}
func (v TunnelAdmissionRequest) DeviceAdmissionTranscript() []byte {
fields := []string{v.SessionID, v.GatewayID, v.Audience, v.Grant, fmt.Sprintf("%d", v.ReconnectSequence), v.ClientNonce, v.Capabilities.Transport, v.Capabilities.Framing, v.Capabilities.Media, v.Capabilities.Audio, v.Capabilities.SourceRateControl, v.Capabilities.ClientDecode}
fields := []string{v.SessionID, v.GatewayID, v.Audience, v.Grant, fmt.Sprintf("%d", v.ReconnectSequence), v.ClientNonce, v.Capabilities.Transport, v.Capabilities.Framing, v.Capabilities.Media, v.Capabilities.Audio, v.Capabilities.SourceRateControl, fmt.Sprintf("%d", len(v.Capabilities.ClientDecode))}
fields = append(fields, v.Capabilities.ClientDecode...)
var transcript strings.Builder
transcript.WriteString("versevdi/tunnel-admission/v1")
for _, field := range fields {