Addressed too-many-positional-arguments in connections,

reduced number of instance attributes.
This commit is contained in:
Lee Miller 2024-10-28 03:40:10 +02:00
parent a046bbeb31
commit c6f0d71579
Signed by: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
3 changed files with 11 additions and 26 deletions

View File

@ -20,22 +20,19 @@ class ConnectionBase(threading.Thread):
Common code for the connection thread
with minimum command handlers to reuse
"""
def __init__(
self, host, port, s=None, network='ip', server=False,
i2p_remote_dest=b''
):
def __init__(self, host, port, s=None, server=False):
self.host = host
self.port = port
self.network = network
self.i2p_remote_dest = i2p_remote_dest
self.network = 'i2p' if port == 'i2p' else 'ip'
if self.network == 'i2p':
self.host_print = self.i2p_remote_dest[:8].decode()
else:
self.host_print = self.host
self.host_print = (
self.host[:8].decode() if self.network == 'i2p' else self.host)
super().__init__(name='Connection to {}:{}'.format(host, port))
self.s = s
self.server = server
self.send_queue = queue.Queue()
self.vectors_to_get = set()
@ -43,22 +40,13 @@ class ConnectionBase(threading.Thread):
self.vectors_requested = {}
self.status = 'ready'
self.tls = False
self.status = 'connected' if bool(s) else 'ready'
self.verack_received = False
self.verack_sent = False
self.s = s
self.remote_version = None
self.server = server
if bool(s):
self.status = 'connected'
self.buffer_receive = b''
self.buffer_send = b''
@ -238,7 +226,7 @@ class ConnectionBase(threading.Thread):
logging.debug('ssl.SSLError reason: %s', e.reason)
shared.node_pool.discard((self.host, self.port))
return
self.tls = True
logging.debug(
'Established TLS connection with %s:%s (%s)',
self.host_print, self.port, self.s.version())

View File

@ -28,9 +28,7 @@ class I2PDialer(I2PThread):
logging.debug('Connecting to %s', self.destination)
self._connect()
if not self.state.shutting_down and self.success:
c = self.state.connection(
self.destination, 'i2p', self.s, 'i2p',
False, self.destination)
c = self.state.connection(self.destination, 'i2p', self.s, False)
c.start()
self.state.connections.add(c)

View File

@ -45,8 +45,7 @@ class I2PListener(I2PThread):
logging.debug('Rejecting duplicate I2P connection.')
self.s.close()
else:
c = self.state.connection(
destination, 'i2p', self.s, 'i2p', True, destination)
c = self.state.connection(destination, 'i2p', self.s, True)
c.start()
self.state.connections.add(c)
c = None