keep track of dht_storage_item which have been locally added.

for now this is used to make sure all kinds of resources (including rts and replies)
will have a forced refresh for at least two days.
This commit is contained in:
Miguel Freitas 2014-04-06 17:01:39 -03:00
parent 03d037c197
commit 2be53fe95a
2 changed files with 13 additions and 4 deletions

View File

@ -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;
};

View File

@ -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<char> vbuf;
bencode(std::back_inserter(vbuf), value);
std::pair<char const*, int> 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);