Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | |||||
const std::string NET_MESSAGE_COMMAND_OTHER = "*other*"; | const std::string NET_MESSAGE_COMMAND_OTHER = "*other*"; | ||||
// SHA256("netgroup")[0:8] | // SHA256("netgroup")[0:8] | ||||
static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL; | static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL; | ||||
// SHA256("localhostnonce")[0:8] | // SHA256("localhostnonce")[0:8] | ||||
static const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL; | static const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL; | ||||
// SHA256("localhostnonce")[8:16] | // SHA256("localhostnonce")[8:16] | ||||
static const uint64_t RANDOMIZER_ID_EXTRAENTROPY = 0x94b05d41679a4ff7ULL; | static const uint64_t RANDOMIZER_ID_EXTRAENTROPY = 0x94b05d41679a4ff7ULL; | ||||
// SHA256("addrcache")[0:8] | |||||
static const uint64_t RANDOMIZER_ID_ADDRCACHE = 0x1cf2e4ddd306dda9ULL; | |||||
// | // | ||||
// Global state variables | // Global state variables | ||||
// | // | ||||
bool fDiscover = true; | bool fDiscover = true; | ||||
bool fListen = true; | bool fListen = true; | ||||
bool g_relay_txes = !DEFAULT_BLOCKSONLY; | bool g_relay_txes = !DEFAULT_BLOCKSONLY; | ||||
RecursiveMutex cs_mapLocalHost; | RecursiveMutex cs_mapLocalHost; | ||||
std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost); | std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost); | ||||
▲ Show 20 Lines • Show All 2,754 Lines • ▼ Show 20 Lines | if (m_banman) { | ||||
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> | ||||
size_t max_addresses, | CConnman::GetAddresses(CNode &requestor, size_t max_addresses, size_t max_pct) { | ||||
size_t max_pct) { | SOCKET socket; | ||||
WITH_LOCK(requestor.cs_hSocket, socket = requestor.hSocket); | |||||
auto local_socket_bytes = GetBindAddress(socket).GetAddrBytes(); | |||||
uint64_t cache_id = | |||||
GetDeterministicRandomizer(RANDOMIZER_ID_ADDRCACHE) | |||||
.Write(requestor.addr.GetNetwork()) | |||||
.Write(local_socket_bytes.data(), local_socket_bytes.size()) | |||||
.Finalize(); | |||||
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(cache_id) == m_addr_response_caches.end() || | ||||
m_addr_response_caches.end() || | m_addr_response_caches[cache_id].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[cache_id].m_addrs_response_cache = | ||||
GetAddresses(max_addresses, max_pct); | GetAddresses(max_addresses, max_pct); | ||||
// Choosing a proper cache lifetime is a trade-off between the privacy | // Choosing a proper cache lifetime is a trade-off between the privacy | ||||
// leak minimization and the usefulness of ADDR responses to honest | // leak minimization and the usefulness of ADDR responses to honest | ||||
// users. | // users. | ||||
// | // | ||||
// Longer cache lifetime makes it more difficult for an attacker to | // Longer cache lifetime makes it more difficult for an attacker to | ||||
// scrape enough AddrMan data to maliciously infer something useful. By | // scrape enough AddrMan data to maliciously infer something useful. By | ||||
Show All 14 Lines | if (m_addr_response_caches.find(cache_id) == m_addr_response_caches.end() || | ||||
// outdated and less useful for an honest requestor, e.g. if most nodes | // outdated and less useful for an honest requestor, e.g. if most nodes | ||||
// in the ADDR response are no longer active. | // in the ADDR response are no longer active. | ||||
// | // | ||||
// However, the churn in the network is known to be rather low. Since we | // However, the churn in the network is known to be rather low. Since we | ||||
// consider nodes to be "terrible" (see IsTerrible()) if the timestamps | // consider nodes to be "terrible" (see IsTerrible()) if the timestamps | ||||
// are older than 30 days, max. 24 hours of "penalty" due to cache | // are older than 30 days, max. 24 hours of "penalty" due to cache | ||||
// shouldn't make any meaningful difference in terms of the freshness of | // shouldn't make any meaningful difference in terms of the freshness of | ||||
// the response. | // the response. | ||||
m_addr_response_caches[requestor_network].m_update_addr_response = | m_addr_response_caches[cache_id].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[cache_id].m_addrs_response_cache; | ||||
} | } | ||||
bool CConnman::AddNode(const std::string &strNode) { | bool CConnman::AddNode(const std::string &strNode) { | ||||
LOCK(cs_vAddedNodes); | LOCK(cs_vAddedNodes); | ||||
for (const std::string &it : vAddedNodes) { | for (const std::string &it : vAddedNodes) { | ||||
if (strNode == it) { | if (strNode == it) { | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 410 Lines • Show Last 20 Lines |