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:
parent
5337b0aba4
commit
44f6b90777
@ -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}")
|
||||
|
Loading…
Reference in New Issue
Block a user