From 0795217c605cea31872cfd70bb3280f71793d639 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 28 Apr 2015 22:08:46 -0700 Subject: [PATCH 1/2] dont advertise loopback address over mdns --- discovery/mdns.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/discovery/mdns.go b/discovery/mdns.go index 1abd3bd2..6ab3db1e 100644 --- a/discovery/mdns.go +++ b/discovery/mdns.go @@ -44,6 +44,9 @@ type mdnsService struct { func getDialableListenAddr(ph host.Host) (*net.TCPAddr, error) { for _, addr := range ph.Addrs() { + if manet.IsIPLoopback(addr) { + continue + } na, err := manet.ToNetAddr(addr) if err != nil { continue From a8041e64bffc4a7689bff3ef639e6ead828b277e Mon Sep 17 00:00:00 2001 From: Jeromy Date: Wed, 29 Apr 2015 01:02:45 -0700 Subject: [PATCH 2/2] use ALL THE ADDRESSES! --- discovery/mdns.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/discovery/mdns.go b/discovery/mdns.go index 6ab3db1e..74f2c085 100644 --- a/discovery/mdns.go +++ b/discovery/mdns.go @@ -42,21 +42,22 @@ type mdnsService struct { interval time.Duration } -func getDialableListenAddr(ph host.Host) (*net.TCPAddr, error) { +func getDialableListenAddrs(ph host.Host) ([]*net.TCPAddr, error) { + var out []*net.TCPAddr for _, addr := range ph.Addrs() { - if manet.IsIPLoopback(addr) { - continue - } na, err := manet.ToNetAddr(addr) if err != nil { continue } tcp, ok := na.(*net.TCPAddr) if ok { - return tcp, nil + out = append(out, tcp) } } - return nil, errors.New("failed to find good external addr from peerhost") + if len(out) == 0 { + return nil, errors.New("failed to find good external addr from peerhost") + } + return out, nil } func NewMdnsService(peerhost host.Host, interval time.Duration) (Service, error) { @@ -67,12 +68,14 @@ func NewMdnsService(peerhost host.Host, interval time.Duration) (Service, error) var ipaddrs []net.IP port := 4001 - addr, err := getDialableListenAddr(peerhost) + addrs, err := getDialableListenAddrs(peerhost) if err != nil { log.Warning(err) } else { - ipaddrs = []net.IP{addr.IP} - port = addr.Port + port = addrs[0].Port + for _, a := range addrs { + ipaddrs = append(ipaddrs, a.IP) + } } myid := peerhost.ID().Pretty()