-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
discovery: swap mdns lib for grandcat/zeroconf #285
Conversation
p2p/discovery/mdns.go
Outdated
info := strings.Join(e.Text, "|") | ||
|
||
// addripv4 potential issue | ||
log.Debugf("Handling MDNS entry: %s:%d %s", e.AddrIPv4[0], e.Port, info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only decision I wasn't certain of.
p2p/discovery/mdns.go
Outdated
} | ||
|
||
func (m *mdnsService) pollForEntries(ctx context.Context) { | ||
|
||
ticker := time.NewTicker(m.interval) | ||
for { | ||
resolver, err := mdns.NewResolver(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be beast to put resolver in mdnsService
struct and reuse it, instead of creating a new one every iteration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yikes, good catch. Fixed.
p2p/discovery/mdns.go
Outdated
func NewMdnsService(ctx context.Context, peerhost host.Host, interval time.Duration, serviceTag string) (Service, error) { | ||
|
||
// TODO: dont let mdns use logging... | ||
golog.SetOutput(ioutil.Discard) | ||
|
||
var ipaddrs []net.IP | ||
port := 4001 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is old but it is very wrong.
p2p/discovery/mdns.go
Outdated
@@ -165,7 +138,7 @@ func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) { | |||
} | |||
|
|||
maddr, err := manet.FromNetAddr(&net.TCPAddr{ | |||
IP: e.AddrV4, | |||
IP: e.AddrIPv4[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is possibility of multiple addresses, I would iterate over them, crate maddr for each and add it to the peerstore.
@Stebalien @Kubuxu I've addressed the feedback in c92f1f6 In regards to the port, what would you recommend here? Skimmed through https://tools.ietf.org/html/rfc6762 and see that 5353 is used for the listener, but not seeing anything for the port that's announcing. I notice that I'm failing tests due to a gx issue. Any recommendations? I'll need to learn that right quick :) |
@rargulati It was my mistake, I thought it was the port we were announcing to the world but it is mDNS discovery port. @Stebalien correct if I am wrong, but currently mDNS only publishes peerID in local network, not the full multiaddr, is that right? If it is so, is there a reason not to publish maddr so we can connect to it? Publishing just peerID sees little fruitless as it won't work without DHT capabilities (in case that bootstrap didn't work). |
Port is the port of the service. Also, we do announce the IP addresses and we convert port + IP into Note: For now, I'd be fine preserving the existing behavior. The primary concern here is upgrading to a working mDNS library (one that doesn't have memory safety issues). However, we also have a bunch of bugs/inconsistencies that we need to fix. I've written them up here:libp2p/libp2p#28 |
Just to clarify on final things:
Does that sound about right @Stebalien @Kubuxu - I'll get this across the line asap. |
Actually, restore the previous "figure out what port we're using" code. It's not perfect, but it's better than just assuming port 4001.
I'll import this into gx tomorrow. We need to write some proper tutorials but it's on our never ending backlog. |
This will actually require updating some of our dependencies so it may take a week (blocked on a bunch of other stuff). |
Hi, do you know when this commit will be done ? |
It been blocked on:
Once those are done, I'll finally be able to bubble a few low-level updates through the entire tree. The problem here is that this zeroconf library requires a newer version of |
This commit makes the minimal amount of changes to switch us from whyrusleeping/mdns to grandcat/zeroconf. Of note, rather than asking the host.Host which addrs we're available to listen on, we push this to the zeroconf library (which runs across available ifaces).
1. If we receive multiple ipv4 addresses, ensure that we convert them all to multiaddrs and store them in the peerstore. 2. Ensure we don't allocate a new resolver on every tick. Instead reuse this by storing it in our mdns type. 3. Attempt choosing a port.
Ideally, we'd dynamically announce ports based on the current interfaces. However, we'd like to merge this ASAP.
Still need to fix #376 but I'd like to punt on that. |
var out []*net.TCPAddr | ||
for _, addr := range ph.Addrs() { | ||
// Tries to pick the best port. | ||
func getBestPort(addrs []ma.Multiaddr) (int, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fixed by #376
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, just have some confusion regarding some of the handleEntry
function. if that's as intended, feel free to merge.
p2p/discovery/mdns.go
Outdated
log.Debugf("Handling MDNS entry: %s:%d %s", e.AddrV4, e.Port, e.Info) | ||
mpeer, err := peer.IDB58Decode(e.Info) | ||
// pull out the txt | ||
info := strings.Join(e.Text, "|") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this designed to fail if there are less than or more than one entry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be clear, because of the decoding afterwards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Yeah, that looks wrong. We should just take the first entry and ignore the rest.
Blocked on grandcat/zeroconf#38. Fixing that was the reason we went down this road in the first place so there's no real reason to merge this till we get that fixed. |
Given libp2p/specs#80, we should probably just abort this whole thing and implement our own library that:
|
Specifically addressing the request here: #257
This commit makes the minimal amount of changes to switch us from
whyrusleeping/mdns to grandcat/zeroconf. Of note, rather than asking the
host.Host
whichaddrs
we can listen on, we push this to thezeroconf library (which runs across available ifaces).
I haven't had a chance to test this on something complicated to see if it retains the desired behavior (to be honest, still new to this codebase, unsure of what all of those would be!), but tests pass locally.
TODO: