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