Skip to content

Commit

Permalink
Merge pull request libp2p#990 from fouge/feat/mdns-ipv6
Browse files Browse the repository at this point in the history
Added parsing of IPv6 addresses for incoming mDNS requests
  • Loading branch information
Stebalien committed Aug 20, 2020
2 parents c24d028 + 16d314c commit b95d6ae
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions p2p/discovery/mdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -169,8 +169,18 @@ func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) {
return
}

var addr net.IP
if e.AddrV4 != nil {
addr = e.AddrV4
} else if e.AddrV6 != nil {
addr = e.AddrV6
} else {
log.Warning("Error parsing multiaddr from mdns entry: no IP address found")
return
}

maddr, err := manet.FromNetAddr(&net.TCPAddr{
IP: e.AddrV4,
IP: addr,
Port: e.Port,
})
if err != nil {
Expand Down

0 comments on commit b95d6ae

Please sign in to comment.