From 7833e64ad6db680d024c6b2aa20c50f3666fe9b6 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Wed, 30 Oct 2024 13:57:42 -0400 Subject: [PATCH] feat(libp2p): enable shared TCP listeners --- core/node/libp2p/transport.go | 10 ++++++++-- docs/config.md | 3 --- docs/examples/kubo-as-a-library/go.mod | 2 +- docs/examples/kubo-as-a-library/go.sum | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- test/dependencies/go.mod | 3 ++- test/dependencies/go.sum | 4 ++-- 8 files changed, 18 insertions(+), 14 deletions(-) diff --git a/core/node/libp2p/transport.go b/core/node/libp2p/transport.go index 61412ff4fc4..9e58b4568c5 100644 --- a/core/node/libp2p/transport.go +++ b/core/node/libp2p/transport.go @@ -24,12 +24,14 @@ func Transports(tptConfig config.Transports) interface{} { ) (opts Libp2pOpts, err error) { privateNetworkEnabled := params.Fprint != nil - if tptConfig.Network.TCP.WithDefault(true) { + tcpEnabled := tptConfig.Network.TCP.WithDefault(true) + wsEnabled := tptConfig.Network.Websocket.WithDefault(true) + if tcpEnabled { // TODO(9290): Make WithMetrics configurable opts.Opts = append(opts.Opts, libp2p.Transport(tcp.NewTCPTransport, tcp.WithMetrics())) } - if tptConfig.Network.Websocket.WithDefault(true) { + if wsEnabled { if params.ForgeMgr == nil { opts.Opts = append(opts.Opts, libp2p.Transport(websocket.New)) } else { @@ -64,6 +66,10 @@ func Transports(tptConfig config.Transports) interface{} { opts.Opts = append(opts.Opts, libp2p.Transport(webrtc.New)) } + if tcpEnabled || wsEnabled { + opts.Opts = append(opts.Opts, libp2p.ShareTCPListener()) + } + return opts, nil } } diff --git a/docs/config.md b/docs/config.md index e2b169452d9..370f484b5f6 100644 --- a/docs/config.md +++ b/docs/config.md @@ -505,9 +505,6 @@ Kubo will obtain and set up a trusted PKI TLS certificate for it, making it dial > add catch-all `/ip4/0.0.0.0/tcp/4002/tls/sni/*.libp2p.direct/ws` and `/ip6/::/tcp/4002/tls/sni/*.libp2p.direct/ws` to [`Addresses.Swarm`](#addressesswarm) > and **wait 5-15 minutes** for libp2p node to set up and learn about own public addresses via [AutoNAT](#autonat). > - If your node is fresh and just started, the [p2p-forge] client may produce and log ERRORs during this time, but once a publicly diallable addresses are set up, a subsequent retry should be successful. -> - Listeners defined in [`Addresses.Swarm`](#addressesswarm) with `/tls/sni` must use a separate port from other TCP listeners, e.g. `4002` instead of the default `4001`. -> - A separate port (`/tcp/4002`) has to be used instead of `/tcp/4001` because we wait for TCP port sharing ([go-libp2p#2984](https://github.com/libp2p/go-libp2p/issues/2684)) to be implemented. -> - If you use manual port forwarding, make sure incoming connections to this additional port are allowed the same way `4001` ones already are. > - The TLS certificate is used only for [libp2p WebSocket](https://github.com/libp2p/specs/blob/master/websockets/README.md) connections. > - Right now, this is NOT used for hosting a [Gateway](#gateway) over HTTPS (that use case still requires manual TLS setup on reverse proxy, and your own domain). diff --git a/docs/examples/kubo-as-a-library/go.mod b/docs/examples/kubo-as-a-library/go.mod index 69cd5cec216..350fa53ac0f 100644 --- a/docs/examples/kubo-as-a-library/go.mod +++ b/docs/examples/kubo-as-a-library/go.mod @@ -9,7 +9,7 @@ replace github.com/ipfs/kubo => ./../../.. require ( github.com/ipfs/boxo v0.24.3 github.com/ipfs/kubo v0.0.0-00010101000000-000000000000 - github.com/libp2p/go-libp2p v0.37.0 + github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9 github.com/multiformats/go-multiaddr v0.13.0 ) diff --git a/docs/examples/kubo-as-a-library/go.sum b/docs/examples/kubo-as-a-library/go.sum index e12055d9281..17b76aaba4f 100644 --- a/docs/examples/kubo-as-a-library/go.sum +++ b/docs/examples/kubo-as-a-library/go.sum @@ -460,8 +460,8 @@ github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZ github.com/libp2p/go-flow-metrics v0.0.3/go.mod h1:HeoSNUrOJVK1jEpDqVEiUOIXqhbnS27omG0uWU5slZs= github.com/libp2p/go-flow-metrics v0.2.0 h1:EIZzjmeOE6c8Dav0sNv35vhZxATIXWZg6j/C08XmmDw= github.com/libp2p/go-flow-metrics v0.2.0/go.mod h1:st3qqfu8+pMfh+9Mzqb2GTiwrAGjIPszEjZmtksN8Jc= -github.com/libp2p/go-libp2p v0.37.0 h1:8K3mcZgwTldydMCNOiNi/ZJrOB9BY+GlI3UxYzxBi9A= -github.com/libp2p/go-libp2p v0.37.0/go.mod h1:GOKmSN99scDuYGTwaTbQPR8Nt6dxrK3ue7OjW2NGDg4= +github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9 h1:c8mJk6NBIzzuQcatj9ag5UvAG4lNkd31wdP2SkR3WV8= +github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9/go.mod h1:GOKmSN99scDuYGTwaTbQPR8Nt6dxrK3ue7OjW2NGDg4= github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94= github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8= github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g= diff --git a/go.mod b/go.mod index 46e0fa9a57c..54a708e4b04 100644 --- a/go.mod +++ b/go.mod @@ -54,7 +54,7 @@ require ( github.com/jbenet/goprocess v0.1.4 github.com/julienschmidt/httprouter v1.3.0 github.com/libp2p/go-doh-resolver v0.4.0 - github.com/libp2p/go-libp2p v0.37.0 + github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9 github.com/libp2p/go-libp2p-http v0.5.0 github.com/libp2p/go-libp2p-kad-dht v0.27.0 github.com/libp2p/go-libp2p-kbucket v0.6.4 diff --git a/go.sum b/go.sum index b0a1e4cc087..d3baa2abe6e 100644 --- a/go.sum +++ b/go.sum @@ -538,8 +538,8 @@ github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZ github.com/libp2p/go-flow-metrics v0.0.3/go.mod h1:HeoSNUrOJVK1jEpDqVEiUOIXqhbnS27omG0uWU5slZs= github.com/libp2p/go-flow-metrics v0.2.0 h1:EIZzjmeOE6c8Dav0sNv35vhZxATIXWZg6j/C08XmmDw= github.com/libp2p/go-flow-metrics v0.2.0/go.mod h1:st3qqfu8+pMfh+9Mzqb2GTiwrAGjIPszEjZmtksN8Jc= -github.com/libp2p/go-libp2p v0.37.0 h1:8K3mcZgwTldydMCNOiNi/ZJrOB9BY+GlI3UxYzxBi9A= -github.com/libp2p/go-libp2p v0.37.0/go.mod h1:GOKmSN99scDuYGTwaTbQPR8Nt6dxrK3ue7OjW2NGDg4= +github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9 h1:c8mJk6NBIzzuQcatj9ag5UvAG4lNkd31wdP2SkR3WV8= +github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9/go.mod h1:GOKmSN99scDuYGTwaTbQPR8Nt6dxrK3ue7OjW2NGDg4= github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94= github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8= github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g= diff --git a/test/dependencies/go.mod b/test/dependencies/go.mod index 46b022a2b21..7cfaf144842 100644 --- a/test/dependencies/go.mod +++ b/test/dependencies/go.mod @@ -156,7 +156,7 @@ require ( github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-cidranger v1.1.0 // indirect github.com/libp2p/go-flow-metrics v0.2.0 // indirect - github.com/libp2p/go-libp2p v0.37.0 // indirect + github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9 // indirect github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect github.com/libp2p/go-libp2p-kad-dht v0.27.0 // indirect github.com/libp2p/go-libp2p-kbucket v0.6.4 // indirect @@ -165,6 +165,7 @@ require ( github.com/libp2p/go-msgio v0.3.0 // indirect github.com/libp2p/go-nat v0.2.0 // indirect github.com/libp2p/go-netroute v0.2.1 // indirect + github.com/libp2p/go-reuseport v0.4.0 // indirect github.com/lufeee/execinquery v1.2.1 // indirect github.com/macabu/inamedparam v0.1.3 // indirect github.com/magiconair/properties v1.8.7 // indirect diff --git a/test/dependencies/go.sum b/test/dependencies/go.sum index 37a560dd983..b54f5b31166 100644 --- a/test/dependencies/go.sum +++ b/test/dependencies/go.sum @@ -431,8 +431,8 @@ github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38y github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic= github.com/libp2p/go-flow-metrics v0.2.0 h1:EIZzjmeOE6c8Dav0sNv35vhZxATIXWZg6j/C08XmmDw= github.com/libp2p/go-flow-metrics v0.2.0/go.mod h1:st3qqfu8+pMfh+9Mzqb2GTiwrAGjIPszEjZmtksN8Jc= -github.com/libp2p/go-libp2p v0.37.0 h1:8K3mcZgwTldydMCNOiNi/ZJrOB9BY+GlI3UxYzxBi9A= -github.com/libp2p/go-libp2p v0.37.0/go.mod h1:GOKmSN99scDuYGTwaTbQPR8Nt6dxrK3ue7OjW2NGDg4= +github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9 h1:c8mJk6NBIzzuQcatj9ag5UvAG4lNkd31wdP2SkR3WV8= +github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9/go.mod h1:GOKmSN99scDuYGTwaTbQPR8Nt6dxrK3ue7OjW2NGDg4= github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94= github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8= github.com/libp2p/go-libp2p-kad-dht v0.27.0 h1:1Ea32tVTPiAfaLpPMbaBWFJgbsi/JpMqC2YBuFdf32o=