peer.get_socket implementations now must take timeout arg used for initial connection

This commit is contained in:
Kevin F 2022-03-20 12:51:25 -05:00
parent 511803f565
commit a53c31fda7
5 changed files with 6 additions and 6 deletions

View File

@ -17,7 +17,7 @@ def do_announce(peer_set):
our_transport_address = our_transport_address.encode('utf-8')
except AttributeError:
pass
sock = announce_peer.get_socket()
sock = announce_peer.get_socket(12)
sock.sendall(
command_to_byte(GossipCommands.ANNOUNCE) + our_transport_address)
if int.from_bytes(sock.recv(1), 'big') != 1:

View File

@ -15,7 +15,7 @@ MAX_PEERS = 10
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))
# Get 10 max peers
for _ in range(MAX_PEERS):

View File

@ -6,7 +6,7 @@ def connect_peer(peer_set, peer):
if peer in peer_set:
return
try:
s = peer.get_socket()
s = peer.get_socket(12)
except Exception:
logger.warn(f"Could not connect to {peer.transport_address}")
else:

View File

@ -8,7 +8,7 @@ class Peer(Protocol):
def __init__(self):
return
def get_socket(self) -> 'socket.socket':
def get_socket(self, connect_timeout) -> 'socket.socket':
return
def disconnect(self):

View File

@ -10,10 +10,10 @@ class TorPeer:
self.socks_host = socks_host
self.socks_port = socks_port
def get_socket(self) -> socks.socksocket:
def get_socket(self, connect_timeout) -> socks.socksocket:
s = socks.socksocket()
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))
return s