-
Notifications
You must be signed in to change notification settings - Fork 998
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/mdns: Use a random alphanumeric string for peer name #2311
Conversation
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.
Very cool. Thanks a bunch for picking this up @jochasinga!
Would you mind adding a changelog entry as well?
//CC @peat as you have been working on this logic in the past.
In the changelog it is currently 0.32.0rc-1. I didn't find a doc explaining the process. Do you mind advise how this change should be reflected in the versioning? |
Sorry for the confusion @jochasinga. Could you apply the diff below? diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md
index f3287379..a2376242 100644
--- a/protocols/mdns/CHANGELOG.md
+++ b/protocols/mdns/CHANGELOG.md
@@ -1,3 +1,9 @@
+# 0.32.1 [unreleased]
+
+- Use a random alphanumeric string for mDNS peer name (see [PR 2311]).
+
+[PR 2311]: https://github.com/libp2p/rust-libp2p/pull/2311/
+
# 0.32.0 [2021-11-01]
- Make default features of `libp2p-core` optional.
diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml
index 43370a9b..0bf1605e 100644
--- a/protocols/mdns/Cargo.toml
+++ b/protocols/mdns/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "libp2p-mdns"
edition = "2018"
-version = "0.32.0"
+version = "0.32.1"
description = "Implementation of the libp2p mDNS discovery method"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT" |
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 to me.
One small nit that just now caught my attention: Given that the peer name is no longer based on the peer ID, would you mind renaming the references from peer ID to peer name?
Just that I understand it correctly: with this change, the If yes, shouldn't this then also be changed in the examples? E.g. |
Because the peer name is no longer based on peer ID. See also: libp2p#2311 (review)
You are raising a very important point here @elenaf9 that I wish I didn't miss before writing #2285. Sorry for the trouble this will cause @jochasinga. I will write up more details on #2285, just a short summary for now: When receiving an mDNS response, rust-libp2p actually does parse the peer name as a rust-libp2p/protocols/mdns/src/query.rs Lines 162 to 176 in 012287a
The above implies that peers not running this patch will discard any responses send by peers that are running this patch. To prevent a network to split, we will need to do a step in between namely to ignore the peer name of a mDNS response and not discard responses in case there is a mismatch. Once that is rolled out on a network, step two would be to roll out this patch setting the peer name to a random string. |
@mxinden keep me posted on the update. Would love to get this fixed up. |
See #2285 (comment). |
Per @MarcoPolo points that an error isn't useful for the caller and following MdnsPacket API. See also: libp2p#2311 (comment)
(from @elenaf9) With the changes in here now, I don't think this is true anymore. Now the peerid is correct in MdnsResponse, which is used to generate the MdnsEvent. So I don't think we need to change the examples. If this is wrong, then the correct fix is to have the correct |
@jochasinga can you please rebase this branch? |
Rename `encode_peer_id` to `generate_peer_id` Because `encode_peer_id` now does not encode anything.
Update CHANGELOG and Cargo.toml
Because the peer name is no longer based on peer ID. See also: libp2p#2311 (review)
- Remove the peer ID parsing logic and ignore the peer name. - Remove `my_peer_id` from `MdnsPeer::new(...)` parameters. - Ignore addresses with bad or no peer IDs, use the peer ID of the first address with a peer ID as a reference, and ignore all addresses whose peer ID does not match the first peer ID. Note that `MdnsPeer::new(...)` now returns a Result type because there is no gaurantee that there will be a peer ID to create the peer.
Per @MarcoPolo points that an error isn't useful for the caller and following MdnsPacket API. See also: libp2p#2311 (comment)
7dc6b1f
to
f31ce25
Compare
@mxinden can you please run checks on this? |
Refactor match statement to map since it's more idiomatic and concise. Use expect in tests for better cue in the test.
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.
Code looks good to me. Thank you for the many iterations!
Just two comments on the release process:
protocols/mdns/CHANGELOG.md
Outdated
@@ -1,3 +1,9 @@ | |||
# 0.33.1 [unreleased] | |||
|
|||
- Use a random alphanumeric string for mDNS peer name (see [PR 2311]). |
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.
- Use a random alphanumeric string for mDNS peer name (see [PR 2311]). | |
- Use a random alphanumeric string instead of the local peer ID for mDNS peer | |
name (see [PR 2311]). | |
Note that previous versions of `libp2p-mdns` expect the peer name to be a | |
valid peer ID. Thus they will be unable to discover nodes running this new | |
version of `libp2p-mdns`. |
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.
Do I need to correct the protocols/mdns/CHANGELOG
to 0.34.0 as well here?
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.
Yes please 🙏
Co-authored-by: Max Inden <[email protected]>
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 will merge later today unless anyone objects.
Thanks @jochasinga for all the work and thanks @MarcoPolo for the additional help!
…p#2311) With libp2p/specs#368 the definition of the _peer name_ changed in the mDNS specification. > peer-name is the case-insensitive unique identifier of the peer, and is less > than 64 characters. > > As the this field doesn't carry any meaning, it is sufficient to ensure the > uniqueness of this identifier. Peers SHOULD generate a random, lower-case > alphanumeric string of least 32 characters in length when booting up their > node. Peers SHOULD NOT use their Peer ID here because a future Peer ID could > exceed the DNS label limit of 63 characters. https://github.com/libp2p/specs/blob/master/discovery/mdns.md This commit adjusts `libp2p-mdns` accordingly. Also see libp2p/go-libp2p#1222 for the corresponding change on the Golang side. Co-authored-by: Max Inden <[email protected]>
Fixes #2285.