Fix & test shortAgent

This commit is contained in:
Tanguy 2023-02-09 17:27:36 +01:00
parent 0d6c60df05
commit 15a107a368
No known key found for this signature in database
GPG Key ID: 7DD8EC6B6CE6C45E
3 changed files with 15 additions and 3 deletions

View File

@ -75,7 +75,9 @@ when defined(libp2p_agents_metrics):
if p.sendConn.isNil:
"unknown"
else:
p.sendConn.shortAgent
#TODO the sendConn is setup before identify,
#so we have to read the parents short agent..
p.sendConn.getWrapped().shortAgent
func hash*(p: PubSubPeer): Hash =
p.peerId.hash

View File

@ -57,5 +57,5 @@ when defined(libp2p_agents_metrics):
err("toLowerAscii failed")
const
KnownLibP2PAgents* {.strdefine.} = ""
KnownLibP2PAgents* {.strdefine.} = "nim-libp2p"
KnownLibP2PAgentsSeq* = KnownLibP2PAgents.safeToLowerAscii().tryGet().split(",")

View File

@ -19,7 +19,9 @@ import utils,
protocols/pubsub/pubsub,
protocols/pubsub/floodsub,
protocols/pubsub/rpc/messages,
protocols/pubsub/peertable]
protocols/pubsub/peertable,
protocols/pubsub/pubsubpeer
]
import ../../libp2p/protocols/pubsub/errors as pubsub_errors
import ../helpers
@ -62,6 +64,14 @@ suite "FloodSub":
check (await nodes[0].publish("foobar", "Hello!".toBytes())) > 0
check (await completionFut.wait(5.seconds)) == true
when defined(libp2p_agents_metrics):
let
agentA = nodes[0].peers[nodes[1].switch.peerInfo.peerId].shortAgent
agentB = nodes[1].peers[nodes[0].switch.peerInfo.peerId].shortAgent
check:
agentA == "nim-libp2p"
agentB == "nim-libp2p"
await allFuturesThrowing(
nodes[0].switch.stop(),
nodes[1].switch.stop()