DHT bugfix, more logging and less frequent private key generation. Fixed typo in identify_client
This commit is contained in:
parent
e79817cfc5
commit
b386aa23e9
|
@ -118,7 +118,7 @@ namespace libtorrent { namespace dht
|
||||||
udp::endpoint m_remote_endpoint[2];
|
udp::endpoint m_remote_endpoint[2];
|
||||||
std::vector<char> m_send_buf;
|
std::vector<char> m_send_buf;
|
||||||
|
|
||||||
ptime m_last_refresh;
|
ptime m_last_new_key;
|
||||||
deadline_timer m_timer;
|
deadline_timer m_timer;
|
||||||
deadline_timer m_connection_timer;
|
deadline_timer m_connection_timer;
|
||||||
deadline_timer m_refresh_timer;
|
deadline_timer m_refresh_timer;
|
||||||
|
|
|
@ -185,7 +185,7 @@ namespace
|
||||||
, {"SN", "ShareNet"}
|
, {"SN", "ShareNet"}
|
||||||
, {"SS", "SwarmScope"}
|
, {"SS", "SwarmScope"}
|
||||||
, {"SZ", "Shareaza"}
|
, {"SZ", "Shareaza"}
|
||||||
, {"S~", "Shareaza (beta}"}
|
, {"S~", "Shareaza (beta)"}
|
||||||
, {"T", "BitTornado"}
|
, {"T", "BitTornado"}
|
||||||
, {"TN", "Torrent.NET"}
|
, {"TN", "Torrent.NET"}
|
||||||
, {"TR", "Transmission"}
|
, {"TR", "Transmission"}
|
||||||
|
|
|
@ -62,6 +62,11 @@ using libtorrent::dht::packet_iterator;
|
||||||
namespace messages = libtorrent::dht::messages;
|
namespace messages = libtorrent::dht::messages;
|
||||||
using namespace libtorrent::detail;
|
using namespace libtorrent::detail;
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
key_refresh = 5 // generate a new write token key every 5 minutes
|
||||||
|
};
|
||||||
|
|
||||||
using asio::ip::udp;
|
using asio::ip::udp;
|
||||||
typedef asio::ip::address_v4 address;
|
typedef asio::ip::address_v4 address;
|
||||||
|
|
||||||
|
@ -147,7 +152,7 @@ namespace libtorrent { namespace dht
|
||||||
, m_dht(bind(&dht_tracker::send_packet, this, _1), settings
|
, m_dht(bind(&dht_tracker::send_packet, this, _1), settings
|
||||||
, read_id(bootstrap))
|
, read_id(bootstrap))
|
||||||
, m_buffer(0)
|
, m_buffer(0)
|
||||||
, m_last_refresh(time_now() - hours(1))
|
, m_last_new_key(time_now() - minutes(key_refresh))
|
||||||
, m_timer(ios)
|
, m_timer(ios)
|
||||||
, m_connection_timer(ios)
|
, m_connection_timer(ios)
|
||||||
, m_refresh_timer(ios)
|
, m_refresh_timer(ios)
|
||||||
|
@ -274,7 +279,15 @@ namespace libtorrent { namespace dht
|
||||||
m_timer.expires_from_now(minutes(tick_period));
|
m_timer.expires_from_now(minutes(tick_period));
|
||||||
m_timer.async_wait(m_strand.wrap(bind(&dht_tracker::tick, this, _1)));
|
m_timer.async_wait(m_strand.wrap(bind(&dht_tracker::tick, this, _1)));
|
||||||
|
|
||||||
|
ptime now = time_now();
|
||||||
|
if (now - m_last_new_key > minutes(key_refresh))
|
||||||
|
{
|
||||||
|
m_last_new_key = now;
|
||||||
m_dht.new_write_key();
|
m_dht.new_write_key();
|
||||||
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
|
TORRENT_LOG(dht_tracker) << time_now_string() << " new write key";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
static bool first = true;
|
static bool first = true;
|
||||||
|
|
|
@ -126,9 +126,20 @@ node_impl::node_impl(boost::function<void(msg const&)> const& f
|
||||||
bool node_impl::verify_token(msg const& m)
|
bool node_impl::verify_token(msg const& m)
|
||||||
{
|
{
|
||||||
if (m.write_token.type() != entry::string_t)
|
if (m.write_token.type() != entry::string_t)
|
||||||
|
{
|
||||||
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
|
TORRENT_LOG(node) << "token of incorrect type " << m.write_token.type();
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
std::string const& token = m.write_token.string();
|
std::string const& token = m.write_token.string();
|
||||||
if (token.length() != 4) return false;
|
if (token.length() != 4)
|
||||||
|
{
|
||||||
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
|
TORRENT_LOG(node) << "token of incorrect length: " << token.length();
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
hasher h1;
|
hasher h1;
|
||||||
std::string address = m.addr.address().to_string();
|
std::string address = m.addr.address().to_string();
|
||||||
|
@ -143,6 +154,7 @@ bool node_impl::verify_token(msg const& m)
|
||||||
hasher h2;
|
hasher h2;
|
||||||
h2.update(&address[0], address.length());
|
h2.update(&address[0], address.length());
|
||||||
h2.update((char*)&m_secret[1], sizeof(m_secret[1]));
|
h2.update((char*)&m_secret[1], sizeof(m_secret[1]));
|
||||||
|
h2.update((char*)&m.info_hash[0], sha1_hash::size);
|
||||||
h = h2.final();
|
h = h2.final();
|
||||||
if (std::equal(token.begin(), token.end(), (signed char*)&h[0]))
|
if (std::equal(token.begin(), token.end(), (signed char*)&h[0]))
|
||||||
return true;
|
return true;
|
||||||
|
@ -401,6 +413,8 @@ time_duration node_impl::refresh_timeout()
|
||||||
time_duration next_refresh = next - now;
|
time_duration next_refresh = next - now;
|
||||||
time_duration min_next_refresh
|
time_duration min_next_refresh
|
||||||
= minutes(15) / (m_table.num_active_buckets());
|
= minutes(15) / (m_table.num_active_buckets());
|
||||||
|
if (min_next_refresh > seconds(40))
|
||||||
|
min_next_refresh = seconds(40);
|
||||||
|
|
||||||
if (next_refresh < min_next_refresh)
|
if (next_refresh < min_next_refresh)
|
||||||
next_refresh = min_next_refresh;
|
next_refresh = min_next_refresh;
|
||||||
|
@ -448,7 +462,7 @@ void node_impl::on_announce(msg const& m, msg& reply)
|
||||||
{
|
{
|
||||||
reply.message_id = messages::error;
|
reply.message_id = messages::error;
|
||||||
reply.error_code = 203;
|
reply.error_code = 203;
|
||||||
reply.error_msg = "Incorrect write token in announce_peer message";
|
reply.error_msg = "Incorrect token in announce_peer";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ ptime routing_table::next_refresh(int bucket)
|
||||||
assert(bucket >= 0);
|
assert(bucket >= 0);
|
||||||
// lower than or equal to since a refresh of bucket 0 will
|
// lower than or equal to since a refresh of bucket 0 will
|
||||||
// effectively refresh the lowest active bucket as well
|
// effectively refresh the lowest active bucket as well
|
||||||
if (bucket <= m_lowest_active_bucket && bucket > 0)
|
if (bucket < m_lowest_active_bucket && bucket > 0)
|
||||||
return time_now() + minutes(15);
|
return time_now() + minutes(15);
|
||||||
return m_bucket_activity[bucket] + minutes(15);
|
return m_bucket_activity[bucket] + minutes(15);
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,13 @@ bool rpc_manager::incoming(msg const& m)
|
||||||
TORRENT_LOG(rpc) << "Reply with invalid transaction id size: "
|
TORRENT_LOG(rpc) << "Reply with invalid transaction id size: "
|
||||||
<< m.transaction_id.size() << " from " << m.addr;
|
<< m.transaction_id.size() << " from " << m.addr;
|
||||||
#endif
|
#endif
|
||||||
|
msg reply;
|
||||||
|
reply.message_id = messages::error;
|
||||||
|
reply.error_code = 203; // Protocol error
|
||||||
|
reply.error_msg = "reply with invalid transaction id, size " + m.transaction_id.size();
|
||||||
|
reply.addr = m.addr;
|
||||||
|
reply.transaction_id = "";
|
||||||
|
m_send(m);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +143,13 @@ bool rpc_manager::incoming(msg const& m)
|
||||||
TORRENT_LOG(rpc) << "Reply with invalid transaction id: "
|
TORRENT_LOG(rpc) << "Reply with invalid transaction id: "
|
||||||
<< tid << " from " << m.addr;
|
<< tid << " from " << m.addr;
|
||||||
#endif
|
#endif
|
||||||
|
msg reply;
|
||||||
|
reply.message_id = messages::error;
|
||||||
|
reply.error_code = 203; // Protocol error
|
||||||
|
reply.error_msg = "reply with invalid transaction id";
|
||||||
|
reply.addr = m.addr;
|
||||||
|
reply.transaction_id = "";
|
||||||
|
m_send(m);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue