mirror of https://github.com/waku-org/nwaku.git
feat(wakunode2): add nwaku agent-string to switch (#1302)
This commit is contained in:
parent
979f1d397a
commit
d479aacec5
|
@ -36,6 +36,11 @@ type
|
||||||
desc: "prints the version"
|
desc: "prints the version"
|
||||||
defaultValue: false
|
defaultValue: false
|
||||||
name: "version" }: bool
|
name: "version" }: bool
|
||||||
|
|
||||||
|
agentString* {.
|
||||||
|
defaultValue: "nwaku",
|
||||||
|
desc: "Node agent string which is used as identifier in network"
|
||||||
|
name: "agent-string" .}: string
|
||||||
|
|
||||||
nodekey* {.
|
nodekey* {.
|
||||||
desc: "P2P node private key as 64 char hex string.",
|
desc: "P2P node private key as 64 char hex string.",
|
||||||
|
|
|
@ -283,7 +283,8 @@ proc initNode(conf: WakuNodeConf,
|
||||||
dnsResolver,
|
dnsResolver,
|
||||||
conf.relayPeerExchange, # We send our own signed peer record when peer exchange enabled
|
conf.relayPeerExchange, # We send our own signed peer record when peer exchange enabled
|
||||||
dns4DomainName,
|
dns4DomainName,
|
||||||
discv5UdpPort
|
discv5UdpPort,
|
||||||
|
some(conf.agentString)
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
return err("failed to create waku node instance: " & getCurrentExceptionMsg())
|
return err("failed to create waku node instance: " & getCurrentExceptionMsg())
|
||||||
|
|
|
@ -209,3 +209,39 @@ procSuite "WakuNode":
|
||||||
check:
|
check:
|
||||||
node.announcedAddresses.len == 1
|
node.announcedAddresses.len == 1
|
||||||
node.announcedAddresses.contains(expectedDns4Addr)
|
node.announcedAddresses.contains(expectedDns4Addr)
|
||||||
|
|
||||||
|
|
||||||
|
asyncTest "Agent string is set and advertised correctly":
|
||||||
|
let
|
||||||
|
# custom agent string
|
||||||
|
expectedAgentString1 = "node1-agent-string"
|
||||||
|
|
||||||
|
# bump when updating nim-libp2p
|
||||||
|
expectedAgentString2 = "nim-libp2p/0.0.1"
|
||||||
|
let
|
||||||
|
# node with custom agent string
|
||||||
|
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||||
|
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(60000),
|
||||||
|
agentString = some(expectedAgentString1))
|
||||||
|
|
||||||
|
# node with default agent string from libp2p
|
||||||
|
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||||
|
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(60002))
|
||||||
|
|
||||||
|
await node1.start()
|
||||||
|
await node1.mountRelay()
|
||||||
|
|
||||||
|
await node2.start()
|
||||||
|
await node2.mountRelay()
|
||||||
|
|
||||||
|
await node1.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
|
||||||
|
await node2.connectToNodes(@[node1.switch.peerInfo.toRemotePeerInfo()])
|
||||||
|
|
||||||
|
let node1Agent = node2.switch.peerStore[AgentBook][node1.switch.peerInfo.toRemotePeerInfo().peerId]
|
||||||
|
let node2Agent = node1.switch.peerStore[AgentBook][node2.switch.peerInfo.toRemotePeerInfo().peerId]
|
||||||
|
|
||||||
|
check:
|
||||||
|
node1Agent == expectedAgentString1
|
||||||
|
node2Agent == expectedAgentString2
|
||||||
|
|
||||||
|
await allFutures(node1.stop(), node2.stop())
|
|
@ -129,7 +129,9 @@ proc new*(T: type WakuNode,
|
||||||
nameResolver: NameResolver = nil,
|
nameResolver: NameResolver = nil,
|
||||||
sendSignedPeerRecord = false,
|
sendSignedPeerRecord = false,
|
||||||
dns4DomainName = none(string),
|
dns4DomainName = none(string),
|
||||||
discv5UdpPort = none(Port)): T {.raises: [Defect, LPError, IOError, TLSStreamProtocolError].} =
|
discv5UdpPort = none(Port),
|
||||||
|
agentString = none(string), # defaults to nim-libp2p version
|
||||||
|
): T {.raises: [Defect, LPError, IOError, TLSStreamProtocolError].} =
|
||||||
## Creates a Waku Node instance.
|
## Creates a Waku Node instance.
|
||||||
|
|
||||||
## Initialize addresses
|
## Initialize addresses
|
||||||
|
@ -198,7 +200,8 @@ proc new*(T: type WakuNode,
|
||||||
secureKeyPath = secureKey,
|
secureKeyPath = secureKey,
|
||||||
secureCertPath = secureCert,
|
secureCertPath = secureCert,
|
||||||
nameResolver = nameResolver,
|
nameResolver = nameResolver,
|
||||||
sendSignedPeerRecord = sendSignedPeerRecord
|
sendSignedPeerRecord = sendSignedPeerRecord,
|
||||||
|
agentString = agentString
|
||||||
)
|
)
|
||||||
|
|
||||||
let wakuNode = WakuNode(
|
let wakuNode = WakuNode(
|
||||||
|
|
|
@ -70,7 +70,9 @@ proc newWakuSwitch*(
|
||||||
sendSignedPeerRecord = false,
|
sendSignedPeerRecord = false,
|
||||||
wssEnabled: bool = false,
|
wssEnabled: bool = false,
|
||||||
secureKeyPath: string = "",
|
secureKeyPath: string = "",
|
||||||
secureCertPath: string = ""): Switch
|
secureCertPath: string = "",
|
||||||
|
agentString = none(string), # defaults to nim-libp2p version
|
||||||
|
): Switch
|
||||||
{.raises: [Defect, IOError, LPError].} =
|
{.raises: [Defect, IOError, LPError].} =
|
||||||
|
|
||||||
var b = SwitchBuilder
|
var b = SwitchBuilder
|
||||||
|
@ -86,6 +88,8 @@ proc newWakuSwitch*(
|
||||||
.withNameResolver(nameResolver)
|
.withNameResolver(nameResolver)
|
||||||
.withSignedPeerRecord(sendSignedPeerRecord)
|
.withSignedPeerRecord(sendSignedPeerRecord)
|
||||||
|
|
||||||
|
if agentString.isSome():
|
||||||
|
b = b.withAgentVersion(agentString.get())
|
||||||
if privKey.isSome():
|
if privKey.isSome():
|
||||||
b = b.withPrivateKey(privKey.get())
|
b = b.withPrivateKey(privKey.get())
|
||||||
if wsAddress.isSome():
|
if wsAddress.isSome():
|
||||||
|
|
Loading…
Reference in New Issue