move peer id concatenation to switch

This commit is contained in:
Diego 2024-05-17 01:19:23 +02:00
parent 3a659ffddb
commit 1b2b009f79
No known key found for this signature in database
GPG Key ID: C9DAC9BF68D1F806
3 changed files with 6 additions and 7 deletions

View File

@ -18,7 +18,7 @@ import tables, strutils, sets
import multicodec, multihash, multibase, transcoder, vbuffer, peerid,
protobuf/minprotobuf, errors, utility
import stew/[base58, base32, endians2, results]
export results, minprotobuf, vbuffer, utility
export results, minprotobuf, vbuffer, utility, multicodec
logScope:
topics = "libp2p multiaddress"

View File

@ -163,12 +163,9 @@ proc expandWildcardAddresses(
)
addresses.add(wildcardAddresses)
else:
listenAddr.concat(peerIdMa).withValue(ma):
addresses.add(ma)
addresses.add(listenAddr)
else:
let suffixed = listenAddr.concat(peerIdMa).valueOr:
continue
addresses.add(suffixed)
addresses.add(listenAddr)
addresses
method setup*(

View File

@ -344,10 +344,12 @@ proc start*(s: Switch) {.async, public.} =
await s.stop()
raise fut.error
let peerIdMa = MultiAddress.init(multiCodec("p2p"), s.peerInfo.peerId).tryGet()
for t in s.transports: # for each transport
if t.addrs.len > 0 or t.running:
s.acceptFuts.add(s.accept(t))
s.peerInfo.listenAddrs &= t.addrs
let addrs = t.addrs.mapIt(it.concat(peerIdMa).tryget())
s.peerInfo.listenAddrs &= addrs
await s.peerInfo.update()