Browse Source

Deduplicating code when parsing ipv4/ipv6 address; from the comment on the PR

pull/990/head
Cyril Fougeray 4 years ago
parent
commit
16d314cf30
  1. 23
      p2p/discovery/mdns.go

23
p2p/discovery/mdns.go

@ -169,29 +169,24 @@ func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) {
return
}
var maddr ma.Multiaddr
var addr net.IP
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)
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
}
} else if e.AddrV6 != nil {
maddr, err = manet.FromNetAddr(&net.TCPAddr{
IP: e.AddrV6,
maddr, err := manet.FromNetAddr(&net.TCPAddr{
IP: addr,
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,

Loading…
Cancel
Save