Anoncoin  0.9.4
P2P Digital Currency
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 _ANONCOIN_ADDRMAN
6 #define _ANONCOIN_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 // #define DEBUG_ADDRMAN
123 
124 // total number of buckets for tried addresses
125 #define ADDRMAN_TRIED_BUCKET_COUNT 64
126 
127 // maximum allowed number of entries in buckets for tried addresses
128 #define ADDRMAN_TRIED_BUCKET_SIZE 64
129 
130 // total number of buckets for new addresses
131 #define ADDRMAN_NEW_BUCKET_COUNT 256
132 
133 // maximum allowed number of entries in buckets for new addresses
134 #define ADDRMAN_NEW_BUCKET_SIZE 64
135 
136 // over how many buckets entries with tried addresses from a single group (/16 for IPv4) are spread
137 #define ADDRMAN_TRIED_BUCKETS_PER_GROUP 4
138 
139 // over how many buckets entries with new addresses originating from a single group are spread
140 #define ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP 32
141 
142 // in how many buckets for entries with new addresses a single address may occur
143 #define ADDRMAN_NEW_BUCKETS_PER_ADDRESS 4
144 
145 // how many entries in a bucket with tried addresses are inspected, when selecting one to replace
146 #define ADDRMAN_TRIED_ENTRIES_INSPECT_ON_EVICT 4
147 
148 // how old addresses can maximally be
149 #define ADDRMAN_HORIZON_DAYS 30
150 
151 // after how many failed attempts we give up on a new node
152 #define ADDRMAN_RETRIES 3
153 
154 // how many successive failures are allowed ...
155 #define ADDRMAN_MAX_FAILURES 10
156 
157 // ... in at least this many days
158 #define ADDRMAN_MIN_FAIL_DAYS 7
159 
160 // the maximum percentage of nodes to return in a getaddr call
161 #define ADDRMAN_GETADDR_MAX_PCT 23
162 
163 // the maximum number of nodes to return in a getaddr call
164 #define ADDRMAN_GETADDR_MAX 2500
165 
167 class CAddrMan
168 {
169 private:
170  // critical section to protect the inner data structures
172 
173  // secret key to randomize bucket select with
174  std::vector<unsigned char> nKey;
175 
176  // last used nId
177  int nIdCount;
178 
179  // table with information about all nIds
180  std::map<int, CAddrInfo> mapInfo;
181 
182  // find an nId based on its network address
183  std::map<CNetAddr, int> mapAddr;
184 
185  // randomly-ordered vector of all nIds
186  std::vector<int> vRandom;
187 
188  // number of "tried" entries
189  int nTried;
190 
191  // list of "tried" buckets
192  std::vector<std::vector<int> > vvTried;
193 
194  // number of (unique) "new" entries
195  int nNew;
196 
197  // list of "new" buckets
198  std::vector<std::set<int> > vvNew;
199 
200 protected:
201 
202  // Find an entry.
203  CAddrInfo* Find(const CNetAddr& addr, int *pnId = NULL);
204 
205  // find an entry, creating it if necessary.
206  // nTime and nServices of found node is updated, if necessary.
207  CAddrInfo* Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId = NULL);
208 
209  // Swap two elements in vRandom.
210  void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2);
211 
212  // Return position in given bucket to replace.
213  int SelectTried(int nKBucket);
214 
215  // Remove an element from a "new" bucket.
216  // This is the only place where actual deletes occur.
217  // They are never deleted while in the "tried" table, only possibly evicted back to the "new" table.
218  int ShrinkNew(int nUBucket);
219 
220  // Move an entry from the "new" table(s) to the "tried" table
221  // @pre vvUnkown[nOrigin].count(nId) != 0
222  void MakeTried(CAddrInfo& info, int nId, int nOrigin);
223 
224  // Mark an entry "good", possibly moving it from "new" to "tried".
225  void Good_(const CService &addr, int64_t nTime);
226 
227  // Add an entry to the "new" table.
228  bool Add_(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty);
229 
230  // Mark an entry as attempted to connect.
231  void Attempt_(const CService &addr, int64_t nTime);
232 
233  // Select an address to connect to.
234  // nUnkBias determines how much to favor new addresses over tried ones (min=0, max=100)
235  CAddress Select_(int nUnkBias);
236 
237 #ifdef DEBUG_ADDRMAN
238  // Perform consistency check. Returns an error code or zero.
239  int Check_();
240 #endif
241 
242  // Select several addresses at once.
243  void GetAddr_(std::vector<CAddress> &vAddr);
244 
245  // Mark an entry as currently-connected-to.
246  void Connected_(const CService &addr, int64_t nTime);
247 
248 public:
249 
251  (({
252  // serialized format:
253  // * version byte (currently 0)
254  // * nKey
255  // * nNew
256  // * nTried
257  // * number of "new" buckets
258  // * all nNew addrinfos in vvNew
259  // * all nTried addrinfos in vvTried
260  // * for each bucket:
261  // * number of elements
262  // * for each element: index
263  //
264  // Notice that vvTried, mapAddr and vVector are never encoded explicitly;
265  // they are instead reconstructed from the other information.
266  //
267  // vvNew is serialized, but only used if ADDRMAN_UNKOWN_BUCKET_COUNT didn't change,
268  // otherwise it is reconstructed as well.
269  //
270  // This format is more complex, but significantly smaller (at most 1.5 MiB), and supports
271  // changes to the ADDRMAN_ parameters without breaking the on-disk structure.
272  {
273  LOCK(cs);
274  unsigned char nVersion = 0;
275  READWRITE(nVersion);
276  READWRITE(nKey);
277  READWRITE(nNew);
278  READWRITE(nTried);
279 
280  CAddrMan *am = const_cast<CAddrMan*>(this);
281  if (fWrite)
282  {
283  int nUBuckets = ADDRMAN_NEW_BUCKET_COUNT;
284  READWRITE(nUBuckets);
285  std::map<int, int> mapUnkIds;
286  int nIds = 0;
287  for (std::map<int, CAddrInfo>::iterator it = am->mapInfo.begin(); it != am->mapInfo.end(); it++)
288  {
289  if (nIds == nNew) break; // this means nNew was wrong, oh ow
290  mapUnkIds[(*it).first] = nIds;
291  CAddrInfo &info = (*it).second;
292  if (info.nRefCount)
293  {
294  READWRITE(info);
295  nIds++;
296  }
297  }
298  nIds = 0;
299  for (std::map<int, CAddrInfo>::iterator it = am->mapInfo.begin(); it != am->mapInfo.end(); it++)
300  {
301  if (nIds == nTried) break; // this means nTried was wrong, oh ow
302  CAddrInfo &info = (*it).second;
303  if (info.fInTried)
304  {
305  READWRITE(info);
306  nIds++;
307  }
308  }
309  for (std::vector<std::set<int> >::iterator it = am->vvNew.begin(); it != am->vvNew.end(); it++)
310  {
311  const std::set<int> &vNew = (*it);
312  int nSize = vNew.size();
313  READWRITE(nSize);
314  for (std::set<int>::iterator it2 = vNew.begin(); it2 != vNew.end(); it2++)
315  {
316  int nIndex = mapUnkIds[*it2];
317  READWRITE(nIndex);
318  }
319  }
320  } else {
321  int nUBuckets = 0;
322  READWRITE(nUBuckets);
323  am->nIdCount = 0;
324  am->mapInfo.clear();
325  am->mapAddr.clear();
326  am->vRandom.clear();
327  am->vvTried = std::vector<std::vector<int> >(ADDRMAN_TRIED_BUCKET_COUNT, std::vector<int>(0));
328  am->vvNew = std::vector<std::set<int> >(ADDRMAN_NEW_BUCKET_COUNT, std::set<int>());
329  for (int n = 0; n < am->nNew; n++)
330  {
331  CAddrInfo &info = am->mapInfo[n];
332  READWRITE(info);
333  am->mapAddr[info] = n;
334  info.nRandomPos = vRandom.size();
335  am->vRandom.push_back(n);
336  if (nUBuckets != ADDRMAN_NEW_BUCKET_COUNT)
337  {
338  am->vvNew[info.GetNewBucket(am->nKey)].insert(n);
339  info.nRefCount++;
340  }
341  }
342  am->nIdCount = am->nNew;
343  int nLost = 0;
344  for (int n = 0; n < am->nTried; n++)
345  {
346  CAddrInfo info;
347  READWRITE(info);
348  std::vector<int> &vTried = am->vvTried[info.GetTriedBucket(am->nKey)];
349  if (vTried.size() < ADDRMAN_TRIED_BUCKET_SIZE)
350  {
351  info.nRandomPos = vRandom.size();
352  info.fInTried = true;
353  am->vRandom.push_back(am->nIdCount);
354  am->mapInfo[am->nIdCount] = info;
355  am->mapAddr[info] = am->nIdCount;
356  vTried.push_back(am->nIdCount);
357  am->nIdCount++;
358  } else {
359  nLost++;
360  }
361  }
362  am->nTried -= nLost;
363  for (int b = 0; b < nUBuckets; b++)
364  {
365  std::set<int> &vNew = am->vvNew[b];
366  int nSize = 0;
367  READWRITE(nSize);
368  for (int n = 0; n < nSize; n++)
369  {
370  int nIndex = 0;
371  READWRITE(nIndex);
372  CAddrInfo &info = am->mapInfo[nIndex];
373  if (nUBuckets == ADDRMAN_NEW_BUCKET_COUNT && info.nRefCount < ADDRMAN_NEW_BUCKETS_PER_ADDRESS)
374  {
375  info.nRefCount++;
376  vNew.insert(nIndex);
377  }
378  }
379  }
380  }
381  }
382  });)
383 
384  CAddrMan() : vRandom(0), vvTried(ADDRMAN_TRIED_BUCKET_COUNT, std::vector<int>(0)), vvNew(ADDRMAN_NEW_BUCKET_COUNT, std::set<int>())
385  {
386  nKey.resize(32);
387  RAND_bytes(&nKey[0], 32);
388 
389  nIdCount = 0;
390  nTried = 0;
391  nNew = 0;
392  }
393 
394  // Return the number of (unique) addresses in all tables.
395  int size()
396  {
397  return vRandom.size();
398  }
399 
400  // Consistency check
401  void Check()
402  {
403 #ifdef DEBUG_ADDRMAN
404  {
405  LOCK(cs);
406  int err;
407  if ((err=Check_()))
408  LogPrintf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
409  }
410 #endif
411  }
412 
413  // Add a single address.
414  bool Add(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty = 0)
415  {
416  bool fRet = false;
417  {
418  LOCK(cs);
419  Check();
420  fRet |= Add_(addr, source, nTimePenalty);
421  Check();
422  }
423  if (fRet)
424  LogPrint("addrman", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort().c_str(), source.ToString().c_str(), nTried, nNew);
425  return fRet;
426  }
427 
428  // Add multiple addresses.
429  bool Add(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty = 0)
430  {
431  int nAdd = 0;
432  {
433  LOCK(cs);
434  Check();
435  for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++)
436  nAdd += Add_(*it, source, nTimePenalty) ? 1 : 0;
437  Check();
438  }
439  if (nAdd)
440  LogPrint("addrman", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString().c_str(), nTried, nNew);
441  return nAdd > 0;
442  }
443 
444  // Mark an entry as accessible.
445  void Good(const CService &addr, int64_t nTime = GetAdjustedTime())
446  {
447  {
448  LOCK(cs);
449  Check();
450  Good_(addr, nTime);
451  Check();
452  }
453  }
454 
455  // Mark an entry as connection attempted to.
456  void Attempt(const CService &addr, int64_t nTime = GetAdjustedTime())
457  {
458  {
459  LOCK(cs);
460  Check();
461  Attempt_(addr, nTime);
462  Check();
463  }
464  }
465 
466  // Choose an address to connect to.
467  // nUnkBias determines how much "new" entries are favored over "tried" ones (0-100).
468  CAddress Select(int nUnkBias = 50)
469  {
470  CAddress addrRet;
471  {
472  LOCK(cs);
473  Check();
474  addrRet = Select_(nUnkBias);
475  Check();
476  }
477  return addrRet;
478  }
479 
480  // Return a bunch of addresses, selected at random.
481  std::vector<CAddress> GetAddr()
482  {
483  Check();
484  std::vector<CAddress> vAddr;
485  {
486  LOCK(cs);
487  GetAddr_(vAddr);
488  }
489  Check();
490  return vAddr;
491  }
492 
493  // Mark an entry as currently-connected-to.
494  void Connected(const CService &addr, int64_t nTime = GetAdjustedTime())
495  {
496  {
497  LOCK(cs);
498  Check();
499  Connected_(addr, nTime);
500  Check();
501  }
502  }
503 };
504 
505 #endif
int nRefCount
Definition: addrman.h:37
void Attempt(const CService &addr, int64_t nTime=GetAdjustedTime())
Definition: addrman.h:456
int GetNewBucket(const std::vector< unsigned char > &nKey, const CNetAddr &src) const
Definition: addrman.cpp:26
#define READWRITE(obj)
Definition: serialize.h:101
void Init()
Definition: protocol.cpp:92
CAddrInfo * Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId=NULL)
Definition: addrman.cpp:96
std::string ToStringIPPort() const
Definition: netbase.cpp:1314
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:414
#define ADDRMAN_TRIED_BUCKET_COUNT
Definition: addrman.h:125
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:167
std::vector< CAddress > GetAddr()
Definition: addrman.h:481
Extended statistics about a CAddress.
Definition: addrman.h:21
std::vector< int > vRandom
Definition: addrman.h:186
#define LogPrintf(...)
Definition: util.h:118
int64_t GetAdjustedTime()
Definition: util.cpp:1241
int SelectTried(int nKBucket)
Definition: addrman.cpp:128
std::vector< std::set< int > > vvNew
Definition: addrman.h:198
#define LOCK(cs)
Definition: sync.h:157
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netbase.h:109
void MakeTried(CAddrInfo &info, int nId, int nOrigin)
Definition: addrman.cpp:206
void Check()
Definition: addrman.h:401
int64_t nLastTry
Definition: protocol.h:124
A CService with information about it as peer.
Definition: protocol.h:91
int nTried
Definition: addrman.h:189
void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2)
Definition: addrman.cpp:108
int nIdCount
Definition: addrman.h:177
int ShrinkNew(int nUBucket)
Definition: addrman.cpp:152
std::map< CNetAddr, int > mapAddr
Definition: addrman.h:183
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:128
std::vector< std::vector< int > > vvTried
Definition: addrman.h:192
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
Definition: netbase.h:45
int size()
Definition: addrman.h:395
void Good_(const CService &addr, int64_t nTime)
Definition: addrman.cpp:264
std::vector< unsigned char > nKey
Definition: addrman.h:174
CAddrInfo(const CAddress &addrIn, const CNetAddr &addrSource)
Definition: addrman.h:67
#define ADDRMAN_NEW_BUCKET_COUNT
Definition: addrman.h:131
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:515
CAddress Select(int nUnkBias=50)
Definition: addrman.h:468
void GetAddr_(std::vector< CAddress > &vAddr)
Definition: addrman.cpp:493
std::map< int, CAddrInfo > mapInfo
Definition: addrman.h:180
bool Add(const std::vector< CAddress > &vAddr, const CNetAddr &source, int64_t nTimePenalty=0)
Definition: addrman.h:429
int GetNewBucket(const std::vector< unsigned char > &nKey) const
Definition: addrman.h:84
std::string ToString() const
Definition: netbase.cpp:908
int nNew
Definition: addrman.h:195
void Connected(const CService &addr, int64_t nTime=GetAdjustedTime())
Definition: addrman.h:494
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:171
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:251
#define ADDRMAN_NEW_BUCKETS_PER_ADDRESS
Definition: addrman.h:143
CNetAddr source
Definition: addrman.h:25
void Good(const CService &addr, int64_t nTime=GetAdjustedTime())
Definition: addrman.h:445