From 67d0926e89c54b9a31a12482313eeb68c306a2a4 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni <7008900+sinkingsugar@users.noreply.github.com> Date: Sat, 27 Feb 2021 21:31:59 +0900 Subject: [PATCH] use in any case PeerID for peersInIP to avoid keeping references --- libp2p/protocols/pubsub/gossipsub.nim | 2 +- libp2p/protocols/pubsub/gossipsub/scoring.nim | 2 +- libp2p/protocols/pubsub/gossipsub/types.nim | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index beee0be..6fd3a8c 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -198,7 +198,7 @@ method unsubscribePeer*(g: GossipSub, peer: PeerID) = # remove from peer IPs collection too if pubSubPeer.sendConn != nil: g.peersInIP.withValue(pubSubPeer.sendConn.observedAddr, s): - s[].excl(pubSubPeer) + s[].excl(pubSubPeer.peerId) if s[].len == 0: g.peersInIP.del(pubSubPeer.sendConn.observedAddr) diff --git a/libp2p/protocols/pubsub/gossipsub/scoring.nim b/libp2p/protocols/pubsub/gossipsub/scoring.nim index fa8daae..494ad21 100644 --- a/libp2p/protocols/pubsub/gossipsub/scoring.nim +++ b/libp2p/protocols/pubsub/gossipsub/scoring.nim @@ -46,7 +46,7 @@ proc colocationFactor(g: GossipSub, peer: PubSubPeer): float64 = let address = peer.sendConn.observedAddr - g.peersInIP.mgetOrPut(address, initHashSet[PubSubPeer]()).incl(peer) + g.peersInIP.mgetOrPut(address, initHashSet[PeerID]()).incl(peer.peerId) let ipPeers = g.peersInIP[address] len = ipPeers.len.float64 diff --git a/libp2p/protocols/pubsub/gossipsub/types.nim b/libp2p/protocols/pubsub/gossipsub/types.nim index 59844cc..c9fced1 100644 --- a/libp2p/protocols/pubsub/gossipsub/types.nim +++ b/libp2p/protocols/pubsub/gossipsub/types.nim @@ -146,7 +146,7 @@ type parameters*: GossipSubParams topicParams*: Table[string, TopicParams] directPeersLoop*: Future[void] - peersInIP*: Table[MultiAddress, HashSet[PubSubPeer]] + peersInIP*: Table[MultiAddress, HashSet[PeerID]] heartbeatEvents*: seq[AsyncEvent]