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

Improve the networking abstraction of the Platform trait #315

Merged
merged 24 commits into from
Mar 24, 2023

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Mar 19, 2023

This PR modifies the Platform trait exposed by light-base in order to improve the abstraction over "streams" (i.e. TCP or WebSocket connections, or WebRTC substreams).

It now allows closing the sending side, and no longer allows an unlimited amount of outgoing data.

As part of this PR, most of the AsyncStdTcpWebSocket has been rewritten in a clean way. There's no cursed background task that sends and receives messages from the front or whatnot. Instead, things are now "flat" and the socket is polled directly in the future manipulated by the networking task.

Finishing this consists in updating the wasm-node implementation of Platform as well.

@github-actions
Copy link

github-actions bot commented Mar 19, 2023

twiggy diff report

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


 Delta Bytes │ Item
─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
      +10359 ┊ smoldot_light::network_service::tasks::connection_task::{{closure}}::h6c0628a6fbaa3d6b
       -9857 ┊ smoldot_light::network_service::tasks::connection_task::{{closure}}::hb767739b25bffcfc
        +947 ┊ alloc::collections::btree::node::BalancingContext<K,V>::bulk_steal_right::hc9a7c8929bc95300
        +910 ┊ alloc::collections::btree::node::BalancingContext<K,V>::bulk_steal_left::he4adb7e07f6de005
        +891 ┊ <smoldot_light_wasm::platform::Platform as smoldot_light::platform::Platform>::connect::{{closure}}::hff4c435264fe0977
        -852 ┊ <smoldot_light_wasm::platform::Platform as smoldot_light::platform::Platform>::connect::{{closure}}::h7e55ac5e08de9b11
        -849 ┊ alloc::collections::btree::node::BalancingContext<K,V>::bulk_steal_right::h7f138d73241e5281
        -816 ┊ alloc::collections::btree::node::BalancingContext<K,V>::bulk_steal_left::hb6b2eb205295f8e4
        +771 ┊ alloc::collections::btree::remove::<impl alloc::collections::btree::node::Handle<alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::Leaf>,alloc::collections::btree::node::marker::KV>>::remove_leaf_kv::h5bcb337bfe379338
        -754 ┊ alloc::collections::btree::remove::<impl alloc::collections::btree::node::Handle<alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::Leaf>,alloc::collections::btree::node::marker::KV>>::remove_leaf_kv::hcb0c933912d08eef
        -674 ┊ alloc::collections::btree::fix::<impl alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::LeafOrInternal>>::fix_node_through_parent::hbe241ecc34543371
        +674 ┊ alloc::collections::btree::fix::<impl alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::LeafOrInternal>>::fix_node_through_parent::hdf67f56840f1e118
        -673 ┊ alloc::collections::btree::node::Handle<alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Mut,K,V,alloc::collections::btree::node::marker::Leaf>,alloc::collections::btree::node::marker::Edge>::insert_recursing::h59d100c7be33c1de
        +669 ┊ alloc::collections::btree::node::BalancingContext<K,V>::do_merge::h97fcd7b2be0a0ba9
        +669 ┊ alloc::collections::btree::node::BalancingContext<K,V>::do_merge::hfe3dff0ce71b7107
        +629 ┊ alloc::collections::btree::map::entry::VacantEntry<K,V,A>::insert::h2411dd8eb2392f52
        -615 ┊ alloc::collections::btree::node::BalancingContext<K,V>::do_merge::h024f7a24dc61d86e
        -615 ┊ alloc::collections::btree::node::BalancingContext<K,V>::do_merge::hb6484313817647a3
        +590 ┊ <smoldot_light_wasm::platform::Platform as smoldot_light::platform::Platform>::update_stream::{{closure}}::he541593a41967f9e
        -573 ┊ alloc::collections::btree::map::entry::VacantEntry<K,V,A>::insert::h70fa25bd424545f2
       +2006 ┊ ... and 313 more.
       +4033 ┊ Σ [333 Total Rows]

@tomaka tomaka marked this pull request as ready for review March 22, 2023 10:36
@tomaka
Copy link
Contributor Author

tomaka commented Mar 22, 2023

While updating the Platform implementation in the wasm node, I've discovered several bugs where we call *_reset on a connection or stream that has already been reset by the remote. This is now fixed.

@tomaka tomaka enabled auto-merge March 24, 2023 08:26
@tomaka tomaka added this pull request to the merge queue Mar 24, 2023
Merged via the queue into smol-dot:main with commit 9de929e Mar 24, 2023
@tomaka tomaka deleted the platform-write-proper branch March 24, 2023 09:30
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.

1 participant