Onionr/src/gossip/connectpeer.py

19 lines
499 B
Python
Raw Normal View History

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