only send a write token if we have storage space available

This commit is contained in:
Steven Siloti 2016-09-19 20:47:17 -07:00
parent db14df5d0d
commit 6e24bbe77a
4 changed files with 11 additions and 13 deletions

View File

@ -121,8 +121,8 @@ namespace dht
// consider the value of dht_settings::max_peers_reply.
// If noseed is true only peers marked as no seed should be included.
//
// returns true if an entry with the info_hash is found and
// the data is returned inside the (entry) out parameter peers.
// returns true if the maximum number of peers are stored
// for this info_hash.
//
virtual bool get_peers(sha1_hash const& info_hash, udp protocol
, bool noseed, bool scrape

View File

@ -219,10 +219,8 @@ private:
void send_single_refresh(udp::endpoint const& ep, int bucket
, node_id const& id = node_id());
void lookup_peers(sha1_hash const& info_hash, entry& reply
bool lookup_peers(sha1_hash const& info_hash, entry& reply
, bool noseed, bool scrape) const;
bool lookup_torrents(sha1_hash const& target, entry& reply
, char* tags) const;
libtorrent::dht_settings const& m_settings;

View File

@ -189,9 +189,8 @@ namespace
, bool const noseed, bool const scrape
, entry& peers) const override
{
auto const i = m_map.lower_bound(info_hash);
if (i == m_map.end()) return false;
if (i->first != info_hash) return false;
auto const i = m_map.find(info_hash);
if (i == m_map.end()) return int(m_map.size()) >= m_settings.max_torrents;
torrent_entry const& v = i->second;
@ -257,7 +256,7 @@ namespace
++m;
}
}
return true;
return int(i->second.peers.size()) >= m_settings.max_peers;
}
void announce_peer(sha1_hash const& info_hash

View File

@ -750,13 +750,13 @@ void node::status(session_status& s)
}
#endif
void node::lookup_peers(sha1_hash const& info_hash, entry& reply
bool node::lookup_peers(sha1_hash const& info_hash, entry& reply
, bool noseed, bool scrape) const
{
if (m_observer)
m_observer->get_peers(info_hash);
m_storage.get_peers(info_hash, protocol(), noseed, scrape, reply);
return m_storage.get_peers(info_hash, protocol(), noseed, scrape, reply);
}
entry write_nodes_entry(std::vector<node_entry> const& nodes)
@ -848,7 +848,6 @@ void node::incoming_request(msg const& m, entry& e)
}
sha1_hash const info_hash(msg_keys[0].string_ptr());
reply["token"] = generate_token(m.addr, info_hash);
m_counters.inc_stats_counter(counters::dht_get_peers_in);
@ -859,7 +858,9 @@ void node::incoming_request(msg const& m, entry& e)
bool scrape = false;
if (msg_keys[1] && msg_keys[1].int_value() != 0) noseed = true;
if (msg_keys[2] && msg_keys[2].int_value() != 0) scrape = true;
lookup_peers(info_hash, reply, noseed, scrape);
bool full = lookup_peers(info_hash, reply, noseed, scrape);
if (!full) reply["token"] = generate_token(m.addr, info_hash);
#ifndef TORRENT_DISABLE_LOGGING
if (reply.find_key("values") && m_observer)
{