From e355cb2600050abf9b8f8c587c0ca80d18834b03 Mon Sep 17 00:00:00 2001 From: NIC619 Date: Sat, 23 Nov 2019 16:04:22 +0800 Subject: [PATCH] Apply PR feedback: Only use pop method if error handling is in place --- libp2p/pubsub/gossipsub.py | 2 +- libp2p/pubsub/pubsub.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libp2p/pubsub/gossipsub.py b/libp2p/pubsub/gossipsub.py index 3bf5fa11..d09db76e 100644 --- a/libp2p/pubsub/gossipsub.py +++ b/libp2p/pubsub/gossipsub.py @@ -292,7 +292,7 @@ class GossipSub(IPubsubRouter): await self.emit_prune(topic, peer) # Forget mesh[topic] - self.mesh.pop(topic, None) + del self.mesh[topic] # Heartbeat async def heartbeat(self) -> None: diff --git a/libp2p/pubsub/pubsub.py b/libp2p/pubsub/pubsub.py index 869c9688..493a303c 100644 --- a/libp2p/pubsub/pubsub.py +++ b/libp2p/pubsub/pubsub.py @@ -282,7 +282,7 @@ class Pubsub: await stream.write(encode_varint_prefixed(hello.SerializeToString())) except StreamClosed: logger.debug("Fail to add new peer %s: stream closed", peer_id) - self.peers.pop(peer_id, None) + del self.peers[peer_id] return # TODO: Check EOF of this stream. # TODO: Check if the peer in black list. @@ -290,7 +290,7 @@ class Pubsub: self.router.add_peer(peer_id, stream.get_protocol()) except Exception as error: logger.debug("fail to add new peer %s, error %s", peer_id, error) - self.peers.pop(peer_id, None) + del self.peers[peer_id] return logger.debug("added new peer %s", peer_id) @@ -410,7 +410,7 @@ class Pubsub: if topic_id not in self.my_topics: return # Remove topic_id from map if present - self.my_topics.pop(topic_id, None) + del self.my_topics[topic_id] # Create unsubscribe message packet: rpc_pb2.RPC = rpc_pb2.RPC()