forked from premiere/premiere-libtorrent
fixed SOCKS5 bug for routing UDP packets
This commit is contained in:
parent
b0a3b2545b
commit
ef48c92a4e
|
@ -39,6 +39,7 @@
|
|||
incoming connection
|
||||
* added more detailed instrumentation of the disk I/O thread
|
||||
|
||||
* fixed SOCKS5 bug for routing UDP packets
|
||||
* fixed bug on windows when verifying resume data for a torrent where
|
||||
one of its directories had been removed
|
||||
* fixed race condition in peer-list with DHT
|
||||
|
|
|
@ -774,6 +774,8 @@ int main(int argc, char* argv[])
|
|||
" -R <num blocks> number of blocks per read cache line\n"
|
||||
" -O Disallow disk job reordering\n"
|
||||
" -P <host:port> Use the specified SOCKS5 proxy\n"
|
||||
" -L <user:passwd> Use the specified username and password for the\n"
|
||||
" proxy specified by -P\n"
|
||||
" -H Don't start DHT\n"
|
||||
" -W <num peers> Set the max number of peers to keep in the peer list\n"
|
||||
" "
|
||||
|
@ -794,6 +796,8 @@ int main(int argc, char* argv[])
|
|||
settings.disk_cache_algorithm = session_settings::largest_contiguous;
|
||||
settings.volatile_read_cache = true;
|
||||
|
||||
proxy_settings ps;
|
||||
|
||||
int refresh_delay = 1;
|
||||
bool start_dht = true;
|
||||
|
||||
|
@ -947,20 +951,28 @@ int main(int argc, char* argv[])
|
|||
break;
|
||||
}
|
||||
*port++ = 0;
|
||||
proxy_settings ps;
|
||||
ps.hostname = arg;
|
||||
ps.port = atoi(port);
|
||||
if (ps.port == 0) {
|
||||
fprintf(stderr, "invalid proxy port\n");
|
||||
break;
|
||||
}
|
||||
ps.type = proxy_settings::socks5;
|
||||
ses.set_peer_proxy(ps);
|
||||
ses.set_web_seed_proxy(ps);
|
||||
ses.set_tracker_proxy(ps);
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
ses.set_dht_proxy(ps);
|
||||
#endif
|
||||
if (ps.type == proxy_settings::none)
|
||||
ps.type = proxy_settings::socks5;
|
||||
}
|
||||
break;
|
||||
case 'L':
|
||||
{
|
||||
char* pw = (char*) strchr(arg, ':');
|
||||
if (pw == 0)
|
||||
{
|
||||
fprintf(stderr, "invalid proxy username and password specified\n");
|
||||
break;
|
||||
}
|
||||
*pw++ = 0;
|
||||
ps.username = arg;
|
||||
ps.password = pw;
|
||||
ps.type = proxy_settings::socks5_pw;
|
||||
}
|
||||
break;
|
||||
case 'I': outgoing_interface = arg; break;
|
||||
|
@ -968,6 +980,13 @@ int main(int argc, char* argv[])
|
|||
++i; // skip the argument
|
||||
}
|
||||
|
||||
ses.set_peer_proxy(ps);
|
||||
ses.set_web_seed_proxy(ps);
|
||||
ses.set_tracker_proxy(ps);
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
ses.set_dht_proxy(ps);
|
||||
#endif
|
||||
|
||||
ses.listen_on(std::make_pair(listen_port, listen_port + 10)
|
||||
, bind_to_interface.c_str());
|
||||
|
||||
|
|
|
@ -108,6 +108,7 @@ namespace libtorrent
|
|||
void socks_forward_udp(mutex::scoped_lock& l);
|
||||
void connect1(error_code const& e);
|
||||
void connect2(error_code const& e);
|
||||
void hung_up(error_code const& e);
|
||||
|
||||
void wrap(udp::endpoint const& ep, char const* p, int len, error_code& ec);
|
||||
void unwrap(error_code const& e, char const* buf, int size);
|
||||
|
|
|
@ -646,7 +646,7 @@ void udp_socket::socks_forward_udp(mutex::scoped_lock& l)
|
|||
write_uint8(5, p); // SOCKS VERSION 5
|
||||
write_uint8(3, p); // UDP ASSOCIATE command
|
||||
write_uint8(0, p); // reserved
|
||||
write_uint8(0, p); // ATYP IPv4
|
||||
write_uint8(1, p); // ATYP IPv4
|
||||
write_uint32(0, p); // IP any
|
||||
write_uint16(m_bind_port, p);
|
||||
|
||||
|
@ -705,6 +705,22 @@ void udp_socket::connect2(error_code const& e)
|
|||
udp_socket::send(p.ep, &p.buf[0], p.buf.size(), ec);
|
||||
m_queue.pop_front();
|
||||
}
|
||||
|
||||
asio::async_read(m_socks5_sock, asio::buffer(m_tmp_buf, 10)
|
||||
, boost::bind(&udp_socket::hung_up, this, _1));
|
||||
}
|
||||
|
||||
void udp_socket::hung_up(error_code const& e)
|
||||
{
|
||||
CHECK_MAGIC;
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
|
||||
if (e == asio::error::operation_aborted || m_abort) return;
|
||||
|
||||
l.unlock();
|
||||
|
||||
// the socks connection was closed, re-open it
|
||||
set_proxy_settings(m_proxy_settings);
|
||||
}
|
||||
|
||||
rate_limited_udp_socket::rate_limited_udp_socket(io_service& ios
|
||||
|
|
Loading…
Reference in New Issue