-
Notifications
You must be signed in to change notification settings - Fork 1
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
Deterministically de-dupe mdns connections #112
Conversation
We added a check to always close the same connection from both sides, using `b4a.compare(publicKey, remotePublicKey)` additionally we: * destroy the socket instead of closing to match hypercore implementation, and take care of handling posible error events * close mdns connection if its not from a localAddress * add the remote address and port to PeerInfo (instead of local address and port)
Basically, only allow local connections on mdns, using `private-ip`
@tomasciccola is this meant as an alternative to #109? It looks like the only issue right now is package-lock.json needs to be updated by running
Yeah, I think that does makes sense! |
@tomasciccola I'm concerned about merging work like this without any tests. Can we add tests in a follow-up PR? Also at a quick glance the |
} | ||
if (!isIpPrivate(socket.remoteAddress)) socket.destroy() |
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.
@tomasciccola this should return here. Also there are no error handlers on socket at this point so this will crash with an unhandled 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.
so, smth like?
if (!isIpPrivate(socket.remoteAddress)) {
socket.on('error', noop)
socket.destroy()
return
}
I ran a quick benchmark and |
Obviously the check on remote ips is hard to test, but it would be good to simulate some situations where we can test the dedupe code. Running coverage checks can ensure that the dedupe code paths are being tested. |
You're right, I'll open an issue to add tests to the dedup code. Additionally, change private-ip to bogon |
This should close #66
This is done comparing the remote and local publicKeys using
b4a.compare
that sorts the keys.On this branch there's also other changes, mainly:
socket
errors) with logging.