When checking for peer online to add to peer pool, make sure it closes and avoid attempting if its already in the pool

This commit is contained in:
Kevin F 2022-02-27 13:34:16 -06:00
parent 5337b0aba4
commit 44f6b90777

View File

@ -1,11 +1,16 @@
from gossip.commands import GossipCommands, command_to_byte
import logger
def connect_peer(peer_set, peer):
if peer in peer_set:
return
try:
peer.get_socket()
s = peer.get_socket()
except Exception:
logger.warn(f"Could not connect to {peer.transport_address}")
else:
s.sendall(command_to_byte(GossipCommands.CLOSE))
s.close()
peer_set.add(peer)
logger.info(f"connected to {peer.transport_address}")