Bitcoin ABC 0.32.4
P2P Digital Currency
addrman.h
Go to the documentation of this file.
1// Copyright (c) 2012 Pieter Wuille
2// Copyright (c) 2012-2016 The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef BITCOIN_ADDRMAN_H
7#define BITCOIN_ADDRMAN_H
8
9#include <netaddress.h>
10#include <protocol.h>
11#include <streams.h>
12#include <util/time.h>
13
14#include <cstdint>
15#include <memory>
16#include <optional>
17#include <utility>
18#include <vector>
19
20class InvalidAddrManVersionError : public std::ios_base::failure {
21public:
22 InvalidAddrManVersionError(std::string msg) : std::ios_base::failure(msg) {}
23};
24
25class AddrManImpl;
26
28static constexpr int32_t DEFAULT_ADDRMAN_CONSISTENCY_CHECKS{0};
29
68class AddrMan {
69protected:
70 const std::unique_ptr<AddrManImpl> m_impl;
71
72public:
73 AddrMan(std::vector<bool> asmap, bool deterministic,
74 int32_t consistency_check_ratio);
75
77
78 template <typename Stream> void Serialize(Stream &s_) const;
79
80 template <typename Stream> void Unserialize(Stream &s_);
81
83 size_t size() const;
84
96 bool Add(const std::vector<CAddress> &vAddr, const CNetAddr &source,
97 std::chrono::seconds time_penalty = 0s);
98
100 void Good(const CService &addr, bool test_before_evict = true,
101 NodeSeconds time = Now<NodeSeconds>());
102
104 void Attempt(const CService &addr, bool fCountFailure,
105 NodeSeconds time = Now<NodeSeconds>());
106
109 void ResolveCollisions();
110
118 std::pair<CAddress, NodeSeconds> SelectTriedCollision();
119
127 std::pair<CAddress, NodeSeconds> Select(bool newOnly = false) const;
128
142 std::vector<CAddress> GetAddr(size_t max_addresses, size_t max_pct,
143 std::optional<Network> network) const;
144
157 void Connected(const CService &addr, NodeSeconds time = Now<NodeSeconds>());
158
160 void SetServices(const CService &addr, ServiceFlags nServices);
161
162 const std::vector<bool> &GetAsmap() const;
163};
164
165#endif // BITCOIN_ADDRMAN_H
static constexpr int32_t DEFAULT_ADDRMAN_CONSISTENCY_CHECKS
Default for -checkaddrman.
Definition: addrman.h:28
Stochastic address manager.
Definition: addrman.h:68
void Connected(const CService &addr, NodeSeconds time=Now< NodeSeconds >())
We have successfully connected to this peer.
Definition: addrman.cpp:1327
const std::unique_ptr< AddrManImpl > m_impl
Definition: addrman.h:70
std::vector< CAddress > GetAddr(size_t max_addresses, size_t max_pct, std::optional< Network > network) const
Return all or many randomly selected addresses, optionally by network.
Definition: addrman.cpp:1322
const std::vector< bool > & GetAsmap() const
Definition: addrman.cpp:1335
void Attempt(const CService &addr, bool fCountFailure, NodeSeconds time=Now< NodeSeconds >())
Mark an entry as connection attempted to.
Definition: addrman.cpp:1305
std::pair< CAddress, NodeSeconds > Select(bool newOnly=false) const
Choose an address to connect to.
Definition: addrman.cpp:1318
void ResolveCollisions()
See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
Definition: addrman.cpp:1310
void Serialize(Stream &s_) const
Definition: addrman.cpp:1275
size_t size() const
Return the number of (unique) addresses in all tables.
Definition: addrman.cpp:1291
void Unserialize(Stream &s_)
Definition: addrman.cpp:1279
void Good(const CService &addr, bool test_before_evict=true, NodeSeconds time=Now< NodeSeconds >())
Mark an entry as accessible, possibly moving it from "new" to "tried".
Definition: addrman.cpp:1300
std::pair< CAddress, NodeSeconds > SelectTriedCollision()
Randomly select an address in the tried table that another address is attempting to evict.
Definition: addrman.cpp:1314
bool Add(const std::vector< CAddress > &vAddr, const CNetAddr &source, std::chrono::seconds time_penalty=0s)
Attempt to add one or more addresses to addrman's new table.
Definition: addrman.cpp:1295
AddrMan(std::vector< bool > asmap, bool deterministic, int32_t consistency_check_ratio)
Definition: addrman.cpp:1268
void SetServices(const CService &addr, ServiceFlags nServices)
Update an entry's service bits.
Definition: addrman.cpp:1331
Network address.
Definition: netaddress.h:121
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:545
InvalidAddrManVersionError(std::string msg)
Definition: addrman.h:22
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:259
ServiceFlags
nServices flags.
Definition: protocol.h:336
const char * source
Definition: rpcconsole.cpp:56
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds
Definition: time.h:25