Made peers hashable and comparable for their use in the peer set
This commit is contained in:
parent
8d394c76a7
commit
34f9ffbf6b
@ -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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user