Skip to content

Commit

Permalink
Fix dispatcher on_socks5_tcp_data when transport is none
Browse files Browse the repository at this point in the history
  • Loading branch information
xoriole committed Feb 7, 2024
1 parent 83a6eba commit 4eb0b5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/tribler/core/components/tunnel/community/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions src/tribler/core/components/tunnel/tests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4eb0b5e

Please sign in to comment.