Stochastic address manager * * Design goals: * * Keep the address tables in-memory, and asynchronously dump the entire table to peers.dat. * * Make sure no (localized) attacker can fill the entire table with his nodes/addresses. * * To that end: * * Addresses are organized into buckets that can each store up to 64 entries. * * Addresses to which our node has not successfully connecte
| 83 | * configuration option will introduce (expensive) consistency checks for the entire data structure. |
| 84 | */ |
| 85 | class AddrMan |
| 86 | { |
| 87 | protected: |
| 88 | const std::unique_ptr<AddrManImpl> m_impl; |
| 89 | |
| 90 | public: |
| 91 | explicit AddrMan(std::vector<bool> asmap, bool deterministic, int32_t consistency_check_ratio); |
| 92 | |
| 93 | ~AddrMan(); |
| 94 | |
| 95 | template <typename Stream> |
| 96 | void Serialize(Stream& s_) const; |
| 97 | |
| 98 | template <typename Stream> |
| 99 | void Unserialize(Stream& s_); |
| 100 | |
| 101 | //! Return the number of (unique) addresses in all tables. |
| 102 | size_t size() const; |
| 103 | |
| 104 | /** |
| 105 | * Attempt to add one or more addresses to addrman's new table. |
| 106 | * |
| 107 | * @param[in] vAddr Address records to attempt to add. |
| 108 | * @param[in] source The address of the node that sent us these addr records. |
| 109 | * @param[in] nTimePenalty A "time penalty" to apply to the address record's nTime. If a peer |
| 110 | * sends us an address record with nTime=n, then we'll add it to our |
| 111 | * addrman with nTime=(n - nTimePenalty). |
| 112 | * @return true if at least one address is successfully added. */ |
| 113 | bool Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, int64_t nTimePenalty = 0); |
| 114 | |
| 115 | /** |
| 116 | * Mark an address record as accessible and attempt to move it to addrman's tried table. |
| 117 | * |
| 118 | * @param[in] addr Address record to attempt to move to tried table. |
| 119 | * @param[in] nTime The time that we were last connected to this peer. |
| 120 | * @return true if the address is successfully moved from the new table to the tried table. |
| 121 | */ |
| 122 | bool Good(const CService& addr, int64_t nTime = GetAdjustedTime()); |
| 123 | |
| 124 | //! Mark an entry as connection attempted to. |
| 125 | void Attempt(const CService& addr, bool fCountFailure, int64_t nTime = GetAdjustedTime()); |
| 126 | |
| 127 | //! See if any to-be-evicted tried table entries have been tested and if so resolve the collisions. |
| 128 | void ResolveCollisions(); |
| 129 | |
| 130 | /** |
| 131 | * Randomly select an address in the tried table that another address is |
| 132 | * attempting to evict. |
| 133 | * |
| 134 | * @return CAddress The record for the selected tried peer. |
| 135 | * int64_t The last time we attempted to connect to that peer. |
| 136 | */ |
| 137 | std::pair<CAddress, int64_t> SelectTriedCollision(); |
| 138 | |
| 139 | /** |
| 140 | * Choose an address to connect to. |
| 141 | * |
| 142 | * @param[in] newOnly Whether to only select addresses from the new table. |
nothing calls this directly
no test coverage detected