 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
21 std::vector<unsigned char> vchSourceGroupKey = src.
GetGroup();
38 if (
nTime > nNow + 10 * 60)
57 int64_t nSinceLastSeen = nNow -
nTime;
58 int64_t nSinceLastTry = nNow -
nLastTry;
60 if (nSinceLastSeen < 0)
62 if (nSinceLastTry < 0)
66 if (nSinceLastTry < 60 * 10)
70 fChance *= pow(0.66, std::min(
nAttempts, 8));
77 std::map<CNetAddr, int>::iterator it =
mapAddr.find(addr);
82 std::map<int, CAddrInfo>::iterator it2 =
mapInfo.find((*it).second);
84 return &(*it2).second;
102 if (nRndPos1 == nRndPos2)
110 assert(
mapInfo.count(nId1) == 1);
111 assert(
mapInfo.count(nId2) == 1);
113 mapInfo[nId1].nRandomPos = nRndPos2;
114 mapInfo[nId2].nRandomPos = nRndPos1;
122 assert(
mapInfo.count(nId) != 0);
137 if (
vvNew[nUBucket][nUBucketPos] != -1) {
138 int nIdDelete =
vvNew[nUBucket][nUBucketPos];
142 vvNew[nUBucket][nUBucketPos] = -1;
154 if (
vvNew[bucket][pos] == nId) {
155 vvNew[bucket][pos] = -1;
168 if (
vvTried[nKBucket][nKBucketPos] != -1) {
170 int nIdEvict =
vvTried[nKBucket][nKBucketPos];
171 assert(
mapInfo.count(nIdEvict) == 1);
176 vvTried[nKBucket][nKBucketPos] = -1;
183 assert(
vvNew[nUBucket][nUBucketPos] == -1);
187 vvNew[nUBucket][nUBucketPos] = nIdEvict;
190 assert(
vvTried[nKBucket][nKBucketPos] == -1);
192 vvTried[nKBucket][nKBucketPos] = nId;
232 if (
vvNew[nB][nBpos] == nId) {
266 int64_t nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60);
267 if (addr.
nTime && (!pinfo->
nTime || pinfo->
nTime < addr.
nTime - nUpdateInterval - nTimePenalty))
268 pinfo->
nTime = std::max((int64_t)0, addr.
nTime - nTimePenalty);
287 for (
int n = 0; n < pinfo->
nRefCount; n++)
289 if (nFactor > 1 && (
RandomInt(nFactor) != 0))
293 pinfo->
nTime = std::max((int64_t)0, (int64_t)pinfo->
nTime - nTimePenalty);
300 if (
vvNew[nUBucket][nUBucketPos] != nId) {
301 bool fInsert =
vvNew[nUBucket][nUBucketPos] == -1;
312 vvNew[nUBucket][nUBucketPos] = nId;
349 if (newOnly &&
nNew == 0)
355 double fChanceFactor = 1.0;
359 while (
vvTried[nKBucket][nKBucketPos] == -1) {
363 int nId =
vvTried[nKBucket][nKBucketPos];
364 assert(
mapInfo.count(nId) == 1);
368 fChanceFactor *= 1.2;
372 double fChanceFactor = 1.0;
376 while (
vvNew[nUBucket][nUBucketPos] == -1) {
380 int nId =
vvNew[nUBucket][nUBucketPos];
381 assert(
mapInfo.count(nId) == 1);
385 fChanceFactor *= 1.2;
391 int CAddrMan::Check_()
393 std::set<int> setTried;
394 std::map<int, int> mapNew;
399 for (std::map<int, CAddrInfo>::iterator it =
mapInfo.begin(); it !=
mapInfo.end(); it++) {
425 if (setTried.size() !=
nTried)
427 if (mapNew.size() !=
nNew)
433 if (!setTried.count(
vvTried[n][i]))
446 if (
vvNew[n][i] != -1) {
447 if (!mapNew.count(
vvNew[n][i]))
451 if (--mapNew[
vvNew[n][i]] == 0)
452 mapNew.erase(
vvNew[n][i]);
475 for (
unsigned int n = 0; n <
vRandom.size(); n++) {
476 if (vAddr.size() >= nNodes)
504 int64_t nUpdateInterval = 20 * 60;
505 if (nTime - info.
nTime > nUpdateInterval)
A combination of a network address (CNetAddr) and a (TCP) port.
uint256 nKey
secret key to randomize bucket select with
void SetServices_(const CService &addr, ServiceFlags nServices)
Update an entry's service bits.
#define ADDRMAN_MIN_FAIL_DAYS
... in at least this many days
#define ADDRMAN_MAX_FAILURES
how many successive failures are allowed ...
CAddrInfo * Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId=NULL)
find an entry, creating it if necessary.
#define ADDRMAN_TRIED_BUCKET_COUNT_LOG2
Stochastic address manager.
CAddrInfo Select_(bool newOnly)
Select an address to connect to, if newOnly is set to true, only the new table is selected from.
virtual int RandomInt(int nMax)
Wraps GetRandInt to allow tests to override RandomInt and make it determinismistic.
#define ADDRMAN_TRIED_BUCKETS_PER_GROUP
over how many buckets entries with tried addresses from a single group (/16 for IPv4) are spread
void ClearNew(int nUBucket, int nUBucketPos)
Clear a position in a "new" table. This is the only place where entries are actually deleted.
#define ADDRMAN_NEW_BUCKETS_PER_ADDRESS
in how many buckets for entries with new addresses a single address may occur
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
int GetTriedBucket(const uint256 &nKey) const
Calculate in which "tried" bucket this entry belongs.
int64_t nLastSuccess
last successful connection by us
std::vector< unsigned char > GetGroup() const
double GetChance(int64_t nNow=GetAdjustedTime()) const
Calculate the relative chance this entry should be given when selecting nodes to connect to.
ServiceFlags
nServices flags
bool IsTerrible(int64_t nNow=GetAdjustedTime()) const
Determine whether the statistics about this entry are bad enough so that it can just be deleted.
#define ADDRMAN_NEW_BUCKET_COUNT_LOG2
total number of buckets for new addresses
#define ADDRMAN_RETRIES
after how many failed attempts we give up on a new node
int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE]
list of "new" buckets
int64_t nLastGood
last time Good was called (memory only)
Extended statistics about a CAddress.
int64_t nLastCountAttempt
last counted attempt (memory only)
std::string ToString() const
CAddrInfo * Find(const CNetAddr &addr, int *pnId=NULL)
Find an entry.
#define ADDRMAN_BUCKET_SIZE
#define ADDRMAN_TRIED_BUCKET_COUNT
Convenience.
std::map< CNetAddr, int > mapAddr
find an nId based on its network address
void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2)
Swap two elements in vRandom.
int nRefCount
reference count in new sets (memory only)
FastRandomContext insecure_rand
Source of random numbers for randomization in inner loops.
int nRandomPos
position in vRandom
void MakeTried(CAddrInfo &info, int nId)
Move an entry from the "new" table(s) to the "tried" table.
int64_t nLastTry
last try whatsoever by us (memory only)
int nIdCount
last used nId
int GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const
Calculate in which position of a bucket to store this entry.
256-bit unsigned big integer.
std::vector< int > vRandom
randomly-ordered vector of all nIds
#define LogPrint(category,...)
#define ADDRMAN_NEW_BUCKET_COUNT
#define ADDRMAN_BUCKET_SIZE_LOG2
maximum allowed number of entries in buckets for new and tried addresses
#define ADDRMAN_GETADDR_MAX
the maximum number of nodes to return in a getaddr call
int GetNewBucket(const uint256 &nKey, const CNetAddr &src) const
Calculate in which "new" bucket this entry belongs, given a certain source.
int64_t GetAdjustedTime()
A CService with information about it as peer.
int nAttempts
connection attempts since last successful attempt
void Delete(int nId)
Delete an entry. It must not be in tried, and have refcount 0.
void Connected_(const CService &addr, int64_t nTime)
Mark an entry as currently-connected-to.
A writer stream (for serialization) that computes a 256-bit hash.
void GetAddr_(std::vector< CAddress > &vAddr)
Select several addresses at once.
int size()
Return the number of (unique) addresses in all tables.
bool fInTried
in tried set? (memory only)
void Good_(const CService &addr, int64_t nTime)
Mark an entry "good", possibly moving it from "new" to "tried".
#define ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP
over how many buckets entries with new addresses originating from a single group are spread
int nNew
number of (unique) "new" entries
#define ADDRMAN_HORIZON_DAYS
how old addresses can maximally be
std::map< int, CAddrInfo > mapInfo
table with information about all nIds
int vvTried[ADDRMAN_TRIED_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE]
list of "tried" buckets
#define ADDRMAN_GETADDR_MAX_PCT
the maximum percentage of nodes to return in a getaddr call
bool Add_(const CAddress &addr, const CNetAddr &source, int64_t nTimePenalty)
Add an entry to the "new" table.
void Attempt_(const CService &addr, bool fCountFailure, int64_t nTime)
Mark an entry as attempted to connect.
std::vector< unsigned char > GetKey() const
uint64_t randbits(int bits)
Generate a random (bits)-bit integer.