limit refreshes per tick to refresh_per_tick_limit=20, fix boost::ref(item)

This commit is contained in:
Denis Ryabov 2014-07-08 13:56:42 +04:00
parent 61b057175f
commit 066435719d

View File

@ -545,6 +545,7 @@ bool node_impl::refresh_storage() {
ptime const now = time_now(); ptime const now = time_now();
m_next_storage_refresh = now + minutes(60); m_next_storage_refresh = now + minutes(60);
int refresh_per_tick_limit = 20;
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 )
@ -567,25 +568,27 @@ bool node_impl::refresh_storage() {
continue; continue;
} }
lazy_entry p; if( refresh_per_tick_limit > 0) {
int pos;
error_code err;
// FIXME: optimize to avoid bdecode (store seq separated, etc)
int ret = lazy_bdecode(item.p.data(), item.p.data() + item.p.size(), p, err, &pos, 10, 500);
int height = p.dict_find_int_value("height"); lazy_entry p;
if( height > getBestHeight() ) { int pos;
continue; // how? error_code err;
} // FIXME: optimize to avoid bdecode (store seq separated, etc)
int ret = lazy_bdecode(item.p.data(), item.p.data() + item.p.size(), p, err, &pos, 10, 500);
int height = p.dict_find_int_value("height");
if( height > getBestHeight() ) {
continue; // how?
}
const lazy_entry *target = p.dict_find_dict("target"); const lazy_entry *target = p.dict_find_dict("target");
std::string username = target->dict_find_string_value("n"); std::string username = target->dict_find_string_value("n");
std::string resource = target->dict_find_string_value("r"); std::string resource = target->dict_find_string_value("r");
bool multi = (target->dict_find_string_value("t") == "m"); bool multi = (target->dict_find_string_value("t") == "m");
// refresh only signed single posts and mentions // refresh only signed single posts and mentions
if( !multi || (multi && resource == "mention") || if( !multi || (multi && resource == "mention") ||
(multi && item.local_add_time && item.local_add_time + 60*60*24*2 > time(NULL)) ) { (multi && item.local_add_time && item.local_add_time + 60*60*24*2 > time(NULL)) ) {
#ifdef TORRENT_DHT_VERBOSE_LOGGING #ifdef TORRENT_DHT_VERBOSE_LOGGING
printf("node dht: refreshing storage: [%s,%s,%s]\n", printf("node dht: refreshing storage: [%s,%s,%s]\n",
@ -594,26 +597,30 @@ bool node_impl::refresh_storage() {
target->dict_find_string_value("t").c_str()); target->dict_find_string_value("t").c_str());
#endif #endif
processEntryForHashtags(p); processEntryForHashtags(p);
entry entryP; entry entryP;
entryP = p; // lazy to non-lazy entryP = p; // lazy to non-lazy
// search for nodes with ids close to id or with peers // search for nodes with ids close to id or with peers
// for info-hash id. then send putData to them. // for info-hash id. then send putData to them.
boost::intrusive_ptr<dht_get> ta(new dht_get(*this, username, resource, multi, boost::intrusive_ptr<dht_get> ta(new dht_get(*this, username, resource, multi,
boost::bind(&putData_confirm, item), boost::bind(&putData_confirm, boost::ref(item)),
boost::bind(&putData_fun, _1, boost::ref(*this), boost::bind(&putData_fun, _1, boost::ref(*this),
entryP, item.sig_p, item.sig_user), item.confirmed)); entryP, item.sig_p, item.sig_user), item.confirmed));
ta->start(); ta->start();
did_something = true; did_something = true;
// add 10% diffusion to next refresh time --refresh_per_tick_limit;
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 ) { // add 10% diffusion to next refresh time
m_next_storage_refresh = item.next_refresh_time; 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 ) {
m_next_storage_refresh = item.next_refresh_time;
}
} }
} }