diff --git a/ChangeLog b/ChangeLog index 5f1e6be57..f51266df0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,6 +21,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * fix bug in SOCK5 UDP support * fix issue where torrents added by URL would not be started immediately 0.16.10 release diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index 896ff4d04..c50eb5f9f 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -238,7 +238,18 @@ namespace libtorrent bool m_tunnel_packets; bool m_force_proxy; bool m_abort; + + // this is the endpoint the proxy server lives at. + // when performing a UDP associate, we get another + // endpoint (presumably on the same IP) where we're + // supposed to send UDP packets. udp::endpoint m_proxy_addr; + + // this is where UDP packets that are to be forwarded + // are sent. The result from UDP ASSOCIATE is stored + // in here. + udp::endpoint m_udp_proxy_addr; + // while we're connecting to the proxy // we have to queue the packets, we'll flush // them once we're connected diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index 9b255fea0..31516ba45 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -440,7 +440,7 @@ void udp_socket::on_read_impl(udp::socket* s, udp::endpoint const& ep if (m_tunnel_packets) { // if the source IP doesn't match the proxy's, ignore the packet - if (ep == m_proxy_addr) + if (ep == m_udp_proxy_addr) unwrap(e, m_buf, bytes_transferred); } else if (!m_force_proxy) // block incoming packets that aren't coming via the proxy @@ -488,12 +488,12 @@ void udp_socket::wrap(udp::endpoint const& ep, char const* p, int len, error_cod iovec[1] = asio::const_buffer(p, len); #if TORRENT_USE_IPV6 - if (m_proxy_addr.address().is_v4() && m_ipv4_sock.is_open()) + if (m_udp_proxy_addr.address().is_v4() && m_ipv4_sock.is_open()) #endif - m_ipv4_sock.send_to(iovec, m_proxy_addr, 0, ec); + m_ipv4_sock.send_to(iovec, m_udp_proxy_addr, 0, ec); #if TORRENT_USE_IPV6 else - m_ipv6_sock.send_to(iovec, m_proxy_addr, 0, ec); + m_ipv6_sock.send_to(iovec, m_udp_proxy_addr, 0, ec); #endif } @@ -519,12 +519,12 @@ void udp_socket::wrap(char const* hostname, int port, char const* p, int len, er iovec[1] = asio::const_buffer(p, len); #if TORRENT_USE_IPV6 - if (m_proxy_addr.address().is_v4() && m_ipv4_sock.is_open()) + if (m_udp_proxy_addr.address().is_v4() && m_ipv4_sock.is_open()) #endif - m_ipv4_sock.send_to(iovec, m_proxy_addr, 0, ec); + m_ipv4_sock.send_to(iovec, m_udp_proxy_addr, 0, ec); #if TORRENT_USE_IPV6 else - m_ipv6_sock.send_to(iovec, m_proxy_addr, 0, ec); + m_ipv6_sock.send_to(iovec, m_udp_proxy_addr, 0, ec); #endif } @@ -1169,19 +1169,9 @@ void udp_socket::socks_forward_udp() write_uint8(3, p); // UDP ASSOCIATE command write_uint8(0, p); // reserved error_code ec; - tcp::endpoint local = m_socks5_sock.local_endpoint(ec); - write_uint8(local.address().is_v4() ? 1 : 4, p); // ATYP IPv4 - detail::write_address(local.address(), p); - int port = 0; -#if TORRENT_USE_IPV6 - if (local.address().is_v4()) -#endif - port = m_ipv4_sock.local_endpoint(ec).port(); -#if TORRENT_USE_IPV6 - else - port = m_ipv6_sock.local_endpoint(ec).port(); -#endif - detail::write_uint16(port , p); + write_uint8(1, p); // ATYP = IPv4 + write_uint32(0, p); // 0.0.0.0 + write_uint16(0, p); // :0 TORRENT_ASSERT_VAL(p - m_tmp_buf < int(sizeof(m_tmp_buf)), (p - m_tmp_buf)); #if defined TORRENT_ASIO_DEBUGGING add_outstanding_async("udp_socket::connect1"); @@ -1274,8 +1264,8 @@ void udp_socket::connect2(error_code const& e) if (atyp == 1) { - m_proxy_addr.address(address_v4(read_uint32(p))); - m_proxy_addr.port(read_uint16(p)); + m_udp_proxy_addr.address(address_v4(read_uint32(p))); + m_udp_proxy_addr.port(read_uint16(p)); } else {