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

core/upgrade/: Add ReadyUpgrade #2855

Merged
merged 6 commits into from
Sep 7, 2022
Merged

core/upgrade/: Add ReadyUpgrade #2855

merged 6 commits into from
Sep 7, 2022

Conversation

thomaseizinger
Copy link
Contributor

@thomaseizinger thomaseizinger commented Aug 30, 2022

Description

This is the counterpart to PendingUpgrade.

Links to any relevant issues

Extracted out of #2852.

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

core/CHANGELOG.md Outdated Show resolved Hide resolved
@thomaseizinger thomaseizinger changed the title Add ReadyUpgrade core: Add ReadyUpgrade Aug 30, 2022
@thomaseizinger
Copy link
Contributor Author

I am planning to use this throughout the codebase where applicable. Should I do this as part of this PR or send separate ones @mxinden? It could for example be used in the ping protocol.

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.

I am in favor of introducing a ReadyUpgrade.

Note that long term I would like to get rid of the upgrade mechanism in ConnectionHandler, though that still needs more thought.

I am planning to use this throughout the codebase where applicable. Should I do this as part of this PR or send separate ones @mxinden? It could for example be used in the ping protocol.

I think every pull request should be:

  • As small as possible.
  • Atomic.
  • Leave master in the same or better state.

For the sake of the latter, concretely here for the sake of code deduplication, I think this pull request should include the changes across the many use-cases.

@thomaseizinger
Copy link
Contributor Author

@mxinden The only place where it was directly applicable was the ping protocol.

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.

Thanks for the follow up!

Comment on lines -55 to -83
impl UpgradeInfo for Ping {
type Info = &'static [u8];
type InfoIter = iter::Once<Self::Info>;

fn protocol_info(&self) -> Self::InfoIter {
iter::once(PROTOCOL_NAME)
}
}

impl InboundUpgrade<NegotiatedSubstream> for Ping {
type Output = NegotiatedSubstream;
type Error = Void;
type Future = future::Ready<Result<Self::Output, Self::Error>>;

fn upgrade_inbound(self, stream: NegotiatedSubstream, _: Self::Info) -> Self::Future {
future::ok(stream)
}
}

impl OutboundUpgrade<NegotiatedSubstream> for Ping {
type Output = NegotiatedSubstream;
type Error = Void;
type Future = future::Ready<Result<Self::Output, Self::Error>>;

fn upgrade_outbound(self, stream: NegotiatedSubstream, _: Self::Info) -> Self::Future {
future::ok(stream)
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Emphasizing this, though I think we are of the same opinion: While not de-duplicating given that ReadyUpgrade is only used once, I do think these kind of pull requests do a great job simplifying the business logic, here libp2p-ping, moving auxiliary not-directly-related logic to common places, here libp2p-core.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, strong agreement here.

protocols/ping/src/handler.rs Show resolved Hide resolved
@thomaseizinger
Copy link
Contributor Author

Comments addressed, ready to merge from my end @mxinden!

@mxinden mxinden changed the title core: Add ReadyUpgrade core/: Add ReadyUpgrade Sep 7, 2022
@mxinden mxinden changed the title core/: Add ReadyUpgrade core/upgrade/: Add ReadyUpgrade Sep 7, 2022
@mxinden mxinden merged commit 2eca38c into master Sep 7, 2022
@thomaseizinger thomaseizinger deleted the ready-upgrade branch September 19, 2022 06:10
@thomaseizinger thomaseizinger added this to the Simplify ConnectionHandler trait milestone Sep 18, 2023
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