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

refactor(request-response): revise public API to follow naming convention #3159

Merged
merged 31 commits into from
Dec 13, 2022

Conversation

jxs
Copy link
Member

@jxs jxs commented Nov 22, 2022

Description

Notes

Continues addressing #2217.
Per commit review is suggested :)

Open Questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Nice work! Thanks :)

#[doc(hidden)]
pub enum RequestResponseHandlerEvent<TCodec>
pub enum HandlerEvent<TCodec>
Copy link
Contributor

Choose a reason for hiding this comment

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

Would just Event be pushing it too far? :D

Copy link
Contributor

@thomaseizinger thomaseizinger Nov 22, 2022

Choose a reason for hiding this comment

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

In case it isn't I think the handler module should be private so this Event can't clash with the other one.

Copy link
Member

Choose a reason for hiding this comment

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

Intuitively libp2p::request_response::handler::Event reads better than libp2p::request_response::handler::HandlerEvent and would be inline with the convention this pull request is enforcing.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah makes sense to me, thanks for the suggestion,
So, there is request_response::Event and request_response::handler::Event now. Can you expand on Event's clashing Thomas?
There will still be request_response::RequestResponseHandlerEvent which is deprecated and suggests request_response::handler::Event, if we make handler private how can we export both?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah if we make handler private, we can no longer export it. What I meant with clashing is that from the outside, there is really only one event that is interesting for users and it is the NetworkBehaviour's OutEvent.

Given that we are already making this a breaking change, we might as well make handler private. In my opinion, no one should be depending on just the ConnectionHandler.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the explanation Thomas. Handler and Event can't be private because NetworkBehaviour::ConnectionBehaviour associated type needs to be public, and by consequence ConnectionHandler's also

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation Thomas. Handler and Event can't be private because NetworkBehaviour::ConnectionBehaviour associated type needs to be public, and by consequence ConnectionHandler's also

Hmm that is news to me! We have a lot of protocols where the ConnectionHandler implementation is completely private to the crate. For example ping:

Copy link
Contributor

Choose a reason for hiding this comment

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

I just tested it locally and things compile if I make the handler module private. However, I'd suggest that we don't do this for now. I think together with #3159 (comment), we can make this completely non-breaking?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for digging this deeper Thomas! Did you understand what is it that with request-response that was making the compiler complain?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the issue is fairly subtle:

If you have a public type that implements a trait, the compiler enforces that the associated types also need to be public. It does however not check whether the type is within a public or private module in regards to the crate.

In our usecase, this means we can have a pub struct Handler that implements ConnectionHandler but define it within a crate-private module handler. This may or may not be a bug in Rust but I think one can argue that it makes sense:

The API contract promised to the user is that Behaviour implements NetworkBehaviour. NetworkBehaviour enforces that NetworkBehaviour::ConnectionHandler implements IntoConnectionHandler. The user can refer to this type as <Behaviour::ConnectionHandler as IntoConnectionHandler> and call all public APIs on that. They don't need to know the concrete type that implements the functionality. This way, only the minimal promised API is actually exposed.

protocols/request-response/src/handler.rs Outdated Show resolved Hide resolved
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Other than the comments by Thomas above, this looks good to me.

Thanks @jxs.

#[doc(hidden)]
pub enum RequestResponseHandlerEvent<TCodec>
pub enum HandlerEvent<TCodec>
Copy link
Member

Choose a reason for hiding this comment

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

Intuitively libp2p::request_response::handler::Event reads better than libp2p::request_response::handler::HandlerEvent and would be inline with the convention this pull request is enforcing.

@jxs jxs force-pushed the rename-request-response branch 2 times, most recently from 149a2c5 to eddda25 Compare November 24, 2022 11:43
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

This is missing a version bump in the root Cargo.toml, right?

protocols/request-response/CHANGELOG.md Show resolved Hide resolved
/// protocol family and how they are encoded / decoded on an I/O stream.
#[deprecated(
since = "0.23.0",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
since = "0.23.0",
since = "0.24.0",

#[doc(hidden)]
pub struct RequestResponseHandler<TCodec>
#[deprecated(
since = "0.23.0",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
since = "0.23.0",
since = "0.24.0",

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks Max, addressed.

#[doc(hidden)]
pub enum RequestResponseHandlerEvent<TCodec>
#[deprecated(
since = "0.23.0",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
since = "0.23.0",
since = "0.24.0",

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks Max, addressed.

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!

A few minor comments :)

protocols/autonat/src/behaviour.rs Outdated Show resolved Hide resolved
protocols/request-response/src/codec.rs Outdated Show resolved Hide resolved
protocols/request-response/src/codec.rs Outdated Show resolved Hide resolved
protocols/request-response/src/codec.rs Show resolved Hide resolved
protocols/request-response/src/handler.rs Outdated Show resolved Hide resolved
protocols/request-response/src/handler.rs Outdated Show resolved Hide resolved
protocols/request-response/src/lib.rs Outdated Show resolved Hide resolved
protocols/request-response/src/lib.rs Outdated Show resolved Hide resolved
protocols/request-response/src/lib.rs Outdated Show resolved Hide resolved
protocols/request-response/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Changes look good to me. No objections to merging other than the missing version change and changelog entry.

@thomaseizinger any remaining comments?

Cargo.toml Outdated
@@ -106,7 +106,7 @@ libp2p-plaintext = { version = "0.38.0", path = "transports/plaintext", optional
libp2p-pnet = { version = "0.22.2", path = "transports/pnet", optional = true }
libp2p-relay = { version = "0.14.0", path = "protocols/relay", optional = true }
libp2p-rendezvous = { version = "0.11.0", path = "protocols/rendezvous", optional = true }
libp2p-request-response = { version = "0.23.0", path = "protocols/request-response", optional = true }
libp2p-request-response = { version = "0.24.0", path = "protocols/request-response", optional = true }
Copy link
Member

Choose a reason for hiding this comment

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

Given that this is a breaking change for libp2p, this pull request needs to bump the libp2p version to v0.51.0. Can you please also add a changelog entry to the root CHANGELOG.md file. See previous entries for reference.

@thomaseizinger
Copy link
Contributor

@thomaseizinger any remaining comments?

Nope, LGTM!

@thomaseizinger
Copy link
Contributor

@thomaseizinger any remaining comments?

Nope, LGTM!

Actually, I do want to finish one discussion: #3159 (comment)

@thomaseizinger thomaseizinger changed the title protocols/request-response: Revise symbol naming refactor(request-response): revise public API to follow naming convention Dec 8, 2022
@mergify
Copy link
Contributor

mergify bot commented Dec 9, 2022

This pull request has merge conflicts. Could you please resolve them @jxs? 🙏

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Lovely, thanks so much!

I am thrilled that this is backwards-compatible now :)

@mergify
Copy link
Contributor

mergify bot commented Dec 12, 2022

This pull request has merge conflicts. Could you please resolve them @jxs? 🙏

@jxs
Copy link
Member Author

jxs commented Dec 12, 2022

fixed the merge conflicts, and updated the deprecation message to 0.24

@mergify
Copy link
Contributor

mergify bot commented Dec 12, 2022

This pull request has merge conflicts. Could you please resolve them @jxs? 🙏

@mergify mergify bot merged commit f828db6 into libp2p:master Dec 13, 2022
umgefahren pushed a commit to umgefahren/rust-libp2p that referenced this pull request Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants