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

misc/multistream-select: Implement simultaneous open extension #2066

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8ecd5f4
misc/multistream-select: Implement simultaneous open extension
mxinden May 4, 2021
b71abd8
Merge branch 'libp2p/master' into sim-open
mxinden Jun 2, 2021
2cfaec9
core/: Integrate Simultaneous Open extension
mxinden Jun 30, 2021
1213669
Merge branch 'libp2p/master' into sim-open
mxinden Jun 30, 2021
11542d1
core/src/transport/upgrade: Make DialFuture aware of SimOpenRole
mxinden Jul 4, 2021
618ccd5
core/src/transport: Use Transport::and_then for Authenticated::apply
mxinden Jul 4, 2021
1134173
core/: Clean type structure
mxinden Jul 4, 2021
dab4ceb
core/: Enforce upgrade version at compile time
mxinden Jul 4, 2021
9861a53
Merge branch 'libp2p/master' into sim-open
mxinden Jul 4, 2021
227363f
misc/multistream-select: Document V1SimOpen
mxinden Jul 7, 2021
224141e
*: Rename V1SimOpen to V1SimultaneousOpen
mxinden Jul 7, 2021
cadb065
misc/multistream-select: Document SimOpenRole
mxinden Jul 7, 2021
bd76946
*: Rename SimOpenRole to Role
mxinden Jul 7, 2021
ade2aff
misc/multistream-select: Document reponder role process
mxinden Jul 7, 2021
b66b4eb
misc/multistream-select: Bump version and add changelog entry
mxinden Jul 7, 2021
16da533
core/CHANGELOG: Add entry
mxinden Jul 7, 2021
4a9fef3
core/src/upgrade: Assert Initiator when not using SimOpen
mxinden Jul 7, 2021
41c884c
core/upgrade/apply: Document different versions
mxinden Jul 7, 2021
cf2e3ef
misc/multistream-select: Derive Eq for Role
mxinden Jul 7, 2021
a4264fc
*: Fix documentation links
mxinden Jul 7, 2021
94793bc
misc/multistream-select: Fix doc link
mxinden Jul 7, 2021
deb5e10
src/lib: Call upgrade without Version
mxinden Jul 7, 2021
b251211
Merge branch 'libp2p/master' into sim-open
mxinden Jul 23, 2021
9dc1271
Merge commit '008561283ed0a0530d449fdc7ff4dc9f3ab9ce73' into sim-open
mxinden Aug 13, 2021
d49cedd
*: Format with rustfmt
mxinden Aug 13, 2021
58d8131
Merge branch 'libp2p/master' into sim-open
mxinden Aug 13, 2021
ed0ef92
Merge branch 'libp2p/master' into sim-open
mxinden Aug 23, 2021
ae26a87
Merge branch 'libp2p/master' into sim-open
mxinden Sep 26, 2021
00532e0
Merge branch 'libp2p/master' into sim-open
mxinden Nov 18, 2021
62e88f8
misc/multistream-select/src/protocol.rs: Fix typo
mxinden Nov 20, 2021
624c2de
misc/multistream-select: Supress needless collect warning
mxinden Nov 20, 2021
29eb097
misc/multistream-select: Fix version usage in tests
mxinden Nov 21, 2021
aad7e72
Merge branch 'master' into sim-open
mxinden Nov 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,43 @@
Introduce `upgrade::read_length_prefixed` and `upgrade::write_length_prefixed`.
See [PR 2111](https://github.com/libp2p/rust-libp2p/pull/2111).

- Add support for multistream-select [simultaneous open extension] to assign _initiator_ and
_responder_ role during authentication protocol negotiation on simultaneously opened connection.

This is one important component of the greater effort to support hole punching in rust-libp2p.

- `Transport::upgrade` no longer takes a multistream-select `Version`. Instead the
multistream-select `Version`s `V1`, `V1Lazy` and `V1SimultaneousOpen` can be selected when
setting the authentication upgrade via `Builder::authenticate_with_version` and the
multistream-select `Version`s `V1` and `V1Lazy` can be selected when setting the multiplexing
upgrade via `Builder::multiplex_with_version`.

Users merely wanting to maintain the status quo should use the following call chain depending
on which `Version` they previously used:

- `Version::V1`

```rust
my_transport.upgrade()
.authenticate(my_authentication)
.multiplex(my_multiplexer)
Comment on lines +100 to +102
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered adding a .upgrade_sim_open() API instead of changing the existing one? That would:

a) be backwards compatible
b) perhaps avoid the trickery around two Version enums?

```
- `Version::V1Lazy`

```rust
my_transport.upgrade()
.authenticate_with_version(my_authentication, Version::V1Lazy)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a different type, isn't it?

Suggested change
.authenticate_with_version(my_authentication, Version::V1Lazy)
.authenticate_with_version(my_authentication, AuthenticationVersion::V1Lazy)

.multiplex_with_version(my_multiplexer, Version::V1Lazy)
```
Comment on lines +99 to +110
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's worth adding the explicit _with_version methods. I'd just change the signatures of authenticate and multiplex. Version already provides a Default impl.


- `Builder::multiplex_ext` is removed in favor of the new simultaneous open workflow. Please reach
out in case you depend on `Builder::multiplex_ext`.

See [PR 2066].

[PR 2090]: https://github.com/libp2p/rust-libp2p/pull/2090
[simultaneous open extension]: https://github.com/libp2p/specs/blob/master/connections/simopen.md
[PR 2066]: https://github.com/libp2p/rust-libp2p/pull/2066

# 0.28.3 [2021-04-26]

Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ libsecp256k1 = { version = "0.7.0", optional = true }
log = "0.4"
multiaddr = { version = "0.13.0" }
multihash = { version = "0.14", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"] }
multistream-select = { version = "0.10", path = "../misc/multistream-select" }
multistream-select = { version = "0.11", path = "../misc/multistream-select" }
parking_lot = "0.11.0"
pin-project = "1.0.0"
prost = "0.9"
Expand Down
34 changes: 22 additions & 12 deletions core/src/connection/listeners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,6 @@ where

#[cfg(test)]
mod tests {
use futures::{future::BoxFuture, stream::BoxStream};

use super::*;
use crate::transport;

Expand Down Expand Up @@ -463,12 +461,18 @@ mod tests {
impl transport::Transport for DummyTrans {
type Output = ();
type Error = std::io::Error;
type Listener = BoxStream<
'static,
Result<ListenerEvent<Self::ListenerUpgrade, std::io::Error>, std::io::Error>,
type Listener = Pin<
Box<
dyn Stream<
Item = Result<
ListenerEvent<Self::ListenerUpgrade, std::io::Error>,
std::io::Error,
>,
>,
>,
>;
type ListenerUpgrade = BoxFuture<'static, Result<Self::Output, Self::Error>>;
type Dial = BoxFuture<'static, Result<Self::Output, Self::Error>>;
type ListenerUpgrade = Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>>>>;
type Dial = Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>>>>;

fn listen_on(
self,
Expand Down Expand Up @@ -519,12 +523,18 @@ mod tests {
impl transport::Transport for DummyTrans {
type Output = ();
type Error = std::io::Error;
type Listener = BoxStream<
'static,
Result<ListenerEvent<Self::ListenerUpgrade, std::io::Error>, std::io::Error>,
type Listener = Pin<
Box<
dyn Stream<
Item = Result<
ListenerEvent<Self::ListenerUpgrade, std::io::Error>,
std::io::Error,
>,
>,
>,
>;
type ListenerUpgrade = BoxFuture<'static, Result<Self::Output, Self::Error>>;
type Dial = BoxFuture<'static, Result<Self::Output, Self::Error>>;
type ListenerUpgrade = Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>>>>;
type Dial = Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>>>>;

fn listen_on(
self,
Expand Down
5 changes: 2 additions & 3 deletions core/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub use self::boxed::Boxed;
pub use self::choice::OrTransport;
pub use self::memory::MemoryTransport;
pub use self::optional::OptionalTransport;
pub use self::upgrade::Upgrade;

/// A transport provides connection-oriented communication between two peers
/// through ordered streams of data (i.e. connections).
Expand Down Expand Up @@ -198,12 +197,12 @@ pub trait Transport {

/// Begins a series of protocol upgrades via an
/// [`upgrade::Builder`](upgrade::Builder).
fn upgrade(self, version: upgrade::Version) -> upgrade::Builder<Self>
fn upgrade(self) -> upgrade::Builder<Self>
where
Self: Sized,
Self::Error: 'static,
{
upgrade::Builder::new(self, version)
upgrade::Builder::new(self)
}
}

Expand Down
Loading