Changeset View
Changeset View
Standalone View
Standalone View
src/net.h
Show All 26 Lines | |||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <util/check.h> | #include <util/check.h> | ||||
#include <validation.h> // For cs_main | #include <validation.h> // For cs_main | ||||
#include <atomic> | #include <atomic> | ||||
#include <condition_variable> | #include <condition_variable> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <deque> | #include <deque> | ||||
#include <map> | |||||
#include <memory> | #include <memory> | ||||
#include <thread> | #include <thread> | ||||
#include <vector> | #include <vector> | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
#include <arpa/inet.h> | #include <arpa/inet.h> | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 294 Lines • ▼ Show 20 Lines | public: | ||||
}; | }; | ||||
// Addrman functions | // Addrman functions | ||||
void SetServices(const CService &addr, ServiceFlags nServices); | void SetServices(const CService &addr, ServiceFlags nServices); | ||||
void MarkAddressGood(const CAddress &addr); | void MarkAddressGood(const CAddress &addr); | ||||
void AddNewAddresses(const std::vector<CAddress> &vAddr, | void AddNewAddresses(const std::vector<CAddress> &vAddr, | ||||
const CAddress &addrFrom, int64_t nTimePenalty = 0); | const CAddress &addrFrom, int64_t nTimePenalty = 0); | ||||
std::vector<CAddress> GetAddresses(); | std::vector<CAddress> GetAddresses(); | ||||
/** | |||||
* Cache is used to minimize topology leaks, so it should | |||||
* be used for all non-trusted calls, for example, p2p. | |||||
* A non-malicious call (from RPC) should | |||||
* call the function without a parameter to avoid using the cache. | |||||
*/ | |||||
std::vector<CAddress> GetAddresses(Network requestor_network); | |||||
// This allows temporarily exceeding m_max_outbound_full_relay, with the | // This allows temporarily exceeding m_max_outbound_full_relay, with the | ||||
// goal of finding a peer that is better than all our current peers. | // goal of finding a peer that is better than all our current peers. | ||||
void SetTryNewOutboundPeer(bool flag); | void SetTryNewOutboundPeer(bool flag); | ||||
bool GetTryNewOutboundPeer(); | bool GetTryNewOutboundPeer(); | ||||
// Return the number of outbound peers we have in excess of our target (eg, | // Return the number of outbound peers we have in excess of our target (eg, | ||||
// if we previously called SetTryNewOutboundPeer(true), and have since set | // if we previously called SetTryNewOutboundPeer(true), and have since set | ||||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | private: | ||||
RecursiveMutex cs_vAddedNodes; | RecursiveMutex cs_vAddedNodes; | ||||
std::vector<CNode *> vNodes GUARDED_BY(cs_vNodes); | std::vector<CNode *> vNodes GUARDED_BY(cs_vNodes); | ||||
std::list<CNode *> vNodesDisconnected; | std::list<CNode *> vNodesDisconnected; | ||||
mutable RecursiveMutex cs_vNodes; | mutable RecursiveMutex cs_vNodes; | ||||
std::atomic<NodeId> nLastNodeId{0}; | std::atomic<NodeId> nLastNodeId{0}; | ||||
unsigned int nPrevNodeCount{0}; | unsigned int nPrevNodeCount{0}; | ||||
/** | /** | ||||
* Cache responses to addr requests to minimize privacy leak. | |||||
* Attack example: scraping addrs in real-time may allow an attacker | |||||
* to infer new connections of the victim by detecting new records | |||||
* with fresh timestamps (per self-announcement). | |||||
*/ | |||||
struct CachedAddrResponse { | |||||
std::vector<CAddress> m_addrs_response_cache; | |||||
std::chrono::microseconds m_update_addr_response{0}; | |||||
}; | |||||
/** | |||||
* Addr responses stored in different caches | |||||
* per network prevent cross-network node identification. | |||||
* If a node for example is multi-homed under Tor and IPv6, | |||||
* a single cache (or no cache at all) would let an attacker | |||||
* to easily detect that it is the same node by comparing responses. | |||||
* The used memory equals to 1000 CAddress records (or around 32 bytes) per | |||||
* distinct Network (up to 5) we have/had an inbound peer from, | |||||
* resulting in at most ~160 KB. | |||||
*/ | |||||
std::map<Network, CachedAddrResponse> m_addr_response_caches; | |||||
/** | |||||
* Services this instance offers. | * Services this instance offers. | ||||
* | * | ||||
* This data is replicated in each CNode instance we create during peer | * This data is replicated in each CNode instance we create during peer | ||||
* connection (in ConnectNode()) under a member also called | * connection (in ConnectNode()) under a member also called | ||||
* nLocalServices. | * nLocalServices. | ||||
* | * | ||||
* This data is not marked const, but after being set it should not | * This data is not marked const, but after being set it should not | ||||
* change. See the note in CNode::nLocalServices documentation. | * change. See the note in CNode::nLocalServices documentation. | ||||
▲ Show 20 Lines • Show All 798 Lines • Show Last 20 Lines |