Skip to content

Commit f1a869a

Browse files
fix(libp2p): consolidate AddrsFactory logic for all transports
1 parent a8faeb3 commit f1a869a

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/ethereum/go-ethereum v1.15.11
1414
github.com/ethersphere/batch-archive v0.0.4
1515
github.com/ethersphere/go-price-oracle-abi v0.6.9
16-
github.com/ethersphere/go-storage-incentives-abi v0.9.4
16+
github.com/ethersphere/go-storage-incentives-abi v0.9.3-rc4
1717
github.com/ethersphere/go-sw3-abi v0.6.9
1818
github.com/ethersphere/langos v1.0.0
1919
github.com/go-playground/validator/v10 v10.11.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ github.com/ethersphere/batch-archive v0.0.4 h1:PHmwQfmUEyDJgoX2IqI/R0alQ63+aLPXf
239239
github.com/ethersphere/batch-archive v0.0.4/go.mod h1:41BPb192NoK9CYjNB8BAE1J2MtiI/5aq0Wtas5O7A7Q=
240240
github.com/ethersphere/go-price-oracle-abi v0.6.9 h1:bseen6he3PZv5GHOm+KD6s4awaFmVSD9LFx+HpB6rCU=
241241
github.com/ethersphere/go-price-oracle-abi v0.6.9/go.mod h1:sI/Qj4/zJ23/b1enzwMMv0/hLTpPNVNacEwCWjo6yBk=
242-
github.com/ethersphere/go-storage-incentives-abi v0.9.4 h1:mSIWXQXg5OQmH10QvXMV5w0vbSibFMaRlBL37gPLTM0=
243-
github.com/ethersphere/go-storage-incentives-abi v0.9.4/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
242+
github.com/ethersphere/go-storage-incentives-abi v0.9.3-rc4 h1:YK9FpiQz29ctU5V46CuwMt+4X5Xn8FTBwy6E2v/ix8s=
243+
github.com/ethersphere/go-storage-incentives-abi v0.9.3-rc4/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
244244
github.com/ethersphere/go-sw3-abi v0.6.9 h1:TnWLnYkWE5UvC17mQBdUmdkzhPhO8GcqvWy4wvd1QJQ=
245245
github.com/ethersphere/go-sw3-abi v0.6.9/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU=
246246
github.com/ethersphere/langos v1.0.0 h1:NBtNKzXTTRSue95uOlzPN4py7Aofs0xWPzyj4AI1Vcc=

pkg/p2p/libp2p/libp2p.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,20 @@ func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay
391391
if o.EnableWSS {
392392
wsOpt := ws.WithTLSConfig(certManager.TLSConfig())
393393
transports = append(transports, libp2p.Transport(ws.New, wsOpt))
394-
// AddrsFactory takes the multiaddrs we're listening on and sets the multiaddrs to advertise to the network.
395-
// We use the AutoTLS address factory so that the `*` in the AutoTLS address string is replaced with the
396-
// actual IP address of the host once detected
397-
certManagerAddressFactory := certManager.AddressFactory()
398-
opts = append(opts, libp2p.AddrsFactory(func(addrs []ma.Multiaddr) []ma.Multiaddr {
399-
addrs = includeNatResolvedAddresses(addrs, newCompositeAddressResolver(tcpResolver, wssResolver), logger)
394+
}
395+
396+
if o.EnableWS {
397+
transports = append(transports, libp2p.Transport(ws.New))
398+
}
399+
400+
opts = append(opts, libp2p.AddrsFactory(func(addrs []ma.Multiaddr) []ma.Multiaddr {
401+
addrs = includeNatResolvedAddresses(addrs, newCompositeAddressResolver(tcpResolver, wssResolver), logger)
400402

403+
if o.EnableWSS {
404+
// AddrsFactory takes the multiaddrs we're listening on and sets the multiaddrs to advertise to the network.
405+
// We use the AutoTLS address factory so that the `*` in the AutoTLS address string is replaced with the
406+
// actual IP address of the host once detected
407+
certManagerAddressFactory := certManager.AddressFactory()
401408
addrs = certManagerAddressFactory(addrs)
402409

403410
slices.SortStableFunc(addrs, func(a, b ma.Multiaddr) int {
@@ -413,11 +420,10 @@ func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay
413420
}
414421
return 0
415422
})
416-
return addrs
417-
}))
418-
} else if o.EnableWS {
419-
transports = append(transports, libp2p.Transport(ws.New))
420-
}
423+
}
424+
425+
return addrs
426+
}))
421427

422428
opts = append(opts, transports...)
423429

0 commit comments

Comments
 (0)