Skip to content

Commit

Permalink
wip: add webrtc support
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Nov 3, 2023
1 parent 2f93080 commit 08924cb
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ type Transports struct {
TCP Flag `json:",omitempty"`
Websocket Flag `json:",omitempty"`
Relay Flag `json:",omitempty"`
// except WebTransport which is experimental and optin.
// except WebTransport and WebRTC which are experimental and optin.
WebTransport Flag `json:",omitempty"`
WebRTC Flag `json:",omitempty"`
}

// Security specifies the transports used to encrypt insecure network
Expand Down
10 changes: 10 additions & 0 deletions core/node/libp2p/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/libp2p/go-libp2p/core/metrics"
quic "github.com/libp2p/go-libp2p/p2p/transport/quic"
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
webrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc"
"github.com/libp2p/go-libp2p/p2p/transport/websocket"
webtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport"

Expand Down Expand Up @@ -49,6 +50,15 @@ func Transports(tptConfig config.Transports) interface{} {
opts.Opts = append(opts.Opts, libp2p.Transport(webtransport.New))
}

if tptConfig.Network.WebRTC.WithDefault(!privateNetworkEnabled) {
if privateNetworkEnabled {
return opts, fmt.Errorf(
"WebRTC transport does not support private networks, please disable Swarm.Transports.Network.WebRTC",
)
}
opts.Opts = append(opts.Opts, libp2p.Transport(webrtc.New))

Check warning on line 59 in core/node/libp2p/transport.go

View check run for this annotation

Codecov / codecov/patch

core/node/libp2p/transport.go#L53-L59

Added lines #L53 - L59 were not covered by tests
}

return opts, nil
}
}
Expand Down
11 changes: 11 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,17 @@ Default: Enabled

Type: `flag`

#### `Swarm.Transports.Network.WebRTC`

A new feature of [`go-libp2p`](https://github.com/libp2p/go-libp2p/releases/tag/v0.30.0)
is the [WebRTC](https://github.com/libp2p/go-libp2p/pull/2337) transport.

**TODO**: write something better here.

Default: Enabled

Type: `flag`

### `Swarm.Transports.Security`

Configuration section for libp2p _security_ transports. Transports enabled in
Expand Down
19 changes: 19 additions & 0 deletions docs/examples/kubo-as-a-library/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 // indirect
github.com/cskr/pubsub v1.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/dgraph-io/badger v1.6.2 // indirect
Expand Down Expand Up @@ -142,7 +143,24 @@ require (
github.com/openzipkin/zipkin-go v0.4.1 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 // indirect
github.com/pion/datachannel v1.5.5 // indirect
github.com/pion/dtls/v2 v2.2.7 // indirect
github.com/pion/ice/v2 v2.3.6 // indirect
github.com/pion/interceptor v0.1.17 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/mdns v0.0.7 // 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.7 // indirect
github.com/pion/sdp/v3 v3.0.6 // indirect
github.com/pion/srtp/v2 v2.0.15 // indirect
github.com/pion/stun v0.6.0 // indirect
github.com/pion/transport/v2 v2.2.1 // indirect
github.com/pion/turn/v2 v2.1.0 // indirect
github.com/pion/webrtc/v3 v3.2.9 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
Expand All @@ -155,6 +173,7 @@ require (
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/samber/lo v1.36.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/ucarion/urlpath v0.0.0-20200424170820-7ccc79b76bbb // indirect
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc // indirect
Expand Down
77 changes: 77 additions & 0 deletions docs/examples/kubo-as-a-library/go.sum

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ require (
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/openzipkin/zipkin-go v0.4.1 // indirect
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 // indirect
github.com/pion/datachannel v1.5.5 // indirect
github.com/pion/dtls/v2 v2.2.7 // indirect
github.com/pion/ice/v2 v2.3.6 // indirect
github.com/pion/interceptor v0.1.17 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/mdns v0.0.7 // 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.7 // indirect
github.com/pion/sdp/v3 v3.0.6 // indirect
github.com/pion/srtp/v2 v2.0.15 // indirect
github.com/pion/stun v0.6.0 // indirect
github.com/pion/transport/v2 v2.2.1 // indirect
github.com/pion/turn/v2 v2.1.0 // indirect
github.com/pion/webrtc/v3 v3.2.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
Expand Down
Loading

0 comments on commit 08924cb

Please sign in to comment.