From d7aa59a59365ea0e1cfc48a57a668cb26227c6a0 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Wed, 7 Feb 2024 08:37:31 +0100 Subject: [PATCH 1/3] Fix network name is no longer available error --- src/tribler/core/components/socks_servers/socks5/connection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tribler/core/components/socks_servers/socks5/connection.py b/src/tribler/core/components/socks_servers/socks5/connection.py index 060fe4de425..2c1d1794f29 100644 --- a/src/tribler/core/components/socks_servers/socks5/connection.py +++ b/src/tribler/core/components/socks_servers/socks5/connection.py @@ -215,3 +215,4 @@ def close(self, reason='unspecified'): if self.transport: self.transport.close() + self.transport = None From c994f08bfab4c39822a9b246713d69ee29fed41c Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Wed, 7 Feb 2024 08:56:53 +0100 Subject: [PATCH 2/3] Fix socks connection tests --- .../components/socks_servers/socks5/tests/test_connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tribler/core/components/socks_servers/socks5/tests/test_connection.py b/src/tribler/core/components/socks_servers/socks5/tests/test_connection.py index 13094ed2362..6e9e0041fe4 100644 --- a/src/tribler/core/components/socks_servers/socks5/tests/test_connection.py +++ b/src/tribler/core/components/socks_servers/socks5/tests/test_connection.py @@ -50,7 +50,7 @@ def test_invalid_version(connection): Test passing an invalid version to the socks5 server """ connection.data_received(unhexlify('040100')) - assert not connection.transport.connected + assert not connection.transport def test_method_request(connection): From 85c7517ad036597b6432820121cae6f51ac2e96c Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Wed, 7 Feb 2024 14:19:55 +0100 Subject: [PATCH 3/3] Fix dispatcher on_socks5_tcp_data when transport is none --- .../core/components/tunnel/community/dispatcher.py | 8 ++++++-- .../core/components/tunnel/tests/test_dispatcher.py | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/tribler/core/components/tunnel/community/dispatcher.py b/src/tribler/core/components/tunnel/community/dispatcher.py index d7a3b2cb135..fa88a76b1a0 100644 --- a/src/tribler/core/components/tunnel/community/dispatcher.py +++ b/src/tribler/core/components/tunnel/community/dispatcher.py @@ -93,9 +93,13 @@ async def on_socks5_tcp_data(self, tcp_connection, destination, request): self._logger.info('Failed to get HTTP response using tunnels: %s', e) return + transport = tcp_connection.transport + if not transport: + return + if response: - tcp_connection.transport.write(response) - tcp_connection.transport.close() + transport.write(response) + transport.close() def select_circuit(self, connection, request): if request.destination[1] == CIRCUIT_ID_PORT: diff --git a/src/tribler/core/components/tunnel/tests/test_dispatcher.py b/src/tribler/core/components/tunnel/tests/test_dispatcher.py index c31c5cea7e2..e1cc953b0ae 100644 --- a/src/tribler/core/components/tunnel/tests/test_dispatcher.py +++ b/src/tribler/core/components/tunnel/tests/test_dispatcher.py @@ -94,6 +94,14 @@ async def test_on_socks_in_tcp(dispatcher): tcp_connection.transport.write.assert_called_once_with(b'test') +async def test_on_socks5_tcp_data_with_transport_none(dispatcher): + tcp_connection = Mock(transport=None) + dispatcher.set_socks_servers([tcp_connection.socksserver]) + + dispatcher.tunnels.perform_http_request = Mock(return_value=succeed(b'test')) + await dispatcher.on_socks5_tcp_data(tcp_connection, ("0.0.0.0", 1024), b'') + + def test_circuit_dead(dispatcher, mock_circuit): """ Test whether the correct peers are removed when a circuit breaks