forked from premiere/premiere-libtorrent
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];
|
||||
std::vector<char> m_send_buf;
|
||||
|
||||
ptime m_last_refresh;
|
||||
ptime m_last_new_key;
|
||||
deadline_timer m_timer;
|
||||
deadline_timer m_connection_timer;
|
||||
deadline_timer m_refresh_timer;
|
||||
|
|
|
@ -185,7 +185,7 @@ namespace
|
|||
, {"SN", "ShareNet"}
|
||||
, {"SS", "SwarmScope"}
|
||||
, {"SZ", "Shareaza"}
|
||||
, {"S~", "Shareaza (beta}"}
|
||||
, {"S~", "Shareaza (beta)"}
|
||||
, {"T", "BitTornado"}
|
||||
, {"TN", "Torrent.NET"}
|
||||
, {"TR", "Transmission"}
|
||||
|
|
|
@ -62,6 +62,11 @@ using libtorrent::dht::packet_iterator;
|
|||
namespace messages = libtorrent::dht::messages;
|
||||
using namespace libtorrent::detail;
|
||||
|
||||
enum
|
||||
{
|
||||
key_refresh = 5 // generate a new write token key every 5 minutes
|
||||
};
|
||||
|
||||
using asio::ip::udp;
|
||||
typedef asio::ip::address_v4 address;
|
||||
|
||||
|
@ -147,7 +152,7 @@ namespace libtorrent { namespace dht
|
|||
, m_dht(bind(&dht_tracker::send_packet, this, _1), settings
|
||||
, read_id(bootstrap))
|
||||
, m_buffer(0)
|
||||
, m_last_refresh(time_now() - hours(1))
|
||||
, m_last_new_key(time_now() - minutes(key_refresh))
|
||||
, m_timer(ios)
|
||||
, m_connection_timer(ios)
|
||||
, m_refresh_timer(ios)
|
||||
|
@ -274,7 +279,15 @@ namespace libtorrent { namespace dht
|
|||
m_timer.expires_from_now(minutes(tick_period));
|
||||
m_timer.async_wait(m_strand.wrap(bind(&dht_tracker::tick, this, _1)));
|
||||
|
||||
m_dht.new_write_key();
|
||||
ptime now = time_now();
|
||||
if (now - m_last_new_key > minutes(key_refresh))
|
||||
{
|
||||
m_last_new_key = now;
|
||||
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
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
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;
|
||||
std::string address = m.addr.address().to_string();
|
||||
|
@ -139,10 +150,11 @@ bool node_impl::verify_token(msg const& m)
|
|||
sha1_hash h = h1.final();
|
||||
if (std::equal(token.begin(), token.end(), (signed char*)&h[0]))
|
||||
return true;
|
||||
|
||||
|
||||
hasher h2;
|
||||
h2.update(&address[0], address.length());
|
||||
h2.update((char*)&m_secret[1], sizeof(m_secret[1]));
|
||||
h2.update((char*)&m.info_hash[0], sha1_hash::size);
|
||||
h = h2.final();
|
||||
if (std::equal(token.begin(), token.end(), (signed char*)&h[0]))
|
||||
return true;
|
||||
|
@ -391,7 +403,7 @@ time_duration node_impl::refresh_timeout()
|
|||
{
|
||||
assert(refresh > -1);
|
||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||
TORRENT_LOG(node) << "refreshing bucket: " << refresh;
|
||||
TORRENT_LOG(node) << "refreshing bucket: " << refresh;
|
||||
#endif
|
||||
refresh_bucket(refresh);
|
||||
}
|
||||
|
@ -401,6 +413,8 @@ time_duration node_impl::refresh_timeout()
|
|||
time_duration next_refresh = next - now;
|
||||
time_duration min_next_refresh
|
||||
= minutes(15) / (m_table.num_active_buckets());
|
||||
if (min_next_refresh > seconds(40))
|
||||
min_next_refresh = seconds(40);
|
||||
|
||||
if (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.error_code = 203;
|
||||
reply.error_msg = "Incorrect write token in announce_peer message";
|
||||
reply.error_msg = "Incorrect token in announce_peer";
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ ptime routing_table::next_refresh(int bucket)
|
|||
assert(bucket >= 0);
|
||||
// lower than or equal to since a refresh of bucket 0 will
|
||||
// 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 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: "
|
||||
<< m.transaction_id.size() << " from " << m.addr;
|
||||
#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;
|
||||
}
|
||||
|
||||
|
@ -136,6 +143,13 @@ bool rpc_manager::incoming(msg const& m)
|
|||
TORRENT_LOG(rpc) << "Reply with invalid transaction id: "
|
||||
<< tid << " from " << m.addr;
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue