 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
30 return std::clamp<int32_t>(g_setup->
m_node.
args->
GetIntArg(
"-checkaddrman", 0), 0, 1000000);
37 g_setup = testing_setup.get();
47 }
catch (
const std::exception&) {
61 static const std::map<uint8_t, uint8_t> net_len_map = {{1,
ADDR_IPV4_SIZE},
66 uint8_t net = fast_random_context.
randrange(5) + 1;
74 s << fast_random_context.
randbytes(net_len_map.at(net));
82 v4_addr.s_addr = 0x05050505;
102 for (
size_t i = 0; i < num_sources; ++i) {
103 const auto source =
RandAddr(fuzzed_data_provider, fast_random_context);
104 const size_t num_addresses = fast_random_context.randrange(500) + 1;
106 for (
size_t j = 0; j < num_addresses; ++j) {
108 const auto time_penalty = fast_random_context.randrange(100000001);
109 addrman.
Add({addr},
source, time_penalty);
111 if (n > 0 && addrman.
size() % n == 0) {
116 if (fast_random_context.randrange(10) == 0 && prev_source.IsValid()) {
117 addrman.
Add({addr}, prev_source, time_penalty);
152 auto addrinfo_hasher = [](
const AddrInfo& a) {
154 auto addr_key = a.GetKey();
155 auto source_key = a.source.GetAddrBytes();
156 hasher.
Write(a.nLastSuccess);
157 hasher.
Write(a.nAttempts);
158 hasher.
Write(a.nRefCount);
159 hasher.
Write(a.fInTried);
160 hasher.
Write(a.GetNetwork());
161 hasher.
Write(a.source.GetNetwork());
162 hasher.
Write(addr_key.size());
163 hasher.
Write(source_key.size());
164 hasher.
Write(addr_key.data(), addr_key.size());
165 hasher.
Write(source_key.data(), source_key.size());
171 std::tie(
static_cast<const CService&
>(rhs), rhs.source, rhs.nLastSuccess, rhs.nAttempts, rhs.nRefCount, rhs.fInTried);
174 using Addresses = std::unordered_set<
AddrInfo, decltype(addrinfo_hasher), decltype(addrinfo_eq)>;
176 const size_t num_addresses{
m_impl->mapInfo.size()};
178 Addresses addresses{num_addresses, addrinfo_hasher, addrinfo_eq};
179 for (
const auto& [
id, addr] :
m_impl->mapInfo) {
180 addresses.insert(addr);
183 Addresses other_addresses{num_addresses, addrinfo_hasher, addrinfo_eq};
184 for (
const auto& [
id, addr] : other.
m_impl->mapInfo) {
185 other_addresses.insert(addr);
188 if (addresses != other_addresses) {
193 if (
id == -1 && other_id == -1) {
196 if ((
id == -1 && other_id != -1) || (
id != -1 && other_id == -1)) {
199 return m_impl->mapInfo.at(
id) == other.
m_impl->mapInfo.at(other_id);
207 if (!IdsReferToSameAddress(
m_impl->vvNew[i][j], other.
m_impl->vvNew[i][j])) {
216 if (!IdsReferToSameAddress(
m_impl->vvTried[i][j], other.
m_impl->vvTried[i][j])) {
237 std::vector<bool> asmap =
ConsumeAsmap(fuzzed_data_provider);
238 auto addr_man_ptr = std::make_unique<AddrManDeterministic>(asmap, fuzzed_data_provider);
242 const auto ser_version{fuzzed_data_provider.
ConsumeIntegral<int32_t>()};
246 }
catch (
const std::ios_base::failure&) {
247 addr_man_ptr = std::make_unique<AddrManDeterministic>(asmap, fuzzed_data_provider);
253 fuzzed_data_provider,
261 std::vector<CAddress> addresses;
263 const std::optional<CAddress> opt_address = ConsumeDeserializable<CAddress>(fuzzed_data_provider);
267 addresses.push_back(*opt_address);
269 const std::optional<CNetAddr> opt_net_addr = ConsumeDeserializable<CNetAddr>(fuzzed_data_provider);
275 const std::optional<CService> opt_service = ConsumeDeserializable<CService>(fuzzed_data_provider);
281 const std::optional<CService> opt_service = ConsumeDeserializable<CService>(fuzzed_data_provider);
287 const std::optional<CService> opt_service = ConsumeDeserializable<CService>(fuzzed_data_provider);
293 const std::optional<CService> opt_service = ConsumeDeserializable<CService>(fuzzed_data_provider);
299 const AddrMan& const_addr_man{addr_man};
304 (void)const_addr_man.Select(fuzzed_data_provider.
ConsumeBool());
305 (void)const_addr_man.size();
307 data_stream << const_addr_man;
316 std::vector<bool> asmap =
ConsumeAsmap(fuzzed_data_provider);
323 data_stream << addr_man1;
324 data_stream >> addr_man2;
325 assert(addr_man1 == addr_man2);
static constexpr int ADDRV2_FORMAT
A flag that is ORed into the protocol version to designate that addresses should be serialized in (un...
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
A combination of a network address (CNetAddr) and a (TCP) port.
int64_t nLastSuccess
last successful connection by us
CNetAddr RandAddr(FuzzedDataProvider &fuzzed_data_provider, FastRandomContext &fast_random_context)
Generate a random address.
int nAttempts
connection attempts since last successful attempt
Stochastic address manager.
size_t size() const
Return the number of (unique) addresses in all tables.
int64_t GetTime()
DEPRECATED Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
std::vector< unsigned char > randbytes(size_t len)
Generate random bytes.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
static constexpr int ADDRMAN_TRIED_BUCKET_COUNT
Extended statistics about a CAddress.
CNetAddr ConsumeNetAddr(FuzzedDataProvider &fuzzed_data_provider) noexcept
const std::unique_ptr< AddrManImpl > m_impl
void Connected(const CService &addr, int64_t nTime=GetAdjustedTime())
We have successfully connected to this peer.
static constexpr int ADDRMAN_BUCKET_SIZE
void FillAddrman(AddrMan &addrman, FuzzedDataProvider &fuzzed_data_provider)
Fill addrman with lots of addresses from lots of sources.
std::vector< bool > ConsumeRandomLengthBitVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
void initialize_addrman()
bool Good(const CService &addr, int64_t nTime=GetAdjustedTime())
Mark an address record as accessible and attempt to move it to addrman's tried table.
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
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.
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
uint64_t Finalize() const
Compute the 64-bit SipHash-2-4 of the data written so far.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
CDataStream ConsumeDataStream(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
static const std::string REGTEST
constexpr ServiceFlags ALL_SERVICE_FLAGS[]
std::vector< uint8_t > ConsumeRandomLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
CNetAddr source
where knowledge about this address first came from
std::pair< CAddress, int64_t > SelectTriedCollision()
Randomly select an address in the tried table that another address is attempting to evict.
std::vector< bool > ConsumeAsmap(FuzzedDataProvider &fuzzed_data_provider) noexcept
AddrManDeterministic(std::vector< bool > asmap, FuzzedDataProvider &fuzzed_data_provider)
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
void Attempt(const CService &addr, bool fCountFailure, int64_t nTime=GetAdjustedTime())
Mark an entry as connection attempted to.
static int32_t GetCheckRatio(const NodeContext &node_ctx)
A CService with information about it as peer.
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
int nRefCount
reference count in new sets (memory only)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
static constexpr int ADDRMAN_NEW_BUCKET_COUNT
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
uint64_t randrange(uint64_t range) noexcept
Generate a random integer in the range [0..range).
Double ended buffer combining vector and stream-like interfaces.
void ReadFromStream(AddrMan &addr, CDataStream &ssPeers)
Only used by tests.
WeakEnumType ConsumeWeakEnum(FuzzedDataProvider &fuzzed_data_provider, const WeakEnumType(&all_types)[size]) noexcept
void ResolveCollisions()
See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
bool operator==(const AddrManDeterministic &other)
Compare with another AddrMan.
bool fInTried
in tried set? (memory only)
T ConsumeIntegralInRange(T min, T max)
FUZZ_TARGET_INIT(data_stream_addr_man, initialize_addrman)
bool SanityCheckASMap(const std::vector< bool > &asmap, int bits)
void SetServices(const CService &addr, ServiceFlags nServices)
Update an entry's service bits.
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.
static const int INIT_PROTO_VERSION
initial proto version, to be increased after version/verack negotiation
static const int PROTOCOL_VERSION
network protocol versioning
CSipHasher & Write(uint64_t data)
Hash a 64-bit integer worth of data It is treated as if this was the little-endian interpretation of ...