From c6f0d715796a7b79c11f8577be96b5a97010a0e4 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Mon, 28 Oct 2024 03:40:10 +0200 Subject: [PATCH] Addressed too-many-positional-arguments in connections, reduced number of instance attributes. --- minode/connection.py | 30 +++++++++--------------------- minode/i2p/dialer.py | 4 +--- minode/i2p/listener.py | 3 +-- 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/minode/connection.py b/minode/connection.py index 05d552a..314ceea 100644 --- a/minode/connection.py +++ b/minode/connection.py @@ -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()) diff --git a/minode/i2p/dialer.py b/minode/i2p/dialer.py index 36e4aa0..ff094cd 100644 --- a/minode/i2p/dialer.py +++ b/minode/i2p/dialer.py @@ -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) diff --git a/minode/i2p/listener.py b/minode/i2p/listener.py index f63de06..7ec1954 100644 --- a/minode/i2p/listener.py +++ b/minode/i2p/listener.py @@ -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