mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Merge #19658: [rpc] Allow RPC to fetch all addrman records and add records to addrman
37a480e0cd[net] Add addpeeraddress RPC method (John Newbery)ae8051bbd8[test] Test that getnodeaddresses() can return all known addresses (John Newbery)f26502e9fc[addrman] Specify max addresses and pct when calling GetAddresses() (John Newbery) Pull request description: Currently addrman only allows a maximum of 1000 records or 23% of all records to be returned in a call to `GetAddr()`. Relax this limit and have the client specify the max records they want. For p2p, behaviour is unchanged (but the rate limiting is set inside net_processing, where it belongs). For RPC, `getnodeaddresses` can now return the complete addrman, which is helpful for testing and monitoring. Also add a test-only RPC `addpeeraddress`, which adds an IP address:port to addrman. This is helpful for testing (eg #18991). ACKs for top commit: naumenkogs: utACK37a480e0cdlaanwj: Code review and lightly manually tested ACK37a480e0cdTree-SHA512: f86dcd410aaebaf6e9ca18ce6f23556e5e4649c1325577213d873aa09967298e65ab2dc19a72670641ae92211a923afda1fe124a82e9d2c1cad73d478ef27fdc
This commit is contained in:
12
src/net.cpp
12
src/net.cpp
@@ -2521,14 +2521,14 @@ void CConnman::MarkAddressGood(const CAddress& addr)
|
||||
addrman.Good(addr);
|
||||
}
|
||||
|
||||
void CConnman::AddNewAddresses(const std::vector<CAddress>& vAddr, const CAddress& addrFrom, int64_t nTimePenalty)
|
||||
bool CConnman::AddNewAddresses(const std::vector<CAddress>& vAddr, const CAddress& addrFrom, int64_t nTimePenalty)
|
||||
{
|
||||
addrman.Add(vAddr, addrFrom, nTimePenalty);
|
||||
return addrman.Add(vAddr, addrFrom, nTimePenalty);
|
||||
}
|
||||
|
||||
std::vector<CAddress> CConnman::GetAddresses()
|
||||
std::vector<CAddress> CConnman::GetAddresses(size_t max_addresses, size_t max_pct)
|
||||
{
|
||||
std::vector<CAddress> addresses = addrman.GetAddr();
|
||||
std::vector<CAddress> addresses = addrman.GetAddr(max_addresses, max_pct);
|
||||
if (m_banman) {
|
||||
addresses.erase(std::remove_if(addresses.begin(), addresses.end(),
|
||||
[this](const CAddress& addr){return m_banman->IsDiscouraged(addr) || m_banman->IsBanned(addr);}),
|
||||
@@ -2537,12 +2537,12 @@ std::vector<CAddress> CConnman::GetAddresses()
|
||||
return addresses;
|
||||
}
|
||||
|
||||
std::vector<CAddress> CConnman::GetAddresses(Network requestor_network)
|
||||
std::vector<CAddress> CConnman::GetAddresses(Network requestor_network, size_t max_addresses, size_t max_pct)
|
||||
{
|
||||
const auto current_time = GetTime<std::chrono::microseconds>();
|
||||
if (m_addr_response_caches.find(requestor_network) == m_addr_response_caches.end() ||
|
||||
m_addr_response_caches[requestor_network].m_update_addr_response < current_time) {
|
||||
m_addr_response_caches[requestor_network].m_addrs_response_cache = GetAddresses();
|
||||
m_addr_response_caches[requestor_network].m_addrs_response_cache = GetAddresses(max_addresses, max_pct);
|
||||
m_addr_response_caches[requestor_network].m_update_addr_response = current_time + std::chrono::hours(21) + GetRandMillis(std::chrono::hours(6));
|
||||
}
|
||||
return m_addr_response_caches[requestor_network].m_addrs_response_cache;
|
||||
|
||||
Reference in New Issue
Block a user