Browse Source

Added parsing of IPv6 addresses for incomming mDNS requests

pull/990/head
Cyril Fougeray 4 years ago
parent
commit
3fa37a3452
  1. 29
      p2p/discovery/mdns.go

29
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
}

Loading…
Cancel
Save