Changeset View
Changeset View
Standalone View
Standalone View
src/addrman.h
Show First 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | |||||
//! ... in at least this many days | //! ... in at least this many days | ||||
#define ADDRMAN_MIN_FAIL_DAYS 7 | #define ADDRMAN_MIN_FAIL_DAYS 7 | ||||
//! how recent a successful connection should be before we allow an address to | //! how recent a successful connection should be before we allow an address to | ||||
//! be evicted from tried | //! be evicted from tried | ||||
#define ADDRMAN_REPLACEMENT_SECONDS (4 * 60 * 60) | #define ADDRMAN_REPLACEMENT_SECONDS (4 * 60 * 60) | ||||
//! the maximum percentage of nodes to return in a getaddr call | |||||
#define ADDRMAN_GETADDR_MAX_PCT 23 | |||||
//! the maximum number of nodes to return in a getaddr call | |||||
#define ADDRMAN_GETADDR_MAX 1000 | |||||
//! Convenience | //! Convenience | ||||
#define ADDRMAN_TRIED_BUCKET_COUNT (1 << ADDRMAN_TRIED_BUCKET_COUNT_LOG2) | #define ADDRMAN_TRIED_BUCKET_COUNT (1 << ADDRMAN_TRIED_BUCKET_COUNT_LOG2) | ||||
#define ADDRMAN_NEW_BUCKET_COUNT (1 << ADDRMAN_NEW_BUCKET_COUNT_LOG2) | #define ADDRMAN_NEW_BUCKET_COUNT (1 << ADDRMAN_NEW_BUCKET_COUNT_LOG2) | ||||
#define ADDRMAN_BUCKET_SIZE (1 << ADDRMAN_BUCKET_SIZE_LOG2) | #define ADDRMAN_BUCKET_SIZE (1 << ADDRMAN_BUCKET_SIZE_LOG2) | ||||
//! the maximum number of tried addr collisions to store | //! the maximum number of tried addr collisions to store | ||||
#define ADDRMAN_SET_TRIED_COLLISION_SIZE 10 | #define ADDRMAN_SET_TRIED_COLLISION_SIZE 10 | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | protected: | ||||
CAddrInfo SelectTriedCollision_() EXCLUSIVE_LOCKS_REQUIRED(cs); | CAddrInfo SelectTriedCollision_() EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
#ifdef DEBUG_ADDRMAN | #ifdef DEBUG_ADDRMAN | ||||
//! Perform consistency check. Returns an error code or zero. | //! Perform consistency check. Returns an error code or zero. | ||||
int Check_() EXCLUSIVE_LOCKS_REQUIRED(cs); | int Check_() EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
#endif | #endif | ||||
//! Select several addresses at once. | //! Select several addresses at once. | ||||
void GetAddr_(std::vector<CAddress> &vAddr) EXCLUSIVE_LOCKS_REQUIRED(cs); | void GetAddr_(std::vector<CAddress> &vAddr, size_t max_addresses, | ||||
size_t max_pct) EXCLUSIVE_LOCKS_REQUIRED(cs); | |||||
//! Mark an entry as currently-connected-to. | //! Mark an entry as currently-connected-to. | ||||
void Connected_(const CService &addr, int64_t nTime) | void Connected_(const CService &addr, int64_t nTime) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
//! Update an entry's service bits. | //! Update an entry's service bits. | ||||
void SetServices_(const CService &addr, ServiceFlags nServices) | void SetServices_(const CService &addr, ServiceFlags nServices) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
▲ Show 20 Lines • Show All 411 Lines • ▼ Show 20 Lines | CAddrInfo Select(bool newOnly = false) { | ||||
Check(); | Check(); | ||||
addrRet = Select_(newOnly); | addrRet = Select_(newOnly); | ||||
Check(); | Check(); | ||||
} | } | ||||
return addrRet; | return addrRet; | ||||
} | } | ||||
//! Return a bunch of addresses, selected at random. | //! Return a bunch of addresses, selected at random. | ||||
std::vector<CAddress> GetAddr() { | std::vector<CAddress> GetAddr(size_t max_addresses, size_t max_pct) { | ||||
Check(); | Check(); | ||||
std::vector<CAddress> vAddr; | std::vector<CAddress> vAddr; | ||||
{ | { | ||||
LOCK(cs); | LOCK(cs); | ||||
GetAddr_(vAddr); | GetAddr_(vAddr, max_addresses, max_pct); | ||||
} | } | ||||
Check(); | Check(); | ||||
return vAddr; | return vAddr; | ||||
} | } | ||||
//! Mark an entry as currently-connected-to. | //! Mark an entry as currently-connected-to. | ||||
void Connected(const CService &addr, int64_t nTime = GetAdjustedTime()) { | void Connected(const CService &addr, int64_t nTime = GetAdjustedTime()) { | ||||
LOCK(cs); | LOCK(cs); | ||||
Show All 14 Lines |