mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
More error handling around interface iteration
If we can't iterate host interfaces give a warning to the user. Also don't bail early if a single interface fails, other interfaces might still be in a good condition. Resolves pion/ice#75
This commit is contained in:
@@ -15,10 +15,11 @@ const (
|
||||
stunGatherTimeout = time.Second * 5
|
||||
)
|
||||
|
||||
func (a *Agent) localInterfaces(networkTypes []NetworkType) (ips []net.IP) {
|
||||
func (a *Agent) localInterfaces(networkTypes []NetworkType) ([]net.IP, error) {
|
||||
ips := []net.IP{}
|
||||
ifaces, err := a.net.Interfaces()
|
||||
if err != nil {
|
||||
return ips
|
||||
return ips, err
|
||||
}
|
||||
|
||||
var IPv4Requested, IPv6Requested bool
|
||||
@@ -42,7 +43,7 @@ func (a *Agent) localInterfaces(networkTypes []NetworkType) (ips []net.IP) {
|
||||
|
||||
addrs, err := iface.Addrs()
|
||||
if err != nil {
|
||||
return ips
|
||||
continue
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
@@ -71,7 +72,7 @@ func (a *Agent) localInterfaces(networkTypes []NetworkType) (ips []net.IP) {
|
||||
ips = append(ips, ip)
|
||||
}
|
||||
}
|
||||
return ips
|
||||
return ips, nil
|
||||
}
|
||||
|
||||
func (a *Agent) listenUDP(portMax, portMin int, network string, laddr *net.UDPAddr) (vnet.UDPPacketConn, error) {
|
||||
@@ -167,7 +168,12 @@ func (a *Agent) gatherCandidatesLocal(networkTypes []NetworkType) {
|
||||
var wg sync.WaitGroup
|
||||
defer wg.Wait()
|
||||
|
||||
localIPs := a.localInterfaces(networkTypes)
|
||||
localIPs, err := a.localInterfaces(networkTypes)
|
||||
if err != nil {
|
||||
a.log.Warnf("failed to iterate local interfaces, host candidates will not be gathered %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
wg.Add(len(localIPs) * len(supportedNetworks))
|
||||
for _, ip := range localIPs {
|
||||
for _, network := range supportedNetworks {
|
||||
|
||||
+3
-1
@@ -11,9 +11,11 @@ func TestListenUDP(t *testing.T) {
|
||||
t.Fatalf("Failed to create agent: %s", err)
|
||||
}
|
||||
|
||||
localIPs := a.localInterfaces([]NetworkType{NetworkTypeUDP4})
|
||||
localIPs, err := a.localInterfaces([]NetworkType{NetworkTypeUDP4})
|
||||
if len(localIPs) == 0 {
|
||||
t.Fatal("localInterfaces found no interfaces, unable to test")
|
||||
} else if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ip := localIPs[0]
|
||||
|
||||
+9
-3
@@ -20,9 +20,11 @@ func TestVNetGather(t *testing.T) {
|
||||
t.Fatalf("Failed to create agent: %s", err)
|
||||
}
|
||||
|
||||
localIPs := a.localInterfaces([]NetworkType{NetworkTypeUDP4})
|
||||
localIPs, err := a.localInterfaces([]NetworkType{NetworkTypeUDP4})
|
||||
if len(localIPs) > 0 {
|
||||
t.Fatal("should return no local IP")
|
||||
} else if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -58,9 +60,11 @@ func TestVNetGather(t *testing.T) {
|
||||
t.Fatalf("Failed to create agent: %s", err)
|
||||
}
|
||||
|
||||
localIPs := a.localInterfaces([]NetworkType{NetworkTypeUDP4})
|
||||
localIPs, err := a.localInterfaces([]NetworkType{NetworkTypeUDP4})
|
||||
if len(localIPs) == 0 {
|
||||
t.Fatal("should have one local IP")
|
||||
} else if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, ip := range localIPs {
|
||||
@@ -97,9 +101,11 @@ func TestVNetGather(t *testing.T) {
|
||||
t.Fatalf("Failed to create agent: %s", err)
|
||||
}
|
||||
|
||||
localIPs := a.localInterfaces([]NetworkType{NetworkTypeUDP4})
|
||||
localIPs, err := a.localInterfaces([]NetworkType{NetworkTypeUDP4})
|
||||
if len(localIPs) == 0 {
|
||||
t.Fatal("localInterfaces found no interfaces, unable to test")
|
||||
} else if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ip := localIPs[0]
|
||||
|
||||
@@ -4,7 +4,7 @@ go 1.12
|
||||
|
||||
require (
|
||||
github.com/pion/logging v0.2.2
|
||||
github.com/pion/mdns v0.0.2
|
||||
github.com/pion/mdns v0.0.3
|
||||
github.com/pion/stun v0.3.1
|
||||
github.com/pion/transport v0.8.6
|
||||
github.com/pion/turn v1.3.2
|
||||
|
||||
@@ -8,8 +8,8 @@ github.com/pion/logging v0.2.1 h1:LwASkBKZ+2ysGJ+jLv1E/9H1ge0k1nTfi1X+5zirkDk=
|
||||
github.com/pion/logging v0.2.1/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
|
||||
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
|
||||
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
|
||||
github.com/pion/mdns v0.0.2 h1:T22Gg4dSuYVYsZ21oRFh9z7twzAm27+5PEKiABbjCvM=
|
||||
github.com/pion/mdns v0.0.2/go.mod h1:VrN3wefVgtfL8QgpEblPUC46ag1reLIfpqekCnKunLE=
|
||||
github.com/pion/mdns v0.0.3 h1:DxdOYd0pgwLKiDlIIxfU0qdG5iWh1Xn6CsS9vc6cMAY=
|
||||
github.com/pion/mdns v0.0.3/go.mod h1:VrN3wefVgtfL8QgpEblPUC46ag1reLIfpqekCnKunLE=
|
||||
github.com/pion/stun v0.3.1 h1:d09JJzOmOS8ZzIp8NppCMgrxGZpJ4Ix8qirfNYyI3BA=
|
||||
github.com/pion/stun v0.3.1/go.mod h1:xrCld6XM+6GWDZdvjPlLMsTU21rNxnO6UO8XsAvHr/M=
|
||||
github.com/pion/transport v0.8.6 h1:xHQq2mxAjB+UrFs90aUBaXwlmIACfQAZnOiVAX3uqMw=
|
||||
|
||||
Reference in New Issue
Block a user