Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
addrman.h
Go to the documentation of this file.
1 // Copyright (c) 2012 Pieter Wuille
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef _BITCOIN_ADDRMAN
6 #define _BITCOIN_ADDRMAN 1
7 
8 #include "netbase.h"
9 #include "protocol.h"
10 #include "sync.h"
11 #include "util.h"
12 
13 #include <map>
14 #include <set>
15 #include <stdint.h>
16 #include <vector>
17 
18 #include <openssl/rand.h>
19 
21 class CAddrInfo : public CAddress
22 {
23 private:
24  // where knowledge about this address first came from
26 
27  // last successful connection by us
28  int64_t nLastSuccess;
29 
30  // last try whatsoever by us:
31  // int64_t CAddress::nLastTry
32 
33  // connection attempts since last successful attempt
34  int nAttempts;
35 
36  // reference count in new sets (memory only)
37  int nRefCount;
38 
39  // in tried set? (memory only)
40  bool fInTried;
41 
42  // position in vRandom
44 
45  friend class CAddrMan;
46 
47 public:
48 
50  CAddress* pthis = (CAddress*)(this);
51  READWRITE(*pthis);
52  READWRITE(source);
53  READWRITE(nLastSuccess);
54  READWRITE(nAttempts);
55  )
56 
57  void Init()
58  {
59  nLastSuccess = 0;
60  nLastTry = 0;
61  nAttempts = 0;
62  nRefCount = 0;
63  fInTried = false;
64  nRandomPos = -1;
65  }
66 
67  CAddrInfo(const CAddress &addrIn, const CNetAddr &addrSource) : CAddress(addrIn), source(addrSource)
68  {
69  Init();
70  }
71 
72  CAddrInfo() : CAddress(), source()
73  {
74  Init();
75  }
76 
77  // Calculate in which "tried" bucket this entry belongs
78  int GetTriedBucket(const std::vector<unsigned char> &nKey) const;
79 
80  // Calculate in which "new" bucket this entry belongs, given a certain source
81  int GetNewBucket(const std::vector<unsigned char> &nKey, const CNetAddr& src) const;
82 
83  // Calculate in which "new" bucket this entry belongs, using its default source
84  int GetNewBucket(const std::vector<unsigned char> &nKey) const
85  {
86  return GetNewBucket(nKey, source);
87  }
88 
89  // Determine whether the statistics about this entry are bad enough so that it can just be deleted
90  bool IsTerrible(int64_t nNow = GetAdjustedTime()) const;
91 
92  // Calculate the relative chance this entry should be given when selecting nodes to connect to
93  double GetChance(int64_t nNow = GetAdjustedTime()) const;
94 
95 };
96 
97 // Stochastic address manager
98 //
99 // Design goals:
100 // * Only keep a limited number of addresses around, so that addr.dat and memory requirements do not grow without bound.
101 // * Keep the address tables in-memory, and asynchronously dump the entire to able in addr.dat.
102 // * Make sure no (localized) attacker can fill the entire table with his nodes/addresses.
103 //
104 // To that end:
105 // * Addresses are organized into buckets.
106 // * Address that have not yet been tried go into 256 "new" buckets.
107 // * Based on the address range (/16 for IPv4) of source of the information, 32 buckets are selected at random
108 // * The actual bucket is chosen from one of these, based on the range the address itself is located.
109 // * One single address can occur in up to 4 different buckets, to increase selection chances for addresses that
110 // are seen frequently. The chance for increasing this multiplicity decreases exponentially.
111 // * When adding a new address to a full bucket, a randomly chosen entry (with a bias favoring less recently seen
112 // ones) is removed from it first.
113 // * Addresses of nodes that are known to be accessible go into 64 "tried" buckets.
114 // * Each address range selects at random 4 of these buckets.
115 // * The actual bucket is chosen from one of these, based on the full address.
116 // * When adding a new good address to a full bucket, a randomly chosen entry (with a bias favoring less recently
117 // tried ones) is evicted from it, back to the "new" buckets.
118 // * Bucket selection is based on cryptographic hashing, using a randomly-generated 256-bit key, which should not
119 // be observable by adversaries.
120 // * Several indexes are kept for high performance. Defining DEBUG_ADDRMAN will introduce frequent (and expensive)
121 // consistency checks for the entire data structure.
122 
123 // total number of buckets for tried addresses
124 #define ADDRMAN_TRIED_BUCKET_COUNT 64
125 
126 // maximum allowed number of entries in buckets for tried addresses
127 #define ADDRMAN_TRIED_BUCKET_SIZE 64
128 
129 // total number of buckets for new addresses
130 #define ADDRMAN_NEW_BUCKET_COUNT 256
131 
132 // maximum allowed number of entries in buckets for new addresses
133 #define ADDRMAN_NEW_BUCKET_SIZE 64
134 
135 // over how many buckets entries with tried addresses from a single group (/16 for IPv4) are spread
136 #define ADDRMAN_TRIED_BUCKETS_PER_GROUP 4
137 
138 // over how many buckets entries with new addresses originating from a single group are spread
139 #define ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP 32
140 
141 // in how many buckets for entries with new addresses a single address may occur
142 #define ADDRMAN_NEW_BUCKETS_PER_ADDRESS 4
143 
144 // how many entries in a bucket with tried addresses are inspected, when selecting one to replace
145 #define ADDRMAN_TRIED_ENTRIES_INSPECT_ON_EVICT 4
146 
147 // how old addresses can maximally be
148 #define ADDRMAN_HORIZON_DAYS 30
149 
150 // after how many failed attempts we give up on a new node
151 #define ADDRMAN_RETRIES 3
152 
153 // how many successive failures are allowed ...
154 #define ADDRMAN_MAX_FAILURES 10
155 
156 // ... in at least this many days
157 #define ADDRMAN_MIN_FAIL_DAYS 7
158 
159 // the maximum percentage of nodes to return in a getaddr call
160 #define ADDRMAN_GETADDR_MAX_PCT 23
161 
162 // the maximum number of nodes to return in a getaddr call
163 #define ADDRMAN_GETADDR_MAX 2500
164 
166 class CAddrMan
167 {
168 private:
169  // critical section to protect the inner data structures
171 
172  // secret key to randomize bucket select with
173  std::vector<unsigned char> nKey;
174 
175  // last used nId
176  int nIdCount;
177 
178  // table with information about all nIds
179  std::map<int, CAddrInfo> mapInfo;
180 
181  // find an nId based on its network address
182  std::map<CNetAddr, int> mapAddr;
183 
184  // randomly-ordered vector of all nIds
185  std::vector<int> vRandom;
186 
187  // number of "tried" entries
188  int nTried;
189 
190  // list of "tried" buckets
191  std::vector<std::vector<int> > vvTried;
192 
193  // number of (unique) "new" entries
194  int nNew;
195 
196  // list of "new" buckets
197  std::vector<std::set<int> > vvNew;
198 
199 protected:
200 
201  // Find an entry.
202  CAddrInfo* Find(const CNetAddr& addr, int *pnId = NULL);
203 
204  // find an entry, creating it if necessary.
205  // nTime and nServices of found node is updated, if necessary.
206  CAddrInfo* Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId = NULL);
207 
208  // Swap two elements in vRandom.
209  void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2);
210 
211  // Return position in given bucket to replace.
212  int SelectTried(int nKBucket);
213 
214  // Remove an element from a "new" bucket.
215  // This is the only place where actual deletes occur.
216  // They are never deleted while in the "tried" table, only possibly evicted back to the "new" table.
217  int ShrinkNew(int nUBucket);
218 
219  // Move an entry from the "new" table(s) to the "tried" table
220  // @pre vvUnkown[nOrigin].count(nId) != 0
221  void MakeTried(CAddrInfo& info, int nId, int nOrigin);
222 
223  // Mark an entry "good", possibly moving it from "new" to "tried".
224  void Good_(const CService &addr, int64_t nTime);
225 
226  // Add an entry to the "new" table.
227  bool Add_(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty);
228 
229  // Mark an entry as attempted to connect.
230  void Attempt_(const CService &addr, int64_t nTime);
231 
232  // Select an address to connect to.
233  // nUnkBias determines how much to favor new addresses over tried ones (min=0, max=100)
234  CAddress Select_(int nUnkBias);
235 
236 #ifdef DEBUG_ADDRMAN
237  // Perform consistency check. Returns an error code or zero.
238  int Check_();
239 #endif
240 
241  // Select several addresses at once.
242  void GetAddr_(std::vector<CAddress> &vAddr);
243 
244  // Mark an entry as currently-connected-to.
245  void Connected_(const CService &addr, int64_t nTime);
246 
247 public:
248 
250  (({
251  // serialized format:
252  // * version byte (currently 0)
253  // * nKey
254  // * nNew
255  // * nTried
256  // * number of "new" buckets
257  // * all nNew addrinfos in vvNew
258  // * all nTried addrinfos in vvTried
259  // * for each bucket:
260  // * number of elements
261  // * for each element: index
262  //
263  // Notice that vvTried, mapAddr and vVector are never encoded explicitly;
264  // they are instead reconstructed from the other information.
265  //
266  // vvNew is serialized, but only used if ADDRMAN_UNKOWN_BUCKET_COUNT didn't change,
267  // otherwise it is reconstructed as well.
268  //
269  // This format is more complex, but significantly smaller (at most 1.5 MiB), and supports
270  // changes to the ADDRMAN_ parameters without breaking the on-disk structure.
271  {
272  LOCK(cs);
273  unsigned char nVersion = 0;
274  READWRITE(nVersion);
275  READWRITE(nKey);
276  READWRITE(nNew);
277  READWRITE(nTried);
278 
279  CAddrMan *am = const_cast<CAddrMan*>(this);
280  if (fWrite)
281  {
282  int nUBuckets = ADDRMAN_NEW_BUCKET_COUNT;
283  READWRITE(nUBuckets);
284  std::map<int, int> mapUnkIds;
285  int nIds = 0;
286  for (std::map<int, CAddrInfo>::iterator it = am->mapInfo.begin(); it != am->mapInfo.end(); it++)
287  {
288  if (nIds == nNew) break; // this means nNew was wrong, oh ow
289  mapUnkIds[(*it).first] = nIds;
290  CAddrInfo &info = (*it).second;
291  if (info.nRefCount)
292  {
293  READWRITE(info);
294  nIds++;
295  }
296  }
297  nIds = 0;
298  for (std::map<int, CAddrInfo>::iterator it = am->mapInfo.begin(); it != am->mapInfo.end(); it++)
299  {
300  if (nIds == nTried) break; // this means nTried was wrong, oh ow
301  CAddrInfo &info = (*it).second;
302  if (info.fInTried)
303  {
304  READWRITE(info);
305  nIds++;
306  }
307  }
308  for (std::vector<std::set<int> >::iterator it = am->vvNew.begin(); it != am->vvNew.end(); it++)
309  {
310  const std::set<int> &vNew = (*it);
311  int nSize = vNew.size();
312  READWRITE(nSize);
313  for (std::set<int>::iterator it2 = vNew.begin(); it2 != vNew.end(); it2++)
314  {
315  int nIndex = mapUnkIds[*it2];
316  READWRITE(nIndex);
317  }
318  }
319  } else {
320  int nUBuckets = 0;
321  READWRITE(nUBuckets);
322  am->nIdCount = 0;
323  am->mapInfo.clear();
324  am->mapAddr.clear();
325  am->vRandom.clear();
326  am->vvTried = std::vector<std::vector<int> >(ADDRMAN_TRIED_BUCKET_COUNT, std::vector<int>(0));
327  am->vvNew = std::vector<std::set<int> >(ADDRMAN_NEW_BUCKET_COUNT, std::set<int>());
328  for (int n = 0; n < am->nNew; n++)
329  {
330  CAddrInfo &info = am->mapInfo[n];
331  READWRITE(info);
332  am->mapAddr[info] = n;
333  info.nRandomPos = vRandom.size();
334  am->vRandom.push_back(n);
335  if (nUBuckets != ADDRMAN_NEW_BUCKET_COUNT)
336  {
337  am->vvNew[info.GetNewBucket(am->nKey)].insert(n);
338  info.nRefCount++;
339  }
340  }
341  am->nIdCount = am->nNew;
342  int nLost = 0;
343  for (int n = 0; n < am->nTried; n++)
344  {
345  CAddrInfo info;
346  READWRITE(info);
347  std::vector<int> &vTried = am->vvTried[info.GetTriedBucket(am->nKey)];
348  if (vTried.size() < ADDRMAN_TRIED_BUCKET_SIZE)
349  {
350  info.nRandomPos = vRandom.size();
351  info.fInTried = true;
352  am->vRandom.push_back(am->nIdCount);
353  am->mapInfo[am->nIdCount] = info;
354  am->mapAddr[info] = am->nIdCount;
355  vTried.push_back(am->nIdCount);
356  am->nIdCount++;
357  } else {
358  nLost++;
359  }
360  }
361  am->nTried -= nLost;
362  for (int b = 0; b < nUBuckets; b++)
363  {
364  std::set<int> &vNew = am->vvNew[b];
365  int nSize = 0;
366  READWRITE(nSize);
367  for (int n = 0; n < nSize; n++)
368  {
369  int nIndex = 0;
370  READWRITE(nIndex);
371  CAddrInfo &info = am->mapInfo[nIndex];
372  if (nUBuckets == ADDRMAN_NEW_BUCKET_COUNT && info.nRefCount < ADDRMAN_NEW_BUCKETS_PER_ADDRESS)
373  {
374  info.nRefCount++;
375  vNew.insert(nIndex);
376  }
377  }
378  }
379  }
380  }
381  });)
382 
383  CAddrMan() : vRandom(0), vvTried(ADDRMAN_TRIED_BUCKET_COUNT, std::vector<int>(0)), vvNew(ADDRMAN_NEW_BUCKET_COUNT, std::set<int>())
384  {
385  nKey.resize(32);
386  RAND_bytes(&nKey[0], 32);
387 
388  nIdCount = 0;
389  nTried = 0;
390  nNew = 0;
391  }
392 
393  // Return the number of (unique) addresses in all tables.
394  int size()
395  {
396  return vRandom.size();
397  }
398 
399  // Consistency check
400  void Check()
401  {
402 #ifdef DEBUG_ADDRMAN
403  {
404  LOCK(cs);
405  int err;
406  if ((err=Check_()))
407  LogPrintf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
408  }
409 #endif
410  }
411 
412  // Add a single address.
413  bool Add(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty = 0)
414  {
415  bool fRet = false;
416  {
417  LOCK(cs);
418  Check();
419  fRet |= Add_(addr, source, nTimePenalty);
420  Check();
421  }
422  if (fRet)
423  LogPrint("addrman", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort().c_str(), source.ToString().c_str(), nTried, nNew);
424  return fRet;
425  }
426 
427  // Add multiple addresses.
428  bool Add(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty = 0)
429  {
430  int nAdd = 0;
431  {
432  LOCK(cs);
433  Check();
434  for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++)
435  nAdd += Add_(*it, source, nTimePenalty) ? 1 : 0;
436  Check();
437  }
438  if (nAdd)
439  LogPrint("addrman", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString().c_str(), nTried, nNew);
440  return nAdd > 0;
441  }
442 
443  // Mark an entry as accessible.
444  void Good(const CService &addr, int64_t nTime = GetAdjustedTime())
445  {
446  {
447  LOCK(cs);
448  Check();
449  Good_(addr, nTime);
450  Check();
451  }
452  }
453 
454  // Mark an entry as connection attempted to.
455  void Attempt(const CService &addr, int64_t nTime = GetAdjustedTime())
456  {
457  {
458  LOCK(cs);
459  Check();
460  Attempt_(addr, nTime);
461  Check();
462  }
463  }
464 
465  // Choose an address to connect to.
466  // nUnkBias determines how much "new" entries are favored over "tried" ones (0-100).
467  CAddress Select(int nUnkBias = 50)
468  {
469  CAddress addrRet;
470  {
471  LOCK(cs);
472  Check();
473  addrRet = Select_(nUnkBias);
474  Check();
475  }
476  return addrRet;
477  }
478 
479  // Return a bunch of addresses, selected at random.
480  std::vector<CAddress> GetAddr()
481  {
482  Check();
483  std::vector<CAddress> vAddr;
484  {
485  LOCK(cs);
486  GetAddr_(vAddr);
487  }
488  Check();
489  return vAddr;
490  }
491 
492  // Mark an entry as currently-connected-to.
493  void Connected(const CService &addr, int64_t nTime = GetAdjustedTime())
494  {
495  {
496  LOCK(cs);
497  Check();
498  Connected_(addr, nTime);
499  Check();
500  }
501  }
502 };
503 
504 #endif
int nRefCount
Definition: addrman.h:37
void Attempt(const CService &addr, int64_t nTime=GetAdjustedTime())
Definition: addrman.h:455
int GetNewBucket(const std::vector< unsigned char > &nKey, const CNetAddr &src) const
Definition: addrman.cpp:26
#define READWRITE(obj)
Definition: serialize.h:92
void Init()
Definition: protocol.cpp:90
CAddrInfo * Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId=NULL)
Definition: addrman.cpp:96
std::string ToStringIPPort() const
Definition: netbase.cpp:1102
int nAttempts
Definition: addrman.h:34
CAddress Select_(int nUnkBias)
Definition: addrman.cpp:389
int nRandomPos
Definition: addrman.h:43
bool Add(const CAddress &addr, const CNetAddr &source, int64_t nTimePenalty=0)
Definition: addrman.h:413
#define ADDRMAN_TRIED_BUCKET_COUNT
Definition: addrman.h:124
double GetChance(int64_t nNow=GetAdjustedTime()) const
Definition: addrman.cpp:60
bool fInTried
Definition: addrman.h:40
CAddrInfo * Find(const CNetAddr &addr, int *pnId=NULL)
Definition: addrman.cpp:83
Stochastical (IP) address manager.
Definition: addrman.h:166
std::vector< CAddress > GetAddr()
Definition: addrman.h:480
Extended statistics about a CAddress.
Definition: addrman.h:21
std::vector< int > vRandom
Definition: addrman.h:185
#define LogPrintf(...)
Definition: util.h:117
int64_t GetAdjustedTime()
Definition: util.cpp:1236
int SelectTried(int nKBucket)
Definition: addrman.cpp:128
std::vector< std::set< int > > vvNew
Definition: addrman.h:197
static int LogPrint(const char *category, const char *format)
Definition: util.h:143
#define LOCK(cs)
Definition: sync.h:156
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netbase.h:94
void MakeTried(CAddrInfo &info, int nId, int nOrigin)
Definition: addrman.cpp:206
void Check()
Definition: addrman.h:400
int64_t nLastTry
Definition: protocol.h:101
A CService with information about it as peer.
Definition: protocol.h:68
int nTried
Definition: addrman.h:188
void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2)
Definition: addrman.cpp:108
int nIdCount
Definition: addrman.h:176
int ShrinkNew(int nUBucket)
Definition: addrman.cpp:152
std::map< CNetAddr, int > mapAddr
Definition: addrman.h:182
IMPLEMENT_SERIALIZE(CAddress *pthis=(CAddress *)(this);READWRITE(*pthis);READWRITE(source);READWRITE(nLastSuccess);READWRITE(nAttempts);) void Init()
Definition: addrman.h:49
CAddrInfo()
Definition: addrman.h:72
#define ADDRMAN_TRIED_BUCKET_SIZE
Definition: addrman.h:127
std::vector< std::vector< int > > vvTried
Definition: addrman.h:191
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
Definition: netbase.h:40
int size()
Definition: addrman.h:394
void Good_(const CService &addr, int64_t nTime)
Definition: addrman.cpp:264
std::vector< unsigned char > nKey
Definition: addrman.h:173
CAddrInfo(const CAddress &addrIn, const CNetAddr &addrSource)
Definition: addrman.h:67
#define ADDRMAN_NEW_BUCKET_COUNT
Definition: addrman.h:130
int GetTriedBucket(const std::vector< unsigned char > &nKey) const
Definition: addrman.cpp:12
bool Add_(const CAddress &addr, const CNetAddr &source, int64_t nTimePenalty)
Definition: addrman.cpp:313
void Connected_(const CService &addr, int64_t nTime)
Definition: addrman.cpp:509
CAddress Select(int nUnkBias=50)
Definition: addrman.h:467
void GetAddr_(std::vector< CAddress > &vAddr)
Definition: addrman.cpp:493
std::map< int, CAddrInfo > mapInfo
Definition: addrman.h:179
bool Add(const std::vector< CAddress > &vAddr, const CNetAddr &source, int64_t nTimePenalty=0)
Definition: addrman.h:428
int GetNewBucket(const std::vector< unsigned char > &nKey) const
Definition: addrman.h:84
std::string ToString() const
Definition: netbase.cpp:772
int nNew
Definition: addrman.h:194
void Connected(const CService &addr, int64_t nTime=GetAdjustedTime())
Definition: addrman.h:493
void Attempt_(const CService &addr, int64_t nTime)
Definition: addrman.cpp:370
int64_t nLastSuccess
Definition: addrman.h:28
bool IsTerrible(int64_t nNow=GetAdjustedTime()) const
Definition: addrman.cpp:40
CCriticalSection cs
Definition: addrman.h:170
IMPLEMENT_SERIALIZE(({{LOCK(cs);unsigned char nVersion=0;READWRITE(nVersion);READWRITE(nKey);READWRITE(nNew);READWRITE(nTried);CAddrMan *am=const_cast< CAddrMan * >(this);if(fWrite){int nUBuckets=ADDRMAN_NEW_BUCKET_COUNT;READWRITE(nUBuckets);std::map< int, int > mapUnkIds;int nIds=0;for(std::map< int, CAddrInfo >::iterator it=am->mapInfo.begin();it!=am->mapInfo.end();it++){if(nIds==nNew) break;mapUnkIds[(*it).first]=nIds;CAddrInfo &info=(*it).second;if(info.nRefCount){READWRITE(info);nIds++;}}nIds=0;for(std::map< int, CAddrInfo >::iterator it=am->mapInfo.begin();it!=am->mapInfo.end();it++){if(nIds==nTried) break;CAddrInfo &info=(*it).second;if(info.fInTried){READWRITE(info);nIds++;}}for(std::vector< std::set< int > >::iterator it=am->vvNew.begin();it!=am->vvNew.end();it++){const std::set< int > &vNew=(*it);int nSize=vNew.size();READWRITE(nSize);for(std::set< int >::iterator it2=vNew.begin();it2!=vNew.end();it2++){int nIndex=mapUnkIds[*it2];READWRITE(nIndex);}}}else{int nUBuckets=0;READWRITE(nUBuckets);am->nIdCount=0;am->mapInfo.clear();am->mapAddr.clear();am->vRandom.clear();am->vvTried=std::vector< std::vector< int > >(ADDRMAN_TRIED_BUCKET_COUNT, std::vector< int >(0));am->vvNew=std::vector< std::set< int > >(ADDRMAN_NEW_BUCKET_COUNT, std::set< int >());for(int n=0;n< am->nNew;n++){CAddrInfo &info=am->mapInfo[n];READWRITE(info);am->mapAddr[info]=n;info.nRandomPos=vRandom.size();am->vRandom.push_back(n);if(nUBuckets!=ADDRMAN_NEW_BUCKET_COUNT){am->vvNew[info.GetNewBucket(am->nKey)].insert(n);info.nRefCount++;}}am->nIdCount=am->nNew;int nLost=0;for(int n=0;n< am->nTried;n++){CAddrInfo info;READWRITE(info);std::vector< int > &vTried=am->vvTried[info.GetTriedBucket(am->nKey)];if(vTried.size()< ADDRMAN_TRIED_BUCKET_SIZE){info.nRandomPos=vRandom.size();info.fInTried=true;am->vRandom.push_back(am->nIdCount);am->mapInfo[am->nIdCount]=info;am->mapAddr[info]=am->nIdCount;vTried.push_back(am->nIdCount);am->nIdCount++;}else{nLost++;}}am->nTried-=nLost;for(int b=0;b< nUBuckets;b++){std::set< int > &vNew=am->vvNew[b];int nSize=0;READWRITE(nSize);for(int n=0;n< nSize;n++){int nIndex=0;READWRITE(nIndex);CAddrInfo &info=am->mapInfo[nIndex];if(nUBuckets==ADDRMAN_NEW_BUCKET_COUNT &&info.nRefCount< ADDRMAN_NEW_BUCKETS_PER_ADDRESS){info.nRefCount++;vNew.insert(nIndex);}}}}}});) CAddrMan()
Definition: addrman.h:250
#define ADDRMAN_NEW_BUCKETS_PER_ADDRESS
Definition: addrman.h:142
CNetAddr source
Definition: addrman.h:25
void Good(const CService &addr, int64_t nTime=GetAdjustedTime())
Definition: addrman.h:444