Browse Source

use the same proxy settings (like Tor socks5) for libtorrent as well. DHT still won't work.

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
1ff690e9a0
  1. 2
      libtorrent/src/udp_socket.cpp
  2. 4
      src/init.cpp
  3. 38
      src/twister.cpp

2
libtorrent/src/udp_socket.cpp

@ -813,8 +813,10 @@ void udp_socket::on_name_lookup(error_code const& e, tcp::resolver::iterator i) @@ -813,8 +813,10 @@ void udp_socket::on_name_lookup(error_code const& e, tcp::resolver::iterator i)
void udp_socket::on_timeout()
{
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
if(m_outstanding_timeout > 0) { // without this check it breaks using socks5
TORRENT_ASSERT(m_outstanding_timeout > 0);
--m_outstanding_timeout;
}
#endif
TORRENT_ASSERT(m_outstanding_ops > 0);
--m_outstanding_ops;

4
src/init.cpp

@ -607,8 +607,10 @@ bool AppInit2(boost::thread_group& threadGroup) @@ -607,8 +607,10 @@ bool AppInit2(boost::thread_group& threadGroup)
if (!addrProxy.IsValid())
return InitError(strprintf(_("Invalid -proxy address: '%s'"), mapArgs["-proxy"].c_str()));
if (!IsLimited(NET_IPV4))
if (!IsLimited(NET_IPV4)) {
SetProxy(NET_IPV4, addrProxy, nSocksVersion);
SetReachable(NET_IPV4);
}
if (nSocksVersion > 4) {
#ifdef USE_IPV6
if (!IsLimited(NET_IPV6))

38
src/twister.cpp

@ -38,6 +38,7 @@ twister::twister() @@ -38,6 +38,7 @@ twister::twister()
using namespace libtorrent;
static session *ses = NULL;
static bool m_usingProxy;
static int num_outstanding_resume_data;
static CCriticalSection cs_dhtgetMap;
@ -216,14 +217,27 @@ void ThreadWaitExtIP() @@ -216,14 +217,27 @@ void ThreadWaitExtIP()
int listen_port = GetListenPort() + LIBTORRENT_PORT_OFFSET;
std::string bind_to_interface = "";
proxyType proxyInfoOut;
m_usingProxy = GetProxy(NET_IPV4, proxyInfoOut);
printf("Creating new libtorrent session ext_ip=%s port=%d\n", ipStr.c_str(), listen_port);
printf("Creating new libtorrent session ext_ip=%s port=%d proxy=%s\n",
ipStr.c_str(), !m_usingProxy ? listen_port : 0,
m_usingProxy ? proxyInfoOut.first.ToStringIPPort().c_str() : "");
ses = new session(*m_swarmDb, fingerprint("TW", LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0)
, session::add_default_plugins
, alert::dht_notification
, ipStr.size() ? ipStr.c_str() : NULL
, std::make_pair(listen_port, listen_port));
, !m_usingProxy ? std::make_pair(listen_port, listen_port) : std::make_pair(0, 0) );
if( m_usingProxy ) {
proxy_settings proxy;
proxy.hostname = proxyInfoOut.first.ToStringIP();
proxy.port = proxyInfoOut.first.GetPort();
proxy.type = HaveNameProxy() ? proxy_settings::socks5 :
proxy_settings::socks4;
ses->set_proxy(proxy);
}
// session will be paused until we have an up-to-date blockchain
ses->pause();
@ -237,6 +251,7 @@ void ThreadWaitExtIP() @@ -237,6 +251,7 @@ void ThreadWaitExtIP()
ses->load_state(e);
}
if( !m_usingProxy ) {
ses->start_upnp();
ses->start_natpmp();
@ -251,10 +266,11 @@ void ThreadWaitExtIP() @@ -251,10 +266,11 @@ void ThreadWaitExtIP()
dht_settings dhts;
// settings to test local connections
dhts.restrict_routing_ips = false;
dhts.restrict_search_ips = false;
//dhts.restrict_routing_ips = false;
//dhts.restrict_search_ips = false;
ses->set_dht_settings(dhts);
ses->start_dht();
}
session_settings settings;
// settings to test local connections
@ -262,7 +278,12 @@ void ThreadWaitExtIP() @@ -262,7 +278,12 @@ void ThreadWaitExtIP()
//settings.enable_outgoing_utp = false; // (false to see connections in netstat)
//settings.dht_announce_interval = 60; // test
//settings.min_announce_interval = 60; // test
if( !m_usingProxy ) {
settings.anonymous_mode = false; // (false => send peer_id, avoid connecting to itself)
} else {
settings.anonymous_mode = true;
settings.force_proxy = true; // DHT won't work
}
// disable read cache => there is still some bug due to twister piece size changes
settings.use_read_cache = false;
settings.cache_size = 0;
@ -392,6 +413,7 @@ void ThreadMaintainDHTNodes() @@ -392,6 +413,7 @@ void ThreadMaintainDHTNodes()
int totalNodesCandidates = (int)(vNodesSize + vAddr.size());
if( ((!dht_nodes && totalNodesCandidates) ||
(dht_nodes < 5 && totalNodesCandidates > 10)) &&
!m_usingProxy &&
totalNodesCandidates != lastTotalNodesCandidates) {
lastTotalNodesCandidates = totalNodesCandidates;
printf("ThreadMaintainDHTNodes: too few dht_nodes, trying to add some...\n");
@ -682,7 +704,13 @@ void stopSessionTorrent() @@ -682,7 +704,13 @@ void stopSessionTorrent()
printf("\nsaving session state\n");
entry session_state;
ses->save_state(session_state);
ses->save_state(session_state,
session::save_settings |
session::save_dht_settings |
session::save_dht_state |
session::save_encryption_settings |
session::save_as_map |
session::save_feeds);
std::vector<char> out;
bencode(std::back_inserter(out), session_state);

Loading…
Cancel
Save