fix: filter out peers with port 1 from DHT peer lists. (#5218)

This commit is contained in:
Charles Kerr 2023-03-13 19:27:47 -05:00 committed by GitHub
parent 6224b60728
commit a87d39f3bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -377,6 +377,19 @@ private:
return std::chrono::seconds{ call_again_in_n_secs }; return std::chrono::seconds{ call_again_in_n_secs };
} }
static auto remove_bad_pex(std::vector<tr_pex>&& pex)
{
static constexpr auto IsBadPex = [](tr_pex const& pex)
{
// paper over a bug in some DHT implementation that gives port 1.
// Xref: https://github.com/transmission/transmission/issues/527
return pex.port.host() == 1;
};
pex.erase(std::remove_if(std::begin(pex), std::end(pex), IsBadPex), std::end(pex));
return pex;
}
static void callback(void* vself, int event, unsigned char const* info_hash, void const* data, size_t data_len) static void callback(void* vself, int event, unsigned char const* info_hash, void const* data, size_t data_len)
{ {
auto* const self = static_cast<tr_dht_impl*>(vself); auto* const self = static_cast<tr_dht_impl*>(vself);
@ -385,12 +398,12 @@ private:
if (event == DHT_EVENT_VALUES) if (event == DHT_EVENT_VALUES)
{ {
auto const pex = tr_pex::from_compact_ipv4(data, data_len, nullptr, 0); auto const pex = remove_bad_pex(tr_pex::from_compact_ipv4(data, data_len, nullptr, 0));
self->mediator_.addPex(hash, std::data(pex), std::size(pex)); self->mediator_.addPex(hash, std::data(pex), std::size(pex));
} }
else if (event == DHT_EVENT_VALUES6) else if (event == DHT_EVENT_VALUES6)
{ {
auto const pex = tr_pex::from_compact_ipv6(data, data_len, nullptr, 0); auto const pex = remove_bad_pex(tr_pex::from_compact_ipv6(data, data_len, nullptr, 0));
self->mediator_.addPex(hash, std::data(pex), std::size(pex)); self->mediator_.addPex(hash, std::data(pex), std::size(pex));
} }
} }