From 34f9ffbf6b559462480fbbffe4b182a33269f581 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Sat, 26 Feb 2022 01:06:17 -0600 Subject: [PATCH] Made peers hashable and comparable for their use in the peer set --- src/gossip/peer.py | 12 ++++++++---- static-data/default-plugins/tor/torpeer.py | 9 +++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/gossip/peer.py b/src/gossip/peer.py index a39ac693..8d007d32 100644 --- a/src/gossip/peer.py +++ b/src/gossip/peer.py @@ -4,10 +4,7 @@ if TYPE_CHECKING: class Peer(Protocol): - stats = {} - sock = None - id = "" - node_address = "" + transport_address = "" def __init__(self): return @@ -16,3 +13,10 @@ class Peer(Protocol): def disconnect(self): return + + def __eq__(self, other): + return + + def __hash__(self): + """Use the transport address""" + return \ No newline at end of file diff --git a/static-data/default-plugins/tor/torpeer.py b/static-data/default-plugins/tor/torpeer.py index e76377b5..f0134a49 100644 --- a/static-data/default-plugins/tor/torpeer.py +++ b/static-data/default-plugins/tor/torpeer.py @@ -13,3 +13,12 @@ class TorPeer: s.set_proxy(socks.SOCKS4, self.socks_host, self.socks_port, rdns=True) s.connect((self.onion_address, 80)) return s + + def __hash__(self): + return hash(self.transport_address) + + def __eq__(self, other): + try: + return self.transport_address == other.transport_address + except AttributeError: + return False