mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 02:25:40 +01:00
net: Optionally include terrible addresses in GetAddr results
This commit is contained in:
parent
058488276f
commit
e16f420547
@ -800,7 +800,7 @@ int AddrManImpl::GetEntry(bool use_tried, size_t bucket, size_t position) const
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
|
std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered) const
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs);
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
@ -830,7 +830,7 @@ std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct
|
|||||||
if (network != std::nullopt && ai.GetNetClass() != network) continue;
|
if (network != std::nullopt && ai.GetNetClass() != network) continue;
|
||||||
|
|
||||||
// Filter for quality
|
// Filter for quality
|
||||||
if (ai.IsTerrible(now)) continue;
|
if (ai.IsTerrible(now) && filtered) continue;
|
||||||
|
|
||||||
addresses.push_back(ai);
|
addresses.push_back(ai);
|
||||||
}
|
}
|
||||||
@ -1214,11 +1214,11 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select(bool new_only, std::optiona
|
|||||||
return addrRet;
|
return addrRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CAddress> AddrManImpl::GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
|
std::vector<CAddress> AddrManImpl::GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered) const
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
Check();
|
Check();
|
||||||
auto addresses = GetAddr_(max_addresses, max_pct, network);
|
auto addresses = GetAddr_(max_addresses, max_pct, network, filtered);
|
||||||
Check();
|
Check();
|
||||||
return addresses;
|
return addresses;
|
||||||
}
|
}
|
||||||
@ -1317,9 +1317,9 @@ std::pair<CAddress, NodeSeconds> AddrMan::Select(bool new_only, std::optional<Ne
|
|||||||
return m_impl->Select(new_only, network);
|
return m_impl->Select(new_only, network);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CAddress> AddrMan::GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
|
std::vector<CAddress> AddrMan::GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered) const
|
||||||
{
|
{
|
||||||
return m_impl->GetAddr(max_addresses, max_pct, network);
|
return m_impl->GetAddr(max_addresses, max_pct, network, filtered);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::pair<AddrInfo, AddressPosition>> AddrMan::GetEntries(bool use_tried) const
|
std::vector<std::pair<AddrInfo, AddressPosition>> AddrMan::GetEntries(bool use_tried) const
|
||||||
|
@ -164,10 +164,11 @@ public:
|
|||||||
* @param[in] max_addresses Maximum number of addresses to return (0 = all).
|
* @param[in] max_addresses Maximum number of addresses to return (0 = all).
|
||||||
* @param[in] max_pct Maximum percentage of addresses to return (0 = all).
|
* @param[in] max_pct Maximum percentage of addresses to return (0 = all).
|
||||||
* @param[in] network Select only addresses of this network (nullopt = all).
|
* @param[in] network Select only addresses of this network (nullopt = all).
|
||||||
|
* @param[in] filtered Select only addresses that are considered good quality (false = all).
|
||||||
*
|
*
|
||||||
* @return A vector of randomly selected addresses from vRandom.
|
* @return A vector of randomly selected addresses from vRandom.
|
||||||
*/
|
*/
|
||||||
std::vector<CAddress> GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network) const;
|
std::vector<CAddress> GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an information-location pair for all addresses in the selected addrman table.
|
* Returns an information-location pair for all addresses in the selected addrman table.
|
||||||
|
@ -129,7 +129,7 @@ public:
|
|||||||
std::pair<CAddress, NodeSeconds> Select(bool new_only, std::optional<Network> network) const
|
std::pair<CAddress, NodeSeconds> Select(bool new_only, std::optional<Network> network) const
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(!cs);
|
EXCLUSIVE_LOCKS_REQUIRED(!cs);
|
||||||
|
|
||||||
std::vector<CAddress> GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
|
std::vector<CAddress> GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(!cs);
|
EXCLUSIVE_LOCKS_REQUIRED(!cs);
|
||||||
|
|
||||||
std::vector<std::pair<AddrInfo, AddressPosition>> GetEntries(bool from_tried) const
|
std::vector<std::pair<AddrInfo, AddressPosition>> GetEntries(bool from_tried) const
|
||||||
@ -261,7 +261,7 @@ private:
|
|||||||
* */
|
* */
|
||||||
int GetEntry(bool use_tried, size_t bucket, size_t position) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
int GetEntry(bool use_tried, size_t bucket, size_t position) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
|
||||||
std::vector<CAddress> GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
std::vector<CAddress> GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
|
||||||
std::vector<std::pair<AddrInfo, AddressPosition>> GetEntries_(bool from_tried) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
std::vector<std::pair<AddrInfo, AddressPosition>> GetEntries_(bool from_tried) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
|
||||||
|
@ -3410,9 +3410,9 @@ CConnman::~CConnman()
|
|||||||
Stop();
|
Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CAddress> CConnman::GetAddresses(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
|
std::vector<CAddress> CConnman::GetAddresses(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered) const
|
||||||
{
|
{
|
||||||
std::vector<CAddress> addresses = addrman.GetAddr(max_addresses, max_pct, network);
|
std::vector<CAddress> addresses = addrman.GetAddr(max_addresses, max_pct, network, filtered);
|
||||||
if (m_banman) {
|
if (m_banman) {
|
||||||
addresses.erase(std::remove_if(addresses.begin(), addresses.end(),
|
addresses.erase(std::remove_if(addresses.begin(), addresses.end(),
|
||||||
[this](const CAddress& addr){return m_banman->IsDiscouraged(addr) || m_banman->IsBanned(addr);}),
|
[this](const CAddress& addr){return m_banman->IsDiscouraged(addr) || m_banman->IsBanned(addr);}),
|
||||||
|
@ -1172,8 +1172,9 @@ public:
|
|||||||
* @param[in] max_addresses Maximum number of addresses to return (0 = all).
|
* @param[in] max_addresses Maximum number of addresses to return (0 = all).
|
||||||
* @param[in] max_pct Maximum percentage of addresses to return (0 = all).
|
* @param[in] max_pct Maximum percentage of addresses to return (0 = all).
|
||||||
* @param[in] network Select only addresses of this network (nullopt = all).
|
* @param[in] network Select only addresses of this network (nullopt = all).
|
||||||
|
* @param[in] filtered Select only addresses that are considered high quality (false = all).
|
||||||
*/
|
*/
|
||||||
std::vector<CAddress> GetAddresses(size_t max_addresses, size_t max_pct, std::optional<Network> network) const;
|
std::vector<CAddress> GetAddresses(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const;
|
||||||
/**
|
/**
|
||||||
* Cache is used to minimize topology leaks, so it should
|
* Cache is used to minimize topology leaks, so it should
|
||||||
* be used for all non-trusted calls, for example, p2p.
|
* be used for all non-trusted calls, for example, p2p.
|
||||||
|
Loading…
Reference in New Issue
Block a user