Setup agent/proto version identifiers in libp2p. (#2079)
* Supply `nim-libp2p` with `agent-string` and `proto-string` as configured parameters. * Remove protoString and rng check. * Fix compilation problem.
This commit is contained in:
parent
e7f2735271
commit
db030eb944
|
@ -103,6 +103,11 @@ type
|
|||
"file (default: false)"
|
||||
name: "insecure-netkey-password" }: bool
|
||||
|
||||
agentString* {.
|
||||
defaultValue: "nimbus",
|
||||
desc: "Node agent string which is used as identifier in network"
|
||||
name: "agent-string" }: string
|
||||
|
||||
case cmd* {.
|
||||
command
|
||||
defaultValue: noCommand }: BNStartUpCmd
|
||||
|
|
|
@ -11,10 +11,12 @@ import
|
|||
json_serialization, json_serialization/std/[net, options],
|
||||
chronos, chronicles, metrics,
|
||||
# TODO: create simpler to use libp2p modules that use re-exports
|
||||
libp2p/[switch, standard_setup, peerinfo,
|
||||
libp2p/[switch, peerinfo,
|
||||
multiaddress, multicodec, crypto/crypto, crypto/secp,
|
||||
protocols/identify, protocols/protocol],
|
||||
libp2p/protocols/secure/[secure, secio],
|
||||
libp2p/muxers/muxer, libp2p/muxers/mplex/mplex,
|
||||
libp2p/transports/[transport, tcptransport],
|
||||
libp2p/protocols/secure/[secure, noise],
|
||||
libp2p/protocols/pubsub/[pubsub, rpc/message, rpc/messages],
|
||||
libp2p/transports/tcptransport,
|
||||
libp2p/stream/connection,
|
||||
|
@ -1499,6 +1501,25 @@ func msgIdProvider(m: messages.Message): seq[byte] =
|
|||
except CatchableError:
|
||||
gossipId(m.data, false)
|
||||
|
||||
proc newBeaconSwitch*(conf: BeaconNodeConf, seckey: PrivateKey,
|
||||
address: MultiAddress,
|
||||
rng: ref BrHmacDrbgContext): Switch =
|
||||
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 = conf.agentString
|
||||
|
||||
let identify = newIdentify(peerInfo)
|
||||
|
||||
newSwitch(peerInfo, transports, identify, muxers, secureManagers)
|
||||
|
||||
proc createEth2Node*(rng: ref BrHmacDrbgContext,
|
||||
conf: BeaconNodeConf,
|
||||
netKeys: KeyPair,
|
||||
|
@ -1510,18 +1531,13 @@ proc createEth2Node*(rng: ref BrHmacDrbgContext,
|
|||
else: @[tcpEndPoint(extIp.get(), extTcpPort)]
|
||||
|
||||
debug "Initializing networking", hostAddress,
|
||||
network_public_key = netKeys.pubkey,
|
||||
announcedAddresses
|
||||
network_public_key = netKeys.pubkey,
|
||||
announcedAddresses
|
||||
|
||||
# TODO nim-libp2p still doesn't have support for announcing addresses
|
||||
# that are different from the host address (this is relevant when we
|
||||
# are running behind a NAT).
|
||||
var switch = newStandardSwitch(some netKeys.seckey, hostAddress,
|
||||
transportFlags = {ServerFlags.ReuseAddr},
|
||||
secureManagers = [
|
||||
SecureProtocol.Noise, # Only noise in ETH2!
|
||||
],
|
||||
rng = rng)
|
||||
var switch = newBeaconSwitch(conf, netKeys.seckey, hostAddress, rng)
|
||||
|
||||
let
|
||||
params =
|
||||
|
|
Loading…
Reference in New Issue