2024-08-21 12:54:18 +00:00
|
|
|
when (NimMajor, NimMinor) < (1, 4):
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
else:
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
2024-10-25 20:59:02 +00:00
|
|
|
std/[options, net, strformat],
|
2024-08-21 12:54:18 +00:00
|
|
|
chronicles,
|
|
|
|
chronos,
|
|
|
|
metrics,
|
|
|
|
libbacktrace,
|
|
|
|
libp2p/crypto/crypto,
|
|
|
|
confutils,
|
|
|
|
libp2p/wire
|
|
|
|
|
|
|
|
import
|
2024-10-25 20:59:02 +00:00
|
|
|
waku/[
|
|
|
|
factory/external_config,
|
|
|
|
node/peer_manager,
|
|
|
|
waku_lightpush/common,
|
|
|
|
waku_relay,
|
|
|
|
waku_filter_v2,
|
|
|
|
waku_peer_exchange/protocol,
|
|
|
|
waku_core/multiaddrstr,
|
|
|
|
waku_enr/capabilities,
|
|
|
|
]
|
2024-08-21 12:54:18 +00:00
|
|
|
logScope:
|
|
|
|
topics = "diagnose connections"
|
|
|
|
|
2024-10-25 20:59:02 +00:00
|
|
|
proc `$`*(cap: Capabilities): string =
|
|
|
|
case cap
|
|
|
|
of Capabilities.Relay:
|
|
|
|
return "Relay"
|
|
|
|
of Capabilities.Store:
|
|
|
|
return "Store"
|
|
|
|
of Capabilities.Filter:
|
|
|
|
return "Filter"
|
|
|
|
of Capabilities.Lightpush:
|
|
|
|
return "Lightpush"
|
|
|
|
of Capabilities.Sync:
|
|
|
|
return "Sync"
|
|
|
|
|
|
|
|
proc allPeers(pm: PeerManager): string =
|
|
|
|
var allStr: string = ""
|
|
|
|
for idx, peer in pm.wakuPeerStore.peers():
|
|
|
|
allStr.add(
|
|
|
|
" " & $idx & ". | " & constructMultiaddrStr(peer) & " | protos: " &
|
|
|
|
$peer.protocols & " | caps: " & $peer.enr.map(getCapabilities) & "\n"
|
|
|
|
)
|
|
|
|
return allStr
|
2024-08-21 12:54:18 +00:00
|
|
|
|
2024-10-25 20:59:02 +00:00
|
|
|
proc logSelfPeers*(pm: PeerManager) =
|
|
|
|
let selfLighpushPeers = pm.wakuPeerStore.getPeersByProtocol(WakuLightPushCodec)
|
|
|
|
let selfRelayPeers = pm.wakuPeerStore.getPeersByProtocol(WakuRelayCodec)
|
|
|
|
let selfFilterPeers = pm.wakuPeerStore.getPeersByProtocol(WakuFilterSubscribeCodec)
|
|
|
|
let selfPxPeers = pm.wakuPeerStore.getPeersByProtocol(WakuPeerExchangeCodec)
|
|
|
|
|
|
|
|
let printable = catch:
|
|
|
|
"""*------------------------------------------------------------------------------------------*
|
|
|
|
| Self ({constructMultiaddrStr(pm.switch.peerInfo)}) peers:
|
2024-08-21 12:54:18 +00:00
|
|
|
*------------------------------------------------------------------------------------------*
|
|
|
|
| Lightpush peers({selfLighpushPeers.len()}): ${selfLighpushPeers}
|
|
|
|
*------------------------------------------------------------------------------------------*
|
|
|
|
| Filter peers({selfFilterPeers.len()}): ${selfFilterPeers}
|
|
|
|
*------------------------------------------------------------------------------------------*
|
|
|
|
| Relay peers({selfRelayPeers.len()}): ${selfRelayPeers}
|
2024-10-25 20:59:02 +00:00
|
|
|
*------------------------------------------------------------------------------------------*
|
|
|
|
| PX peers({selfPxPeers.len()}): ${selfPxPeers}
|
|
|
|
*------------------------------------------------------------------------------------------*
|
|
|
|
| All peers with protocol support:
|
|
|
|
{allPeers(pm)}
|
2024-08-21 12:54:18 +00:00
|
|
|
*------------------------------------------------------------------------------------------*""".fmt()
|
|
|
|
|
2024-10-25 20:59:02 +00:00
|
|
|
if printable.isErr():
|
|
|
|
echo "Error while printing statistics: " & printable.error().msg
|
|
|
|
else:
|
|
|
|
echo printable.get()
|