|
|
@ -38,6 +38,7 @@ twister::twister() |
|
|
|
|
|
|
|
|
|
|
|
using namespace libtorrent; |
|
|
|
using namespace libtorrent; |
|
|
|
static session *ses = NULL; |
|
|
|
static session *ses = NULL; |
|
|
|
|
|
|
|
static bool m_usingProxy; |
|
|
|
static int num_outstanding_resume_data; |
|
|
|
static int num_outstanding_resume_data; |
|
|
|
|
|
|
|
|
|
|
|
static CCriticalSection cs_dhtgetMap; |
|
|
|
static CCriticalSection cs_dhtgetMap; |
|
|
@ -216,14 +217,27 @@ void ThreadWaitExtIP() |
|
|
|
|
|
|
|
|
|
|
|
int listen_port = GetListenPort() + LIBTORRENT_PORT_OFFSET; |
|
|
|
int listen_port = GetListenPort() + LIBTORRENT_PORT_OFFSET; |
|
|
|
std::string bind_to_interface = ""; |
|
|
|
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) |
|
|
|
ses = new session(*m_swarmDb, fingerprint("TW", LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0) |
|
|
|
, session::add_default_plugins |
|
|
|
, session::add_default_plugins |
|
|
|
, alert::dht_notification |
|
|
|
, alert::dht_notification |
|
|
|
, ipStr.size() ? ipStr.c_str() : NULL |
|
|
|
, 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
|
|
|
|
// session will be paused until we have an up-to-date blockchain
|
|
|
|
ses->pause(); |
|
|
|
ses->pause(); |
|
|
@ -237,6 +251,7 @@ void ThreadWaitExtIP() |
|
|
|
ses->load_state(e); |
|
|
|
ses->load_state(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( !m_usingProxy ) { |
|
|
|
ses->start_upnp(); |
|
|
|
ses->start_upnp(); |
|
|
|
ses->start_natpmp(); |
|
|
|
ses->start_natpmp(); |
|
|
|
|
|
|
|
|
|
|
@ -251,10 +266,11 @@ void ThreadWaitExtIP() |
|
|
|
|
|
|
|
|
|
|
|
dht_settings dhts; |
|
|
|
dht_settings dhts; |
|
|
|
// settings to test local connections
|
|
|
|
// settings to test local connections
|
|
|
|
dhts.restrict_routing_ips = false; |
|
|
|
//dhts.restrict_routing_ips = false;
|
|
|
|
dhts.restrict_search_ips = false; |
|
|
|
//dhts.restrict_search_ips = false;
|
|
|
|
ses->set_dht_settings(dhts); |
|
|
|
ses->set_dht_settings(dhts); |
|
|
|
ses->start_dht(); |
|
|
|
ses->start_dht(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
session_settings settings; |
|
|
|
session_settings settings; |
|
|
|
// settings to test local connections
|
|
|
|
// settings to test local connections
|
|
|
@ -262,7 +278,12 @@ void ThreadWaitExtIP() |
|
|
|
//settings.enable_outgoing_utp = false; // (false to see connections in netstat)
|
|
|
|
//settings.enable_outgoing_utp = false; // (false to see connections in netstat)
|
|
|
|
//settings.dht_announce_interval = 60; // test
|
|
|
|
//settings.dht_announce_interval = 60; // test
|
|
|
|
//settings.min_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)
|
|
|
|
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
|
|
|
|
// disable read cache => there is still some bug due to twister piece size changes
|
|
|
|
settings.use_read_cache = false; |
|
|
|
settings.use_read_cache = false; |
|
|
|
settings.cache_size = 0; |
|
|
|
settings.cache_size = 0; |
|
|
@ -392,7 +413,8 @@ void ThreadMaintainDHTNodes() |
|
|
|
int totalNodesCandidates = (int)(vNodesSize + vAddr.size()); |
|
|
|
int totalNodesCandidates = (int)(vNodesSize + vAddr.size()); |
|
|
|
if( ((!dht_nodes && totalNodesCandidates) || |
|
|
|
if( ((!dht_nodes && totalNodesCandidates) || |
|
|
|
(dht_nodes < 5 && totalNodesCandidates > 10)) && |
|
|
|
(dht_nodes < 5 && totalNodesCandidates > 10)) && |
|
|
|
totalNodesCandidates != lastTotalNodesCandidates ) { |
|
|
|
!m_usingProxy && |
|
|
|
|
|
|
|
totalNodesCandidates != lastTotalNodesCandidates) { |
|
|
|
lastTotalNodesCandidates = totalNodesCandidates; |
|
|
|
lastTotalNodesCandidates = totalNodesCandidates; |
|
|
|
printf("ThreadMaintainDHTNodes: too few dht_nodes, trying to add some...\n"); |
|
|
|
printf("ThreadMaintainDHTNodes: too few dht_nodes, trying to add some...\n"); |
|
|
|
BOOST_FOREACH(const CAddress &a, vAddr) { |
|
|
|
BOOST_FOREACH(const CAddress &a, vAddr) { |
|
|
@ -682,7 +704,13 @@ void stopSessionTorrent() |
|
|
|
printf("\nsaving session state\n"); |
|
|
|
printf("\nsaving session state\n"); |
|
|
|
|
|
|
|
|
|
|
|
entry session_state; |
|
|
|
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; |
|
|
|
std::vector<char> out; |
|
|
|
bencode(std::back_inserter(out), session_state); |
|
|
|
bencode(std::back_inserter(out), session_state); |
|
|
|