diff --git a/libtorrent/include/libtorrent/kademlia/node.hpp b/libtorrent/include/libtorrent/kademlia/node.hpp index a229190b..5906b1ca 100644 --- a/libtorrent/include/libtorrent/kademlia/node.hpp +++ b/libtorrent/include/libtorrent/kademlia/node.hpp @@ -118,14 +118,16 @@ struct torrent_entry struct dht_storage_item { // FIXME: optimize so bdecode is not needed all the time - dht_storage_item() : p(), sig_p(), sig_user() {} + dht_storage_item() : p(), sig_p(), sig_user(), local_add_time(0) {} dht_storage_item(std::string const &_p, lazy_entry const *_sig_p, lazy_entry const *_sig_user) - : p(_p), sig_p(_sig_p->string_value()), sig_user(_sig_user->string_value()) {} + : p(_p), sig_p(_sig_p->string_value()), sig_user(_sig_user->string_value()), + local_add_time(0) {} dht_storage_item(std::string const &_p, std::string const &_sig_p, std::string const &_sig_user) - : p(_p), sig_p(_sig_p), sig_user(_sig_user) {} + : p(_p), sig_p(_sig_p), sig_user(_sig_user), local_add_time(0) {} std::string p; std::string sig_p; std::string sig_user; + boost::int64_t local_add_time; // the last time we heard about this //ptime last_seen; }; diff --git a/libtorrent/src/kademlia/node.cpp b/libtorrent/src/kademlia/node.cpp index 9f5ff009..1f92bb8c 100644 --- a/libtorrent/src/kademlia/node.cpp +++ b/libtorrent/src/kademlia/node.cpp @@ -464,6 +464,7 @@ void node_impl::putData(std::string const &username, std::string const &resource // store it locally so it will be automatically refreshed with the rest dht_storage_item item(str_p, sig_p, sig_user); + item.local_add_time = time(NULL); std::vector vbuf; bencode(std::back_inserter(vbuf), value); std::pair bufv = std::make_pair(vbuf.data(), vbuf.size()); @@ -566,7 +567,8 @@ bool node_impl::refresh_storage() { bool multi = (target->dict_find_string_value("t") == "m"); // 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)) ) { num_refreshable++; if( refresh_next_item ) { @@ -689,6 +691,8 @@ bool node_impl::save_storage(entry &save) const { entry_item["p"] = item.p; entry_item["sig_p"] = item.sig_p; entry_item["sig_user"] = item.sig_user; + if( item.local_add_time ) + entry_item["local_add_time"] = item.local_add_time; save_list.list().push_back(entry_item); } } @@ -720,6 +724,9 @@ void node_impl::load_storage(entry const* e) { item.p = j->find_key("p")->string(); item.sig_p = j->find_key("sig_p")->string(); item.sig_user = j->find_key("sig_user")->string(); + entry const *local_add_time( j->find_key("local_add_time") ); + if(local_add_time) + item.local_add_time = local_add_time->integer(); // just for printf for now bool expired = has_expired(item);