Made peers hashable and comparable for their use in the peer set

This commit is contained in:
Kevin F 2022-02-26 01:06:17 -06:00
parent 8d394c76a7
commit 34f9ffbf6b
2 changed files with 17 additions and 4 deletions

View File

@ -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

View File

@ -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