diff --git a/p2p/discovery/mdns.go b/p2p/discovery/mdns.go index 18a139b90..94fed3d31 100644 --- a/p2p/discovery/mdns.go +++ b/p2p/discovery/mdns.go @@ -157,7 +157,7 @@ func (m *mdnsService) pollForEntries(ctx context.Context) { } func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) { - log.Debugf("Handling MDNS entry: %s:%d %s", e.AddrV4, e.Port, e.Info) + log.Debugf("Handling MDNS entry: [IPv4 %s][IPv6 %s]:%d %s", e.AddrV4, e.AddrV6, e.Port, e.Info) mpeer, err := peer.IDB58Decode(e.Info) if err != nil { log.Warning("Error parsing peer ID from mdns entry: ", err) @@ -169,12 +169,27 @@ func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) { return } - maddr, err := manet.FromNetAddr(&net.TCPAddr{ - IP: e.AddrV4, - Port: e.Port, - }) - if err != nil { - log.Warning("Error parsing multiaddr from mdns entry: ", err) + var maddr ma.Multiaddr + if e.AddrV4 != nil { + maddr, err = manet.FromNetAddr(&net.TCPAddr{ + IP: e.AddrV4, + Port: e.Port, + }) + if err != nil { + log.Warning("Error parsing multiaddr from mdns entry: ", err) + return + } + } else if e.AddrV6 != nil { + maddr, err = manet.FromNetAddr(&net.TCPAddr{ + IP: e.AddrV6, + Port: e.Port, + }) + if err != nil { + log.Warning("Error parsing multiaddr from mdns entry: ", err) + return + } + } else { + log.Warning("Error parsing multiaddr from mdns entry: no IP address found") return }