mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-11 07:17:53 +00:00
maintain list of multivalued dht items ordered (newer first) by height. discard the last when size exceeds.
This commit is contained in:
parent
82ea843b46
commit
425c355b72
@ -203,7 +203,7 @@ class TORRENT_EXTRA_EXPORT node_impl : boost::noncopyable
|
||||
typedef std::map<node_id, torrent_entry> table_t;
|
||||
typedef std::map<node_id, dht_immutable_item> dht_immutable_table_t;
|
||||
typedef std::map<node_id, dht_mutable_item> dht_mutable_table_t;
|
||||
typedef std::vector<dht_storage_item> dht_storage_list_t;
|
||||
typedef std::list<dht_storage_item> dht_storage_list_t;
|
||||
typedef std::map<node_id, dht_storage_list_t> dht_storage_table_t;
|
||||
|
||||
public:
|
||||
|
@ -990,6 +990,7 @@ namespace libtorrent
|
||||
, max_fail_count(20)
|
||||
, max_torrents(2000)
|
||||
, max_dht_items(700)
|
||||
, max_entries_per_multi(50)
|
||||
, max_torrent_search_reply(20)
|
||||
, restrict_routing_ips(true)
|
||||
, restrict_search_ips(true)
|
||||
@ -1027,6 +1028,9 @@ namespace libtorrent
|
||||
// max number of items the DHT will store
|
||||
int max_dht_items;
|
||||
|
||||
// max multi entries per DHT item
|
||||
int max_entries_per_multi;
|
||||
|
||||
// the max number of torrents to return in a
|
||||
// torrent search query to the DHT
|
||||
int max_torrent_search_reply;
|
||||
|
@ -1290,9 +1290,10 @@ void node_impl::incoming_request(msg const& m, entry& e)
|
||||
} else {
|
||||
dht_storage_list_t & lsto = i->second;
|
||||
|
||||
int j;
|
||||
for( j = 0; j < lsto.size(); j++) {
|
||||
dht_storage_item &olditem = lsto[j];
|
||||
dht_storage_list_t::reverse_iterator j, rend(lsto.rend());
|
||||
dht_storage_list_t::iterator insert_pos = lsto.end();
|
||||
for( j = lsto.rbegin(); j != rend; ++j) {
|
||||
dht_storage_item &olditem = *j;
|
||||
|
||||
lazy_entry p;
|
||||
int pos;
|
||||
@ -1312,16 +1313,27 @@ void node_impl::incoming_request(msg const& m, entry& e)
|
||||
|
||||
// compare contents before adding to the list
|
||||
std::pair<char const*, int> bufoldv = p.dict_find("v")->data_section();
|
||||
if( bufv.second == bufoldv.second &&
|
||||
!memcmp(bufv.first, bufoldv.first,bufv.second)) {
|
||||
if( bufv.second == bufoldv.second && !memcmp(bufv.first, bufoldv.first,bufv.second) ) {
|
||||
// break so it wont be inserted
|
||||
break;
|
||||
}
|
||||
|
||||
// if new entry is newer than existing one, it will be inserted before
|
||||
if( msg_keys[mk_height]->int_value() >= p.dict_find_int_value("height") ) {
|
||||
insert_pos = j.base();
|
||||
insert_pos--;
|
||||
}
|
||||
}
|
||||
if(multi && j == lsto.size()) {
|
||||
}
|
||||
if(multi && j == rend) {
|
||||
// new entry
|
||||
lsto.push_back(item);
|
||||
lsto.insert(insert_pos, item);
|
||||
}
|
||||
|
||||
if(lsto.size() > m_settings.max_entries_per_multi) {
|
||||
lsto.resize(m_settings.max_entries_per_multi);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if (strcmp(query, "getData") == 0)
|
||||
|
Loading…
Reference in New Issue
Block a user