-
Notifications
You must be signed in to change notification settings - Fork 993
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
protocols/identify Check multiaddr has valid peer id component prior to caching #2338
protocols/identify Check multiaddr has valid peer id component prior to caching #2338
Conversation
tagging @mxinden here on GH as well |
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.
🚀 couple of minor comments. Other than that this looks good to me. Thanks for the help.
Good job getting started so quickly!
protocols/identify/src/identify.rs
Outdated
fn check_multiaddr_matches_peer_id() { | ||
let peer_id = PeerId::random(); | ||
let other_peer_id = PeerId::random(); | ||
let mut addr: Multiaddr = ("/ip4/147.75.69.143/tcp/4001".to_string()) |
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.
let mut addr: Multiaddr = ("/ip4/147.75.69.143/tcp/4001".to_string()) | |
let mut addr: Multiaddr = "/ip4/147.75.69.143/tcp/4001".to_string() |
Are these needed?
Yes, a node could advertise a dnsaddr as their listen address. |
Thanks for the follow-up. Just missing a changelog entry (see release docs). |
Done, should I also enable this by default or do that in another PR? (essentially undoing this PR: #2312) |
... or none at all. We don't want to cache a multiaddr with a purposely wrong multiaddr. e.g. something that ends with .../p2p/some-other-peer. While this should fail to dial because we [check this before dialing](https://github.com/libp2p/rust-libp2p/blob/master/core/src/connection/pool/concurrent_dial.rs#L144), it's probably better to not cache this in the first place.
27340f8
to
314c0f0
Compare
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.
Thanks @MarcoPolo.
Done, should I also enable this by default or do that in another PR? (essentially undoing this PR: #2312)
I think it is fine for now. I would suggest enabling it by default once people had the chance to test it out on a larger deployment.
Context
Resolves #2302.
#2232 introduced a change to the Identify protocol implementation that caches the discovered
listenAddrs
from the Identify message. The cache is then used in the addresses_of_peer method that is called by swarm code to find possible addresses to dial for a given peer.This lets the Identify assist in peer discovery of a given network behavior automatically. See #2216 for more information.
This cache was disabled in #2312 because we weren't doing any validation. This PR adds the peer id validation.
Proposed Solution
This adds a simple validation before we cache the multiaddr. We don't cache a multiaddr with a wrong final peer-id component. e.g. something that ends with
.../p2p/Qmsome-other-peer
. While this should fail to dial because we check this before dialing, it's probably better to not cache this in the first place.If the multiaddr doesn't have a final
.../p2p/Qmfoo
component, we consider it valid.Testing this locally, it seems like all
listenAddrs
in Identify messages generally don't include the.../p2p/
component (except for dnsaddr, but do these even show up in identify messages?)Rollback strategy
This is safe to revert. Without this, multiaddrs with a wrong peerid will fail to dial.
Next steps
This doesn't enable the caching, I can do that in this PR or another one if we want to keep things smaller.