Skip to content

Commit e3f1ea6

Browse files
committed
[move-only] Move CAddrInfo to test-only header file
Now that no bitcoind callers require knowledge of the CAddrInfo object, it can be moved into the test-only header file. Review hint: use git diff --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
1 parent 7cba9d5 commit e3f1ea6

File tree

3 files changed

+73
-72
lines changed

3 files changed

+73
-72
lines changed

src/addrman.h

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -24,78 +24,6 @@ class AddrManImpl;
2424
/** Default for -checkaddrman */
2525
static constexpr int32_t DEFAULT_ADDRMAN_CONSISTENCY_CHECKS{0};
2626

27-
/**
28-
* Extended statistics about a CAddress
29-
*/
30-
class CAddrInfo : public CAddress
31-
{
32-
public:
33-
//! last try whatsoever by us (memory only)
34-
int64_t nLastTry{0};
35-
36-
//! last counted attempt (memory only)
37-
int64_t nLastCountAttempt{0};
38-
39-
private:
40-
//! where knowledge about this address first came from
41-
CNetAddr source;
42-
43-
//! last successful connection by us
44-
int64_t nLastSuccess{0};
45-
46-
//! connection attempts since last successful attempt
47-
int nAttempts{0};
48-
49-
//! reference count in new sets (memory only)
50-
int nRefCount{0};
51-
52-
//! in tried set? (memory only)
53-
bool fInTried{false};
54-
55-
//! position in vRandom
56-
mutable int nRandomPos{-1};
57-
58-
friend class AddrManImpl;
59-
friend class CAddrManDeterministic;
60-
61-
public:
62-
63-
SERIALIZE_METHODS(CAddrInfo, obj)
64-
{
65-
READWRITEAS(CAddress, obj);
66-
READWRITE(obj.source, obj.nLastSuccess, obj.nAttempts);
67-
}
68-
69-
CAddrInfo(const CAddress &addrIn, const CNetAddr &addrSource) : CAddress(addrIn), source(addrSource)
70-
{
71-
}
72-
73-
CAddrInfo() : CAddress(), source()
74-
{
75-
}
76-
77-
//! Calculate in which "tried" bucket this entry belongs
78-
int GetTriedBucket(const uint256 &nKey, const std::vector<bool> &asmap) const;
79-
80-
//! Calculate in which "new" bucket this entry belongs, given a certain source
81-
int GetNewBucket(const uint256 &nKey, const CNetAddr& src, const std::vector<bool> &asmap) const;
82-
83-
//! Calculate in which "new" bucket this entry belongs, using its default source
84-
int GetNewBucket(const uint256 &nKey, const std::vector<bool> &asmap) const
85-
{
86-
return GetNewBucket(nKey, source, asmap);
87-
}
88-
89-
//! Calculate in which position of a bucket to store this entry.
90-
int GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const;
91-
92-
//! Determine whether the statistics about this entry are bad enough so that it can just be deleted
93-
bool IsTerrible(int64_t nNow = GetAdjustedTime()) const;
94-
95-
//! Calculate the relative chance this entry should be given when selecting nodes to connect to
96-
double GetChance(int64_t nNow = GetAdjustedTime()) const;
97-
};
98-
9927
/** Stochastic address manager
10028
*
10129
* Design goals:

src/addrman_impl.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,78 @@
55
#ifndef BITCOIN_ADDRMAN_IMPL_H
66
#define BITCOIN_ADDRMAN_IMPL_H
77

8+
/**
9+
* Extended statistics about a CAddress
10+
*/
11+
class CAddrInfo : public CAddress
12+
{
13+
public:
14+
//! last try whatsoever by us (memory only)
15+
int64_t nLastTry{0};
16+
17+
//! last counted attempt (memory only)
18+
int64_t nLastCountAttempt{0};
19+
20+
private:
21+
//! where knowledge about this address first came from
22+
CNetAddr source;
23+
24+
//! last successful connection by us
25+
int64_t nLastSuccess{0};
26+
27+
//! connection attempts since last successful attempt
28+
int nAttempts{0};
29+
30+
//! reference count in new sets (memory only)
31+
int nRefCount{0};
32+
33+
//! in tried set? (memory only)
34+
bool fInTried{false};
35+
36+
//! position in vRandom
37+
mutable int nRandomPos{-1};
38+
39+
friend class AddrManImpl;
40+
friend class CAddrManDeterministic;
41+
42+
public:
43+
44+
SERIALIZE_METHODS(CAddrInfo, obj)
45+
{
46+
READWRITEAS(CAddress, obj);
47+
READWRITE(obj.source, obj.nLastSuccess, obj.nAttempts);
48+
}
49+
50+
CAddrInfo(const CAddress &addrIn, const CNetAddr &addrSource) : CAddress(addrIn), source(addrSource)
51+
{
52+
}
53+
54+
CAddrInfo() : CAddress(), source()
55+
{
56+
}
57+
58+
//! Calculate in which "tried" bucket this entry belongs
59+
int GetTriedBucket(const uint256 &nKey, const std::vector<bool> &asmap) const;
60+
61+
//! Calculate in which "new" bucket this entry belongs, given a certain source
62+
int GetNewBucket(const uint256 &nKey, const CNetAddr& src, const std::vector<bool> &asmap) const;
63+
64+
//! Calculate in which "new" bucket this entry belongs, using its default source
65+
int GetNewBucket(const uint256 &nKey, const std::vector<bool> &asmap) const
66+
{
67+
return GetNewBucket(nKey, source, asmap);
68+
}
69+
70+
//! Calculate in which position of a bucket to store this entry.
71+
int GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const;
72+
73+
//! Determine whether the statistics about this entry are bad enough so that it can just be deleted
74+
bool IsTerrible(int64_t nNow = GetAdjustedTime()) const;
75+
76+
//! Calculate the relative chance this entry should be given when selecting nodes to connect to
77+
double GetChance(int64_t nNow = GetAdjustedTime()) const;
78+
};
79+
880
class AddrManImpl
981
{
1082
public:

src/test/fuzz/deserialize.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <addrdb.h>
66
#include <addrman.h>
7+
#include <addrman_impl.h>
78
#include <blockencodings.h>
89
#include <blockfilter.h>
910
#include <chain.h>

0 commit comments

Comments
 (0)