Bitcoin Core 22.99.0
P2P Digital Currency
addrman.h
Go to the documentation of this file.
1// Copyright (c) 2012 Pieter Wuille
2// Copyright (c) 2012-2020 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 <timedata.h>
13
14#include <cstdint>
15#include <memory>
16#include <optional>
17#include <utility>
18#include <vector>
19
20class AddrManImpl;
21
23static constexpr int32_t DEFAULT_ADDRMAN_CONSISTENCY_CHECKS{0};
24
55{
56 const std::unique_ptr<AddrManImpl> m_impl;
57
58public:
59 explicit AddrMan(std::vector<bool> asmap, bool deterministic, int32_t consistency_check_ratio);
60
62
63 template <typename Stream>
64 void Serialize(Stream& s_) const;
65
66 template <typename Stream>
67 void Unserialize(Stream& s_);
68
70 size_t size() const;
71
81 bool Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, int64_t nTimePenalty = 0);
82
84 void Good(const CService& addr, int64_t nTime = GetAdjustedTime());
85
87 void Attempt(const CService& addr, bool fCountFailure, int64_t nTime = GetAdjustedTime());
88
90 void ResolveCollisions();
91
99 std::pair<CAddress, int64_t> SelectTriedCollision();
100
108 std::pair<CAddress, int64_t> Select(bool newOnly = false) const;
109
119 std::vector<CAddress> GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network) const;
120
132 void Connected(const CService& addr, int64_t nTime = GetAdjustedTime());
133
135 void SetServices(const CService& addr, ServiceFlags nServices);
136
137 const std::vector<bool>& GetAsmap() const;
138
139 friend class AddrManTest;
141};
142
143#endif // BITCOIN_ADDRMAN_H
static constexpr int32_t DEFAULT_ADDRMAN_CONSISTENCY_CHECKS
Default for -checkaddrman.
Definition: addrman.h:23
Stochastic address manager.
Definition: addrman.h:55
std::pair< CAddress, int64_t > SelectTriedCollision()
Randomly select an address in the tried table that another address is attempting to evict.
Definition: addrman.cpp:1173
const std::unique_ptr< AddrManImpl > m_impl
Definition: addrman.h:56
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:1183
const std::vector< bool > & GetAsmap() const
Definition: addrman.cpp:1198
bool Add(const std::vector< CAddress > &vAddr, const CNetAddr &source, int64_t nTimePenalty=0)
Attempt to add one or more addresses to addrman's new table.
Definition: addrman.cpp:1153
void Good(const CService &addr, int64_t nTime=GetAdjustedTime())
Mark an entry as accessible, possibly moving it from "new" to "tried".
Definition: addrman.cpp:1158
void ResolveCollisions()
See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
Definition: addrman.cpp:1168
void Connected(const CService &addr, int64_t nTime=GetAdjustedTime())
We have successfully connected to this peer.
Definition: addrman.cpp:1188
void Attempt(const CService &addr, bool fCountFailure, int64_t nTime=GetAdjustedTime())
Mark an entry as connection attempted to.
Definition: addrman.cpp:1163
void Serialize(Stream &s_) const
Definition: addrman.cpp:1128
size_t size() const
Return the number of (unique) addresses in all tables.
Definition: addrman.cpp:1148
void Unserialize(Stream &s_)
Definition: addrman.cpp:1134
AddrMan(std::vector< bool > asmap, bool deterministic, int32_t consistency_check_ratio)
Definition: addrman.cpp:1122
std::pair< CAddress, int64_t > Select(bool newOnly=false) const
Choose an address to connect to.
Definition: addrman.cpp:1178
void SetServices(const CService &addr, ServiceFlags nServices)
Update an entry's service bits.
Definition: addrman.cpp:1193
Network address.
Definition: netaddress.h:119
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:523
ServiceFlags
nServices flags
Definition: protocol.h:271
const char * source
Definition: rpcconsole.cpp:63
int64_t GetAdjustedTime()
Definition: timedata.cpp:35