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)"
|
"file (default: false)"
|
||||||
name: "insecure-netkey-password" }: bool
|
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* {.
|
case cmd* {.
|
||||||
command
|
command
|
||||||
defaultValue: noCommand }: BNStartUpCmd
|
defaultValue: noCommand }: BNStartUpCmd
|
||||||
|
|
|
@ -11,10 +11,12 @@ import
|
||||||
json_serialization, json_serialization/std/[net, options],
|
json_serialization, json_serialization/std/[net, options],
|
||||||
chronos, chronicles, metrics,
|
chronos, chronicles, metrics,
|
||||||
# TODO: create simpler to use libp2p modules that use re-exports
|
# 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,
|
multiaddress, multicodec, crypto/crypto, crypto/secp,
|
||||||
protocols/identify, protocols/protocol],
|
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/protocols/pubsub/[pubsub, rpc/message, rpc/messages],
|
||||||
libp2p/transports/tcptransport,
|
libp2p/transports/tcptransport,
|
||||||
libp2p/stream/connection,
|
libp2p/stream/connection,
|
||||||
|
@ -1499,6 +1501,25 @@ func msgIdProvider(m: messages.Message): seq[byte] =
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
gossipId(m.data, false)
|
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,
|
proc createEth2Node*(rng: ref BrHmacDrbgContext,
|
||||||
conf: BeaconNodeConf,
|
conf: BeaconNodeConf,
|
||||||
netKeys: KeyPair,
|
netKeys: KeyPair,
|
||||||
|
@ -1516,12 +1537,7 @@ proc createEth2Node*(rng: ref BrHmacDrbgContext,
|
||||||
# TODO nim-libp2p still doesn't have support for announcing addresses
|
# TODO nim-libp2p still doesn't have support for announcing addresses
|
||||||
# that are different from the host address (this is relevant when we
|
# that are different from the host address (this is relevant when we
|
||||||
# are running behind a NAT).
|
# are running behind a NAT).
|
||||||
var switch = newStandardSwitch(some netKeys.seckey, hostAddress,
|
var switch = newBeaconSwitch(conf, netKeys.seckey, hostAddress, rng)
|
||||||
transportFlags = {ServerFlags.ReuseAddr},
|
|
||||||
secureManagers = [
|
|
||||||
SecureProtocol.Noise, # Only noise in ETH2!
|
|
||||||
],
|
|
||||||
rng = rng)
|
|
||||||
|
|
||||||
let
|
let
|
||||||
params =
|
params =
|
||||||
|
|
Loading…
Reference in New Issue