aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2015-03-08 06:30:05 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2015-03-23 17:00:32 -0700
commitb23add5521e4207085d41a0266617e94435fc22e (patch)
tree256976b0c67cda4452c6e00041ee8ff4a39bd349 /src/addrman.h
parentf3948a30cd27928fdf9dffbbf90ea6430c869edf (diff)
Switch addrman key from vector to uint256
Diffstat (limited to 'src/addrman.h')
-rw-r--r--src/addrman.h21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/addrman.h b/src/addrman.h
index d47217683c..04c7b32eaf 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -10,6 +10,7 @@
#include "random.h"
#include "sync.h"
#include "timedata.h"
+#include "uint256.h"
#include "util.h"
#include <map>
@@ -79,13 +80,13 @@ public:
}
//! Calculate in which "tried" bucket this entry belongs
- int GetTriedBucket(const std::vector<unsigned char> &nKey) const;
+ int GetTriedBucket(const uint256 &nKey) const;
//! Calculate in which "new" bucket this entry belongs, given a certain source
- int GetNewBucket(const std::vector<unsigned char> &nKey, const CNetAddr& src) const;
+ int GetNewBucket(const uint256 &nKey, const CNetAddr& src) const;
//! Calculate in which "new" bucket this entry belongs, using its default source
- int GetNewBucket(const std::vector<unsigned char> &nKey) const
+ int GetNewBucket(const uint256 &nKey) const
{
return GetNewBucket(nKey, source);
}
@@ -176,7 +177,7 @@ private:
mutable CCriticalSection cs;
//! secret key to randomize bucket select with
- std::vector<unsigned char> nKey;
+ uint256 nKey;
//! last used nId
int nIdCount;
@@ -284,6 +285,7 @@ public:
unsigned char nVersion = 0;
s << nVersion;
+ s << ((unsigned char)32);
s << nKey;
s << nNew;
s << nTried;
@@ -328,6 +330,9 @@ public:
unsigned char nVersion;
s >> nVersion;
+ unsigned char nKeySize;
+ s >> nKeySize;
+ if (nKeySize != 32) throw std::ios_base::failure("Incorrect keysize in addrman");
s >> nKey;
s >> nNew;
s >> nTried;
@@ -393,14 +398,18 @@ public:
CAddrMan() : vRandom(0), vvTried(ADDRMAN_TRIED_BUCKET_COUNT, std::vector<int>(0)), vvNew(ADDRMAN_NEW_BUCKET_COUNT, std::set<int>())
{
- nKey.resize(32);
- GetRandBytes(&nKey[0], 32);
+ nKey = GetRandHash();
nIdCount = 0;
nTried = 0;
nNew = 0;
}
+ ~CAddrMan()
+ {
+ nKey.SetNull();
+ }
+
//! Return the number of (unique) addresses in all tables.
int size()
{