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 WebRTC transport #2622

Merged
merged 264 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
264 commits
Select commit Hold shift + click to select a range
3c7f796
fix feature syntax err
melekes Jun 29, 2022
d5b2e09
enable webrtc by default (temporary)
melekes Jun 29, 2022
bd8091f
Revert "enable webrtc by default (temporary)"
melekes Jun 30, 2022
6d703f8
add libp2p_webrtc to libp2p
melekes Jun 30, 2022
64d60e9
fix ErrShortBuffer error by increasing the temporary buffer size
melekes Jul 11, 2022
e8207f9
Merge branch 'master' into anton/webrtc-transport
melekes Jul 11, 2022
d96b499
update to support new Transport interface
melekes Jul 11, 2022
0e5b812
remove unused func and cleanup imports
melekes Jul 12, 2022
809d23e
remove commented methods
melekes Jul 12, 2022
a31f1bf
uncomment flushing and closing in poll_close
melekes Jul 12, 2022
414f945
refactor in_addr and listeners
melekes Jul 13, 2022
84c5461
support ipv6 as well
melekes Jul 13, 2022
66f6c78
format code
melekes Jul 14, 2022
8ca428c
disable fingerprint verification on server side
melekes Jul 15, 2022
802c012
Merge branch 'master' into anton/webrtc-transport
melekes Jul 18, 2022
cf2c11d
flatten StreamMuxer interface
melekes Jul 18, 2022
35bc4eb
get rid of `loop` in UDPMuxNewAddr
melekes Jul 19, 2022
212936f
brush up code
melekes Jul 21, 2022
4643359
add close_listener test
melekes Jul 21, 2022
e32aa57
updates after @thomaseizinger review
melekes Jul 22, 2022
cd7786f
extract webrtc related logic into a sep mod
melekes Jul 23, 2022
8306743
extract perform_noise_handshake fn
melekes Jul 25, 2022
136edc2
fix addr in smoke test
melekes Jul 25, 2022
6a11aa0
generate random ufrag when connecting
melekes Jul 25, 2022
d0c95a4
updates after @mxinden review
melekes Jul 26, 2022
ef5e306
return None in WebRTCListenStream when udp_mux is closed
melekes Jul 26, 2022
04542f8
revert ef5e3065
melekes Jul 26, 2022
273bd2c
fix doc links
melekes Jul 26, 2022
5abaec4
introduce WebRTCConfiguration wrapper
melekes Jul 27, 2022
a4e7be4
perform_noise_handshake over abstract AsyncRead/Write
melekes Jul 27, 2022
29ff7c9
poll API fro UDPMuxNewAddr
melekes Jul 28, 2022
da94baf
add Fingerprint type
melekes Jul 29, 2022
385c51e
updates after @thomaseizinger review
melekes Jul 29, 2022
ecf7250
simplify create_initial_upgrade_data_channel negotiated arg
melekes Jul 29, 2022
e781ef5
closed detached channel if failed to send
melekes Aug 1, 2022
f5f930f
fix smoke test
melekes Aug 2, 2022
604fcc8
reset outbound_fut and close_fut
melekes Aug 3, 2022
8bd8233
add concurrent_connections_and_streams test
melekes Aug 3, 2022
9821580
Merge branch 'master' into anton/webrtc-transport
melekes Aug 3, 2022
59894fb
get rid of ConnectionInner
melekes Aug 3, 2022
b770a04
point webrtc and webrtc-data crates to master (temp)
melekes Aug 4, 2022
59617de
transports/webrtc/: Test message framing sizes
mxinden Aug 19, 2022
7dc3ce1
transports/webrtc/: Implement message framing
mxinden Aug 22, 2022
503e32f
transports/webrtc: Update protobuf
mxinden Aug 22, 2022
59e0ded
transports/webrtc/: Remove pin_project dependency (#2)
mxinden Aug 29, 2022
a2c74c6
get rid of negotiated arg
melekes Aug 29, 2022
3effb2e
Reduce webrtc dependency to a single one (#3)
thomaseizinger Aug 29, 2022
71e56dd
multiaddr 0.15 (master)
melekes Aug 31, 2022
38175fd
Refactor `UdpMuxNewAddr` to be lock-less (#1)
thomaseizinger Aug 31, 2022
9ff67a3
update webrtc version
melekes Sep 2, 2022
9b1547d
Don't use versions for dev-dependencies (#6)
thomaseizinger Sep 2, 2022
91df66c
Remove unnecessary `async` from `create_swarm` (#5)
thomaseizinger Sep 2, 2022
8d0006b
fix smoke test
melekes Sep 2, 2022
bcdb4ef
Merge branch 'master' into anton/webrtc-transport
melekes Sep 2, 2022
6399627
Connection: rename poll_address_change to poll
melekes Sep 2, 2022
22e97a0
Merge remote-tracking branch 'melekes/anton/webrtc-transport' into we…
mxinden Sep 5, 2022
55da918
transports/webrtc/: Change semantic of RESET
mxinden Sep 5, 2022
a2ae49f
sdp: move pub functions up
melekes Sep 5, 2022
31ae422
simplify IfWatcher integration
melekes Sep 5, 2022
e0fe0de
Fix `dial_failure` test
thomaseizinger Sep 6, 2022
2163b4b
Fix clippy warnings
thomaseizinger Sep 6, 2022
4b23256
Revert "Fix `dial_failure` test"
thomaseizinger Sep 6, 2022
23e779b
Fix more clippy lints
thomaseizinger Sep 6, 2022
44506ee
Make `concurrent_connections_and_streams` pass by not using quickcheck
thomaseizinger Sep 6, 2022
bb29c7a
Fix intra doc link and adjust docs
thomaseizinger Sep 6, 2022
11c016f
transports/webrtc/: Import message_proto types
mxinden Sep 10, 2022
1a6e4bd
transports/webrtc/: Refactor AsyncRead match arm
mxinden Sep 10, 2022
d46a171
transports/webrtc/: Handle flags when read side closed
mxinden Sep 10, 2022
9cd4ef7
transports/webrtc: Enforce maximum message length
mxinden Sep 11, 2022
3a46fd0
upgrade webrtc-rs to 0.5.0
melekes Sep 12, 2022
af76971
Merge remote-tracking branch 'upstream/master' into anton/webrtc-tran…
melekes Sep 12, 2022
018854d
fix Fingerprint::to_ufrag
melekes Sep 14, 2022
31e019a
minor refactoring
melekes Sep 19, 2022
6f57ed6
rename PollDataChannel to Substream
melekes Sep 19, 2022
421a8ec
Merge branch 'master' into webrtc-message-framing
melekes Sep 19, 2022
4a1d4d6
add comments
melekes Sep 19, 2022
c6c5a96
add debug to handle_flag
melekes Sep 20, 2022
3d1d2f1
Merge branch 'master' into anton/webrtc-transport
melekes Sep 22, 2022
7e630a6
use newly added NoiseConfig::with_prologue
melekes Sep 22, 2022
2868d48
use into_authenticated fn
melekes Sep 22, 2022
0c45291
Slim down public interface of `libp2p-webrtc`
thomaseizinger Sep 23, 2022
bbd7e75
Remove `Fingerprint` argument from `render_client_session_description`
thomaseizinger Sep 23, 2022
e84eb7b
Refactor `Fingerprint` type
thomaseizinger Sep 23, 2022
c709da9
Add test for noise_prologue
thomaseizinger Sep 23, 2022
6ddf754
Remove `dbg!`
thomaseizinger Sep 23, 2022
299575f
Fix tests not compiling
thomaseizinger Sep 23, 2022
d3da8f7
Don't use magic constants
thomaseizinger Sep 23, 2022
5b44aca
Only pass fingerprint to `render_server_session_description`
thomaseizinger Sep 23, 2022
b052190
Fix clippy
thomaseizinger Sep 23, 2022
1b0b671
Create noise-prologue from server + client FP in fixed order
thomaseizinger Sep 26, 2022
aa38c81
Make `substream` a top-level module
thomaseizinger Sep 27, 2022
d0e918b
Replace nightly feature with refactoring
thomaseizinger Sep 27, 2022
171c613
Remove use of import rename
thomaseizinger Sep 27, 2022
cb481a6
Merge branch 'anton/webrtc-transport' into webrtc-message-framing
thomaseizinger Sep 27, 2022
6402665
Remove unused public API
thomaseizinger Sep 27, 2022
d537696
Make sure we don't construct substreams outside of this crate
thomaseizinger Sep 27, 2022
c8c2446
Don't expose public APIs for temporary workarounds
thomaseizinger Sep 27, 2022
d58f219
Remove pub where not necessary
thomaseizinger Sep 27, 2022
eb09d36
Remove utilities below usage
thomaseizinger Sep 27, 2022
99af2a1
Remove stale derive
thomaseizinger Sep 27, 2022
2d85ab4
Update docs
thomaseizinger Sep 27, 2022
6e2aeb1
Fix clippy warnings
thomaseizinger Sep 27, 2022
2c900b5
change noise channel ID to 0
melekes Sep 28, 2022
226f293
only allow one addr per ufrag
melekes Sep 28, 2022
a6b2aac
Revert "Create noise-prologue from server + client FP in fixed order"
thomaseizinger Oct 6, 2022
afac31c
Merge branch 'master' into webrtc-message-framing
thomaseizinger Oct 7, 2022
71c390f
Merge branch 'master' into anton/webrtc-transport
thomaseizinger Oct 7, 2022
d5dcdd1
Update to latest core and noise version
thomaseizinger Oct 7, 2022
b43f861
Don't call `Transport::map` via trait
thomaseizinger Oct 7, 2022
fcf55b2
Append certhash to emitted listen address
thomaseizinger Oct 7, 2022
979b179
Remove unnecessary `pub`
thomaseizinger Oct 7, 2022
1055efc
Follow naming convention of other transports
thomaseizinger Oct 7, 2022
c5ca42d
Don't require users to generate a certificate themselves
thomaseizinger Oct 7, 2022
0942424
Only calculate fingerprint once
thomaseizinger Oct 7, 2022
e59b93b
Use naming convention of other transports
thomaseizinger Oct 7, 2022
2133789
Remove `Fingerprint` from public API
thomaseizinger Oct 7, 2022
87f138b
Move utilities to the bottom of the file
thomaseizinger Oct 7, 2022
7fc56ed
Be consistent in how we import symbols
thomaseizinger Oct 7, 2022
969d037
Parse certhash before starting dial
thomaseizinger Oct 7, 2022
5e7b964
Refactor multiaddr parsing
thomaseizinger Oct 7, 2022
268d0fc
Remove unused error variant
thomaseizinger Oct 7, 2022
ba71d9b
Don't use `#[from]` if we never use it
thomaseizinger Oct 7, 2022
7452c4b
Don't repeat `Error` name in variant
thomaseizinger Oct 7, 2022
15a09ad
Rename noise error variant and improve printed log
thomaseizinger Oct 7, 2022
69e2f59
Don't have errors print their inner source
thomaseizinger Oct 7, 2022
d0a0bb6
Straight up require addresses to specify a peer ID
thomaseizinger Oct 7, 2022
3d38e93
Move noise upgrades to dedicated module
thomaseizinger Oct 7, 2022
43eb42a
Have `WebRTCConnection::{accept,connect}` to the entire upgrade
thomaseizinger Oct 7, 2022
a989577
Make `setting_engine` a free function
thomaseizinger Oct 7, 2022
d5e67c2
Move `WebRTCConnection` to `upgrade` module
thomaseizinger Oct 7, 2022
410fc77
Simplify call to `WebRTCConnection::connect`
thomaseizinger Oct 7, 2022
d363369
Inline `upgrade` function
thomaseizinger Oct 7, 2022
7108323
Fix imports and modules
thomaseizinger Oct 7, 2022
41f7ab1
Remove unnecessary path prefix
thomaseizinger Oct 7, 2022
0ba6954
Get rid of `WebRTCConnection` object
thomaseizinger Oct 7, 2022
9e3c1db
Extract helper for creating random ufrag
thomaseizinger Oct 7, 2022
88c29fb
Extract helpers for new connections
thomaseizinger Oct 7, 2022
a2136c9
Inline `api` variable
thomaseizinger Oct 7, 2022
116e498
Don't use boolean arguments when we can match on an enum
thomaseizinger Oct 7, 2022
2935ca7
Only set read_buf_capacity once
thomaseizinger Oct 7, 2022
033e485
Close data channel before verifying peer ID
thomaseizinger Oct 7, 2022
c5c5b8d
Improve variable naming
thomaseizinger Oct 7, 2022
ef45b58
Directly return RTCSessionDescription from `sdp` module
thomaseizinger Oct 7, 2022
d4c89bf
Remove unnecessary `pub(crate)`
thomaseizinger Oct 7, 2022
4795f81
Consistent structure between inbound and outbound fns
thomaseizinger Oct 7, 2022
e0bec13
Consistent logging
thomaseizinger Oct 7, 2022
ba961c3
Remove log before noise handshake
thomaseizinger Oct 7, 2022
f5f4476
Inline `ufrag` variable
thomaseizinger Oct 7, 2022
f643e09
Improve naming of `sdp` module functions
thomaseizinger Oct 7, 2022
8a74009
Remove superfluous comments
thomaseizinger Oct 7, 2022
b9917d5
Replace `select` macro with `select` fn
thomaseizinger Oct 7, 2022
f5d105e
Close noise data channel as part of upgrade
thomaseizinger Oct 7, 2022
d4448ad
Group creation of arguments to next fn together
thomaseizinger Oct 7, 2022
afa35bb
Remove need for comment by renaming function
thomaseizinger Oct 7, 2022
030d210
Remove outdated comment
thomaseizinger Oct 7, 2022
ceba78e
Perform peer ID check outside of ugprade functions
thomaseizinger Oct 7, 2022
ed9fad1
Remove WebRTC prefix
thomaseizinger Oct 7, 2022
06be476
Remove wrong log
thomaseizinger Oct 7, 2022
5d20a00
Don't import log macros
thomaseizinger Oct 7, 2022
52c9705
Inline variable
thomaseizinger Oct 7, 2022
afaaea9
Remove duplicate logging
thomaseizinger Oct 7, 2022
c032343
Remove duplication in constructing local addr
thomaseizinger Oct 7, 2022
3d44ac4
Better use of whitespace
thomaseizinger Oct 7, 2022
e98a981
Remove superfluous logs
thomaseizinger Oct 7, 2022
f5095a0
Remove duplication in `poll_if_watcher`
thomaseizinger Oct 7, 2022
09235a3
Remove unnecessary functions from `Config`
thomaseizinger Oct 7, 2022
b2cee23
Reduce boilerplate in `do_listen`
thomaseizinger Oct 7, 2022
dce2371
Inline `do_listen`
thomaseizinger Oct 7, 2022
577a24e
Less verbose error mapping
thomaseizinger Oct 7, 2022
fab5a32
Inline `webrtc` in `full` feature
thomaseizinger Oct 7, 2022
316052c
Log new connections on debug
thomaseizinger Oct 7, 2022
ee8fe4e
Make noise module private
thomaseizinger Oct 7, 2022
c5b86d7
Move test utils to bottom
thomaseizinger Oct 7, 2022
db45602
Fix formatting issues
thomaseizinger Oct 7, 2022
85aa4ef
Fix clippy lints
thomaseizinger Oct 7, 2022
8709473
Merge branch 'master' into anton/webrtc-transport
melekes Oct 10, 2022
f6431fb
remove TODO
melekes Oct 10, 2022
8266fc4
Merge remote-tracking branch 'melekes/anton/webrtc-transport' into we…
thomaseizinger Oct 11, 2022
d2da793
Add initial test suite for substream state machine
thomaseizinger Oct 11, 2022
1b520a9
Precompute substream ID
thomaseizinger Oct 11, 2022
e483974
Implement new state machine
thomaseizinger Oct 11, 2022
29d6f74
Reset flag clears buffer
thomaseizinger Oct 11, 2022
d829fda
Remove substream ID
thomaseizinger Oct 11, 2022
058a153
Remove use of `map_err`
thomaseizinger Oct 11, 2022
e1df3c4
Replace error with `Poll::Pending`
thomaseizinger Oct 11, 2022
8c8feaa
Remove unnecessary dependency
thomaseizinger Oct 11, 2022
e6c177c
Group imports
thomaseizinger Oct 11, 2022
b2961a0
Add spec wording to constant
thomaseizinger Oct 11, 2022
f827f62
Introduce dedicated `State` submodule
thomaseizinger Oct 11, 2022
16433db
Send reset flag for dropped substreams
thomaseizinger Oct 11, 2022
834ec64
Fix clippy warnings
thomaseizinger Oct 11, 2022
7e0e46d
Fix docs
thomaseizinger Oct 11, 2022
225453b
Merge pull request #10 from libp2p/webrtc-message-framing
melekes Oct 12, 2022
35e2c50
fixed order for fingerprints in Noise prologue
melekes Oct 11, 2022
de191a6
reverse the noise roles
melekes Oct 11, 2022
c435df0
don't use Multihash in Noise prologue
melekes Oct 11, 2022
95665ec
add comments to Fingerprint
melekes Oct 12, 2022
67a13b8
fix doc links
melekes Oct 12, 2022
806d7e3
Revert "don't use Multihash in Noise prologue"
melekes Oct 13, 2022
114f539
rename noise functions
melekes Oct 13, 2022
e7f9dc2
Merge branch 'master' into anton/webrtc-transport
melekes Oct 13, 2022
6c8cce9
don't clone the raw `mpsc::Sender`
melekes Oct 13, 2022
c89f95a
add some comments
melekes Oct 14, 2022
84032f0
do not allocate read buffer every time
melekes Oct 14, 2022
ef6bf9b
Merge branch 'master' into anton/webrtc-transport
melekes Oct 14, 2022
3d3951f
remove default-features flag from libp2p-core
melekes Oct 14, 2022
3fae663
rename tokio-crate to tokio
melekes Oct 14, 2022
05a9b00
set noise data channel label to `noise`
melekes Oct 14, 2022
f7c8ab5
move transport into `tokio` dir and feature gate it
melekes Oct 17, 2022
1785a85
enable tokio feature on libp2p-webrtc
melekes Oct 17, 2022
8ddd225
empty data channel labels
melekes Oct 17, 2022
6326131
apply suggestions from @mxinden
melekes Oct 18, 2022
fe84427
bump prost-codec version
melekes Oct 18, 2022
0810bed
replace unwrap with expect
melekes Oct 18, 2022
5429e55
add missing licences
melekes Oct 18, 2022
82edf3f
rename FramedDC to FramedDc and listen_multi_address fn
melekes Oct 18, 2022
7af1e80
remove obsolete comment
melekes Oct 18, 2022
7eb35f2
specify correct version of libp2p-webrtc
melekes Oct 18, 2022
532b410
remove duplicated check
melekes Oct 18, 2022
9238efc
don't do framing during noise handshake
melekes Oct 18, 2022
4d1cb7c
Revert "don't do framing during noise handshake"
melekes Oct 18, 2022
3383872
set max-message-size to 16384
melekes Oct 19, 2022
93ea5d4
add end-of-candidates attribute to server's SDP
melekes Oct 19, 2022
ce8e742
make certificate an argument in `Transport::new`
melekes Oct 20, 2022
03cbefd
set `PollDataChannel` read buffer size to the frame max size
melekes Oct 24, 2022
61b00f9
remove pathed multiaddr
melekes Oct 24, 2022
ba964f3
bump prost-codec to 0.2.1 (not 0.3.0)
melekes Oct 24, 2022
f5757b9
remove unused deps
melekes Oct 24, 2022
0e9fcf2
release `peer_conn` lock as soon as possible
melekes Oct 24, 2022
c179ecd
update comment when creating noise stream
melekes Oct 24, 2022
7d9d531
remove TODO from poll_flush
melekes Oct 24, 2022
c1e4297
make peer ID optional
melekes Oct 24, 2022
b4472a8
use the same ufrag for both client and server
melekes Oct 24, 2022
9a80510
replace futures_lite w/ futures
melekes Oct 25, 2022
e5e9c46
Append `PeerId` to listen address
thomaseizinger Oct 26, 2022
36012ed
prepare for deterministic certificates
melekes Oct 27, 2022
19a8a6c
prefix ufrag
melekes Oct 28, 2022
9e7c0eb
Merge branch 'master' into anton/webrtc-transport
thomaseizinger Oct 31, 2022
c41e930
Add `listen_ping` example
thomaseizinger Oct 31, 2022
d1c50b5
don't log empty label
melekes Nov 3, 2022
35e02d2
set high watermark on Framed to frame size
melekes Nov 4, 2022
c7cb26b
correct max for `Framed` codec and `high_water_mark`
melekes Nov 5, 2022
e0a95d8
Merge branch 'master' into anton/webrtc-transport
melekes Nov 5, 2022
58210d4
update webrtc-rs
melekes Nov 7, 2022
e1ba1d5
asynchronous-codec 0.6.1
melekes Nov 8, 2022
430f6a8
rename to_multi_hash to to_multihash
melekes Nov 9, 2022
fc4bedb
add from_pem and serialize_pem to Certificate
melekes Nov 16, 2022
d2fc5f6
Merge branch 'master' into anton/webrtc-transport
melekes Nov 16, 2022
06d53d9
format code
melekes Nov 17, 2022
0b0be1d
remove webrtc-pem feature
melekes Nov 17, 2022
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: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ full = [
"wasm-bindgen",
"wasm-ext",
"wasm-ext-websocket",
"webrtc",
"websocket",
"yamux",
]
Expand Down Expand Up @@ -75,11 +76,12 @@ rsa = ["libp2p-core/rsa"]
secp256k1 = ["libp2p-core/secp256k1"]
serde = ["libp2p-core/serde", "libp2p-kad?/serde", "libp2p-gossipsub?/serde"]
tcp = ["dep:libp2p-tcp"]
tokio = ["libp2p-swarm/tokio", "libp2p-mdns?/tokio", "libp2p-tcp?/tokio", "libp2p-dns?/tokio", "libp2p-quic?/tokio"]
tokio = ["libp2p-swarm/tokio", "libp2p-mdns?/tokio", "libp2p-tcp?/tokio", "libp2p-dns?/tokio", "libp2p-quic?/tokio", "libp2p-webrtc?/tokio"]
uds = ["dep:libp2p-uds"]
wasm-bindgen = ["futures-timer/wasm-bindgen", "instant/wasm-bindgen", "getrandom/js"]
wasm-ext = ["dep:libp2p-wasm-ext"]
wasm-ext-websocket = ["wasm-ext", "libp2p-wasm-ext?/websocket"]
webrtc = ["dep:libp2p-webrtc", "libp2p-webrtc?/pem"]
websocket = ["dep:libp2p-websocket"]
yamux = ["dep:libp2p-yamux"]

Expand Down Expand Up @@ -108,6 +110,7 @@ libp2p-request-response = { version = "0.23.0", path = "protocols/request-respon
libp2p-swarm = { version = "0.41.0", path = "swarm" }
libp2p-uds = { version = "0.37.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.38.0", path = "transports/wasm-ext", optional = true }
libp2p-webrtc = { version = "0.1.0-alpha", path = "transports/webrtc", optional = true }
libp2p-yamux = { version = "0.42.0", path = "muxers/yamux", optional = true }
multiaddr = { version = "0.16.0" }
parking_lot = "0.12.0"
Expand Down Expand Up @@ -168,7 +171,8 @@ members = [
"transports/tcp",
"transports/uds",
"transports/websocket",
"transports/wasm-ext"
"transports/wasm-ext",
"transports/webrtc"
]

[[example]]
Expand Down
3 changes: 3 additions & 0 deletions misc/prost-codec/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

# 0.3.0 [unreleased]

- Implement `From` trait for `std::io::Error`. See [PR 2622].
- Don't leak `prost` dependency in `Error` type. See [PR 3058].

[PR 2622]: https://github.com/libp2p/rust-libp2p/pull/2622/
[PR 3058]: https://github.com/libp2p/rust-libp2p/pull/3058/

# 0.2.0
Expand Down
2 changes: 1 addition & 1 deletion misc/prost-codec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }
[dev-dependencies]
prost-build = "0.11"

# Passing arguments to the docsrs builder in order to properly document cfg's.
# 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
Expand Down
6 changes: 6 additions & 0 deletions misc/prost-codec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ impl<In, Out: Message + Default> Decoder for Codec<In, Out> {
#[derive(thiserror::Error, Debug)]
#[error("Failed to encode/decode message")]
pub struct Error(#[from] std::io::Error);

impl From<Error> for std::io::Error {
melekes marked this conversation as resolved.
Show resolved Hide resolved
fn from(e: Error) -> Self {
e.0
}
}
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ pub use libp2p_uds as uds;
#[cfg(feature = "wasm-ext")]
#[doc(inline)]
pub use libp2p_wasm_ext as wasm_ext;
#[cfg(feature = "webrtc")]
#[cfg_attr(docsrs, doc(cfg(feature = "webrtc")))]
#[doc(inline)]
pub use libp2p_webrtc as webrtc;
#[cfg(feature = "websocket")]
#[cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))]
#[doc(inline)]
Expand Down
58 changes: 58 additions & 0 deletions transports/webrtc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[package]
name = "libp2p-webrtc"
version = "0.1.0-alpha"
authors = ["Parity Technologies <[email protected]>"]
description = "WebRTC transport for libp2p"
repository = "https://github.com/libp2p/rust-libp2p"
license = "MIT"
edition = "2021"
keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]

[dependencies]
async-trait = "0.1"
asynchronous-codec = "0.6.1"
bytes = "1"
futures = "0.3"
futures-timer = "3"
hex = "0.4"
if-watch = "2.0"
libp2p-core = { version = "0.38.0", path = "../../core" }
libp2p-noise = { version = "0.41.0", path = "../../transports/noise" }
log = "0.4"
multihash = { version = "0.16", default-features = false, features = ["sha2"] }
prost = "0.11"
prost-codec = { version = "0.3.0", path = "../../misc/prost-codec" }
rand = "0.8"
rcgen = "0.9.3"
melekes marked this conversation as resolved.
Show resolved Hide resolved
serde = { version = "1.0", features = ["derive"] }
stun = "0.4"
thiserror = "1"
tinytemplate = "1.2"
tokio = { version = "1.19", features = ["net"], optional = true}
tokio-util = { version = "0.7", features = ["compat"], optional = true }
webrtc = { version = "0.6.0", optional = true }

[features]
tokio = ["dep:tokio", "dep:tokio-util", "dep:webrtc"]
pem = ["webrtc?/pem"]

[build-dependencies]
prost-build = "0.11"

[dev-dependencies]
anyhow = "1.0"
env_logger = "0.9"
hex-literal = "0.3"
libp2p = { path = "../..", features = ["full"] }
tokio = { version = "1.19", features = ["full"] }
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }
void = "1"

[[test]]
name = "smoke"
required-features = ["tokio"]

[[example]]
name = "listen_ping"
required-features = ["tokio"]
23 changes: 23 additions & 0 deletions transports/webrtc/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2022 Protocol Labs.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

fn main() {
prost_build::compile_protos(&["src/message.proto"], &["src"]).unwrap();
}
66 changes: 66 additions & 0 deletions transports/webrtc/examples/listen_ping.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use anyhow::Result;
use futures::StreamExt;
use libp2p::swarm::{keep_alive, NetworkBehaviour};
use libp2p::Transport;
use libp2p::{ping, Swarm};
use libp2p_core::identity;
use libp2p_core::muxing::StreamMuxerBox;
use rand::thread_rng;
use void::Void;

/// An example WebRTC server that will accept connections and run the ping protocol on them.
#[tokio::main]
async fn main() -> Result<()> {
let mut swarm = create_swarm()?;

swarm.listen_on("/ip4/127.0.0.1/udp/0/webrtc".parse()?)?;

loop {
let event = swarm.next().await.unwrap();
eprintln!("New event: {event:?}")
}
}

fn create_swarm() -> Result<Swarm<Behaviour>> {
let id_keys = identity::Keypair::generate_ed25519();
let peer_id = id_keys.public().to_peer_id();
let transport = libp2p_webrtc::tokio::Transport::new(
id_keys,
libp2p_webrtc::tokio::Certificate::generate(&mut thread_rng())?,
);

let transport = transport
.map(|(peer_id, conn), _| (peer_id, StreamMuxerBox::new(conn)))
.boxed();

Ok(Swarm::with_tokio_executor(
transport,
Behaviour::default(),
peer_id,
))
}

#[derive(NetworkBehaviour, Default)]
#[behaviour(out_event = "Event", event_process = false)]
struct Behaviour {
ping: ping::Behaviour,
keep_alive: keep_alive::Behaviour,
}

#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
enum Event {
Ping(ping::Event),
}

impl From<ping::Event> for Event {
fn from(e: ping::Event) -> Self {
Event::Ping(e)
}
}

impl From<Void> for Event {
fn from(event: Void) -> Self {
void::unreachable(event)
}
}
90 changes: 90 additions & 0 deletions transports/webrtc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2022 Parity Technologies (UK) Ltd.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

//! Implementation of the [`libp2p_core::Transport`] trait for WebRTC protocol without a signaling
//! server.
//!
//! # Overview
//!
//! ## ICE
//!
//! RFCs: 8839, 8445 See also:
//! <https://tools.ietf.org/id/draft-ietf-rtcweb-sdp-08.html#rfc.section.5.2.3>
//!
//! The WebRTC protocol uses ICE in order to establish a connection.
//!
//! In a typical ICE setup, there are two endpoints, called agents, that want to communicate. One
//! of these two agents can be the local browser, while the other agent is the target of the
//! connection.
//!
//! Even though in this specific context all we want is a simple client-server communication, it is
//! helpful to keep in mind that ICE was designed to solve the problem of NAT traversal.
//!
//! The ICE workflow works as follows:
//!
//! - An "offerer" determines ways in which it could be accessible (either an
//! IP address or through a relay using a TURN server), which are called "candidates". It then
//! generates a small text payload in a format called SDP, that describes the request for a
//! connection.
//! - The offerer sends this SDP-encoded message to the answerer. The medium through which this
//! exchange is done is out of scope of the ICE protocol.
//! - The answerer then finds its own candidates, and generates an answer, again in the SDP format.
//! This answer is sent back to the offerer.
//! - Each agent then tries to connect to the remote's candidates.
//!
//! We pretend to send the offer to the remote agent (the target of the connection), then pretend
//! that it has found a valid IP address for itself (i.e. a candidate), then pretend that the SDP
//! answer containing this candidate has been sent back. This will cause the offerer to execute
//! step 4: try to connect to the remote's candidate.
//!
//! ## TCP or UDP
//!
//! WebRTC by itself doesn't hardcode any specific protocol for media streams. Instead, it is the
//! SDP message of the offerer that specifies which protocol to use. In our use case (one or more
//! data channels), we know that the offerer will always request either TCP+DTLS+SCTP, or
//! UDP+DTLS+SCTP.
//!
//! The implementation only supports UDP at the moment, so if the offerer requests TCP+DTLS+SCTP, it
//! will not respond. Support for TCP may be added in the future (see
//! <https://github.com/webrtc-rs/webrtc/issues/132>).
//!
//! ## DTLS+SCTP
//!
//! RFCs: 8841, 8832
//!
//! In both cases (TCP or UDP), the next layer is DTLS. DTLS is similar to the well-known TLS
//! protocol, except that it doesn't guarantee ordering of delivery (as this is instead provided by
//! the SCTP layer on top of DTLS). In other words, once the TCP or UDP connection is established,
//! the browser will try to perform a DTLS handshake.
//!
//! During the ICE negotiation, each agent must include in its SDP packet a hash of the self-signed
//! certificate that it will use during the DTLS handshake. In our use-case, where we try to
//! hand-crate the SDP answer generated by the remote, this is problematic. A way to solve this
//! is to make the hash a part of the remote's multiaddr. On the server side, we turn
//! certificate verification off.

mod message_proto {
#![allow(clippy::derive_partial_eq_without_eq)]

include!(concat!(env!("OUT_DIR"), "/webrtc.pb.rs"));
}

#[cfg(feature = "tokio")]
pub mod tokio;
20 changes: 20 additions & 0 deletions transports/webrtc/src/message.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto2";

package webrtc.pb;

message Message {
enum Flag {
// The sender will no longer send messages on the stream.
FIN = 0;
// The sender will no longer read messages on the stream. Incoming data is
// being discarded on receipt.
STOP_SENDING = 1;
// The sender abruptly terminates the sending part of the stream. The
// receiver can discard any data that it already received on that stream.
RESET = 2;
}

optional Flag flag=1;

optional bytes message = 2;
}
Loading