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

Perform the multi-stream connections handshake inside smoldot #2755

Merged
merged 3 commits into from
Sep 15, 2022

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Sep 15, 2022

cc #2754

In terms of API, this removes the necessity to pass a PeerId when creating a "multi-stream connection". The inner implementation now performs the substream opening and Noise negotiation internally.

@tomaka tomaka requested a review from melekes September 15, 2022 11:05
Copy link
Contributor

@mergify mergify bot left a comment

Choose a reason for hiding this comment

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

Automatically approving tomaka's pull requests. This auto-approval will be removed once more maintainers are active.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 15, 2022

twiggy diff report

Difference in .wasm size before and after this pull request.


 Delta Bytes │ Item
─────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       -8627 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h109c5b84e4bef32f
       +8624 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hf6a4eec029e8ff75
       -3385 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h9df03109fffbe8fc
       +3326 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h3e744d7e7db6ffac
        +871 ┊ smoldot::libp2p::collection::multi_stream::MultiStreamConnectionTask<TNow,TSubId>::substream_read_write::h86f8ee4480b47eb2
        -791 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::he183e243778ca743
        +755 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h3cb712fc2622b718
        -511 ┊ smoldot::libp2p::collection::multi_stream::MultiStreamConnectionTask<TNow,TSubId>::new::h3bb34b28a0274823
        +445 ┊ smoldot::libp2p::collection::multi_stream::MultiStreamConnectionTask<TNow,TSubId>::new::hc742c6c7cc0d513f
        -398 ┊ core::ptr::drop_in_place<core::future::from_generator::GenFuture<smoldot_light::network_service::tasks::connection_task<smoldot_light_wasm::platform::Platform>::{{closure}}>>::h73107793b246aa38
        +360 ┊ core::ptr::drop_in_place<core::future::from_generator::GenFuture<smoldot_light::network_service::tasks::connection_task<smoldot_light_wasm::platform::Platform>::{{closure}}>>::hbfdd6ab1124aee53
        -351 ┊ smoldot::network::service::ChainNetwork<TNow>::pending_outcome_ok_multi_stream::h01c40207a31920c0
        +325 ┊ smoldot::network::service::ChainNetwork<TNow>::pending_outcome_ok_multi_stream::h3b3f8ddbacac09c6
        +321 ┊ <futures_util::future::poll_fn::PollFn<F> as core::future::future::Future>::poll::h18ad5e85d98e1acb
        -321 ┊ <futures_util::future::poll_fn::PollFn<F> as core::future::future::Future>::poll::h84d8c430c812f3ae
        -208 ┊ futures_util::async_await::random::shuffle::h32ed49da917f59cd
        +208 ┊ futures_util::async_await::random::shuffle::h443f2c022cf2eea2
        -197 ┊ core::ptr::drop_in_place<core::future::from_generator::GenFuture<smoldot_light::network_service::update_round<smoldot_light_wasm::platform::Platform>::{{closure}}>>::he4ac8a3471968db9
        +197 ┊ core::ptr::drop_in_place<core::future::from_generator::GenFuture<smoldot_light::network_service::update_round<smoldot_light_wasm::platform::Platform>::{{closure}}>>::hf8f4e3742c8ddac1
        -197 ┊ smoldot_light::network_service::tasks::connection_task::{{closure}}::{{closure}}::{{closure}}::h4e967583f3ccbfd6
       +1053 ┊ ... and 112 more.
       +1898 ┊ Σ [132 Total Rows]

@tomaka
Copy link
Contributor Author

tomaka commented Sep 15, 2022

Note that the code has a couple of todo!s and unimplemented things, because I don't actually expect it to work first try anyway. This PR is merely an attempt to move #2579 forward. The code that this PR touches isn't used anywhere at the moment (apart from #2579).

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

are you sure this is easier than the old approach + Rust binding called from JS, which performs Noise handshake?

src/libp2p/collection/multi_stream.rs Show resolved Hide resolved
src/libp2p/collection.rs Show resolved Hide resolved
@tomaka
Copy link
Contributor Author

tomaka commented Sep 15, 2022

are you sure this is easier than the old approach + Rust binding called from JS, which performs Noise handshake?

This is definitely easier. The old approach requires going through the JS<->Rust FFI layer, which is kind of complicated. It also requires proper handling of what to do if an exception is thrown by smoldot, which is also super complicated.

@tomaka tomaka added the automerge Automatically merge pull request as soon as possible label Sep 15, 2022
@mergify mergify bot merged commit 047371f into paritytech:main Sep 15, 2022
@tomaka tomaka deleted the multi-stream-handshake-inside branch September 15, 2022 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge pull request as soon as possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants