use libp2p builder

This commit is contained in:
Dmitriy Ryajov 2021-04-05 14:21:27 -06:00 committed by zah
parent 9cd946a192
commit 920de91c37
2 changed files with 13 additions and 23 deletions

View File

@ -21,7 +21,8 @@ import
chronos, chronicles, metrics,
libp2p/[switch, peerinfo, multicodec,
multiaddress, crypto/crypto, crypto/secp,
protocols/identify, protocols/protocol],
protocols/identify, protocols/protocol,
builders],
libp2p/muxers/muxer, libp2p/muxers/mplex/mplex,
libp2p/transports/[transport, tcptransport],
libp2p/protocols/secure/[secure, noise],
@ -1532,27 +1533,16 @@ proc newBeaconSwitch*(config: BeaconNodeConf, seckey: PrivateKey,
address: MultiAddress,
rng: ref BrHmacDrbgContext): Switch {.raises: [Defect, CatchableError].} =
try:
proc createMplex(conn: Connection): Muxer =
Mplex.init(conn, inTimeout = 5.minutes, outTimeout = 5.minutes)
let
peerInfo = PeerInfo.init(seckey, [address])
mplexProvider = newMuxerProvider(createMplex, MplexCodec)
transports = @[Transport(TcpTransport.init({ServerFlags.ReuseAddr}))]
muxers = {MplexCodec: mplexProvider}.toTable
secureManagers = [Secure(newNoise(rng, seckey))]
peerInfo.agentVersion = config.agentString
let identify = newIdentify(peerInfo)
newSwitch(
peerInfo,
transports,
identify,
muxers,
secureManagers,
maxConnections = config.maxPeers)
SwitchBuilder
.init()
.withPrivateKey(seckey)
.withAddress(address)
.withRng(rng)
.withMplex(5.minutes, 5.minutes)
.withTcpTransport({ServerFlags.ReuseAddr})
.withNoise()
.withAgentVersion(config.agentString)
.build()
except CatchableError as exc: raise exc
except Exception as exc: # TODO fix libp2p
if exc is Defect: raise (ref Defect)exc

2
vendor/nim-libp2p vendored

@ -1 +1 @@
Subproject commit 54031c9e9bc9882a2e8c2d5937031731ed63ab5e
Subproject commit a21d300e3e9a15f9a0ba5232c4115b48cf95bf4e