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: Implement webrtc private transport #2177

Closed
wants to merge 227 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
227 commits
Select commit Hold shift + click to select a range
ef185f4
WebRTC transport implementation
ckousik Jul 8, 2022
60d6e9e
remove bytes.Buffer from datachannel
ckousik Nov 18, 2022
d801b5c
fix staticcheck error
ckousik Nov 18, 2022
de05336
fix go fmt
ckousik Nov 18, 2022
96c0899
remove deadlines and cleanup
ckousik Nov 21, 2022
2464486
simplify read
ckousik Nov 22, 2022
6d37367
remove comments
ckousik Nov 28, 2022
433437e
rewrite udpmux
ckousik Nov 28, 2022
1c426a2
rewrite mux
ckousik Nov 28, 2022
fa8010b
remove default multihash
ckousik Nov 28, 2022
e8453ad
go mod tidy
ckousik Nov 28, 2022
1701b89
simplify mux
ckousik Nov 28, 2022
2e65c7d
better deadlines
ckousik Nov 28, 2022
cea2557
minor packetbuffer tests
ckousik Nov 28, 2022
b1bcf29
add unwrap to error type
ckousik Nov 28, 2022
6632095
add test for stream closure
ckousik Nov 29, 2022
b6a33d4
fix gofmt
ckousik Nov 29, 2022
48ab83d
maxbuffersize fix
ckousik Dec 2, 2022
c7cc27f
fix
ckousik Dec 2, 2022
7cc271d
fix read
ckousik Dec 2, 2022
3aa333d
fix
ckousik Dec 2, 2022
e3228aa
fix deadlock
ckousik Dec 2, 2022
9b51205
added tests
ckousik Dec 5, 2022
b8bde3f
start readloop on first read call
ckousik Dec 5, 2022
7d48528
fix issue
ckousik Dec 5, 2022
6081523
update pion
ckousik Dec 6, 2022
5a54581
Add comment
ckousik Dec 6, 2022
e0c7f25
remove example
ckousik Dec 6, 2022
1bc7c7e
gofmt
ckousik Dec 6, 2022
ee3e979
fix test
ckousik Dec 6, 2022
2c7578b
address review
ckousik Dec 7, 2022
1cfdae8
add reset to packetqueue
ckousik Dec 7, 2022
cea86fb
more comments
ckousik Dec 7, 2022
cfc5b7f
updated webrtc/v3 with setReadDeadline
ckousik Dec 12, 2022
67683fc
tidy
ckousik Dec 12, 2022
3258011
address regression in pion/datachannel
ckousik Dec 13, 2022
aec4b9c
force close
ckousik Dec 13, 2022
6329af2
Workaround for datachannel closure
ckousik Dec 13, 2022
320d047
use buffers from pool for connections
ckousik Dec 14, 2022
99c9659
add test for stream closure
ckousik Dec 19, 2022
c7dffaa
fix staticcheck error
ckousik Dec 19, 2022
c7c1ed0
address review
ckousik Jan 7, 2023
8409639
stream and connection limiting
ckousik Jan 8, 2023
0f5a089
fix test
ckousik Jan 8, 2023
f90c634
revert to uint32
ckousik Jan 8, 2023
fdbb178
fixes
ckousik Jan 9, 2023
2aa8e2b
fix receiveMTU
ckousik Jan 9, 2023
f59a656
update ice version
ckousik Jan 9, 2023
cd5e06a
fix sdp test
ckousik Jan 9, 2023
75ddec6
temporarily skip test
ckousik Jan 9, 2023
a125544
simplify packetqueue
ckousik Jan 10, 2023
e7bd1e1
fix 1 layer of race conditions
ckousik Jan 10, 2023
99e7c05
cleanup
ckousik Jan 10, 2023
cb74d23
more cleanup
ckousik Jan 11, 2023
ea5987c
string benchmarks
ckousik Jan 11, 2023
4af5cd1
grow builder
ckousik Jan 11, 2023
9f760b1
benchmark packetqueue and prevent panic on close
ckousik Jan 11, 2023
9ca5597
document lock in packetqueue
ckousik Jan 11, 2023
1bdfea7
explicit arguments in sdp functions
ckousik Jan 12, 2023
00ec1e5
fix default return value of getSupported hashes
ckousik Jan 12, 2023
91634b6
move to go:generate
ckousik Jan 12, 2023
ab21d09
polish from load tests
ckousik Jan 14, 2023
648c02a
update go mod
ckousik Jan 14, 2023
33bf244
update testplans go.mod
ckousik Jan 14, 2023
115caff
update protoc version
ckousik Jan 14, 2023
f76dfc4
address remarks of myself of original PR
Jan 17, 2023
1be11e9
improve state.go
Jan 17, 2023
b22eed7
Add notes from ckousik to codebase
Jan 18, 2023
5285989
enable transport (webrtc) tests that do work
Jan 18, 2023
c6f290e
make DiaerCanCreateStreams test pass again
Jan 19, 2023
6b78134
further improve state management
Jan 19, 2023
1a9a515
minor code changes
Jan 19, 2023
94dbcfa
minor improvements mux.go (webrtc)
Jan 19, 2023
a5c45d2
do not pass string by value in mux.go where not needed
Jan 19, 2023
50e7394
fix bug in webrtc mux: refactor now passes all tests
Jan 19, 2023
624a0f5
fix staticcheck tests
Jan 19, 2023
64b60d9
add link to go-libp2p webrtc spec
Jan 19, 2023
464fe64
add WebRTC benchmarking tool
Jan 19, 2023
aa80e25
disable std transport test on purpose for WebRTC
Jan 21, 2023
8c572bf
start cleaning up webrtc bench tool
Jan 21, 2023
d000415
implement metrics tracker (stdout or csv file)
Jan 21, 2023
9b29f54
fix linting issues
Jan 21, 2023
370544d
improve metrics tracking
Jan 23, 2023
787de4e
add report metrics cmd
Jan 23, 2023
56e4413
add metrics vis and improve reporting + doc
Jan 24, 2023
a73e4d7
remove unused pool extra MTU size
Jan 24, 2023
f0356a2
document how to profile using the webrtc benchmark tool
Jan 24, 2023
91d834c
remove TODO from README of webrtc benchmark
Jan 24, 2023
10e00ba
add Benchmark chapter to WebRTC BM tool README
Jan 25, 2023
b3acaa0
use correct scripts for benchmark example cmds
Jan 25, 2023
a75e179
also keep tracks of bytes read/written in metrics for WebRTC
Jan 25, 2023
705706d
bugfix metrics collection client/server (webrtc)
Jan 25, 2023
dffbd1c
move visualise to sep dir & support autogen csv metrics file name
Jan 26, 2023
bc3b211
make visualise script work with multiple files (e.g. server/client)
Jan 26, 2023
8e52e36
include results (CSV) in benchmark results
Jan 26, 2023
ac077ce
continue to improve benchmark code
Jan 26, 2023
0aa7c6b
define transports for benchmark explicitly
Jan 26, 2023
a0c421f
add fork reference and update listrenPort
Jan 26, 2023
4bd827e
give back 9999 listen port for benchmark tool as def
Jan 26, 2023
624fc78
divide CPU % by total cpu cores as to get actual %
Jan 26, 2023
9801531
remove dead code (client sdp (2))
Jan 26, 2023
62d698f
support merge on single datapoint for webrtc bench
Jan 28, 2023
a636032
refactor metrics script and easily print metric stats as MD table
Jan 28, 2023
1d087c9
remove flag dep from lib runner code
Jan 28, 2023
3c47f7f
fix linter error
Jan 28, 2023
062ebc4
add multirunner tool
Jan 28, 2023
cf1c6d8
fix runner: now it works :)
Jan 28, 2023
0fc8cf1
update benchmark README: simplify cmds now that we have multinner
Jan 28, 2023
3b3b459
add benchmark files for webrtc and other transports
Jan 30, 2023
fd7bd8f
add more graphs to webrtc README benchmark
Jan 30, 2023
7912d1f
fix cases for ws png image link in README
Jan 30, 2023
74cdf10
fix dial cmd multirunner for s2 benchmark
Jan 30, 2023
01dae45
go mod tidy
Jan 30, 2023
bbcf8d2
fix tests CI (multirunner flag parse)
Jan 30, 2023
8423c52
sync SDP messages with Rust version
Jan 31, 2023
e4fc599
make sdp tests pass again (webrtc)
Jan 31, 2023
bb8aea4
add benchmark results comparing quic to webrtc
Jan 31, 2023
26bf7ec
support bench multirunner to use only a single transport
Jan 31, 2023
2f4f0c6
update benchmark results to latest webrtc
Jan 31, 2023
e177fc6
upgrade pion dependencies (webrtc)
Jan 31, 2023
4bb2012
remove webrtc options for dialing that are incompatible
Jan 31, 2023
36a4208
fix README cmds
Jan 31, 2023
453d6dd
fix open TODOs that can be fixed
Feb 1, 2023
bb35fbe
minor improvement, mostly styling
Feb 1, 2023
135af07
remove outdated code and remove unneeded string alloc
Feb 1, 2023
56cc945
optimise hex conversions further and string allocs
Feb 1, 2023
a0a43ec
remove duplicate hex code
Feb 1, 2023
ce7e970
avoid even more string allocs
Feb 1, 2023
4ed95a0
go mod tidy
Feb 1, 2023
e33a05e
update benchmarks based on latest PR branch status
Feb 1, 2023
61177e9
avoid more string allocs
Feb 1, 2023
13ffbee
add TODO to flaky test
Feb 1, 2023
3567409
fix ch leak and minor ux improvements
Feb 2, 2023
ca29407
remove TODO regarding flaky test, might have been fixed already
Feb 2, 2023
161d12e
log dial error when it occurs in prod
Feb 2, 2023
4b79b20
Merge remote-tracking branch 'origin/master' into feat/webrtc
Feb 3, 2023
b79924e
go mod tidy
Feb 3, 2023
c51ef68
minor improvements and more docs
Feb 3, 2023
7d63c7b
go mod tidy testplans
Feb 3, 2023
a5aa714
increase dial timeout for MaxInFlightRequests test
Feb 3, 2023
ff689f2
resolve data race in muxed_connection.go
Feb 4, 2023
64154c8
code cleanup
Feb 4, 2023
eea5874
clean up code
Feb 4, 2023
a1cb991
simplify code regarding maxInFlight
Feb 4, 2023
748519f
refactor stream.go (webrtc)
Feb 5, 2023
9a65869
skip broken tests (due to refactor)
Feb 5, 2023
0613582
ensure response writer can handle if responseCh is blocked :)
Feb 5, 2023
ae5c5ec
swap done check
Feb 5, 2023
1fda8b0
remove unused varf
Feb 5, 2023
e42c314
split up stream code (webrtc)
Feb 6, 2023
0633a90
move util webrtc code to internal package (soc)
Feb 6, 2023
898f668
move Signal also to its own internal package for WebRTC
Feb 6, 2023
70f33af
add forgotten pointer for ref function
Feb 6, 2023
7c246a7
move state back into webrtc stream
Feb 7, 2023
ca1a374
more refactor: deadline fix
Feb 8, 2023
5be3cdc
simplify/refactor stream code
Feb 9, 2023
264ce0c
remove unused props/types of stream
Feb 9, 2023
ade34df
Merge remote-tracking branch 'origin/master' into feat/webrtc
Feb 9, 2023
0febdbd
fix max in flight conn test
Feb 9, 2023
b350d71
sync code with original ckousik code
Feb 9, 2023
c06e1a3
re-add closeErr hack defined by ckousik (just to be sure)
Feb 9, 2023
dd1f3a8
fix tests: all should pass now
Feb 9, 2023
3437272
update benchmarks for webrtc for latest code
Feb 9, 2023
e2b107c
update S2 benchmarks (FC)
Feb 9, 2023
3df32db
simplify WebRTC reader code (fix deadline bug)
Feb 9, 2023
e9a0d49
accept webrtc accept queue better
Feb 9, 2023
9545df6
switch establishing conns (webrtc) to worker pool
Feb 10, 2023
c201a81
remove benchmark to sep repo
Feb 12, 2023
cd47d16
doc hex interpersed + remove async/mutex
Feb 12, 2023
82be234
resolve more review comments
Feb 12, 2023
cbe1061
give pckt queue ctx done its own err
Feb 12, 2023
4f7ecf1
resolve more comments from review
Feb 12, 2023
09da05e
update link to new benchmark repo
Feb 12, 2023
fb8837c
go mod tidy (remove pidusage dep)
Feb 12, 2023
3c43902
handle more review comments
Feb 13, 2023
79193f8
fix linter error
Feb 13, 2023
dae5b9d
address some more review comments
Feb 14, 2023
7e21fa3
improve webrtc by resolving more review comments
Feb 19, 2023
957fab9
further clean up code
Feb 19, 2023
9bb2578
remove wg from stream
Feb 19, 2023
4a55ff7
add more comments and resolve MR review
Feb 21, 2023
0b5fcc4
merge stream back into one
Feb 21, 2023
62b3b1c
switch to mafmt.UDP to also allow DNS addresses (not just IP)
Feb 22, 2023
4981ecb
prevent pkt queue alloc when not used (webrtc)
Feb 22, 2023
2039cfc
remove shorter read in packetsQueue::pop
Feb 23, 2023
c771813
bugfix muxed_connection.go
Feb 23, 2023
40fa481
fix dialMatcher selection + test
Feb 23, 2023
f4764d2
skip failing tests to get an idea of what is failing
Feb 23, 2023
8fe8727
fix broken TestTransportWebRTC_Read test
Feb 24, 2023
fcb4b45
fix last remaining failing unit tests
Feb 25, 2023
abe126d
fix unit test (linux) + linter (check)
Feb 25, 2023
bd2903b
fix linter (check): unused var
Feb 25, 2023
094ed17
fix conns in flight, this is now properly respecting the max
Feb 26, 2023
d8ab714
Merge remote-tracking branch 'origin/master' into feat/webrtc
Feb 26, 2023
57d3c3d
remove dirty err hack that used to be needed for read errs
Feb 26, 2023
d322b52
apply some feeback alreay
Mar 1, 2023
c2aa10b
clean up code further and apply feedback
Mar 1, 2023
367bcc4
use go-msgio to write prefixe msg on wire
Mar 1, 2023
4c3f2c2
add fuzz test for hex interperse util
Mar 1, 2023
ed64f22
correctly check if slice in EncodeInterperseHexToBuilder is empty
Mar 2, 2023
e2ca309
fix hex webrtc util code based on fuzz tests
Mar 2, 2023
cf1dff5
resolve more review comments
Mar 3, 2023
f20f40f
max in flight conns with a single worker
Mar 3, 2023
cf6093e
handle previously ignored errors
Mar 3, 2023
133e9ae
improve testing and code for webrtc
Mar 3, 2023
4842b38
more hex tests
Mar 3, 2023
bf9e3fc
move awaitPeerConnectionOpen out internal to avoid needing log there
Mar 3, 2023
130b2c4
fix lint checks
Mar 3, 2023
6db8135
address more review comments
Mar 9, 2023
feb2551
Merge remote-tracking branch 'origin/master' into feat/webrtc
Mar 9, 2023
db47c11
remove priv key from connection (no longer needed)
Mar 9, 2023
4dfc547
address more comments
Mar 9, 2023
deb7d7d
address more comments
Mar 11, 2023
181fa15
drop custom CondVar sync primitive
Mar 14, 2023
6f35a1b
move GetDataChannel to private function in root webrtc pkg
Mar 14, 2023
1ba7457
add comment to explain why connection internal setters are required
Mar 14, 2023
131c48a
add high level webrtc test
Mar 14, 2023
99ba632
use IncludeLoopbackCandidate(true) for webrtc's pion
Mar 14, 2023
dfdbb26
Update p2p/transport/webrtc/stream.go
GlenDC Mar 15, 2023
87b988d
do not make ICE timeouts configurable for WebRTC
Mar 15, 2023
2b4d03d
Merge remote-tracking branch 'origin/master' into feat/webrtc
Mar 15, 2023
2e6eb77
fix more comments
Mar 15, 2023
9a9b7ea
feat: Initial webrtc-w3c implementation
ckousik Mar 6, 2023
820c499
base test
ckousik Mar 6, 2023
58a5c44
start adding a transport for webrtc w3c
ckousik Mar 16, 2023
56119e9
rename protofile
ckousik Mar 16, 2023
3ef0f32
fix staticcheck issues
ckousik Mar 16, 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
42 changes: 30 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,21 @@ require (
github.com/multiformats/go-multistream v0.4.1
github.com/multiformats/go-varint v0.0.7
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
github.com/pion/datachannel v1.5.5
github.com/pion/ice/v2 v2.2.13
github.com/pion/logging v0.2.2
github.com/pion/stun v0.4.0
github.com/pion/webrtc/v3 v3.1.51
github.com/prometheus/client_golang v1.14.0
github.com/quic-go/quic-go v0.33.0
github.com/quic-go/webtransport-go v0.5.2
github.com/raulk/go-watchdog v1.3.0
github.com/stretchr/testify v1.8.1
go.uber.org/fx v1.18.2
go.uber.org/goleak v1.1.12
golang.org/x/crypto v0.4.0
golang.org/x/crypto v0.5.0
golang.org/x/sync v0.1.0
golang.org/x/sys v0.3.0
golang.org/x/sys v0.4.0
golang.org/x/tools v0.3.0
google.golang.org/protobuf v1.28.1
nhooyr.io/websocket v1.8.7
Expand All @@ -60,13 +65,12 @@ require (
require (
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/cgroups v1.0.4 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgraph-io/badger v1.6.2 // indirect
github.com/dgraph-io/ristretto v0.0.2 // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
Expand All @@ -75,24 +79,38 @@ require (
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/pprof v0.0.0-20221203041831-ce31453925ec // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.1 // indirect
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
github.com/koron/go-ssdp v0.0.3 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/ginkgo/v2 v2.5.1 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/pion/dtls/v2 v2.1.5 // indirect
github.com/pion/interceptor v0.1.12 // indirect
github.com/pion/mdns v0.0.5 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.10 // indirect
github.com/pion/rtp v1.7.13 // indirect
github.com/pion/sctp v1.8.6 // indirect
github.com/pion/sdp/v3 v3.0.6 // indirect
github.com/pion/srtp/v2 v2.0.11 // indirect
github.com/pion/transport v0.14.1 // indirect
github.com/pion/transport/v2 v2.0.0 // indirect
github.com/pion/turn/v2 v2.0.9 // indirect
github.com/pion/udp v0.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
Expand All @@ -102,15 +120,15 @@ require (
github.com/quic-go/qtls-go1-19 v0.2.1 // indirect
github.com/quic-go/qtls-go1-20 v0.1.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/dig v1.15.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/text v0.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
)
123 changes: 105 additions & 18 deletions go.sum

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions p2p/test/webrtc/webrtc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package webrtc_test

import (
"context"
"fmt"
"io"
"testing"
"time"

"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
libp2pwebrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc"
"github.com/stretchr/testify/require"
)

func TestWebRTCStream(t *testing.T) {
h1, err := libp2p.New(
libp2p.Transport(libp2pwebrtc.New),
libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/webrtc"),
)
require.NoError(t, err)

const proto = "/testing"
h1.SetStreamHandler(proto, func(str network.Stream) {
data, err := io.ReadAll(str)
require.NoError(t, err)
fmt.Println("read:", string(data))
})

h2, err := libp2p.New(
libp2p.Transport(libp2pwebrtc.New),
libp2p.NoListenAddrs,
)
require.NoError(t, err)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

err = h2.Connect(ctx, peer.AddrInfo{ID: h1.ID(), Addrs: h1.Addrs()})
require.NoError(t, err)

str, err := h2.NewStream(ctx, h1.ID(), proto)
require.NoError(t, err)
defer str.Close()

_, err = str.Write([]byte("foobar"))
require.NoError(t, err)
}
Loading