merged UDP SOCKS5 fix from RC_0_16

This commit is contained in:
Arvid Norberg 2013-05-24 06:28:46 +00:00
parent d96ddfad9a
commit 9db408b416
3 changed files with 24 additions and 22 deletions

View File

@ -21,6 +21,7 @@
* fix uTP edge case where udp socket buffer fills up * fix uTP edge case where udp socket buffer fills up
* fix nagle implementation in uTP * fix nagle implementation in uTP
* fix bug in SOCK5 UDP support
* fix issue where torrents added by URL would not be started immediately * fix issue where torrents added by URL would not be started immediately
0.16.10 release 0.16.10 release

View File

@ -238,7 +238,18 @@ namespace libtorrent
bool m_tunnel_packets; bool m_tunnel_packets;
bool m_force_proxy; bool m_force_proxy;
bool m_abort; 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; 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 // while we're connecting to the proxy
// we have to queue the packets, we'll flush // we have to queue the packets, we'll flush
// them once we're connected // them once we're connected

View File

@ -440,7 +440,7 @@ void udp_socket::on_read_impl(udp::socket* s, udp::endpoint const& ep
if (m_tunnel_packets) if (m_tunnel_packets)
{ {
// if the source IP doesn't match the proxy's, ignore the packet // 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); unwrap(e, m_buf, bytes_transferred);
} }
else if (!m_force_proxy) // block incoming packets that aren't coming via the proxy 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); iovec[1] = asio::const_buffer(p, len);
#if TORRENT_USE_IPV6 #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 #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 #if TORRENT_USE_IPV6
else 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 #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); iovec[1] = asio::const_buffer(p, len);
#if TORRENT_USE_IPV6 #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 #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 #if TORRENT_USE_IPV6
else 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 #endif
} }
@ -1169,19 +1169,9 @@ void udp_socket::socks_forward_udp()
write_uint8(3, p); // UDP ASSOCIATE command write_uint8(3, p); // UDP ASSOCIATE command
write_uint8(0, p); // reserved write_uint8(0, p); // reserved
error_code ec; error_code ec;
tcp::endpoint local = m_socks5_sock.local_endpoint(ec); write_uint8(1, p); // ATYP = IPv4
write_uint8(local.address().is_v4() ? 1 : 4, p); // ATYP IPv4 write_uint32(0, p); // 0.0.0.0
detail::write_address(local.address(), p); write_uint16(0, p); // :0
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);
TORRENT_ASSERT_VAL(p - m_tmp_buf < int(sizeof(m_tmp_buf)), (p - m_tmp_buf)); TORRENT_ASSERT_VAL(p - m_tmp_buf < int(sizeof(m_tmp_buf)), (p - m_tmp_buf));
#if defined TORRENT_ASIO_DEBUGGING #if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("udp_socket::connect1"); add_outstanding_async("udp_socket::connect1");
@ -1274,8 +1264,8 @@ void udp_socket::connect2(error_code const& e)
if (atyp == 1) if (atyp == 1)
{ {
m_proxy_addr.address(address_v4(read_uint32(p))); m_udp_proxy_addr.address(address_v4(read_uint32(p)));
m_proxy_addr.port(read_uint16(p)); m_udp_proxy_addr.port(read_uint16(p));
} }
else else
{ {