remove redundant protocol parameter (#1128)

This commit is contained in:
Steven Siloti 2016-09-21 20:00:39 -07:00 committed by Arvid Norberg
parent 269e384c2c
commit c75b243490
4 changed files with 11 additions and 10 deletions

View File

@ -124,7 +124,7 @@ namespace dht
// 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
virtual bool get_peers(sha1_hash const& info_hash
, bool noseed, bool scrape, address const& requester
, entry& peers) const = 0;

View File

@ -185,7 +185,7 @@ namespace
m_node_ids = ids;
}
bool get_peers(sha1_hash const& info_hash, udp const protocol
bool get_peers(sha1_hash const& info_hash
, bool const noseed, bool const scrape, address const& requester
, entry& peers) const override
{
@ -213,11 +213,12 @@ namespace
}
else
{
tcp const protocol = requester.is_v4() ? tcp::v4() : tcp::v6();
int max = m_settings.max_peers_reply;
// if these are IPv6 peers their addresses are 4x the size of IPv4
// so reduce the max peers 4 fold to compensate
// max_peers_reply should probably be specified in bytes
if (!v.peers.empty() && protocol == udp::v6())
if (!v.peers.empty() && protocol == tcp::v6())
max /= 4;
// we're picking "to_pick" from a list of "num" at random.
int const to_pick = std::min(int(v.peers.size()), max);
@ -231,7 +232,7 @@ namespace
if (noseed && iter->seed) continue;
// only include peers with the right address family
if (iter->addr.protocol().family() != protocol.family())
if (iter->addr.protocol() != protocol)
continue;
++t;

View File

@ -756,7 +756,7 @@ bool node::lookup_peers(sha1_hash const& info_hash, entry& reply
if (m_observer)
m_observer->get_peers(info_hash);
return m_storage.get_peers(info_hash, protocol(), noseed, scrape, requester, reply);
return m_storage.get_peers(info_hash, noseed, scrape, requester, reply);
}
entry write_nodes_entry(std::vector<node_entry> const& nodes)

View File

@ -100,7 +100,7 @@ TORRENT_TEST(announce_peer)
std::unique_ptr<dht_storage_interface> s(create_default_dht_storage(sett));
entry peers;
s->get_peers(n1, udp::v4(), false, false, address(), peers);
s->get_peers(n1, false, false, address(), peers);
TEST_CHECK(peers["n"].string().empty())
TEST_CHECK(peers["values"].list().empty());
@ -112,7 +112,7 @@ TORRENT_TEST(announce_peer)
s->announce_peer(n1, p1, "torrent_name", false);
peers = entry();
s->get_peers(n1, udp::v4(), false, false, address(), peers);
s->get_peers(n1, false, false, address(), peers);
TEST_EQUAL(peers["n"].string(), "torrent_name")
TEST_EQUAL(peers["values"].list().size(), 1)
@ -120,7 +120,7 @@ TORRENT_TEST(announce_peer)
s->announce_peer(n2, p3, "torrent_name1", false);
s->announce_peer(n3, p4, "torrent_name2", false);
peers = entry();
s->get_peers(n3, udp::v4(), false, false, address(), peers);
s->get_peers(n3, false, false, address(), peers);
TEST_CHECK(!peers.find_key("values"));
}
@ -142,11 +142,11 @@ TORRENT_TEST(dual_stack)
s->announce_peer(n1, p5, "torrent_name", false);
entry peers4;
s->get_peers(n1, udp::v4(), false, false, address(), peers4);
s->get_peers(n1, false, false, address(), peers4);
TEST_EQUAL(peers4["values"].list().size(), 3);
entry peers6;
s->get_peers(n1, udp::v6(), false, false, address(), peers6);
s->get_peers(n1, false, false, address_v6(), peers6);
TEST_EQUAL(peers6["values"].list().size(), 2);
}