diff --git a/libp2p/network/swarm.py b/libp2p/network/swarm.py index 18676b3d..de80dd82 100644 --- a/libp2p/network/swarm.py +++ b/libp2p/network/swarm.py @@ -270,9 +270,11 @@ class Swarm(INetwork): """Simply remove the connection from Swarm's records, without closing the connection.""" peer_id = swarm_conn.muxed_conn.peer_id + if peer_id not in self.connections: + return # TODO: Should be changed to remove the exact connection, # if we have several connections per peer in the future. - self.connections.pop(peer_id, None) + del self.connections[peer_id] # Notifee diff --git a/libp2p/pubsub/gossipsub.py b/libp2p/pubsub/gossipsub.py index e9d0f355..3bf5fa11 100644 --- a/libp2p/pubsub/gossipsub.py +++ b/libp2p/pubsub/gossipsub.py @@ -353,8 +353,8 @@ class GossipSub(IPubsubRouter): # TODO: there's no way time_since_last_publish gets set anywhere yet if self.time_since_last_publish[topic] > self.time_to_live: # Remove topic from fanout - self.fanout.pop(topic, None) - self.time_since_last_publish.pop(topic, None) + del self.fanout[topic] + del self.time_since_last_publish[topic] else: num_fanout_peers_in_topic = len(self.fanout[topic]) diff --git a/libp2p/pubsub/pubsub.py b/libp2p/pubsub/pubsub.py index ba1994ea..869c9688 100644 --- a/libp2p/pubsub/pubsub.py +++ b/libp2p/pubsub/pubsub.py @@ -298,7 +298,7 @@ class Pubsub: def _handle_dead_peer(self, peer_id: ID) -> None: if peer_id not in self.peers: return - self.peers.pop(peer_id, None) + del self.peers[peer_id] for topic in self.peer_topics: if peer_id in self.peer_topics[topic]: