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
|
@ -37,6 +37,11 @@ type
|
|||
defaultValue: false
|
||||
name: "version" }: bool
|
||||
|
||||
agentString* {.
|
||||
defaultValue: "nwaku",
|
||||
desc: "Node agent string which is used as identifier in network"
|
||||
name: "agent-string" .}: string
|
||||
|
||||
nodekey* {.
|
||||
desc: "P2P node private key as 64 char hex string.",
|
||||
defaultValue: defaultPrivateKey()
|
||||
|
|
|
@ -283,7 +283,8 @@ proc initNode(conf: WakuNodeConf,
|
|||
dnsResolver,
|
||||
conf.relayPeerExchange, # We send our own signed peer record when peer exchange enabled
|
||||
dns4DomainName,
|
||||
discv5UdpPort
|
||||
discv5UdpPort,
|
||||
some(conf.agentString)
|
||||
)
|
||||
except:
|
||||
return err("failed to create waku node instance: " & getCurrentExceptionMsg())
|
||||
|
|
|
@ -209,3 +209,39 @@ procSuite "WakuNode":
|
|||
check:
|
||||
node.announcedAddresses.len == 1
|
||||
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,
|
||||
sendSignedPeerRecord = false,
|
||||
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.
|
||||
|
||||
## Initialize addresses
|
||||
|
@ -198,7 +200,8 @@ proc new*(T: type WakuNode,
|
|||
secureKeyPath = secureKey,
|
||||
secureCertPath = secureCert,
|
||||
nameResolver = nameResolver,
|
||||
sendSignedPeerRecord = sendSignedPeerRecord
|
||||
sendSignedPeerRecord = sendSignedPeerRecord,
|
||||
agentString = agentString
|
||||
)
|
||||
|
||||
let wakuNode = WakuNode(
|
||||
|
|
|
@ -70,7 +70,9 @@ proc newWakuSwitch*(
|
|||
sendSignedPeerRecord = false,
|
||||
wssEnabled: bool = false,
|
||||
secureKeyPath: string = "",
|
||||
secureCertPath: string = ""): Switch
|
||||
secureCertPath: string = "",
|
||||
agentString = none(string), # defaults to nim-libp2p version
|
||||
): Switch
|
||||
{.raises: [Defect, IOError, LPError].} =
|
||||
|
||||
var b = SwitchBuilder
|
||||
|
@ -86,6 +88,8 @@ proc newWakuSwitch*(
|
|||
.withNameResolver(nameResolver)
|
||||
.withSignedPeerRecord(sendSignedPeerRecord)
|
||||
|
||||
if agentString.isSome():
|
||||
b = b.withAgentVersion(agentString.get())
|
||||
if privKey.isSome():
|
||||
b = b.withPrivateKey(privKey.get())
|
||||
if wsAddress.isSome():
|
||||
|
|
Loading…
Reference in New Issue