mirror of https://github.com/vacp2p/nim-libp2p.git
fix build with libp2p_agents_metrics switch
This commit is contained in:
parent
70deac9e0d
commit
4760df1e31
|
@ -71,9 +71,9 @@ proc disconnectPeer(g: GossipSub, peer: PubSubPeer) {.async.} =
|
|||
peer.shortAgent
|
||||
else:
|
||||
if peer.sendConn != nil:
|
||||
let shortAgent = peer.sendConn.peerInfo.agentVersion.split("/")[0].toLowerAscii()
|
||||
if KnownLibP2PAgentsSeq.contains(shortAgent):
|
||||
peer.shortAgent = shortAgent
|
||||
let shortAgent = peer.sendConn.peerInfo.agentVersion.split("/")[0].safeToLowerAscii()
|
||||
if shortAgent.isOk() and KnownLibP2PAgentsSeq.contains(shortAgent.get()):
|
||||
peer.shortAgent = shortAgent.get()
|
||||
else:
|
||||
peer.shortAgent = "unknown"
|
||||
peer.shortAgent
|
||||
|
@ -165,9 +165,9 @@ proc updateScores*(g: GossipSub) = # avoid async
|
|||
peer.shortAgent
|
||||
else:
|
||||
if peer.sendConn != nil:
|
||||
let shortAgent = peer.sendConn.peerInfo.agentVersion.split("/")[0].toLowerAscii()
|
||||
if KnownLibP2PAgentsSeq.contains(shortAgent):
|
||||
peer.shortAgent = shortAgent
|
||||
let shortAgent = peer.sendConn.peerInfo.agentVersion.split("/")[0].safeToLowerAscii()
|
||||
if shortAgent.isOk() and KnownLibP2PAgentsSeq.contains(shortAgent.get()):
|
||||
peer.shortAgent = shortAgent.get()
|
||||
else:
|
||||
peer.shortAgent = "unknown"
|
||||
peer.shortAgent
|
||||
|
@ -221,9 +221,9 @@ proc updateScores*(g: GossipSub) = # avoid async
|
|||
peer.shortAgent
|
||||
else:
|
||||
if peer.sendConn != nil:
|
||||
let shortAgent = peer.sendConn.peerInfo.agentVersion.split("/")[0].toLowerAscii()
|
||||
if KnownLibP2PAgentsSeq.contains(shortAgent):
|
||||
peer.shortAgent = shortAgent
|
||||
let shortAgent = peer.sendConn.peerInfo.agentVersion.split("/")[0].safeToLowerAscii()
|
||||
if shortAgent.isOk() and KnownLibP2PAgentsSeq.contains(shortAgent.get()):
|
||||
peer.shortAgent = shortAgent.get()
|
||||
else:
|
||||
peer.shortAgent = "unknown"
|
||||
peer.shortAgent
|
||||
|
|
|
@ -79,9 +79,9 @@ when defined(libp2p_agents_metrics):
|
|||
if not s.tracked:
|
||||
if not isNil(s.peerInfo) and s.peerInfo.agentVersion.len > 0:
|
||||
# / seems a weak "standard" so for now it's reliable
|
||||
let shortAgent = s.peerInfo.agentVersion.split("/")[0].toLowerAscii()
|
||||
if KnownLibP2PAgentsSeq.contains(shortAgent):
|
||||
s.shortAgent = shortAgent
|
||||
let shortAgent = s.peerInfo.agentVersion.split("/")[0].safeToLowerAscii()
|
||||
if shortAgent.isOk() and KnownLibP2PAgentsSeq.contains(shortAgent.get()):
|
||||
s.shortAgent = shortAgent.get()
|
||||
else:
|
||||
s.shortAgent = "unknown"
|
||||
libp2p_peers_identity.inc(labelValues = [s.shortAgent])
|
||||
|
|
|
@ -39,6 +39,18 @@ func shortLog*(item: string): string =
|
|||
result &= item[(item.len - split)..item.high]
|
||||
|
||||
when defined(libp2p_agents_metrics):
|
||||
import strutils
|
||||
export split
|
||||
|
||||
import stew/results
|
||||
export results
|
||||
|
||||
proc safeToLowerAscii*(s: string): Result[string, cstring] =
|
||||
try:
|
||||
ok(s.toLowerAscii())
|
||||
except:
|
||||
err("toLowerAscii failed")
|
||||
|
||||
const
|
||||
KnownLibP2PAgents* {.strdefine.} = ""
|
||||
KnownLibP2PAgentsSeq* = KnownLibP2PAgents.toLowerAscii().split(",")
|
||||
KnownLibP2PAgentsSeq* = KnownLibP2PAgents.safeToLowerAscii().tryGet().split(",")
|
||||
|
|
Loading…
Reference in New Issue