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

feat: add websocket transport for browser environment based on web-sys #3679

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
fff3b46
Add Websys Websocket transport
vincev Mar 26, 2023
f3874c7
Add rust version
vincev Mar 26, 2023
62ddf7f
Fix docs test
vincev Mar 26, 2023
3c0069b
Fix docs test
vincev Mar 26, 2023
5a86d7c
Include websys feature to full features.
vincev Mar 26, 2023
50e38e3
Fix semver error.
vincev Mar 26, 2023
25843d5
Fix semver error.
vincev Mar 26, 2023
f794aee
Don't use libp2p in dev-dependencies
vincev Mar 26, 2023
b8503e0
Add deprecation warning for wasm-ext.
vincev Mar 27, 2023
378c03f
Fix clippy error for wasm-ext deprecation
vincev Mar 27, 2023
631dc8b
Merge branch 'libp2p:master' into websys
vincev Mar 27, 2023
d5912c5
Rename transport package
vincev Apr 2, 2023
2e4922a
Remove deprecated mplex from doc test
vincev Apr 2, 2023
5534114
Return MultiaddrNotSupported for invalid multi addr.
vincev Apr 2, 2023
d50ea63
Use weak pointer in the Websocket callbacks to avoid cycle
vincev Apr 3, 2023
4603ca6
Set version to 0.1.0 for new package
vincev Apr 8, 2023
f5b7965
Fix Yamux doc comment
vincev Apr 8, 2023
487828a
Use different wakers for read and write
vincev Apr 8, 2023
c688acb
Use debug_assert for unexpected data format
vincev Apr 8, 2023
bbdd5fe
Merge branch 'master' into websys
vincev Apr 8, 2023
17e8799
Make websocket constructor error user friendly.
vincev Apr 8, 2023
0af2389
Rewrite style of cargo features
thomaseizinger Apr 10, 2023
4337fc9
Fix spelling of `web-sys`
thomaseizinger Apr 10, 2023
883552d
Misc clean-up
thomaseizinger Apr 10, 2023
b0b6de8
use early return
thomaseizinger Apr 10, 2023
27ef99d
Refactor booleans to state
thomaseizinger Apr 10, 2023
0fb9c50
Avoid unnecessary wake-ups
thomaseizinger Apr 10, 2023
c3f2abf
Properly implement `poll_close`
thomaseizinger Apr 10, 2023
37cb0cc
Reduce indentation
thomaseizinger Apr 10, 2023
a30256e
Use `Vec` instead of `VecDeque`
thomaseizinger Apr 10, 2023
4062264
Remove unused dependencies
thomaseizinger Apr 10, 2023
aad22e7
Add changelog entry
thomaseizinger Apr 10, 2023
c28b83c
Bump version
thomaseizinger Apr 10, 2023
ae393eb
Remove unnecessary `pub(crate)`
thomaseizinger Apr 10, 2023
8a5c568
Merge branch 'master' into websys
thomaseizinger Apr 10, 2023
f24468f
Add new changelog entry
thomaseizinger Apr 10, 2023
f44f546
Merge branch 'master' into websys
thomaseizinger Apr 28, 2023
0f267cf
Fixup changelog
thomaseizinger Apr 28, 2023
49c5d17
Prevent direct construction of `Transport`
thomaseizinger Apr 28, 2023
baace18
Fix formatting
thomaseizinger Apr 28, 2023
989b58f
Fix doc tests
thomaseizinger Apr 28, 2023
de4dc52
Merge branch 'master' into websys
thomaseizinger May 1, 2023
d3bfb66
Merge branch 'master' into websys
thomaseizinger May 2, 2023
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
- [`libp2p-pnet` CHANGELOG](transports/pnet/CHANGELOG.md)
- [`libp2p-quic` CHANGELOG](transports/quic/CHANGELOG.md)
- [`libp2p-tcp` CHANGELOG](transports/tcp/CHANGELOG.md)
- [`libp2p-tls` CHANGELOG](transports/tls/CHANGELOG.md)
- [`libp2p-uds` CHANGELOG](transports/uds/CHANGELOG.md)
- [`libp2p-wasm-ext` CHANGELOG](transports/wasm-ext/CHANGELOG.md)
- [`libp2p-websocket` CHANGELOG](transports/websocket/CHANGELOG.md)
- [`libp2p-tls` CHANGELOG](transports/tls/CHANGELOG.md)
- [`libp2p-websys-websocket` CHANGELOG](transports/websys-websocket/CHANGELOG.md)

## Multiplexers

Expand Down
30 changes: 27 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ members = [
"transports/wasm-ext",
"transports/webrtc",
"transports/websocket",
"transports/websys-websocket",
]
resolver = "2"

Expand Down
9 changes: 7 additions & 2 deletions libp2p/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
## 0.51.3

- Deprecate the `mplex` feature.
The recommended baseline stream multiplexer is `yamux`.
See [PR 3689].
The recommended baseline stream multiplexer is `yamux`.
See [PR 3689].

- Introduce `libp2p::websys_websocket` module behind `websys-websocket` feature flag.
This supersedes the existing `libp2p::wasm_ext` module which is now deprecated.
See [PR 3679].

[PR 3689]: https://github.com/libp2p/rust-libp2p/pull/3689
[PR 3679]: https://github.com/libp2p/rust-libp2p/pull/3679

## 0.51.2

Expand Down
4 changes: 3 additions & 1 deletion libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ full = [
"wasm-bindgen",
"wasm-ext",
"wasm-ext-websocket",
"websys-websocket",
"webrtc",
"websocket",
"yamux",
Expand Down Expand Up @@ -85,6 +86,7 @@ uds = ["dep:libp2p-uds"]
wasm-bindgen = ["futures-timer/wasm-bindgen", "instant/wasm-bindgen", "getrandom/js", "libp2p-swarm/wasm-bindgen"]
wasm-ext = ["dep:libp2p-wasm-ext"]
wasm-ext-websocket = ["wasm-ext", "libp2p-wasm-ext?/websocket"]
websys-websocket = ["dep:libp2p-websys-websocket"]
webrtc = ["dep:libp2p-webrtc", "libp2p-webrtc?/pem"]
websocket = ["dep:libp2p-websocket"]
yamux = ["dep:libp2p-yamux"]
Expand Down Expand Up @@ -116,8 +118,8 @@ libp2p-rendezvous = { workspace = true, optional = true }
libp2p-request-response = { workspace = true, optional = true }
libp2p-swarm = { workspace = true }
libp2p-wasm-ext = { workspace = true, optional = true }
libp2p-websys-websocket = { version = "0.1.0", path = "../transports/websys-websocket", optional = true }
libp2p-yamux = { workspace = true, optional = true }

multiaddr = { version = "0.17.0" }
pin-project = "1.0.0"

Expand Down
10 changes: 9 additions & 1 deletion libp2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,16 @@ pub use libp2p_tls as tls;
#[doc(inline)]
pub use libp2p_uds as uds;
#[cfg(feature = "wasm-ext")]
#[deprecated(
note = "`wasm-ext` is deprecated and will be removed in favor of `libp2p-websys-websocket`."
)]
pub mod wasm_ext {
#[doc(inline)]
pub use libp2p_wasm_ext::*;
}
#[cfg(feature = "websys-websocket")]
#[doc(inline)]
pub use libp2p_wasm_ext as wasm_ext;
pub use libp2p_websys_websocket as websys_websocket;
#[cfg(feature = "webrtc")]
#[cfg_attr(docsrs, doc(cfg(feature = "webrtc")))]
#[cfg(not(target_arch = "wasm32"))]
Expand Down
3 changes: 3 additions & 0 deletions transports/websys-websocket/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.1.0 - unreleased

- Add Websys Websocket transport.
33 changes: 33 additions & 0 deletions transports/websys-websocket/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "libp2p-websys-websocket"
edition = "2021"
rust-version = "1.60.0"
description = "libp2p websocket transports for WASM browser runtime."
version = "0.1.0"
authors = ["Vince Vasta <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]

[dependencies]
futures = "0.3.26"
js-sys = "0.3.61"
libp2p-core = { version = "0.39", path = "../../core" }
parking_lot = "0.12.1"
send_wrapper = "0.6.0"
thiserror = "1.0.38"
wasm-bindgen = "0.2.84"
web-sys = { version = "0.3.61", features = ["BinaryType", "CloseEvent", "MessageEvent", "WebSocket"] }

[dev-dependencies]
libp2p-identity = { path = "../../identity" }
libp2p-noise = { path = "../noise" }
libp2p-yamux = { path = "../../muxers/yamux" }

# Passing arguments to the docsrs builder in order to properly document cfg's.
# More information: https://docs.rs/about/builds#cross-compiling
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
rustc-args = ["--cfg", "docsrs"]
Loading