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(webrtc): add WebRTC for WASM environments #4248

Merged
merged 256 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
256 commits
Select commit Hold shift + click to select a range
e215808
utils
DougAnderson444 Jul 24, 2023
19d20f1
fingerprint intial commit
DougAnderson444 Jul 24, 2023
10ca24c
errors init commit
DougAnderson444 Jul 24, 2023
1790f01
add FusedJsPromise
DougAnderson444 Jul 24, 2023
5d34fd3
It compiles (TM), more work to do
DougAnderson444 Jul 24, 2023
132c1e6
commit lockfile
DougAnderson444 Jul 24, 2023
15fa477
commit lockfile
DougAnderson444 Jul 24, 2023
a188e60
Merge branch 'websys-rtc' of https://github.com/DougAnderson444/rust-…
DougAnderson444 Jul 24, 2023
babd0da
Merge branch 'master' into websys-rtc
DougAnderson444 Jul 24, 2023
dd30772
add license = "MIT"
DougAnderson444 Jul 24, 2023
8e3a65e
rm unused code
DougAnderson444 Jul 24, 2023
ee537f2
corrections for ci
DougAnderson444 Jul 24, 2023
56e66da
add webrtc-websys-test-server
DougAnderson444 Jul 25, 2023
0302655
clean up deps for ci
DougAnderson444 Jul 25, 2023
74ca3c0
configure Manifest for split: tokio/websys
DougAnderson444 Jul 26, 2023
950569f
mv into /webrtc/websys path under feature flag
DougAnderson444 Jul 26, 2023
d1ee35e
add Fused Callback Future & maybe_init
DougAnderson444 Jul 26, 2023
4d4eae0
move state to common folder
DougAnderson444 Jul 26, 2023
fb6e3bc
add common mod
DougAnderson444 Jul 27, 2023
a3d281b
add libp2p-core to test
DougAnderson444 Jul 27, 2023
431dcfc
add dial server test
DougAnderson444 Jul 27, 2023
5248eaf
add logging to test server
DougAnderson444 Jul 31, 2023
16d8943
set up client test logging
DougAnderson444 Jul 31, 2023
ccfef61
create libp2p-webrtc-utils
DougAnderson444 Aug 2, 2023
ba5bf7f
move common out of webrtc/tokio
DougAnderson444 Aug 2, 2023
d237dc6
it handshakes
DougAnderson444 Aug 2, 2023
e3a78fd
restrict log
DougAnderson444 Aug 2, 2023
682151a
add to roadmap
DougAnderson444 Aug 2, 2023
312e724
use milliseconds
DougAnderson444 Aug 2, 2023
429f511
re-org names, folders, crates
DougAnderson444 Aug 2, 2023
bc45750
rm local utils module
DougAnderson444 Aug 2, 2023
65f9499
rm local utils import
DougAnderson444 Aug 2, 2023
0a8bb18
add WebRTC web-sys to interop tests
DougAnderson444 Aug 3, 2023
e8d97e3
rename Substream to Stream
DougAnderson444 Aug 4, 2023
7754bd9
use log::debug!
DougAnderson444 Aug 4, 2023
3aa336c
rename utils/stream
DougAnderson444 Aug 4, 2023
3d77c61
rename stream, address thomas' comments
DougAnderson444 Aug 4, 2023
976faef
refactor create data channel, rename stream
DougAnderson444 Aug 4, 2023
949b697
refactored DataChannel::new function
DougAnderson444 Aug 4, 2023
b13337f
rm comment
DougAnderson444 Aug 4, 2023
a040dc4
use WebRTCDirect
DougAnderson444 Aug 4, 2023
492fc63
only listen on non wasm32 arch
DougAnderson444 Aug 4, 2023
983e2d1
readme consistent with test-plans/multidim-interop
DougAnderson444 Aug 4, 2023
af4ecee
lock file
DougAnderson444 Aug 4, 2023
97b2085
add cfg windows guard for local testing
DougAnderson444 Aug 4, 2023
f78f88d
rm pub from utils
DougAnderson444 Aug 4, 2023
ac1c82a
reduce to two top-level free functions
DougAnderson444 Aug 4, 2023
c8995ac
fix log::debug, general cleanup
DougAnderson444 Aug 4, 2023
7af14f7
refactor log::debug
DougAnderson444 Aug 4, 2023
ac538ac
use new upgrade::outbound() fn
DougAnderson444 Aug 4, 2023
b0079d8
refactor log::debug
DougAnderson444 Aug 4, 2023
4b674d6
fix typo
DougAnderson444 Aug 4, 2023
052b6bb
sw to Localhost, rm WebRTCWebSys
DougAnderson444 Aug 5, 2023
190fc1b
fix buggy close sequence
DougAnderson444 Aug 5, 2023
5bdd56f
set readme to webrtc-direc naming
DougAnderson444 Aug 5, 2023
a749145
rename WebRTCStream to simply `Stream`
DougAnderson444 Aug 5, 2023
c982e13
rename WebRTCStream to simply `Stream`
DougAnderson444 Aug 5, 2023
e099807
convert `CbFutures` to `futures::Channel`
DougAnderson444 Aug 7, 2023
3f076b7
rm readme.md
DougAnderson444 Aug 7, 2023
efc2a3b
convert `CbFutures` to `futures::channel`
DougAnderson444 Aug 7, 2023
61cce46
refactor RtcDataChannelBuilder
DougAnderson444 Aug 7, 2023
e8d1f53
rm dead sdp code
DougAnderson444 Aug 7, 2023
de485ed
rm dead code
DougAnderson444 Aug 7, 2023
612732a
clean up logging
DougAnderson444 Aug 7, 2023
f957e4a
fix wasm Closure
DougAnderson444 Aug 9, 2023
bf7bf2a
add trace logging
DougAnderson444 Aug 9, 2023
b0229c1
convert to `try_send` and `log::trace`
DougAnderson444 Aug 9, 2023
5f34cc3
add example (so awesome seeing it in action)
DougAnderson444 Aug 9, 2023
73d3924
audit dependencies, rm unused
DougAnderson444 Aug 9, 2023
ec5cb38
correct naming: webrtc-direct
DougAnderson444 Aug 9, 2023
a34bc3b
update readme dialer instr
DougAnderson444 Aug 9, 2023
06824e8
revert chromedriver condition for windows
DougAnderson444 Aug 9, 2023
66852d8
mv ./stream/mod.rs to ./stream.rs
DougAnderson444 Aug 11, 2023
56baebf
test server formatting
DougAnderson444 Aug 15, 2023
254d67b
logging
DougAnderson444 Aug 15, 2023
ac23860
stream identifier for web-sys
DougAnderson444 Aug 15, 2023
68d0564
rm callback futures module
DougAnderson444 Aug 15, 2023
080c27e
rm unused dep
DougAnderson444 Aug 16, 2023
305dadf
mv sdp noise fngerprnt err to libp2p-webrtc-utils
DougAnderson444 Aug 16, 2023
de6098d
bump deps
DougAnderson444 Aug 16, 2023
e00166a
update ROADMAP
DougAnderson444 Aug 16, 2023
1618c49
asynchronous-codec = "0.6"
DougAnderson444 Aug 17, 2023
358b86c
commit lock file
DougAnderson444 Aug 17, 2023
7b8db4b
merge yamux from main
DougAnderson444 Aug 17, 2023
adbbe4e
Merge branch 'master' into websys-rtc
DougAnderson444 Aug 17, 2023
2e8c2e5
fix reqwest version
DougAnderson444 Aug 17, 2023
da71eb3
fix merge error
DougAnderson444 Aug 17, 2023
2913fbe
fix licences
DougAnderson444 Aug 17, 2023
01dd0ee
rm chrono dep
DougAnderson444 Aug 17, 2023
8842070
add trunk note
DougAnderson444 Aug 17, 2023
c825cc3
fix test
DougAnderson444 Aug 17, 2023
a55ea68
fix missing dep
DougAnderson444 Aug 17, 2023
7116393
commit lockfile
DougAnderson444 Aug 17, 2023
a37a727
fix formatting
DougAnderson444 Aug 17, 2023
d10203c
leptos uses nightly
DougAnderson444 Aug 17, 2023
12fdffa
fix test
DougAnderson444 Aug 17, 2023
97ed723
add rust-version.workspace
DougAnderson444 Aug 17, 2023
99cc8da
switch Leptos example to rust stable channel
DougAnderson444 Aug 18, 2023
ef6ebee
switch to Ipv6Addr::UNSPECIFIED for CI
DougAnderson444 Aug 18, 2023
b26046e
rust-version = { workspace = true }
DougAnderson444 Aug 18, 2023
1777566
cleanup & docs
DougAnderson444 Aug 18, 2023
f7ecb18
rename bin to webrtc-example-server
DougAnderson444 Aug 18, 2023
40b24e8
log, publish (false) and naming
DougAnderson444 Aug 18, 2023
66bbf6c
refactor example/client to vanilla wasm
DougAnderson444 Aug 19, 2023
6e0b93b
use bounded channel
DougAnderson444 Aug 19, 2023
7bb0884
cleanup
DougAnderson444 Aug 19, 2023
de88725
only spawn axum server once
DougAnderson444 Aug 19, 2023
6aa2cfe
update example readme to remove leptos refs
DougAnderson444 Aug 19, 2023
8aa139a
fix cargo categories, fix single line
DougAnderson444 Aug 19, 2023
e0c0ca4
rm dead comment
DougAnderson444 Aug 19, 2023
dc0d569
switch to `warn`
DougAnderson444 Aug 19, 2023
a562d18
fix cargo categories, single line
DougAnderson444 Aug 19, 2023
f6fb6fa
fixed formatting discrepancoes
DougAnderson444 Aug 20, 2023
75aed7f
revert tokio specific code back into webrtc crate
DougAnderson444 Aug 21, 2023
16f72a6
wasm specific code into webrtc-websys crate
DougAnderson444 Aug 21, 2023
049823c
rm unneeded comment
DougAnderson444 Aug 21, 2023
c5f5af8
set libp2p-webrtc = "0.7.0-alpha"
DougAnderson444 Aug 21, 2023
aa3b15a
use Fingerprint From
DougAnderson444 Aug 21, 2023
d424782
use wasm-logger
DougAnderson444 Aug 21, 2023
e37e985
simplify: remove remote addr option
DougAnderson444 Aug 21, 2023
9484a79
remove duplicate test folder
DougAnderson444 Aug 21, 2023
d82906f
rm utils feature tokio
DougAnderson444 Aug 21, 2023
2541c35
rm utils feature wasm-bindgen
DougAnderson444 Aug 21, 2023
1dbc906
update members to reflect removed folders
DougAnderson444 Aug 21, 2023
693ada7
move random_ufrag to libp2p-webrtc-utils
DougAnderson444 Aug 21, 2023
a5c0bdc
mv `parse_webrtc_dial_addr` to `utils`
DougAnderson444 Aug 24, 2023
50e9e9d
encapsulate utils in user crate sub modules
DougAnderson444 Aug 24, 2023
b02a560
mv env vars to `main.rs`
DougAnderson444 Aug 24, 2023
c018124
auto derive NetworkBehaviour, use libp2p path
DougAnderson444 Aug 24, 2023
bd808c5
impl From for `utils` errors (Public API)
DougAnderson444 Aug 24, 2023
6609c0b
single line deps
DougAnderson444 Aug 24, 2023
3c50865
add static and multiaddr servers
DougAnderson444 Aug 24, 2023
0419302
apply loop improvement, use server module
DougAnderson444 Aug 24, 2023
919863b
update example readme
DougAnderson444 Aug 24, 2023
a1dca96
minimize diff
DougAnderson444 Aug 24, 2023
21833e3
fix small example stuff
DougAnderson444 Aug 24, 2023
328ea89
minimize diff
DougAnderson444 Aug 24, 2023
be50b1f
fixes for minimal diff
DougAnderson444 Aug 25, 2023
4f4c5cc
rm extraneous logging
DougAnderson444 Aug 28, 2023
d355a43
implement `DropListener` logic
DougAnderson444 Aug 28, 2023
36871f7
Merge branch 'master' into websys-rtc
DougAnderson444 Aug 28, 2023
f993450
imporve example loop logic
DougAnderson444 Aug 28, 2023
8b3a400
cleaner deps
DougAnderson444 Aug 28, 2023
b9e55c4
fix clippy
DougAnderson444 Aug 29, 2023
f650469
set time@0.3.23 to support rustc v1.65
DougAnderson444 Aug 29, 2023
14cd90f
fix more clippy errors
DougAnderson444 Aug 29, 2023
464faea
rm panic error logging
DougAnderson444 Aug 29, 2023
82c862b
substreams as streams everywhere
DougAnderson444 Aug 29, 2023
092dc57
revert auto formatting
DougAnderson444 Aug 29, 2023
5ddd2ca
revert auto formatting
DougAnderson444 Aug 29, 2023
2769297
Merge branch 'websys-rtc' of https://github.com/DougAnderson444/rust-…
DougAnderson444 Aug 29, 2023
ac60389
fix rustdoc error
DougAnderson444 Aug 29, 2023
4d8af29
add/update CHANGELOGs & README
DougAnderson444 Aug 29, 2023
0e1c189
Reduce diff
thomaseizinger Aug 31, 2023
f584f39
Reduce diff on lockfile
thomaseizinger Aug 31, 2023
ed811ac
Use single line dependency syntax
thomaseizinger Aug 31, 2023
d93d453
Remove unnecessary whitespace
thomaseizinger Aug 31, 2023
3e7865e
Init logger directly instead of setting var
thomaseizinger Aug 31, 2023
4457789
Reduce to 1 HTTP server
thomaseizinger Aug 31, 2023
69e3e86
Remove infallible error
thomaseizinger Aug 31, 2023
d8a09d9
Remove `.html` fallback
thomaseizinger Aug 31, 2023
f5be65d
Inline into 1 file
thomaseizinger Aug 31, 2023
c7e2f73
Convention over configuration
thomaseizinger Aug 31, 2023
716fd75
Print address where we are server the client
thomaseizinger Aug 31, 2023
19c4af3
Break from loop if channel is disconnected
thomaseizinger Aug 31, 2023
3a13278
Use `thiserror`
thomaseizinger Aug 31, 2023
1820e7e
Inline `error.rs` file
thomaseizinger Aug 31, 2023
31ae801
Add newline to end of files
thomaseizinger Aug 31, 2023
0b21a3f
Have event loop block `fn main`
thomaseizinger Aug 31, 2023
3546f56
Simplify `fetch_server_addr`
thomaseizinger Aug 31, 2023
8fec2e5
Fix docs
thomaseizinger Aug 31, 2023
c0d74d3
Remove feature that should not be set for libraries
thomaseizinger Aug 31, 2023
2643b73
Update transports/webrtc-websys/CHANGELOG.md
DougAnderson444 Aug 31, 2023
4ca20fb
Merge branch 'master' into websys-rtc
DougAnderson444 Aug 31, 2023
681994f
Switch back to IPv4 for interop-tests
thomaseizinger Sep 1, 2023
99fb67d
Update instructions for webrtc-direct
thomaseizinger Sep 1, 2023
aab3c78
Extend instructions with redis
thomaseizinger Sep 1, 2023
6619124
Remove unused imports
thomaseizinger Sep 3, 2023
7182dcf
Merge branch 'master' into websys-rtc
thomaseizinger Sep 3, 2023
fdf106a
Simplify wasm code
thomaseizinger Sep 3, 2023
6a377dd
Merge client and server into one crate
thomaseizinger Sep 3, 2023
e00da70
Remove need for fetching address
thomaseizinger Sep 3, 2023
09317d0
Merge branch 'master' into websys-rtc
thomaseizinger Sep 5, 2023
311062b
Remove `stream_identifier` hack
thomaseizinger Sep 5, 2023
0180da7
Simplify `PollDataChannel` implementation
thomaseizinger Sep 5, 2023
d89ebe1
Ensure DC is ready for writing
thomaseizinger Sep 5, 2023
863647d
Don't leak closures and make them FnMuts
thomaseizinger Sep 5, 2023
d7930d2
Unify `Stream` implementations
thomaseizinger Sep 5, 2023
dd1e8a0
Retain read_buf_capacity for native WebRTC impl
thomaseizinger Sep 5, 2023
507ce67
Unify SPF answer creation
thomaseizinger Sep 5, 2023
8230ca5
Polish SDP creation
thomaseizinger Sep 5, 2023
519a48b
Tidy up upgrade process by introducing wrapper for web_sys object
thomaseizinger Sep 5, 2023
75fcbdf
Tidy comments and fn names
thomaseizinger Sep 5, 2023
91ca28e
Tidy up new data channel creation
thomaseizinger Sep 5, 2023
66fdf45
Rename field
thomaseizinger Sep 5, 2023
2240f7b
Don't leak closure
thomaseizinger Sep 5, 2023
33f412c
Remove `ConnectionInner`
thomaseizinger Sep 5, 2023
8fb2600
Merge branch 'master' into websys-rtc
thomaseizinger Sep 5, 2023
2e758ab
Restore public API of `libp2p-webrtc`
thomaseizinger Sep 5, 2023
70a2ff3
Minimize diff and get rid of shared error
thomaseizinger Sep 5, 2023
f7d2cb1
Reduce diff
thomaseizinger Sep 5, 2023
c6418df
Reduce `libp2p-webrtc` version to 0.6.1-alpha
thomaseizinger Sep 5, 2023
2499b9f
Reduce diff
thomaseizinger Sep 5, 2023
771ff81
Update lockfile
thomaseizinger Sep 5, 2023
2141fea
Minimize deps
thomaseizinger Sep 5, 2023
ddc1f1d
Move `libp2p-webrtc-utils`to `misc/`
thomaseizinger Sep 5, 2023
3c08227
Merge branch 'master' into websys-rtc
DougAnderson444 Sep 5, 2023
3bb4c53
Update `Cargo.lock`
thomaseizinger Sep 5, 2023
3d50096
Temporarily set `publish = false`
thomaseizinger Sep 5, 2023
8129cb7
Appease clippy
thomaseizinger Sep 5, 2023
92d8f89
Misc fixes to reduce diff / duplication
thomaseizinger Sep 5, 2023
30a0026
Reduce diff
thomaseizinger Sep 5, 2023
5845556
Merge branch 'master' into websys-rtc
thomaseizinger Sep 5, 2023
09055f4
Fix compile error
thomaseizinger Sep 6, 2023
03edec6
rm LICENSE fm example
DougAnderson444 Sep 6, 2023
244a157
add 'description', 'repository' to Cargo.toml
DougAnderson444 Sep 6, 2023
7c56d57
more loquacious comment about content serving
DougAnderson444 Sep 6, 2023
a77603e
Swarm with a capital `S` in README
DougAnderson444 Sep 6, 2023
9e41d00
use `.expect()` instead of `.unwrap()`
DougAnderson444 Sep 6, 2023
870045a
allow `non_upper_case_globals` for rust_embed
DougAnderson444 Sep 6, 2023
4dd3bd1
Fail connection on overload
thomaseizinger Sep 8, 2023
d26864f
Rename function and add docs
thomaseizinger Sep 8, 2023
470fab7
Add docs for `overloaded`
thomaseizinger Sep 8, 2023
ed01381
remove old comment about being "unimplemented"
DougAnderson444 Sep 8, 2023
6c859fa
Merge branch 'master' into websys-rtc
DougAnderson444 Sep 8, 2023
5ec051b
Merge branch 'websys-rtc' of https://github.com/DougAnderson444/rust-…
DougAnderson444 Sep 8, 2023
8505d0d
check if local firefox
DougAnderson444 Sep 8, 2023
75e25b5
use `Ipv6Addr::UNSPECIFIED` instead of `LOCALHOST`
DougAnderson444 Sep 8, 2023
a880251
send reset signal when read Error occurs
DougAnderson444 Sep 8, 2023
fc26ded
set repo to lowercase in docker .yml
DougAnderson444 Sep 8, 2023
8c23eb1
set repo to lowercase in docker .yml
DougAnderson444 Sep 8, 2023
a24d4ed
set REPO to lowercase in docker-image.yml
DougAnderson444 Sep 8, 2023
55b651d
use github env var in docker yml
DougAnderson444 Sep 8, 2023
dd04b4f
Merge branch 'websys-rtc'
DougAnderson444 Sep 8, 2023
4a14e74
add coverage for hostname as IPv6
DougAnderson444 Sep 8, 2023
e3896b8
remove duplicate REPO naming in yml
DougAnderson444 Sep 8, 2023
c4693f0
fix rustdoc hyperlink
DougAnderson444 Sep 8, 2023
65c027b
update webpki 0.22.1 for RUSTSEC-2023-0052
DougAnderson444 Sep 8, 2023
5d30cbf
publish=false, temp fix to CI semver-checks-action
DougAnderson444 Sep 8, 2023
66e7844
Merge branch 'master' into websys-rtc
thomaseizinger Sep 11, 2023
952160e
Make example work in Firefox
thomaseizinger Sep 11, 2023
5d22479
Don't set waker on connection shutdown
thomaseizinger Sep 11, 2023
f4d2ecf
Remove unused import
thomaseizinger Sep 11, 2023
7a2eda1
revert docker.yml casing change
DougAnderson444 Sep 12, 2023
6e3cfe6
Merge branch 'master' into websys-rtc
thomaseizinger Sep 12, 2023
a0abc3e
Merge branch 'master' into websys-rtc
thomaseizinger Sep 12, 2023
1c9f0a7
Merge branch 'master' into websys-rtc
thomaseizinger Sep 12, 2023
0e331a4
Merge branch 'master' into websys-rtc
thomaseizinger Sep 13, 2023
46876ad
revert commit a880251 (send Reset)
Sep 17, 2023
0a74524
Merge branch 'master' into websys-rtc
DougAnderson444 Sep 17, 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
514 changes: 252 additions & 262 deletions Cargo.lock
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ members = [
"transports/websocket",
"transports/webtransport-websys",
"wasm-tests/webtransport-tests",
"wasm-tests/webrtc",
"wasm-tests/webrtc/server",
DougAnderson444 marked this conversation as resolved.
Show resolved Hide resolved
]
resolver = "2"

Expand Down Expand Up @@ -104,7 +106,7 @@ quickcheck = { package = "quickcheck-ext", path = "misc/quickcheck-ext" }
rw-stream-sink = { version = "0.4.0", path = "misc/rw-stream-sink" }
multiaddr = "0.18.0"
multihash = "0.19.0"

webrtc-websys-test-server = { version = "0.1.0", path = "wasm-tests/webrtc/server" }

[patch.crates-io]

Expand Down
58 changes: 52 additions & 6 deletions transports/webrtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,74 @@ bytes = "1"
futures = "0.3"
futures-timer = "3"
hex = "0.4"
if-watch = "3.0"
libp2p-core = { workspace = true }
libp2p-noise = { workspace = true }
libp2p-identity = { workspace = true }
log = "0.4"
sha2 = "0.10.7"
multihash = { workspace = true }
multihash = { workspace = true }
quick-protobuf = "0.8"
quick-protobuf-codec = { workspace = true }
rand = "0.8"
rcgen = "0.10.0"
serde = { version = "1.0", features = ["derive"] }
stun = "0.4"
thiserror = "1"
tinytemplate = "1.2"
tokio = { version = "1.29", features = ["net"], optional = true}

# tokio optional deps
tokio = { version = "1.29", features = ["net"], optional = true }
tokio-util = { version = "0.7", features = ["compat"], optional = true }
webrtc = { version = "0.8.0", optional = true }
stun = { version = "0.4", optional = true }
rand = { version = "0.8", optional = true }
if-watch = { version = "3.0", optional = true }

# wasm-bindgen optional deps
js-sys = { version = "0.3", optional = true }
getrandom = { version = "0.2.9", features = ["js"], optional = true }
regex = { version = "1.9", optional = true }
send_wrapper = { version = "0.6.0", features = ["futures"], optional = true }
wasm-bindgen = { version = "0.2.87", optional = true }
wasm-bindgen-futures = { version = "0.4.37", optional = true }
web-sys = { version = "0.3.64", optional = true, features = [
"MessageEvent",
"RtcPeerConnection",
"RtcSignalingState",
"RtcSdpType",
"RtcSessionDescription",
"RtcSessionDescriptionInit",
"RtcPeerConnectionIceEvent",
"RtcIceCandidate",
"RtcDataChannel",
"RtcDataChannelEvent",
"RtcCertificate",
"RtcConfiguration",
"RtcDataChannelInit",
"RtcDataChannelType",
"RtcDataChannelState",
] }

[features]
tokio = ["dep:tokio", "dep:tokio-util", "dep:webrtc", "if-watch/tokio"]
tokio = [
"dep:tokio",
"dep:tokio-util",
"dep:webrtc",
"dep:if-watch",
"if-watch/tokio",
"dep:rand",
"dep:stun",
]
pem = ["webrtc?/pem"]
wasm-bindgen = [
"dep:js-sys",
"dep:getrandom",
"dep:regex",
"dep:send_wrapper",
"dep:wasm-bindgen",
"dep:wasm-bindgen-futures",
"dep:web-sys",
"futures-timer/wasm-bindgen",
]


[dev-dependencies]
anyhow = "1.0"
Expand Down
1 change: 1 addition & 0 deletions transports/webrtc/src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod substream;
14 changes: 14 additions & 0 deletions transports/webrtc/src/common/substream/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub(crate) mod state;

/// Maximum length of a message.
///
/// "As long as message interleaving is not supported, the sender SHOULD limit the maximum message
/// size to 16 KB to avoid monopolization."
/// Source: <https://www.rfc-editor.org/rfc/rfc8831#name-transferring-user-data-on-a>
pub(crate) const MAX_MSG_LEN: usize = 16384; // 16kiB
/// Length of varint, in bytes.
pub(crate) const VARINT_LEN: usize = 2;
/// Overhead of the protobuf encoding, in bytes.
pub(crate) const PROTO_OVERHEAD: usize = 5;
/// Maximum length of data, in bytes.
pub(crate) const MAX_DATA_LEN: usize = MAX_MSG_LEN - VARINT_LEN - PROTO_OVERHEAD;
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
6 changes: 6 additions & 0 deletions transports/webrtc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ mod proto {

#[cfg(feature = "tokio")]
pub mod tokio;

#[cfg(feature = "wasm-bindgen")]
pub mod websys;

/// Crates common to all features
mod common;
26 changes: 7 additions & 19 deletions transports/webrtc/src/tokio/substream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,15 @@ use std::{
task::{Context, Poll},
};

use crate::proto::{Flag, Message};
use crate::tokio::{
substream::drop_listener::GracefullyClosed,
substream::framed_dc::FramedDc,
substream::state::{Closing, State},
use crate::common::substream::{
state::{Closing, State},
MAX_DATA_LEN,
};
use crate::proto::{Flag, Message};
use crate::tokio::{substream::drop_listener::GracefullyClosed, substream::framed_dc::FramedDc};

mod drop_listener;
mod framed_dc;
mod state;

/// Maximum length of a message.
///
/// "As long as message interleaving is not supported, the sender SHOULD limit the maximum message
/// size to 16 KB to avoid monopolization."
/// Source: <https://www.rfc-editor.org/rfc/rfc8831#name-transferring-user-data-on-a>
const MAX_MSG_LEN: usize = 16384; // 16kiB
/// Length of varint, in bytes.
const VARINT_LEN: usize = 2;
/// Overhead of the protobuf encoding, in bytes.
const PROTO_OVERHEAD: usize = 5;
/// Maximum length of data, in bytes.
const MAX_DATA_LEN: usize = MAX_MSG_LEN - VARINT_LEN - PROTO_OVERHEAD;

pub(crate) use drop_listener::DropListener;
/// A substream on top of a WebRTC data channel.
Expand Down Expand Up @@ -251,6 +237,8 @@ fn io_poll_next(

#[cfg(test)]
mod tests {
use crate::common::substream::{MAX_MSG_LEN, PROTO_OVERHEAD, VARINT_LEN};

use super::*;
use asynchronous_codec::Encoder;
use bytes::BytesMut;
Expand Down
5 changes: 4 additions & 1 deletion transports/webrtc/src/tokio/substream/framed_dc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use webrtc::data::data_channel::{DataChannel, PollDataChannel};

use std::sync::Arc;

use super::{MAX_DATA_LEN, MAX_MSG_LEN, VARINT_LEN};
use crate::common::substream::{
state::{Closing, State},
MAX_DATA_LEN, MAX_MSG_LEN, VARINT_LEN,
};
use crate::proto::Message;

pub(crate) type FramedDc = Framed<Compat<PollDataChannel>, quick_protobuf_codec::Codec<Message>>;
Expand Down
98 changes: 98 additions & 0 deletions transports/webrtc/src/websys/cbfutures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
use futures::FutureExt;
use std::cell::Cell;
use std::future::Future;
use std::pin::Pin;
use std::rc::Rc;
use std::task::{ready, Context, Poll, Waker};

pub struct FusedCbFuture<T>(Option<CbFuture<T>>);

impl<T> FusedCbFuture<T> {
pub(crate) fn new() -> Self {
Self(None)
}

pub(crate) fn maybe_init<F>(&mut self, init: F) -> &mut Self
where
F: FnOnce() -> CbFuture<T>,
{
if self.0.is_none() {
self.0 = Some(init());
}

self
}

/// Checks if future is already running
pub(crate) fn is_active(&self) -> bool {
self.0.is_some()
}
}

#[derive(Clone, Debug)]
pub struct CbFuture<T>(Rc<CallbackFutureInner<T>>);

struct CallbackFutureInner<T> {
waker: Cell<Option<Waker>>,
result: Cell<Option<T>>,
}

impl<T> std::fmt::Debug for CallbackFutureInner<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CallbackFutureInner").finish()
}
}

impl<T> Default for CallbackFutureInner<T> {
fn default() -> Self {
Self {
waker: Cell::new(None),
result: Cell::new(None),
}
}
}

impl<T> CbFuture<T> {
/// New Callback Future
pub(crate) fn new() -> Self {
Self(Rc::new(CallbackFutureInner::<T>::default()))
}

// call this from your callback
pub(crate) fn publish(&self, result: T) {
self.0.result.set(Some(result));
if let Some(w) = self.0.waker.take() {
w.wake()
};
}
}

impl<T> Future for CbFuture<T> {
type Output = T;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.0.result.take() {
Some(x) => Poll::Ready(x),
None => {
self.0.waker.set(Some(cx.waker().clone()));
Poll::Pending
}
}
}
}

impl<T> Future for FusedCbFuture<T> {
type Output = T;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let val = ready!(self
.0
.as_mut()
.expect("FusedCbFuture not initialized")
.poll_unpin(cx));

// Future finished, drop it
self.0.take();

Poll::Ready(val)
}
}
Loading
Loading