mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Expose Priority and Foundation overrides
Allow pion/webrtc to override these as well
This commit is contained in:
@@ -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
|
||||
|
||||
+5
-22
@@ -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)
|
||||
}
|
||||
|
||||
+10
-6
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
+11
-7
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user