Skip to content

Commit 60d8d5c

Browse files
committed
feat(libp2p): enable shared TCP listeners
1 parent 4009ad3 commit 60d8d5c

File tree

8 files changed

+18
-14
lines changed

8 files changed

+18
-14
lines changed

core/node/libp2p/transport.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ func Transports(tptConfig config.Transports) interface{} {
2424
) (opts Libp2pOpts, err error) {
2525
privateNetworkEnabled := params.Fprint != nil
2626

27-
if tptConfig.Network.TCP.WithDefault(true) {
27+
tcpEnabled := tptConfig.Network.TCP.WithDefault(true)
28+
wsEnabled := tptConfig.Network.Websocket.WithDefault(true)
29+
if tcpEnabled {
2830
// TODO(9290): Make WithMetrics configurable
2931
opts.Opts = append(opts.Opts, libp2p.Transport(tcp.NewTCPTransport, tcp.WithMetrics()))
3032
}
3133

32-
if tptConfig.Network.Websocket.WithDefault(true) {
34+
if wsEnabled {
3335
if params.ForgeMgr == nil {
3436
opts.Opts = append(opts.Opts, libp2p.Transport(websocket.New))
3537
} else {
@@ -64,6 +66,10 @@ func Transports(tptConfig config.Transports) interface{} {
6466
opts.Opts = append(opts.Opts, libp2p.Transport(webrtc.New))
6567
}
6668

69+
if tcpEnabled || wsEnabled {
70+
opts.Opts = append(opts.Opts, libp2p.ShareTCPListener())
71+
}
72+
6773
return opts, nil
6874
}
6975
}

docs/config.md

-3
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,6 @@ Kubo will obtain and set up a trusted PKI TLS certificate for it, making it dial
505505
> 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)
506506
> and **wait 5-15 minutes** for libp2p node to set up and learn about own public addresses via [AutoNAT](#autonat).
507507
> - 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.
508-
> - 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`.
509-
> - 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.
510-
> - If you use manual port forwarding, make sure incoming connections to this additional port are allowed the same way `4001` ones already are.
511508
> - The TLS certificate is used only for [libp2p WebSocket](https://github.com/libp2p/specs/blob/master/websockets/README.md) connections.
512509
> - 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).
513510

docs/examples/kubo-as-a-library/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ replace github.com/ipfs/kubo => ./../../..
99
require (
1010
github.com/ipfs/boxo v0.24.2
1111
github.com/ipfs/kubo v0.0.0-00010101000000-000000000000
12-
github.com/libp2p/go-libp2p v0.37.0
12+
github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9
1313
github.com/multiformats/go-multiaddr v0.13.0
1414
)
1515

docs/examples/kubo-as-a-library/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZ
460460
github.com/libp2p/go-flow-metrics v0.0.3/go.mod h1:HeoSNUrOJVK1jEpDqVEiUOIXqhbnS27omG0uWU5slZs=
461461
github.com/libp2p/go-flow-metrics v0.2.0 h1:EIZzjmeOE6c8Dav0sNv35vhZxATIXWZg6j/C08XmmDw=
462462
github.com/libp2p/go-flow-metrics v0.2.0/go.mod h1:st3qqfu8+pMfh+9Mzqb2GTiwrAGjIPszEjZmtksN8Jc=
463-
github.com/libp2p/go-libp2p v0.37.0 h1:8K3mcZgwTldydMCNOiNi/ZJrOB9BY+GlI3UxYzxBi9A=
464-
github.com/libp2p/go-libp2p v0.37.0/go.mod h1:GOKmSN99scDuYGTwaTbQPR8Nt6dxrK3ue7OjW2NGDg4=
463+
github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9 h1:c8mJk6NBIzzuQcatj9ag5UvAG4lNkd31wdP2SkR3WV8=
464+
github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9/go.mod h1:GOKmSN99scDuYGTwaTbQPR8Nt6dxrK3ue7OjW2NGDg4=
465465
github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94=
466466
github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8=
467467
github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g=

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ require (
5454
github.com/jbenet/goprocess v0.1.4
5555
github.com/julienschmidt/httprouter v1.3.0
5656
github.com/libp2p/go-doh-resolver v0.4.0
57-
github.com/libp2p/go-libp2p v0.37.0
57+
github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9
5858
github.com/libp2p/go-libp2p-http v0.5.0
5959
github.com/libp2p/go-libp2p-kad-dht v0.27.0
6060
github.com/libp2p/go-libp2p-kbucket v0.6.4

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZ
538538
github.com/libp2p/go-flow-metrics v0.0.3/go.mod h1:HeoSNUrOJVK1jEpDqVEiUOIXqhbnS27omG0uWU5slZs=
539539
github.com/libp2p/go-flow-metrics v0.2.0 h1:EIZzjmeOE6c8Dav0sNv35vhZxATIXWZg6j/C08XmmDw=
540540
github.com/libp2p/go-flow-metrics v0.2.0/go.mod h1:st3qqfu8+pMfh+9Mzqb2GTiwrAGjIPszEjZmtksN8Jc=
541-
github.com/libp2p/go-libp2p v0.37.0 h1:8K3mcZgwTldydMCNOiNi/ZJrOB9BY+GlI3UxYzxBi9A=
542-
github.com/libp2p/go-libp2p v0.37.0/go.mod h1:GOKmSN99scDuYGTwaTbQPR8Nt6dxrK3ue7OjW2NGDg4=
541+
github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9 h1:c8mJk6NBIzzuQcatj9ag5UvAG4lNkd31wdP2SkR3WV8=
542+
github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9/go.mod h1:GOKmSN99scDuYGTwaTbQPR8Nt6dxrK3ue7OjW2NGDg4=
543543
github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94=
544544
github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8=
545545
github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g=

test/dependencies/go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ require (
156156
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
157157
github.com/libp2p/go-cidranger v1.1.0 // indirect
158158
github.com/libp2p/go-flow-metrics v0.2.0 // indirect
159-
github.com/libp2p/go-libp2p v0.37.0 // indirect
159+
github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9 // indirect
160160
github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect
161161
github.com/libp2p/go-libp2p-kad-dht v0.27.0 // indirect
162162
github.com/libp2p/go-libp2p-kbucket v0.6.4 // indirect
@@ -165,6 +165,7 @@ require (
165165
github.com/libp2p/go-msgio v0.3.0 // indirect
166166
github.com/libp2p/go-nat v0.2.0 // indirect
167167
github.com/libp2p/go-netroute v0.2.1 // indirect
168+
github.com/libp2p/go-reuseport v0.4.0 // indirect
168169
github.com/lufeee/execinquery v1.2.1 // indirect
169170
github.com/macabu/inamedparam v0.1.3 // indirect
170171
github.com/magiconair/properties v1.8.7 // indirect

test/dependencies/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38y
431431
github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic=
432432
github.com/libp2p/go-flow-metrics v0.2.0 h1:EIZzjmeOE6c8Dav0sNv35vhZxATIXWZg6j/C08XmmDw=
433433
github.com/libp2p/go-flow-metrics v0.2.0/go.mod h1:st3qqfu8+pMfh+9Mzqb2GTiwrAGjIPszEjZmtksN8Jc=
434-
github.com/libp2p/go-libp2p v0.37.0 h1:8K3mcZgwTldydMCNOiNi/ZJrOB9BY+GlI3UxYzxBi9A=
435-
github.com/libp2p/go-libp2p v0.37.0/go.mod h1:GOKmSN99scDuYGTwaTbQPR8Nt6dxrK3ue7OjW2NGDg4=
434+
github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9 h1:c8mJk6NBIzzuQcatj9ag5UvAG4lNkd31wdP2SkR3WV8=
435+
github.com/libp2p/go-libp2p v0.37.1-0.20241104193226-9cefe2c8e6f9/go.mod h1:GOKmSN99scDuYGTwaTbQPR8Nt6dxrK3ue7OjW2NGDg4=
436436
github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94=
437437
github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8=
438438
github.com/libp2p/go-libp2p-kad-dht v0.27.0 h1:1Ea32tVTPiAfaLpPMbaBWFJgbsi/JpMqC2YBuFdf32o=

0 commit comments

Comments
 (0)