Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ICE UDPMuxSrflx option #2298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions icegatherer.go
Expand Up @@ -114,6 +114,7 @@ func (g *ICEGatherer) createAgent() error {
LocalPwd: g.api.settingEngine.candidates.Password,
TCPMux: g.api.settingEngine.iceTCPMux,
UDPMux: g.api.settingEngine.iceUDPMux,
UDPMuxSrflx: g.api.settingEngine.iceUDPMuxSrflx,
ProxyDialer: g.api.settingEngine.iceProxyDialer,
}

Expand Down
11 changes: 11 additions & 0 deletions icemux.go
Expand Up @@ -2,6 +2,7 @@ package webrtc

import (
"net"
"time"

"github.com/pion/ice/v2"
"github.com/pion/logging"
Expand All @@ -25,3 +26,13 @@ func NewICEUDPMux(logger logging.LeveledLogger, udpConn net.PacketConn) ice.UDPM
Logger: logger,
})
}

// NewICEUniversalUDPMux creates a new instance of ice.UniversalUDPMux. It allows many PeerConnections with
// host, server reflexive and relayed candidates to by served by a single UDP port.
func NewICEUniversalUDPMux(logger logging.LeveledLogger, udpConn net.PacketConn, xorMappedAddrCacheTTL time.Duration) ice.UniversalUDPMux {
return ice.NewUniversalUDPMuxDefault(ice.UniversalUDPMuxParams{
Logger: logger,
UDPConn: udpConn,
XORMappedAddrCacheTTL: xorMappedAddrCacheTTL,
})
}
23 changes: 18 additions & 5 deletions settingengine.go
Expand Up @@ -67,6 +67,7 @@ type SettingEngine struct {
LoggerFactory logging.LoggerFactory
iceTCPMux ice.TCPMux
iceUDPMux ice.UDPMux
iceUDPMuxSrflx ice.UniversalUDPMux
iceProxyDialer proxy.Dialer
disableMediaEngineCopy bool
srtpProtectionProfiles []dtls.SRTPProtectionProfile
Expand Down Expand Up @@ -168,10 +169,13 @@ func (e *SettingEngine) SetInterfaceFilter(filter func(string) bool) {
// Two types of candidates are supported:
//
// ICECandidateTypeHost:
// The public IP address will be used for the host candidate in the SDP.
//
// The public IP address will be used for the host candidate in the SDP.
//
// ICECandidateTypeSrflx:
// A server reflexive candidate with the given public IP address will be added
// to the SDP.
//
// A server reflexive candidate with the given public IP address will be added
// to the SDP.
//
// Please note that if you choose ICECandidateTypeHost, then the private IP address
// won't be advertised with the peer. Also, this option cannot be used along with mDNS.
Expand All @@ -190,9 +194,12 @@ func (e *SettingEngine) SetNAT1To1IPs(ips []string, candidateType ICECandidateTy
// may be useful when interacting with non-compliant clients or debugging issues.
//
// DTLSRoleActive:
// Act as DTLS Client, send the ClientHello and starts the handshake
//
// Act as DTLS Client, send the ClientHello and starts the handshake
//
// DTLSRolePassive:
// Act as DTLS Server, wait for ClientHello
//
// Act as DTLS Server, wait for ClientHello
func (e *SettingEngine) SetAnsweringDTLSRole(role DTLSRole) error {
if role != DTLSRoleClient && role != DTLSRoleServer {
return errSettingEngineSetAnsweringDTLSRole
Expand Down Expand Up @@ -285,6 +292,12 @@ func (e *SettingEngine) SetICEUDPMux(udpMux ice.UDPMux) {
e.iceUDPMux = udpMux
}

// SetICEUDPMuxSrflx allows ICE traffic from server reflexive candidates to be
// multiplexed onto a single port.
func (e *SettingEngine) SetICEUDPMuxSrflx(udpMuxSrflx ice.UniversalUDPMux) {
e.iceUDPMuxSrflx = udpMuxSrflx
}

// SetICEProxyDialer sets the proxy dialer interface based on golang.org/x/net/proxy.
func (e *SettingEngine) SetICEProxyDialer(d proxy.Dialer) {
e.iceProxyDialer = d
Expand Down