Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for IPv6 peer connections with socks5 proxy #7195

Open
liangzx96 opened this issue Nov 29, 2022 · 6 comments
Open

Support for IPv6 peer connections with socks5 proxy #7195

liangzx96 opened this issue Nov 29, 2022 · 6 comments
Milestone

Comments

@liangzx96
Copy link

Please provide the following information

libtorrent version (or branch): 2.0.8

platform/architecture: Ubuntu 20.04 LTS

compiler and compiler version:
cmake version 3.16.3
gcc version 12.2.1

please describe what symptom you see, what you would expect to see instead and
how to reproduce it.

The socks proxy implementation does not work properly with IPv6 peer connection. This issue happens because libtorrent creates only one socket with default ipv4 endpoint 0.0.0.0 to listen all peers whenever a proxy was enabled. Here is the description from the libtorrent website

when using a proxy, this is the hostname where the proxy is running see proxy_type. Note that when using a proxy, the settings_pack::listen_interfaces setting is overridden and only a single interface is created, just to contact the proxy.

This setting would cause the users unable to connect to ipv6 peers since the session_impl::bind_outgoing_socket function checks if local_endpoint and remote_address belong to the same address family and otherwise fails to bind the outgoing socket to the remote address.
if (is_v4(ls->local_endpoint) != remote_address.is_v4()) continue;

To solve this issue, I find that we can modify the logic in the session_impl:reopen_listen_sockets function to let it push two endpoints v4.any() and v6.any() instead of only v4.any() into eps like this way

          listen_endpoint_t ep_v4(address_v4::any(), port, {}, transport::plaintext, listen_socket_t::proxy);
	  listen_endpoint_t ep_v6(address_v6::any(), port, {}, transport::plaintext, listen_socket_t::proxy);
	  eps.emplace_back(ep_v4);
          eps.emplace_back(ep_v6);

I'm not sure if this modification has any unexpected side effects but this recompiled version works pretty well on my machine so far.

@skbeh
Copy link

skbeh commented Dec 25, 2022

@arvidn The problem also affected me. Applying the above patch did solve my problem.

@stale
Copy link

stale bot commented Apr 2, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 2, 2023
@arvidn arvidn removed the stale label Apr 7, 2023
@arvidn arvidn added this to the 2.0.9 milestone Apr 7, 2023
@arvidn
Copy link
Owner

arvidn commented May 14, 2023

sorry for the delay. This does look like a reasonable solution.

@arvidn
Copy link
Owner

arvidn commented May 14, 2023

how does this look? #7415

@arvidn
Copy link
Owner

arvidn commented May 14, 2023

one problem with this approach, which was exposed in tests in master, is that creating two endpoints will connect twice to the proxy.

@arvidn
Copy link
Owner

arvidn commented May 14, 2023

here's another attempt at fixing this. I'd really appreciate it if one of you could test it!
#7421

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants