Added parsing of IPv6 addresses for incomming mDNS requests
@@ -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,7 +169,9 @@ func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) {
return
}
- maddr, err := manet.FromNetAddr(&net.TCPAddr{
+ var maddr ma.Multiaddr
+ if e.AddrV4 != nil {
+ maddr, err = manet.FromNetAddr(&net.TCPAddr{
IP: e.AddrV4,
Port: e.Port,
})
@@ -177,6 +179,19 @@ func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) {
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
+ }
pi := peer.AddrInfo{
ID: mpeer,
