mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Populate RelayProtocol for relay candidates
The webrtc-stats spec defines this field as: > It is the protocol used by the endpoint to communicate with the TURN > server. This is only present for local candidates. Valid values are > "udp", "tcp", or "tls". https://w3.org/TR/webrtc-stats/#dom-rtcicecandidatestats-relayprotocol
This commit is contained in:
@@ -28,6 +28,7 @@ korymiller1489 <kmiller@unwiredrevolution.com>
|
||||
Kyle Carberry <kyle@carberry.com>
|
||||
Lander Noterman <lander.noterman@basalte.be>
|
||||
Luke Curley <kixelated@gmail.com>
|
||||
Meelap Shah <meelapshah@gmail.com>
|
||||
Michael MacDonald <github@macdonald.cx>
|
||||
Michael MacDonald <mike.macdonald@savantsystems.com>
|
||||
Nevio Vesic <nevio@subspace.com>
|
||||
|
||||
+6
-2
@@ -58,6 +58,10 @@ func (a *Agent) GetLocalCandidatesStats() []CandidateStats {
|
||||
result := make([]CandidateStats, 0, len(agent.localCandidates))
|
||||
for networkType, localCandidates := range agent.localCandidates {
|
||||
for _, c := range localCandidates {
|
||||
relayProtocol := ""
|
||||
if c.Type() == CandidateTypeRelay {
|
||||
relayProtocol = c.(*CandidateRelay).RelayProtocol()
|
||||
}
|
||||
stat := CandidateStats{
|
||||
Timestamp: time.Now(),
|
||||
ID: c.ID(),
|
||||
@@ -67,7 +71,7 @@ func (a *Agent) GetLocalCandidatesStats() []CandidateStats {
|
||||
CandidateType: c.Type(),
|
||||
Priority: c.Priority(),
|
||||
// URL string
|
||||
RelayProtocol: "udp",
|
||||
RelayProtocol: relayProtocol,
|
||||
// Deleted bool
|
||||
}
|
||||
result = append(result, stat)
|
||||
@@ -98,7 +102,7 @@ func (a *Agent) GetRemoteCandidatesStats() []CandidateStats {
|
||||
CandidateType: c.Type(),
|
||||
Priority: c.Priority(),
|
||||
// URL string
|
||||
RelayProtocol: "udp",
|
||||
RelayProtocol: "",
|
||||
}
|
||||
result = append(result, stat)
|
||||
}
|
||||
|
||||
+1
-1
@@ -492,7 +492,7 @@ func UnmarshalCandidate(raw string) (Candidate, error) {
|
||||
case "prflx":
|
||||
return NewCandidatePeerReflexive(&CandidatePeerReflexiveConfig{"", protocol, address, port, component, priority, foundation, relatedAddress, relatedPort})
|
||||
case "relay":
|
||||
return NewCandidateRelay(&CandidateRelayConfig{"", protocol, address, port, component, priority, foundation, relatedAddress, relatedPort, nil})
|
||||
return NewCandidateRelay(&CandidateRelayConfig{"", protocol, address, port, component, priority, foundation, relatedAddress, relatedPort, "", nil})
|
||||
default:
|
||||
}
|
||||
|
||||
|
||||
+20
-12
@@ -8,21 +8,23 @@ import (
|
||||
type CandidateRelay struct {
|
||||
candidateBase
|
||||
|
||||
onClose func() error
|
||||
relayProtocol string
|
||||
onClose func() error
|
||||
}
|
||||
|
||||
// CandidateRelayConfig is the config required to create a new CandidateRelay
|
||||
type CandidateRelayConfig struct {
|
||||
CandidateID string
|
||||
Network string
|
||||
Address string
|
||||
Port int
|
||||
Component uint16
|
||||
Priority uint32
|
||||
Foundation string
|
||||
RelAddr string
|
||||
RelPort int
|
||||
OnClose func() error
|
||||
CandidateID string
|
||||
Network string
|
||||
Address string
|
||||
Port int
|
||||
Component uint16
|
||||
Priority uint32
|
||||
Foundation string
|
||||
RelAddr string
|
||||
RelPort int
|
||||
RelayProtocol string
|
||||
OnClose func() error
|
||||
}
|
||||
|
||||
// NewCandidateRelay creates a new relay candidate
|
||||
@@ -59,10 +61,16 @@ func NewCandidateRelay(config *CandidateRelayConfig) (*CandidateRelay, error) {
|
||||
Port: config.RelPort,
|
||||
},
|
||||
},
|
||||
onClose: config.OnClose,
|
||||
relayProtocol: config.RelayProtocol,
|
||||
onClose: config.OnClose,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// RelayProtocol returns the protocol used between the endpoint and the relay server.
|
||||
func (c *CandidateRelay) RelayProtocol() string {
|
||||
return c.relayProtocol
|
||||
}
|
||||
|
||||
func (c *CandidateRelay) close() error {
|
||||
err := c.candidateBase.close()
|
||||
if c.onClose != nil {
|
||||
|
||||
@@ -262,6 +262,7 @@ func TestCandidateMarshal(t *testing.T) {
|
||||
port: 5000,
|
||||
relatedAddress: &CandidateRelatedAddress{"192.168.0.1", 5001},
|
||||
},
|
||||
"",
|
||||
nil,
|
||||
},
|
||||
"848194626 1 udp 16777215 50.0.0.1 5000 typ relay raddr 192.168.0.1 rport 5001",
|
||||
|
||||
@@ -422,10 +422,11 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
||||
defer wg.Done()
|
||||
TURNServerAddr := fmt.Sprintf("%s:%d", url.Host, url.Port)
|
||||
var (
|
||||
locConn net.PacketConn
|
||||
err error
|
||||
RelAddr string
|
||||
RelPort int
|
||||
locConn net.PacketConn
|
||||
err error
|
||||
RelAddr string
|
||||
RelPort int
|
||||
relayProtocol string
|
||||
)
|
||||
|
||||
switch {
|
||||
@@ -437,6 +438,7 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
||||
|
||||
RelAddr = locConn.LocalAddr().(*net.UDPAddr).IP.String()
|
||||
RelPort = locConn.LocalAddr().(*net.UDPAddr).Port
|
||||
relayProtocol = udp
|
||||
case a.proxyDialer != nil && url.Proto == ProtoTypeTCP &&
|
||||
(url.Scheme == SchemeTypeTURN || url.Scheme == SchemeTypeTURNS):
|
||||
conn, connectErr := a.proxyDialer.Dial(NetworkTypeTCP4.String(), TURNServerAddr)
|
||||
@@ -447,6 +449,11 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
||||
|
||||
RelAddr = conn.LocalAddr().(*net.TCPAddr).IP.String()
|
||||
RelPort = conn.LocalAddr().(*net.TCPAddr).Port
|
||||
if url.Scheme == SchemeTypeTURN {
|
||||
relayProtocol = tcp
|
||||
} else if url.Scheme == SchemeTypeTURNS {
|
||||
relayProtocol = "tls"
|
||||
}
|
||||
locConn = turn.NewSTUNConn(conn)
|
||||
|
||||
case url.Proto == ProtoTypeTCP && url.Scheme == SchemeTypeTURN:
|
||||
@@ -464,6 +471,7 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
||||
|
||||
RelAddr = conn.LocalAddr().(*net.TCPAddr).IP.String()
|
||||
RelPort = conn.LocalAddr().(*net.TCPAddr).Port
|
||||
relayProtocol = tcp
|
||||
locConn = turn.NewSTUNConn(conn)
|
||||
case url.Proto == ProtoTypeUDP && url.Scheme == SchemeTypeTURNS:
|
||||
udpAddr, connectErr := net.ResolveUDPAddr(network, TURNServerAddr)
|
||||
@@ -483,6 +491,7 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
||||
|
||||
RelAddr = conn.LocalAddr().(*net.UDPAddr).IP.String()
|
||||
RelPort = conn.LocalAddr().(*net.UDPAddr).Port
|
||||
relayProtocol = "dtls"
|
||||
locConn = &fakePacketConn{conn}
|
||||
case url.Proto == ProtoTypeTCP && url.Scheme == SchemeTypeTURNS:
|
||||
conn, connectErr := tls.Dial(NetworkTypeTCP4.String(), TURNServerAddr, &tls.Config{
|
||||
@@ -494,6 +503,7 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
||||
}
|
||||
RelAddr = conn.LocalAddr().(*net.TCPAddr).IP.String()
|
||||
RelPort = conn.LocalAddr().(*net.TCPAddr).Port
|
||||
relayProtocol = "tls"
|
||||
locConn = turn.NewSTUNConn(conn)
|
||||
default:
|
||||
a.log.Warnf("Unable to handle URL in gatherCandidatesRelay %v\n", url)
|
||||
@@ -528,12 +538,13 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
||||
|
||||
raddr := relayConn.LocalAddr().(*net.UDPAddr)
|
||||
relayConfig := CandidateRelayConfig{
|
||||
Network: network,
|
||||
Component: ComponentRTP,
|
||||
Address: raddr.IP.String(),
|
||||
Port: raddr.Port,
|
||||
RelAddr: RelAddr,
|
||||
RelPort: RelPort,
|
||||
Network: network,
|
||||
Component: ComponentRTP,
|
||||
Address: raddr.IP.String(),
|
||||
Port: raddr.Port,
|
||||
RelAddr: RelAddr,
|
||||
RelPort: RelPort,
|
||||
RelayProtocol: relayProtocol,
|
||||
OnClose: func() error {
|
||||
client.Close()
|
||||
return locConn.Close()
|
||||
|
||||
Reference in New Issue
Block a user