fix bug in udp_socket when changing socks5 proxy quickly

This commit is contained in:
Arvid Norberg 2014-06-30 08:41:33 +00:00
parent 36e8945968
commit fa4c016d39
4 changed files with 32 additions and 11 deletions

View File

@ -1,5 +1,6 @@
1.0 release
* fix bug in udp_socket when changing socks5 proxy quickly
* fix bugs in convert_to/from_native() on windows
* fix support for web servers not supporting keepalive
* support storing save_path in resume data

View File

@ -185,7 +185,7 @@ namespace libtorrent
void on_name_lookup(error_code const& e, tcp::resolver::iterator i);
void on_timeout();
void on_connect(int ticket);
void on_connected(error_code const& ec);
void on_connected(error_code const& ec, int ticket);
void handshake1(error_code const& e);
void handshake2(error_code const& e);
void handshake3(error_code const& e);

View File

@ -924,10 +924,16 @@ void udp_socket::on_connect(int ticket)
return;
}
if (m_abort) return;
if (is_closed()) return;
if (m_connection_ticket != -1)
{
// there's already an outstanding connect. Cancel it.
m_socks5_sock.close();
m_connection_ticket = -1;
}
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("udp_socket::on_connected");
#endif
@ -940,10 +946,10 @@ void udp_socket::on_connect(int ticket)
++m_outstanding_connect;
#endif
m_socks5_sock.async_connect(tcp::endpoint(m_proxy_addr.address(), m_proxy_addr.port())
, boost::bind(&udp_socket::on_connected, this, _1));
, boost::bind(&udp_socket::on_connected, this, _1, ticket));
}
void udp_socket::on_connected(error_code const& e)
void udp_socket::on_connected(error_code const& e, int ticket)
{
#if defined TORRENT_ASIO_DEBUGGING
complete_async("udp_socket::on_connected");
@ -962,16 +968,14 @@ void udp_socket::on_connected(error_code const& e)
CHECK_MAGIC;
TORRENT_ASSERT(is_single_thread());
if (m_connection_ticket >= 0)
if (m_cc.done(ticket))
{
if (m_cc.done(m_connection_ticket))
// if the tickets mismatch, another connection attempt
// was initiated while waiting for this one to complete.
if (ticket == m_connection_ticket)
m_connection_ticket = -1;
}
if (m_abort) return;
if (e == asio::error::operation_aborted) return;
// we just called done, which means on_timeout
// won't be called. Decrement the outstanding
// ops counter for that
@ -987,6 +991,14 @@ void udp_socket::on_connected(error_code const& e)
+ m_outstanding_resolve
+ m_outstanding_connect_queue
+ m_outstanding_socks);
if (e == asio::error::operation_aborted) return;
// if ticket != m_connection_ticket, it means m_connection_ticket
// will not have been reset, and it means we are still waiting
// for a connection attempt.
if (m_connection_ticket != -1) return;
if (m_abort) return;
if (e)

View File

@ -205,10 +205,18 @@ void test_transfer(int proxy_type, bool test_disk_full = false
if (proxy_type)
{
ps.port = start_proxy(proxy_type);
ps.hostname = "127.0.0.1";
ps.username = "testuser";
ps.password = "testpass";
ps.type = (proxy_settings::proxy_type)proxy_type;
// test resetting the proxy in quick succession.
// specifically the udp_socket connecting to a new
// socks5 proxy while having one connection attempt
// in progress.
ps.hostname = "5.6.7.8";
ses1.set_proxy(ps);
ps.hostname = "127.0.0.1";
ses1.set_proxy(ps);
ses2.set_proxy(ps);
}