From 28df93f66903596ae48fdf05580137de3e499ab2 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Sat, 12 Sep 2020 23:40:36 -0700 Subject: [PATCH] Expose Priority and Foundation overrides Allow pion/webrtc to override these as well --- candidate.go | 8 -------- candidate_base.go | 27 +++++---------------------- candidate_host.go | 16 ++++++++++------ candidate_peer_reflexive.go | 18 +++++++++++------- candidate_relay.go | 18 +++++++++++------- candidate_server_reflexive.go | 18 +++++++++++------- 6 files changed, 48 insertions(+), 57 deletions(-) diff --git a/candidate.go b/candidate.go index f53d7fb..701f8f8 100644 --- a/candidate.go +++ b/candidate.go @@ -23,10 +23,6 @@ type Candidate interface { // have the same type, base IP address, protocol (UDP, TCP, etc.), // and STUN or TURN server. Foundation() string - // setFoundation lets you explicitly override the foundation of a candidate - // if needed. This useful mostly for remote candidates, but can also be helpful - // for debugging - setFoundation(string) // ID is a unique identifier for just this candidate // Unlike the foundation this is different for each candidate @@ -48,10 +44,6 @@ type Candidate interface { Port() int Priority() uint32 - // setPriority lets you explicitly override the priority of a candidate - // if needed. This useful mostly for remote candidates, but can also be helpful - // for debugging - setPriority(uint32) // A transport address related to a // candidate, which is useful for diagnostics and other purposes diff --git a/candidate_base.go b/candidate_base.go index 254a8e5..93c4d64 100644 --- a/candidate_base.go +++ b/candidate_base.go @@ -406,14 +406,6 @@ func (c candidateBase) Marshal() string { return val } -func (c *candidateBase) setFoundation(foundation string) { - c.foundationOverride = foundation -} - -func (c *candidateBase) setPriority(priority uint32) { - c.priorityOverride = priority -} - // UnmarshalCandidate creates a Candidate from its string representation func UnmarshalCandidate(raw string) (Candidate, error) { split := strings.Fields(raw) @@ -482,26 +474,17 @@ func UnmarshalCandidate(raw string) (Candidate, error) { } } - var c Candidate switch typ { case "host": - c, err = NewCandidateHost(&CandidateHostConfig{"", protocol, address, port, uint16(component), tcpType}) + return NewCandidateHost(&CandidateHostConfig{"", protocol, address, port, uint16(component), priority, foundation, tcpType}) case "srflx": - c, err = NewCandidateServerReflexive(&CandidateServerReflexiveConfig{"", protocol, address, port, uint16(component), relatedAddress, relatedPort}) + return NewCandidateServerReflexive(&CandidateServerReflexiveConfig{"", protocol, address, port, uint16(component), priority, foundation, relatedAddress, relatedPort}) case "prflx": - c, err = NewCandidatePeerReflexive(&CandidatePeerReflexiveConfig{"", protocol, address, port, uint16(component), relatedAddress, relatedPort}) + return NewCandidatePeerReflexive(&CandidatePeerReflexiveConfig{"", protocol, address, port, uint16(component), priority, foundation, relatedAddress, relatedPort}) case "relay": - c, err = NewCandidateRelay(&CandidateRelayConfig{"", protocol, address, port, uint16(component), relatedAddress, relatedPort, nil}) + return NewCandidateRelay(&CandidateRelayConfig{"", protocol, address, port, uint16(component), priority, foundation, relatedAddress, relatedPort, nil}) default: - return nil, fmt.Errorf("Unknown candidate typ(%s)", typ) - } - if err != nil { - return nil, err - } - - c.setPriority(priority) - c.setFoundation(foundation) - return c, err + return nil, fmt.Errorf("Unknown candidate typ(%s)", typ) } diff --git a/candidate_host.go b/candidate_host.go index c7d3266..b03dbdb 100644 --- a/candidate_host.go +++ b/candidate_host.go @@ -19,6 +19,8 @@ type CandidateHostConfig struct { Address string Port int Component uint16 + Priority uint32 + Foundation string TCPType TCPType } @@ -32,12 +34,14 @@ func NewCandidateHost(config *CandidateHostConfig) (*CandidateHost, error) { c := &CandidateHost{ candidateBase: candidateBase{ - id: candidateID, - address: config.Address, - candidateType: CandidateTypeHost, - component: config.Component, - port: config.Port, - tcpType: config.TCPType, + id: candidateID, + address: config.Address, + candidateType: CandidateTypeHost, + component: config.Component, + port: config.Port, + tcpType: config.TCPType, + foundationOverride: config.Foundation, + priorityOverride: config.Priority, }, network: config.Network, } diff --git a/candidate_peer_reflexive.go b/candidate_peer_reflexive.go index dbf2260..dda5d75 100644 --- a/candidate_peer_reflexive.go +++ b/candidate_peer_reflexive.go @@ -16,6 +16,8 @@ type CandidatePeerReflexiveConfig struct { Address string Port int Component uint16 + Priority uint32 + Foundation string RelAddr string RelPort int } @@ -39,13 +41,15 @@ func NewCandidatePeerReflexive(config *CandidatePeerReflexiveConfig) (*Candidate return &CandidatePeerReflexive{ candidateBase: candidateBase{ - id: candidateID, - networkType: networkType, - candidateType: CandidateTypePeerReflexive, - address: config.Address, - port: config.Port, - resolvedAddr: createAddr(networkType, ip, config.Port), - component: config.Component, + id: candidateID, + networkType: networkType, + candidateType: CandidateTypePeerReflexive, + address: config.Address, + port: config.Port, + resolvedAddr: createAddr(networkType, ip, config.Port), + component: config.Component, + foundationOverride: config.Foundation, + priorityOverride: config.Priority, relatedAddress: &CandidateRelatedAddress{ Address: config.RelAddr, Port: config.RelPort, diff --git a/candidate_relay.go b/candidate_relay.go index 8865872..44762f7 100644 --- a/candidate_relay.go +++ b/candidate_relay.go @@ -18,6 +18,8 @@ type CandidateRelayConfig struct { Address string Port int Component uint16 + Priority uint32 + Foundation string RelAddr string RelPort int OnClose func() error @@ -43,13 +45,15 @@ func NewCandidateRelay(config *CandidateRelayConfig) (*CandidateRelay, error) { return &CandidateRelay{ candidateBase: candidateBase{ - id: candidateID, - networkType: networkType, - candidateType: CandidateTypeRelay, - address: config.Address, - port: config.Port, - resolvedAddr: &net.UDPAddr{IP: ip, Port: config.Port}, - component: config.Component, + id: candidateID, + networkType: networkType, + candidateType: CandidateTypeRelay, + address: config.Address, + port: config.Port, + resolvedAddr: &net.UDPAddr{IP: ip, Port: config.Port}, + component: config.Component, + foundationOverride: config.Foundation, + priorityOverride: config.Priority, relatedAddress: &CandidateRelatedAddress{ Address: config.RelAddr, Port: config.RelPort, diff --git a/candidate_server_reflexive.go b/candidate_server_reflexive.go index d7563f7..125a537 100644 --- a/candidate_server_reflexive.go +++ b/candidate_server_reflexive.go @@ -16,6 +16,8 @@ type CandidateServerReflexiveConfig struct { Address string Port int Component uint16 + Priority uint32 + Foundation string RelAddr string RelPort int } @@ -39,13 +41,15 @@ func NewCandidateServerReflexive(config *CandidateServerReflexiveConfig) (*Candi return &CandidateServerReflexive{ candidateBase: candidateBase{ - id: candidateID, - networkType: networkType, - candidateType: CandidateTypeServerReflexive, - address: config.Address, - port: config.Port, - resolvedAddr: &net.UDPAddr{IP: ip, Port: config.Port}, - component: config.Component, + id: candidateID, + networkType: networkType, + candidateType: CandidateTypeServerReflexive, + address: config.Address, + port: config.Port, + resolvedAddr: &net.UDPAddr{IP: ip, Port: config.Port}, + component: config.Component, + foundationOverride: config.Foundation, + priorityOverride: config.Priority, relatedAddress: &CandidateRelatedAddress{ Address: config.RelAddr, Port: config.RelPort,