Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 2,858 Lines • ▼ Show 20 Lines | void CConnman::MarkAddressGood(const CAddress &addr) { | ||||
addrman.Good(addr); | addrman.Good(addr); | ||||
} | } | ||||
void CConnman::AddNewAddresses(const std::vector<CAddress> &vAddr, | void CConnman::AddNewAddresses(const std::vector<CAddress> &vAddr, | ||||
const CAddress &addrFrom, int64_t nTimePenalty) { | const CAddress &addrFrom, int64_t nTimePenalty) { | ||||
addrman.Add(vAddr, addrFrom, nTimePenalty); | addrman.Add(vAddr, addrFrom, nTimePenalty); | ||||
} | } | ||||
std::vector<CAddress> CConnman::GetAddresses() { | std::vector<CAddress> CConnman::GetAddresses(size_t max_addresses, | ||||
std::vector<CAddress> addresses = addrman.GetAddr(); | size_t max_pct) { | ||||
std::vector<CAddress> addresses = addrman.GetAddr(max_addresses, max_pct); | |||||
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) { | [this](const CAddress &addr) { | ||||
return m_banman->IsDiscouraged( | return m_banman->IsDiscouraged( | ||||
addr) || | addr) || | ||||
m_banman->IsBanned(addr); | m_banman->IsBanned(addr); | ||||
}), | }), | ||||
addresses.end()); | addresses.end()); | ||||
} | } | ||||
return addresses; | 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>(); | const auto current_time = GetTime<std::chrono::microseconds>(); | ||||
if (m_addr_response_caches.find(requestor_network) == | if (m_addr_response_caches.find(requestor_network) == | ||||
m_addr_response_caches.end() || | m_addr_response_caches.end() || | ||||
m_addr_response_caches[requestor_network].m_update_addr_response < | m_addr_response_caches[requestor_network].m_update_addr_response < | ||||
current_time) { | current_time) { | ||||
m_addr_response_caches[requestor_network].m_addrs_response_cache = | m_addr_response_caches[requestor_network].m_addrs_response_cache = | ||||
GetAddresses(); | GetAddresses(max_addresses, max_pct); | ||||
m_addr_response_caches[requestor_network].m_update_addr_response = | m_addr_response_caches[requestor_network].m_update_addr_response = | ||||
current_time + std::chrono::hours(21) + | current_time + std::chrono::hours(21) + | ||||
GetRandMillis(std::chrono::hours(6)); | GetRandMillis(std::chrono::hours(6)); | ||||
} | } | ||||
return m_addr_response_caches[requestor_network].m_addrs_response_cache; | return m_addr_response_caches[requestor_network].m_addrs_response_cache; | ||||
} | } | ||||
bool CConnman::AddNode(const std::string &strNode) { | bool CConnman::AddNode(const std::string &strNode) { | ||||
▲ Show 20 Lines • Show All 415 Lines • Show Last 20 Lines |