now it works

This commit is contained in:
Denis Ryabov 2014-07-08 12:54:36 +04:00
parent dc275c0b29
commit 3b0294497b
3 changed files with 15 additions and 7 deletions

View File

@ -273,6 +273,8 @@ public:
dht_settings const& settings() const { return m_settings; } dht_settings const& settings() const { return m_settings; }
double getRandom() { return m_random(); }
protected: protected:
void lookup_peers(sha1_hash const& info_hash, int prefix, entry& reply void lookup_peers(sha1_hash const& info_hash, int prefix, entry& reply
@ -313,8 +315,8 @@ private:
udp_socket_interface* m_sock; udp_socket_interface* m_sock;
boost::mt19937 m_random_seed; boost::mt19937 m_random_seed;
boost::uniform_real<> m_random_dist; boost::uniform_real<double> m_random_dist;
boost::variate_generator<boost::mt19937&, boost::uniform_real<> > m_random; boost::variate_generator<boost::mt19937&, boost::uniform_real<double> > m_random;
}; };

View File

@ -65,6 +65,7 @@ namespace libtorrent
time_duration& operator*=(int v) { diff *= v; return *this; } time_duration& operator*=(int v) { diff *= v; return *this; }
time_duration operator+(time_duration const& c) { return time_duration(diff + c.diff); } time_duration operator+(time_duration const& c) { return time_duration(diff + c.diff); }
time_duration operator-(time_duration const& c) { return time_duration(diff - c.diff); } time_duration operator-(time_duration const& c) { return time_duration(diff - c.diff); }
time_duration operator*(double rhs) const { return time_duration( boost::int64_t (diff * rhs) ); }
// internal // internal
boost::int64_t diff; boost::int64_t diff;

View File

@ -543,7 +543,8 @@ bool node_impl::refresh_storage() {
bool did_something = false; bool did_something = false;
ptime const now = time_now(); ptime const now = time_now();
m_next_storage_refresh = now + minutes(10); m_next_storage_refresh = now + minutes(60);
for (dht_storage_table_t::iterator i = m_storage_table.begin(), for (dht_storage_table_t::iterator i = m_storage_table.begin(),
end(m_storage_table.end()); i != end; ++i ) end(m_storage_table.end()); i != end; ++i )
@ -608,7 +609,7 @@ bool node_impl::refresh_storage() {
did_something = true; did_something = true;
// add 10% diffusion to next refresh time // add 10% diffusion to next refresh time
item.next_refresh_time = now + minutes(item.confirmed ? 60 : 1) * (1. + 0.1 * (2. * m_random() - 1.)); item.next_refresh_time = now + minutes(item.confirmed ? 60 : 1) * (1. + 0.1 * (2. * getRandom() - 1.));
if( m_next_storage_refresh > item.next_refresh_time ) { if( m_next_storage_refresh > item.next_refresh_time ) {
m_next_storage_refresh = item.next_refresh_time; m_next_storage_refresh = item.next_refresh_time;
} }
@ -715,7 +716,7 @@ void node_impl::load_storage(entry const* e) {
if( !e || e->type() != entry::dictionary_t) if( !e || e->type() != entry::dictionary_t)
return; return;
ptime now = time_now(); ptime const now = time_now();
printf("node dht: loading storage... (%lu node_id keys)\n", e->dict().size()); printf("node dht: loading storage... (%lu node_id keys)\n", e->dict().size());
@ -756,7 +757,7 @@ void node_impl::load_storage(entry const* e) {
processEntryForHashtags(p); processEntryForHashtags(p);
// randomize refresh time // randomize refresh time
item.next_refresh_time = now + minutes(item.confirmed ? 60 : 1) * m_random(); item.next_refresh_time = now + minutes(item.confirmed ? 60 : 1) * getRandom();
to_add.push_back(item); to_add.push_back(item);
#ifdef ENABLE_DHT_ITEM_EXPIRE #ifdef ENABLE_DHT_ITEM_EXPIRE
@ -1501,6 +1502,10 @@ void node_impl::store_dht_item(dht_storage_item &item, const big_number &target,
bool multi, int seq, int height, std::pair<char const*, int> &bufv) bool multi, int seq, int height, std::pair<char const*, int> &bufv)
{ {
item.next_refresh_time = time_now() + minutes(item.confirmed ? 60 : 1); item.next_refresh_time = time_now() + minutes(item.confirmed ? 60 : 1);
if( m_next_storage_refresh > item.next_refresh_time ) {
m_next_storage_refresh = item.next_refresh_time;
}
dht_storage_table_t::iterator i = m_storage_table.find(target); dht_storage_table_t::iterator i = m_storage_table.find(target);
if (i == m_storage_table.end()) { if (i == m_storage_table.end()) {
// make sure we don't add too many items // make sure we don't add too many items