From 2b7dfc65786834cc128b21d150903b286d6d54a3 Mon Sep 17 00:00:00 2001 From: Alex Hu Date: Mon, 11 Aug 2025 16:28:25 -0700 Subject: [PATCH] add mappers to settingengine --- icegatherer.go | 2 ++ settingengine.go | 34 +++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/icegatherer.go b/icegatherer.go index 2a1bc6b4e08..893b87f4961 100644 --- a/icegatherer.go +++ b/icegatherer.go @@ -132,6 +132,8 @@ func (g *ICEGatherer) createAgent() error { //nolint:cyclop DisableActiveTCP: g.api.settingEngine.iceDisableActiveTCP, MaxBindingRequests: g.api.settingEngine.iceMaxBindingRequests, BindingRequestHandler: g.api.settingEngine.iceBindingRequestHandler, + HostUDPAdvertisedAddrsMapper: g.api.settingEngine.candidates.HostUDPAdvertisedAddrsMapper, + HostTCPAdvertisedAddrsMapper: g.api.settingEngine.candidates.HostTCPAdvertisedAddrsMapper, } requestedNetworkTypes := g.api.settingEngine.candidates.ICENetworkTypes diff --git a/settingengine.go b/settingengine.go index 0291073f52d..924e37db69c 100644 --- a/settingengine.go +++ b/settingengine.go @@ -46,17 +46,19 @@ type SettingEngine struct { ICESTUNGatherTimeout *time.Duration } candidates struct { - ICELite bool - ICENetworkTypes []NetworkType - InterfaceFilter func(string) (keep bool) - IPFilter func(net.IP) (keep bool) - NAT1To1IPs []string - NAT1To1IPCandidateType ICECandidateType - MulticastDNSMode ice.MulticastDNSMode - MulticastDNSHostName string - UsernameFragment string - Password string - IncludeLoopbackCandidate bool + ICELite bool + ICENetworkTypes []NetworkType + InterfaceFilter func(string) (keep bool) + IPFilter func(net.IP) (keep bool) + NAT1To1IPs []string + NAT1To1IPCandidateType ICECandidateType + MulticastDNSMode ice.MulticastDNSMode + MulticastDNSHostName string + UsernameFragment string + Password string + IncludeLoopbackCandidate bool + HostUDPAdvertisedAddrsMapper func(net.IP) []ice.Endpoint + HostTCPAdvertisedAddrsMapper func(net.IP) []ice.Endpoint } replayProtection struct { DTLS *uint @@ -267,6 +269,16 @@ func (e *SettingEngine) SetNAT1To1IPs(ips []string, candidateType ICECandidateTy e.candidates.NAT1To1IPCandidateType = candidateType } +// SetHostUDPAdvertisedAddrsMapper sets the function that maps the local UDP address to the advertised UDP addresses. +func (e *SettingEngine) SetHostUDPAdvertisedAddrsMapper(mapper func(net.IP) []ice.Endpoint) { + e.candidates.HostUDPAdvertisedAddrsMapper = mapper +} + +// SetHostTCPAdvertisedAddrsMapper sets the function that maps the local TCP address to the advertised TCP addresses. +func (e *SettingEngine) SetHostTCPAdvertisedAddrsMapper(mapper func(net.IP) []ice.Endpoint) { + e.candidates.HostTCPAdvertisedAddrsMapper = mapper +} + // SetIncludeLoopbackCandidate enable pion to gather loopback candidates, it is useful // for some VM have public IP mapped to loopback interface. func (e *SettingEngine) SetIncludeLoopbackCandidate(include bool) {