Stochastical (IP) address manager.
More...
#include <addrman.h>
|
| template<typename Stream > |
| void | Serialize (Stream &s, int nType, int nVersionDummy) const |
| | serialized format: More...
|
| |
| template<typename Stream > |
| void | Unserialize (Stream &s, int nType, int nVersionDummy) |
| |
| unsigned int | GetSerializeSize (int nType, int nVersion) const |
| |
| void | Clear () |
| |
| | CAddrMan () |
| |
| | ~CAddrMan () |
| |
| int | size () |
| | Return the number of (unique) addresses in all tables. More...
|
| |
| void | Check () |
| | Consistency check. More...
|
| |
| bool | Add (const CAddress &addr, const CNetAddr &source, int64_t nTimePenalty=0) |
| | Add a single address. More...
|
| |
| bool | Add (const std::vector< CAddress > &vAddr, const CNetAddr &source, int64_t nTimePenalty=0) |
| | Add multiple addresses. More...
|
| |
| void | Good (const CService &addr, int64_t nTime=GetAdjustedTime()) |
| | Mark an entry as accessible. More...
|
| |
| void | Attempt (const CService &addr, bool fCountFailure, int64_t nTime=GetAdjustedTime()) |
| | Mark an entry as connection attempted to. More...
|
| |
| CAddrInfo | Select (bool newOnly=false) |
| | Choose an address to connect to. More...
|
| |
| std::vector< CAddress > | GetAddr () |
| | Return a bunch of addresses, selected at random. More...
|
| |
| void | Connected (const CService &addr, int64_t nTime=GetAdjustedTime()) |
| | Mark an entry as currently-connected-to. More...
|
| |
| void | SetServices (const CService &addr, ServiceFlags nServices) |
| |
|
| CAddrInfo * | Find (const CNetAddr &addr, int *pnId=NULL) |
| | Find an entry. More...
|
| |
| CAddrInfo * | Create (const CAddress &addr, const CNetAddr &addrSource, int *pnId=NULL) |
| | find an entry, creating it if necessary. More...
|
| |
| void | SwapRandom (unsigned int nRandomPos1, unsigned int nRandomPos2) |
| | Swap two elements in vRandom. More...
|
| |
| void | MakeTried (CAddrInfo &info, int nId) |
| | Move an entry from the "new" table(s) to the "tried" table. More...
|
| |
| void | Delete (int nId) |
| | Delete an entry. It must not be in tried, and have refcount 0. More...
|
| |
| void | ClearNew (int nUBucket, int nUBucketPos) |
| | Clear a position in a "new" table. This is the only place where entries are actually deleted. More...
|
| |
| void | Good_ (const CService &addr, int64_t nTime) |
| | Mark an entry "good", possibly moving it from "new" to "tried". More...
|
| |
| bool | Add_ (const CAddress &addr, const CNetAddr &source, int64_t nTimePenalty) |
| | Add an entry to the "new" table. More...
|
| |
| void | Attempt_ (const CService &addr, bool fCountFailure, int64_t nTime) |
| | Mark an entry as attempted to connect. More...
|
| |
| CAddrInfo | Select_ (bool newOnly) |
| | Select an address to connect to, if newOnly is set to true, only the new table is selected from. More...
|
| |
| virtual int | RandomInt (int nMax) |
| | Wraps GetRandInt to allow tests to override RandomInt and make it determinismistic. More...
|
| |
| void | GetAddr_ (std::vector< CAddress > &vAddr) |
| | Select several addresses at once. More...
|
| |
| void | Connected_ (const CService &addr, int64_t nTime) |
| | Mark an entry as currently-connected-to. More...
|
| |
| void | SetServices_ (const CService &addr, ServiceFlags nServices) |
| | Update an entry's service bits. More...
|
| |
Stochastical (IP) address manager.
Definition at line 182 of file addrman.h.
◆ CAddrMan()
◆ ~CAddrMan()
◆ Add() [1/2]
| bool CAddrMan::Add |
( |
const CAddress & |
addr, |
|
|
const CNetAddr & |
source, |
|
|
int64_t |
nTimePenalty = 0 |
|
) |
| |
|
inline |
Add a single address.
Definition at line 505 of file addrman.h.
◆ Add() [2/2]
| bool CAddrMan::Add |
( |
const std::vector< CAddress > & |
vAddr, |
|
|
const CNetAddr & |
source, |
|
|
int64_t |
nTimePenalty = 0 |
|
) |
| |
|
inline |
Add multiple addresses.
Definition at line 518 of file addrman.h.
◆ Add_()
| bool CAddrMan::Add_ |
( |
const CAddress & |
addr, |
|
|
const CNetAddr & |
source, |
|
|
int64_t |
nTimePenalty |
|
) |
| |
|
protected |
Add an entry to the "new" table.
Definition at line 249 of file addrman.cpp.
◆ Attempt()
Mark an entry as connection attempted to.
Definition at line 541 of file addrman.h.
◆ Attempt_()
| void CAddrMan::Attempt_ |
( |
const CService & |
addr, |
|
|
bool |
fCountFailure, |
|
|
int64_t |
nTime |
|
) |
| |
|
protected |
Mark an entry as attempted to connect.
Definition at line 322 of file addrman.cpp.
◆ Check()
Consistency check.
Definition at line 492 of file addrman.h.
◆ Clear()
◆ ClearNew()
| void CAddrMan::ClearNew |
( |
int |
nUBucket, |
|
|
int |
nUBucketPos |
|
) |
| |
|
protected |
Clear a position in a "new" table. This is the only place where entries are actually deleted.
Definition at line 134 of file addrman.cpp.
◆ Connected()
Mark an entry as currently-connected-to.
Definition at line 579 of file addrman.h.
◆ Connected_()
| void CAddrMan::Connected_ |
( |
const CService & |
addr, |
|
|
int64_t |
nTime |
|
) |
| |
|
protected |
Mark an entry as currently-connected-to.
Definition at line 489 of file addrman.cpp.
◆ Create()
find an entry, creating it if necessary.
nTime and nServices of the found node are updated, if necessary.
Definition at line 88 of file addrman.cpp.
◆ Delete()
| void CAddrMan::Delete |
( |
int |
nId | ) |
|
|
protected |
Delete an entry. It must not be in tried, and have refcount 0.
Definition at line 120 of file addrman.cpp.
◆ Find()
◆ GetAddr()
| std::vector<CAddress> CAddrMan::GetAddr |
( |
| ) |
|
|
inline |
Return a bunch of addresses, selected at random.
Definition at line 566 of file addrman.h.
◆ GetAddr_()
| void CAddrMan::GetAddr_ |
( |
std::vector< CAddress > & |
vAddr | ) |
|
|
protected |
Select several addresses at once.
Definition at line 468 of file addrman.cpp.
◆ GetSerializeSize()
| unsigned int CAddrMan::GetSerializeSize |
( |
int |
nType, |
|
|
int |
nVersion |
|
) |
| const |
|
inline |
◆ Good()
Mark an entry as accessible.
Definition at line 532 of file addrman.h.
◆ Good_()
| void CAddrMan::Good_ |
( |
const CService & |
addr, |
|
|
int64_t |
nTime |
|
) |
| |
|
protected |
Mark an entry "good", possibly moving it from "new" to "tried".
- Todo:
- : maybe re-add the node, but for now, just bail out
Definition at line 197 of file addrman.cpp.
◆ MakeTried()
| void CAddrMan::MakeTried |
( |
CAddrInfo & |
info, |
|
|
int |
nId |
|
) |
| |
|
protected |
Move an entry from the "new" table(s) to the "tried" table.
Definition at line 149 of file addrman.cpp.
◆ RandomInt()
| int CAddrMan::RandomInt |
( |
int |
nMax | ) |
|
|
protectedvirtual |
Wraps GetRandInt to allow tests to override RandomInt and make it determinismistic.
Definition at line 509 of file addrman.cpp.
◆ Select()
| CAddrInfo CAddrMan::Select |
( |
bool |
newOnly = false | ) |
|
|
inline |
Choose an address to connect to.
nUnkBias determines how much "new" entries are favored over "tried" ones (0-100).
Definition at line 553 of file addrman.h.
◆ Select_()
Select an address to connect to, if newOnly is set to true, only the new table is selected from.
Definition at line 344 of file addrman.cpp.
◆ Serialize()
template<typename Stream >
| void CAddrMan::Serialize |
( |
Stream & |
s, |
|
|
int |
nType, |
|
|
int |
nVersionDummy |
|
) |
| const |
|
inline |
serialized format:
- version byte (currently 1)
- 0x20 + nKey (serialized as if it were a vector, for backward compatibility)
- nNew
- nTried
- number of "new" buckets XOR 2**30
- all nNew addrinfos in vvNew
- all nTried addrinfos in vvTried
- for each bucket:
- number of elements
- for each element: index
2**30 is xorred with the number of buckets to make addrman deserializer v0 detect it as incompatible. This is necessary because it did not check the version number on deserialization.
Notice that vvTried, mapAddr and vVector are never encoded explicitly; they are instead reconstructed from the other information.
vvNew is serialized, but only used if ADDRMAN_UNKOWN_BUCKET_COUNT didn't change, otherwise it is reconstructed as well.
This format is more complex, but significantly smaller (at most 1.5 MiB), and supports changes to the ADDRMAN_ parameters without breaking the on-disk structure.
We don't use ADD_SERIALIZE_METHODS since the serialization and deserialization code has very little in common.
Definition at line 301 of file addrman.h.
◆ SetServices()
◆ SetServices_()
Update an entry's service bits.
Definition at line 513 of file addrman.cpp.
◆ size()
Return the number of (unique) addresses in all tables.
- Todo:
- : Cache this in an atomic to avoid this overhead
Definition at line 485 of file addrman.h.
◆ SwapRandom()
| void CAddrMan::SwapRandom |
( |
unsigned int |
nRandomPos1, |
|
|
unsigned int |
nRandomPos2 |
|
) |
| |
|
protected |
Swap two elements in vRandom.
Definition at line 100 of file addrman.cpp.
◆ Unserialize()
template<typename Stream >
| void CAddrMan::Unserialize |
( |
Stream & |
s, |
|
|
int |
nType, |
|
|
int |
nVersionDummy |
|
) |
| |
|
inline |
◆ cs
critical section to protect the inner data structures
Definition at line 186 of file addrman.h.
◆ insecure_rand
Source of random numbers for randomization in inner loops.
Definition at line 220 of file addrman.h.
◆ mapAddr
| std::map<CNetAddr, int> CAddrMan::mapAddr |
|
private |
find an nId based on its network address
Definition at line 195 of file addrman.h.
◆ mapInfo
table with information about all nIds
Definition at line 192 of file addrman.h.
◆ nIdCount
◆ nKey
secret key to randomize bucket select with
Definition at line 217 of file addrman.h.
◆ nLastGood
| int64_t CAddrMan::nLastGood |
|
private |
last time Good was called (memory only)
Definition at line 213 of file addrman.h.
◆ nNew
number of (unique) "new" entries
Definition at line 207 of file addrman.h.
◆ nTried
◆ vRandom
| std::vector<int> CAddrMan::vRandom |
|
private |
randomly-ordered vector of all nIds
Definition at line 198 of file addrman.h.
◆ vvNew
list of "new" buckets
Definition at line 210 of file addrman.h.
◆ vvTried
list of "tried" buckets
Definition at line 204 of file addrman.h.
The documentation for this class was generated from the following files: