check the address family of peers in get_peers (#1090)
This commit is contained in:
parent
c25bae163d
commit
3d3367387a
|
@ -125,7 +125,7 @@ namespace dht
|
|||
// returns true if an entry with the info_hash is found and
|
||||
// the data is returned inside the (entry) out parameter peers.
|
||||
//
|
||||
virtual bool get_peers(sha1_hash const& info_hash
|
||||
virtual bool get_peers(sha1_hash const& info_hash, udp protocol
|
||||
, bool noseed, bool scrape
|
||||
, entry& peers) const = 0;
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ namespace
|
|||
m_node_ids = ids;
|
||||
}
|
||||
|
||||
bool get_peers(sha1_hash const& info_hash
|
||||
bool get_peers(sha1_hash const& info_hash, udp protocol
|
||||
, bool const noseed, bool const scrape
|
||||
, entry& peers) const override
|
||||
{
|
||||
|
@ -234,7 +234,7 @@ namespace
|
|||
// 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() && v.peers.begin()->addr.protocol() == tcp::v6())
|
||||
if (!v.peers.empty() && protocol == udp::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);
|
||||
|
@ -247,6 +247,10 @@ namespace
|
|||
// peer list
|
||||
if (noseed && iter->seed) continue;
|
||||
|
||||
// only include peers with the right address family
|
||||
if (iter->addr.protocol().family() != protocol.family())
|
||||
continue;
|
||||
|
||||
++t;
|
||||
std::string* str;
|
||||
if (t <= to_pick)
|
||||
|
|
|
@ -755,7 +755,7 @@ void node::lookup_peers(sha1_hash const& info_hash, entry& reply
|
|||
if (m_observer)
|
||||
m_observer->get_peers(info_hash);
|
||||
|
||||
m_storage.get_peers(info_hash, noseed, scrape, reply);
|
||||
m_storage.get_peers(info_hash, protocol(), noseed, scrape, reply);
|
||||
}
|
||||
|
||||
void write_nodes_entry(entry& r, nodes_t const& nodes)
|
||||
|
|
|
@ -107,7 +107,7 @@ TORRENT_TEST(announce_peer)
|
|||
std::unique_ptr<dht_storage_interface> s(create_default_dht_storage(sett));
|
||||
|
||||
entry peers;
|
||||
s->get_peers(n1, false, false, peers);
|
||||
s->get_peers(n1, udp::v4(), false, false, peers);
|
||||
|
||||
TEST_CHECK(peers["n"].string().empty())
|
||||
TEST_CHECK(peers["values"].list().empty());
|
||||
|
@ -118,17 +118,43 @@ TORRENT_TEST(announce_peer)
|
|||
tcp::endpoint const p4 = ep("124.31.75.24", 1);
|
||||
|
||||
s->announce_peer(n1, p1, "torrent_name", false);
|
||||
s->get_peers(n1, false, false, peers);
|
||||
s->get_peers(n1, udp::v4(), false, false, peers);
|
||||
TEST_EQUAL(peers["n"].string(), "torrent_name")
|
||||
TEST_EQUAL(peers["values"].list().size(), 1)
|
||||
|
||||
s->announce_peer(n2, p2, "torrent_name1", false);
|
||||
s->announce_peer(n2, p3, "torrent_name1", false);
|
||||
s->announce_peer(n3, p4, "torrent_name2", false);
|
||||
bool r = s->get_peers(n1, false, false, peers);
|
||||
bool r = s->get_peers(n1, udp::v4(), false, false, peers);
|
||||
TEST_CHECK(!r);
|
||||
}
|
||||
|
||||
TORRENT_TEST(dual_stack)
|
||||
{
|
||||
dht_settings sett = test_settings();
|
||||
std::unique_ptr<dht_storage_interface> s(create_default_dht_storage(sett));
|
||||
|
||||
tcp::endpoint const p1 = ep("124.31.75.21", 1);
|
||||
tcp::endpoint const p2 = ep("124.31.75.22", 1);
|
||||
tcp::endpoint const p3 = ep("124.31.75.23", 1);
|
||||
tcp::endpoint const p4 = ep("2000::1", 1);
|
||||
tcp::endpoint const p5 = ep("2000::2", 1);
|
||||
|
||||
s->announce_peer(n1, p1, "torrent_name", false);
|
||||
s->announce_peer(n1, p2, "torrent_name", false);
|
||||
s->announce_peer(n1, p3, "torrent_name", false);
|
||||
s->announce_peer(n1, p4, "torrent_name", false);
|
||||
s->announce_peer(n1, p5, "torrent_name", false);
|
||||
|
||||
entry peers4;
|
||||
s->get_peers(n1, udp::v4(), false, false, peers4);
|
||||
TEST_EQUAL(peers4["values"].list().size(), 3);
|
||||
|
||||
entry peers6;
|
||||
s->get_peers(n1, udp::v6(), false, false, peers6);
|
||||
TEST_EQUAL(peers6["values"].list().size(), 2);
|
||||
}
|
||||
|
||||
TORRENT_TEST(put_immutable_item)
|
||||
{
|
||||
dht_settings sett = test_settings();
|
||||
|
|
Loading…
Reference in New Issue