-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat: add with_p2p method on multiaddr #102
feat: add with_p2p method on multiaddr #102
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.
Thank you for tackling this inconsistency across the codebase @stormshield-frb! I am in favor of a helper function in multiaddr
.
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 for working in the feedback! Two points.
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.
Yeah that works, thank you!
Can you update the PR description to reflect our findings? |
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 can't say much whether this addition is useful or not, but from a Rust perspective it looks good to me.
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.
Thank you! Well done.
I suggest I cut a new release once we have some pull request using this new method, e.g. libp2p/rust-libp2p#4596. Sounds good?
PR context
In order to have a uniformized usage of
multiaddr
with a/p2p
suffix in therust-libp2p
repository, we are finding ourselves in need of utility method to easily ensure that amultiaddr
is terminated by thep2p
protocol for a givenPeerId
.Our first thought was to only implement this method in our code base but since it is needed in several crates of ours and it could be useful to other people, we thought it could be a good idea to implement it directly on
Multiaddr
.This is related to the following PR on the
rust-libp2p
repository: libp2p/rust-libp2p#4596Implementation decisions
After some discussions, we (@thomaseizinger and myself) decided to implement a simple
with_p2p
function onmultiaddr
.We studied a possibility to improve the
push
andwith
functions to be smart enough to not append the same protocol twice since it does not have any meaning and would result in an unusablemultiaddr
(except for some protocols likecerthash
). Although it would probably be a great idea and a great improvement, it would result in an important breaking API change since we would then need to return aResult
(because a call towith
orpush
could fail when trying to append the same protocol twice with a different content). Since this seems quite overkill for the current need we decided in the end that we leave thepush
andwith
function as it is for now.We also studied the addition of a
from_str_and_peer
function, but seeing the resulting implementation, we decided it was not worth it to expand the public API surface for a one-line function.