Skip to content
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: support custom compat protocol name #42

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Jan 2, 2023

Changes:

Background: go-bitswap allows customizing the protocol name with its Settings.Prefix API, e.g. lotus uses "/chain" prefix, rust-bitswap should be capable of matching the protocol name in compat mode. Please let me know your feedback, thanks!

Copy link
Contributor

@rkuhn rkuhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, I had to mute github notifications for a while.

This change looks good to me, just two points to discuss.

src/behaviour.rs Outdated
@@ -26,6 +26,8 @@ use libp2p::core::either::EitherOutput;
use libp2p::core::{connection::ConnectionId, Multiaddr, PeerId};
use libp2p::swarm::derive_prelude::{ConnectionClosed, DialFailure, FromSwarm, ListenFailure};
#[cfg(feature = "compat")]
use libp2p::swarm::SubstreamProtocol;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fold this into the following import

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

impl UpgradeInfo for CompatMessage {
type Info = &'static [u8];
type InfoIter = iter::Once<Self::Info>;

fn protocol_info(&self) -> Self::InfoIter {
iter::once(b"/ipfs/bitswap/1.2.0")
unimplemented!()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This smells bad: why not instead remove this impl?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It requires more refactoring to remove UpgradeInfo impl for CompatMessage

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That refactoring is the required proof that this unimplemented!() won’t panic at runtime, though. In other words, I find it reasonable to demand that a production ready library does not contain unimplemented!().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense! However, it's been too long since I made the PR, and I do need some extra time to pick up the context and made the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants