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