merged tracker key patch from RC_0_16

This commit is contained in:
Arvid Norberg 2013-08-31 21:06:43 +00:00
parent 850b81e625
commit 3afe6c23a0
6 changed files with 26 additions and 6 deletions

View File

@ -101,8 +101,8 @@ namespace libtorrent
hasher& operator=(hasher const& h); hasher& operator=(hasher const& h);
#endif #endif
void update(std::string const& data) { update(data.c_str(), data.size()); } hasher& update(std::string const& data) { update(data.c_str(), data.size()); return *this; }
void update(const char* data, int len); hasher& update(const char* data, int len);
sha1_hash final(); sha1_hash final();
void reset(); void reset();

View File

@ -467,6 +467,10 @@ namespace libtorrent
// base64 encoding). // base64 encoding).
std::string tracker_login() const; std::string tracker_login() const;
// generate the tracker key for this torrent.
// The key is passed to http trackers as ``&key=``.
boost::uint32_t tracker_key() const;
// if we need a connect boost, connect some peers // if we need a connect boost, connect some peers
// immediately // immediately
void do_connect_boost(); void do_connect_boost();

View File

@ -125,7 +125,7 @@ namespace libtorrent
event_t event; event_t event;
std::string url; std::string url;
std::string trackerid; std::string trackerid;
int key; boost::uint32_t key;
int num_want; int num_want;
address bind_ip; address bind_ip;
bool send_stats; bool send_stats;

View File

@ -80,7 +80,7 @@ namespace libtorrent
} }
#endif #endif
void hasher::update(const char* data, int len) hasher& hasher::update(const char* data, int len)
{ {
TORRENT_ASSERT(data != 0); TORRENT_ASSERT(data != 0);
TORRENT_ASSERT(len > 0); TORRENT_ASSERT(len > 0);
@ -93,6 +93,7 @@ namespace libtorrent
#else #else
SHA1_update(&m_context, reinterpret_cast<unsigned char const*>(data), len); SHA1_update(&m_context, reinterpret_cast<unsigned char const*>(data), len);
#endif #endif
return *this;
} }
sha1_hash hasher::final() sha1_hash hasher::final()

View File

@ -628,6 +628,7 @@ namespace aux {
, m_tracker_manager(*this, m_proxy) , m_tracker_manager(*this, m_proxy)
, m_num_active_downloading(0) , m_num_active_downloading(0)
, m_num_active_finished(0) , m_num_active_finished(0)
, m_key(0)
, m_listen_port_retries(listen_port_range.second - listen_port_range.first) , m_listen_port_retries(listen_port_range.second - listen_port_range.first)
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
, m_i2p_conn(m_io_service) , m_i2p_conn(m_io_service)
@ -725,7 +726,6 @@ namespace aux {
// ---- generate a peer id ---- // ---- generate a peer id ----
static seed_random_generator seeder; static seed_random_generator seeder;
m_key = random() + (random() << 15) + (random() << 30);
std::string print = cl_fprint.to_string(); std::string print = cl_fprint.to_string();
TORRENT_ASSERT_VAL(print.length() <= 20, print.length()); TORRENT_ASSERT_VAL(print.length() <= 20, print.length());

View File

@ -2358,7 +2358,10 @@ namespace libtorrent
else else
#endif #endif
req.listen_port = m_ses.listen_port(); req.listen_port = m_ses.listen_port();
if (m_ses.m_key)
req.key = m_ses.m_key; req.key = m_ses.m_key;
else
req.key = tracker_key();
ptime now = time_now_hires(); ptime now = time_now_hires();
@ -3780,6 +3783,18 @@ namespace libtorrent
return m_username + ":" + m_password; return m_username + ":" + m_password;
} }
boost::uint32_t torrent::tracker_key() const
{
uintptr_t self = (uintptr_t)this;
uintptr_t ses = (uintptr_t)&m_ses;
sha1_hash h = hasher((char*)&self, sizeof(self))
.update((char*)&m_storage, sizeof(m_storage))
.update((char*)&ses, sizeof(ses))
.final();
unsigned char const* ptr = &h[0];
return detail::read_uint32(ptr);
}
void torrent::set_piece_deadline(int piece, int t, int flags) void torrent::set_piece_deadline(int piece, int t, int flags)
{ {
INVARIANT_CHECK; INVARIANT_CHECK;