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

protocols/noise: Update to futures-preview #1248

Merged
merged 34 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
80e21bf
protocols/noise: Fix obvious future errors
mxinden Sep 5, 2019
a50a853
protocol/noise: Make Handshake methods independent functions
mxinden Sep 5, 2019
61b0465
protocols/noise: Abstract T and C for handshake
mxinden Sep 5, 2019
52cb4e1
protocols/noise: Replace FutureResult with Result
mxinden Sep 5, 2019
4826b8e
protocols/noise: Introduce recv_identity stub
mxinden Sep 5, 2019
7101fe6
protocols/noise: Implement recv_identity stub
mxinden Sep 5, 2019
b94dc21
protocols/noise: Change NoiseConfig::Future from Handshake to Result
mxinden Sep 5, 2019
83684fb
protocols/noise: Adjust to new Poll syntax
mxinden Sep 5, 2019
9f44676
protocols/noise: Return early on state creation failure
mxinden Sep 5, 2019
1e8f34a
protocols/noise: Add bounds Async{Write,Read} to initiator / respoder
mxinden Sep 5, 2019
b184be9
protocols/noise: Add Protocol trait bound for C in rt functions
mxinden Sep 6, 2019
6b0fbcb
protocols/noise: Do io operations on state.io instead of state
mxinden Sep 6, 2019
9c89268
protocols/noise: Have upgrade_xxx return a pinned future
mxinden Sep 6, 2019
edbeb2e
protocols/noise: Have NoiseOutput::poll_read self be mutable
mxinden Sep 6, 2019
8dccad9
protocols/noise: Make recv_identity buffers mutable
mxinden Sep 6, 2019
40854f1
protocols/noise: Fix warnings
mxinden Sep 6, 2019
6efecb2
protocols/noise: Replace NoiseOutput io::Read impl with AsyncRead
mxinden Sep 9, 2019
bf949e6
protocols/noise: Replace NoiseOutput io::Write impl with AsyncWrite
mxinden Sep 10, 2019
ec089c6
protocols/noise: Adjust tests to new futures
mxinden Sep 11, 2019
b5a0bfa
protocols/noise: Don't use {AsyncRead,AsyncWrite,TryStream}*Ext* bound
mxinden Sep 19, 2019
5a89272
protocols/noise: Don't use async_closure feature
mxinden Sep 19, 2019
b7b0891
protocols/noise: use futures::ready! macro
mxinden Sep 19, 2019
fa7d919
protocols/noise: Make NoiseOutput AsyncRead return unsafe NopInitializer
mxinden Sep 19, 2019
d6e179a
protocols/noise: Remove resolved TODO questions
mxinden Sep 19, 2019
af7f093
protocols/noise: Remove 'this = self' comment
mxinden Sep 23, 2019
8a41b80
Remove redundant nested futures.
Sep 19, 2019
1f07367
protocols/noise/Cargo: Update to futures preview 0.3.0-alpha.18
mxinden Sep 26, 2019
ef103c9
protocols/noise: Improve formatting
mxinden Sep 26, 2019
7df47f0
protocols/noise: Return pinned future on authenticated noise upgrade
mxinden Sep 26, 2019
c490e29
protocols/noise: Specify Output of Future embedded in Handshake directly
mxinden Sep 26, 2019
555c2df
*: Ensure Noise handshake futures are Send
mxinden Sep 26, 2019
ed88f01
Revert "*: Ensure Noise handshake futures are Send"
mxinden Sep 30, 2019
ad5fbca
protocols/noise: Ensure NoiseConfig Future is Send
mxinden Sep 30, 2019
4ae908d
protocols/noise: Use relative import path for {In,Out}boundUpgrade
mxinden Sep 30, 2019
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
8 changes: 4 additions & 4 deletions core/src/upgrade/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<C, U, F, T> InboundUpgrade<C> for MapInboundUpgrade<U, F>
where
U: InboundUpgrade<C>,
U::Future: Unpin,
F: FnOnce(U::Output) -> T
F: FnOnce(U::Output) -> T + Send
Copy link
Member

Choose a reason for hiding this comment

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

That's not what I was thinking of.

{
type Output = T;
type Error = U::Error;
Expand Down Expand Up @@ -117,7 +117,7 @@ impl<C, U, F, T> OutboundUpgrade<C> for MapOutboundUpgrade<U, F>
where
U: OutboundUpgrade<C>,
U::Future: Unpin,
F: FnOnce(U::Output) -> T
F: FnOnce(U::Output) -> T + Send
{
type Output = T;
type Error = U::Error;
Expand Down Expand Up @@ -157,7 +157,7 @@ impl<C, U, F, T> InboundUpgrade<C> for MapInboundUpgradeErr<U, F>
where
U: InboundUpgrade<C>,
U::Future: Unpin,
F: FnOnce(U::Error) -> T
F: FnOnce(U::Error) -> T + Send
{
type Output = U::Output;
type Error = T;
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<C, U, F, T> OutboundUpgrade<C> for MapOutboundUpgradeErr<U, F>
where
U: OutboundUpgrade<C>,
U::Future: Unpin,
F: FnOnce(U::Error) -> T
F: FnOnce(U::Error) -> T + Send
{
type Output = U::Output;
type Error = T;
Expand Down
4 changes: 2 additions & 2 deletions core/src/upgrade/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub trait InboundUpgrade<C>: UpgradeInfo {
type Error;
/// Future that performs the handshake with the remote.
// TODO: remove Unpin
type Future: Future<Output = Result<Self::Output, Self::Error>> + Unpin;
type Future: Future<Output = Result<Self::Output, Self::Error>> + Unpin + Send;
Copy link
Member

Choose a reason for hiding this comment

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

This neither.

Copy link
Member Author

Choose a reason for hiding this comment

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

@tomaka I am sorry, I must be misunderstanding something here.

You would like <NoiseAuthenticated<P, C, R> as InboundUpgrade<T>>::Future to be Send, right?

As far as I understood something can only be Send if everything below it is Send.

<NoiseAuthenticated<P, C, R> as InboundUpgrade<T>>::upgrade_inbound calls <NoiseConfig<P, C, R> as InboundUpgrade<T>>::upgrade_inbound which by our requirement above needs to return a Send Future, thus the added trait bound (Send) on the InboundUpgrade trait.

What am I missing?

Copy link
Member

Choose a reason for hiding this comment

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

As you mentioned, the InboundUpgrade is Send if all its components are Send. So all you have to do is require Send on its components within the code of libp2p-noise.

As far as I understood something can only be Send if everything below it is Send.

The exception is Box<dyn Future> which is never send and that you have to replace with Box<dyn Future + Send>. That's the only change that you might have to do outside of libp2p-noise.


/// After we have determined that the remote supports one of the protocols we support, this
/// method is called to start the handshake.
Expand Down Expand Up @@ -186,7 +186,7 @@ pub trait OutboundUpgrade<C>: UpgradeInfo {
type Error;
/// Future that performs the handshake with the remote.
// TODO: remove Unpin
type Future: Future<Output = Result<Self::Output, Self::Error>> + Unpin;
type Future: Future<Output = Result<Self::Output, Self::Error>> + Unpin + Send;

/// After we have determined that the remote supports one of the protocols we support, this
/// method is called to start the handshake.
Expand Down
2 changes: 1 addition & 1 deletion protocols/noise/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2018"
[dependencies]
bytes = "0.4"
curve25519-dalek = "1"
futures-preview = "0.3.0-alpha.17"
futures-preview = "0.3.0-alpha.18"
lazy_static = "1.2"
libp2p-core = { version = "0.12.0", path = "../../core" }
log = "0.4"
Expand Down
Loading