From c75b2434905cc00730683be17736fdd621e8c63d Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Wed, 21 Sep 2016 20:00:39 -0700 Subject: [PATCH] remove redundant protocol parameter (#1128) --- include/libtorrent/kademlia/dht_storage.hpp | 2 +- src/kademlia/dht_storage.cpp | 7 ++++--- src/kademlia/node.cpp | 2 +- test/test_dht_storage.cpp | 10 +++++----- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/libtorrent/kademlia/dht_storage.hpp b/include/libtorrent/kademlia/dht_storage.hpp index 823747c7e..a819649e4 100644 --- a/include/libtorrent/kademlia/dht_storage.hpp +++ b/include/libtorrent/kademlia/dht_storage.hpp @@ -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; diff --git a/src/kademlia/dht_storage.cpp b/src/kademlia/dht_storage.cpp index 0b9575a6b..95125c658 100644 --- a/src/kademlia/dht_storage.cpp +++ b/src/kademlia/dht_storage.cpp @@ -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; diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index b4b46f7b3..223434ef3 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -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 const& nodes) diff --git a/test/test_dht_storage.cpp b/test/test_dht_storage.cpp index b52d0fcce..0d6a89275 100644 --- a/test/test_dht_storage.cpp +++ b/test/test_dht_storage.cpp @@ -100,7 +100,7 @@ TORRENT_TEST(announce_peer) std::unique_ptr 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); }