mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2026-01-09 02:38:19 -05:00
chore(PeerTable): add stringification operator (#1567)
This commit is contained in:
@@ -9,13 +9,25 @@
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[tables, sets, sequtils]
|
||||
import std/[tables, sets, sequtils, strutils]
|
||||
import ./pubsubpeer, ../../peerid
|
||||
|
||||
export tables, sets
|
||||
|
||||
type PeerTable* = Table[string, HashSet[PubSubPeer]] # topic string to peer map
|
||||
|
||||
proc `$`*(table: PeerTable): string =
|
||||
result.add("PeerTable ")
|
||||
result.add("topics (" & $table.len & ")")
|
||||
|
||||
for topic, peers in table:
|
||||
result.add(" topic: ")
|
||||
result.add($topic)
|
||||
result.add(" peers: ")
|
||||
result.add("(" & $peers.len & ") [")
|
||||
result.add(peers.mapIt($it).join(", "))
|
||||
result.add("]")
|
||||
|
||||
proc hasPeerId*(t: PeerTable, topic: string, peerId: PeerId): bool =
|
||||
if topic in t:
|
||||
try:
|
||||
|
||||
@@ -172,6 +172,9 @@ proc getAgent*(peer: PubSubPeer): string =
|
||||
else:
|
||||
"unknown"
|
||||
|
||||
proc `$`*(p: PubSubPeer): string =
|
||||
$p.peerId
|
||||
|
||||
func hash*(p: PubSubPeer): Hash =
|
||||
p.peerId.hash
|
||||
|
||||
|
||||
Reference in New Issue
Block a user