Support 1:1 NAT option

Resolves #835
This commit is contained in:
Yutaka Takeda
2019-09-25 02:04:58 -07:00
parent d7ae1a87ba
commit 918412679f
4 changed files with 51 additions and 6 deletions

View File

@@ -30,10 +30,12 @@ type SettingEngine struct {
ICERelayAcceptanceMinWait *time.Duration
}
candidates struct {
ICELite bool
ICETrickle bool
ICENetworkTypes []NetworkType
InterfaceFilter func(string) bool
ICELite bool
ICETrickle bool
ICENetworkTypes []NetworkType
InterfaceFilter func(string) bool
NAT1To1IPs []string
NAT1To1IPCandidate string
}
LoggerFactory logging.LoggerFactory
}
@@ -114,3 +116,28 @@ func (e *SettingEngine) SetNetworkTypes(candidateTypes []NetworkType) {
func (e *SettingEngine) SetInterfaceFilter(filter func(string) bool) {
e.candidates.InterfaceFilter = filter
}
// SetNAT1To1IPs has a list of external IP addresses of 1:1 (D)NAT.
// This is useful when you are host a server using Pion on an AWS EC2 instance
// which has a private address, behind a 1:1 DNAT with a public IP (e.g.
// Elastic IP). In this case, you can give the public IP address so that
// Pion will use the public IP address in its candidate instead of the private IP
// address.
func (e *SettingEngine) SetNAT1To1IPs(ips []string) {
e.candidates.NAT1To1IPs = ips
}
// SetNAT1To1IPCandidate is used along with SetNAT1To1IPs, to tell Pion which
// type of candidate should use the given public IP address.
// Two types of candidates are supported:
// - "host": The public IP address will be used for the host candidate in the SDP.
// - "srflx": A server reflexive candidate with the given public IP address will be added
// to the SDP. If you choose "host", then the private IP address won't be advertised with
// the peer. Also, this option cannot be used along with mDNS.
// If you choose "srflx", it simply adds a server reflexive candidate with the public IP.
// The host candidate is still available along with mDNS capabilities unaffected.
// Please note that you cannot give STUN server URL at the same time. It will result in
// an error otherwise.
func (e *SettingEngine) SetNAT1To1IPCandidate(candidate string) {
e.candidates.NAT1To1IPCandidate = candidate
}