peer.get_socket implementations now must take timeout arg used for initial connection
This commit is contained in:
parent
511803f565
commit
a53c31fda7
@ -17,7 +17,7 @@ def do_announce(peer_set):
|
|||||||
our_transport_address = our_transport_address.encode('utf-8')
|
our_transport_address = our_transport_address.encode('utf-8')
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
sock = announce_peer.get_socket()
|
sock = announce_peer.get_socket(12)
|
||||||
sock.sendall(
|
sock.sendall(
|
||||||
command_to_byte(GossipCommands.ANNOUNCE) + our_transport_address)
|
command_to_byte(GossipCommands.ANNOUNCE) + our_transport_address)
|
||||||
if int.from_bytes(sock.recv(1), 'big') != 1:
|
if int.from_bytes(sock.recv(1), 'big') != 1:
|
||||||
|
@ -15,7 +15,7 @@ MAX_PEERS = 10
|
|||||||
|
|
||||||
|
|
||||||
def _ask_peer(peer, peer_set):
|
def _ask_peer(peer, peer_set):
|
||||||
s: 'socket' = peer.get_socket()
|
s: 'socket' = peer.get_socket(12)
|
||||||
s.sendall(command_to_byte(GossipCommands.PEER_EXCHANGE))
|
s.sendall(command_to_byte(GossipCommands.PEER_EXCHANGE))
|
||||||
# Get 10 max peers
|
# Get 10 max peers
|
||||||
for _ in range(MAX_PEERS):
|
for _ in range(MAX_PEERS):
|
||||||
|
@ -6,7 +6,7 @@ def connect_peer(peer_set, peer):
|
|||||||
if peer in peer_set:
|
if peer in peer_set:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
s = peer.get_socket()
|
s = peer.get_socket(12)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warn(f"Could not connect to {peer.transport_address}")
|
logger.warn(f"Could not connect to {peer.transport_address}")
|
||||||
else:
|
else:
|
||||||
|
@ -8,7 +8,7 @@ class Peer(Protocol):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
return
|
return
|
||||||
def get_socket(self) -> 'socket.socket':
|
def get_socket(self, connect_timeout) -> 'socket.socket':
|
||||||
return
|
return
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
|
@ -10,10 +10,10 @@ class TorPeer:
|
|||||||
self.socks_host = socks_host
|
self.socks_host = socks_host
|
||||||
self.socks_port = socks_port
|
self.socks_port = socks_port
|
||||||
|
|
||||||
def get_socket(self) -> socks.socksocket:
|
def get_socket(self, connect_timeout) -> socks.socksocket:
|
||||||
s = socks.socksocket()
|
s = socks.socksocket()
|
||||||
s.set_proxy(socks.SOCKS4, self.socks_host, self.socks_port, rdns=True)
|
s.set_proxy(socks.SOCKS4, self.socks_host, self.socks_port, rdns=True)
|
||||||
s.settimeout(60)
|
s.settimeout(connect_timeout)
|
||||||
s.connect((self.onion_address, 80))
|
s.connect((self.onion_address, 80))
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user