Browse Source

maintain list of multivalued dht items ordered (newer first) by height. discard the last when size exceeds.

miguelfreitas
Miguel Freitas 12 years ago
parent
commit
425c355b72
  1. 2
      libtorrent/include/libtorrent/kademlia/node.hpp
  2. 4
      libtorrent/include/libtorrent/session_settings.hpp
  3. 26
      libtorrent/src/kademlia/node.cpp

2
libtorrent/include/libtorrent/kademlia/node.hpp

@ -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, torrent_entry> table_t;
typedef std::map<node_id, dht_immutable_item> dht_immutable_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::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; typedef std::map<node_id, dht_storage_list_t> dht_storage_table_t;
public: public:

4
libtorrent/include/libtorrent/session_settings.hpp

@ -990,6 +990,7 @@ namespace libtorrent
, max_fail_count(20) , max_fail_count(20)
, max_torrents(2000) , max_torrents(2000)
, max_dht_items(700) , max_dht_items(700)
, max_entries_per_multi(50)
, max_torrent_search_reply(20) , max_torrent_search_reply(20)
, restrict_routing_ips(true) , restrict_routing_ips(true)
, restrict_search_ips(true) , restrict_search_ips(true)
@ -1027,6 +1028,9 @@ namespace libtorrent
// max number of items the DHT will store // max number of items the DHT will store
int max_dht_items; int max_dht_items;
// max multi entries per DHT item
int max_entries_per_multi;
// the max number of torrents to return in a // the max number of torrents to return in a
// torrent search query to the DHT // torrent search query to the DHT
int max_torrent_search_reply; int max_torrent_search_reply;

26
libtorrent/src/kademlia/node.cpp

@ -1290,9 +1290,10 @@ void node_impl::incoming_request(msg const& m, entry& e)
} else { } else {
dht_storage_list_t & lsto = i->second; dht_storage_list_t & lsto = i->second;
int j; dht_storage_list_t::reverse_iterator j, rend(lsto.rend());
for( j = 0; j < lsto.size(); j++) { dht_storage_list_t::iterator insert_pos = lsto.end();
dht_storage_item &olditem = lsto[j]; for( j = lsto.rbegin(); j != rend; ++j) {
dht_storage_item &olditem = *j;
lazy_entry p; lazy_entry p;
int pos; int pos;
@ -1312,16 +1313,27 @@ void node_impl::incoming_request(msg const& m, entry& e)
// compare contents before adding to the list // compare contents before adding to the list
std::pair<char const*, int> bufoldv = p.dict_find("v")->data_section(); std::pair<char const*, int> bufoldv = p.dict_find("v")->data_section();
if( bufv.second == bufoldv.second && if( bufv.second == bufoldv.second && !memcmp(bufv.first, bufoldv.first,bufv.second) ) {
!memcmp(bufv.first, bufoldv.first,bufv.second)) { // break so it wont be inserted
break; 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 // 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) else if (strcmp(query, "getData") == 0)

Loading…
Cancel
Save