Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parsing of IPv6 addresses for incoming mDNS requests #990

Merged
merged 2 commits into from
Aug 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can deduplicate some of this code.

var addr net.IP
if e.AddrV4 != nil {
    addr = e.AddrV4
} else if e.AddrV6 != nil {
    addr = e.AddrV6
} else {
    return some error
}

// construct the multiaddr

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