From 01b0fcec4cc196666c9849574193cd1368957dd1 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 b503da4baaea558dea8f7338a6550c9165479739 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 0bb26ac2f69bae6ef65a26a7067ea4e6ebcd2a7d 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 4799da3f0d2..b37466467aa 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): def add_data_if_result(result_func, connection=connection.udp_connection, request=request): diff --git a/src/tribler/core/components/tunnel/tests/test_dispatcher.py b/src/tribler/core/components/tunnel/tests/test_dispatcher.py index 9584844d692..fadbecd7794 100644 --- a/src/tribler/core/components/tunnel/tests/test_dispatcher.py +++ b/src/tribler/core/components/tunnel/tests/test_dispatcher.py @@ -96,6 +96,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