Repository: libp2p/go-libp2p
Pull request #2887 (2024-07-26 08:34:39)

webrtc: remove experimental tag, enable by default
Closes: #2657 


Patch:
diff --git a/defaults.go b/defaults.go
index 1aba3bd7..daf8c461 100644
--- a/defaults.go
+++ b/defaults.go
@@ -15,6 +15,7 @@ import (
 	tls "github.com/libp2p/go-libp2p/p2p/security/tls"
 	quic "github.com/libp2p/go-libp2p/p2p/transport/quic"
 	"github.com/libp2p/go-libp2p/p2p/transport/tcp"
+	libp2pwebrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc"
 	ws "github.com/libp2p/go-libp2p/p2p/transport/websocket"
 	webtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport"
 	"github.com/prometheus/client_golang/prometheus"
@@ -47,6 +48,7 @@ var DefaultTransports = ChainOptions(
 	Transport(quic.NewTransport),
 	Transport(ws.New),
 	Transport(webtransport.New),
+	Transport(libp2pwebrtc.New),
 )
 
 // DefaultPrivateTransports are the default libp2p transports when a PSK is supplied.
@@ -82,9 +84,11 @@ var DefaultListenAddrs = func(cfg *Config) error {
 		"/ip4/0.0.0.0/tcp/0",
 		"/ip4/0.0.0.0/udp/0/quic-v1",
 		"/ip4/0.0.0.0/udp/0/quic-v1/webtransport",
+		"/ip4/0.0.0.0/udp/0/webrtc-direct",
 		"/ip6/::/tcp/0",
 		"/ip6/::/udp/0/quic-v1",
 		"/ip6/::/udp/0/quic-v1/webtransport",
+		"/ip6/::/udp/0/webrtc-direct",
 	}
 	listenAddrs := make([]multiaddr.Multiaddr, 0, len(addrs))
 	for _, s := range addrs {
diff --git a/p2p/transport/webrtc/transport.go b/p2p/transport/webrtc/transport.go
index 68a2988c..db605bcc 100644
--- a/p2p/transport/webrtc/transport.go
+++ b/p2p/transport/webrtc/transport.go
@@ -1,15 +1,5 @@
 // Package libp2pwebrtc implements the WebRTC transport for go-libp2p,
 // as described in https://github.com/libp2p/specs/tree/master/webrtc.
-//
-// At this point, this package is EXPERIMENTAL, and the WebRTC transport is not enabled by default.
-// While we're fairly confident that the implementation correctly implements the specification,
-// we're not making any guarantees regarding its security (especially regarding resource exhaustion attacks).
-// Fixes, even for security-related issues, will be conducted in the open.
-//
-// Experimentation is encouraged. Please open an issue if you encounter any problems with this transport.
-//
-// The udpmux subpackage contains the logic for multiplexing multiple WebRTC (ICE)
-// connections over a single UDP socket.
 package libp2pwebrtc
 
 import (
diff --git a/p2p/transport/webrtc/udpmux/mux.go b/p2p/transport/webrtc/udpmux/mux.go
index 98e60e3f..1ce49098 100644
--- a/p2p/transport/webrtc/udpmux/mux.go
+++ b/p2p/transport/webrtc/udpmux/mux.go
@@ -1,3 +1,5 @@
+// The udpmux package contains the logic for multiplexing multiple WebRTC (ICE)
+// connections over a single UDP socket.
 package udpmux
 
 import (


Test patch:
diff --git a/libp2p_test.go b/libp2p_test.go
index ea52e564..a0513aaf 100644
--- a/libp2p_test.go
+++ b/libp2p_test.go
@@ -92,6 +92,7 @@ func TestInsecure(t *testing.T) {
 func TestDefaultListenAddrs(t *testing.T) {
 	reTCP := regexp.MustCompile("/(ip)[4|6]/((0.0.0.0)|(::))/tcp/")
 	reQUIC := regexp.MustCompile("/(ip)[4|6]/((0.0.0.0)|(::))/udp/([0-9]*)/quic-v1")
+	reWebRTC := regexp.MustCompile("/(ip)[4|6]/((0.0.0.0)|(::))/udp/([0-9]*)/webrtc-direct/certhash/(.*)")
 	reCircuit := regexp.MustCompile("/p2p-circuit")
 
 	// Test 1: Setting the correct listen addresses if userDefined.Transport == nil && userDefined.ListenAddrs == nil
@@ -100,6 +101,7 @@ func TestDefaultListenAddrs(t *testing.T) {
 	for _, addr := range h.Network().ListenAddresses() {
 		if reTCP.FindStringSubmatchIndex(addr.String()) == nil &&
 			reQUIC.FindStringSubmatchIndex(addr.String()) == nil &&
+			reWebRTC.FindStringSubmatchIndex(addr.String()) == nil &&
 			reCircuit.FindStringSubmatchIndex(addr.String()) == nil {
 			t.Error("expected ip4 or ip6 or relay interface")
 		}