aboutsummaryrefslogtreecommitdiff
path: root/src/net.h
diff options
context:
space:
mode:
authorPatrick Strateman <patrick.strateman@gmail.com>2016-05-23 00:21:05 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2016-06-07 16:20:40 +0200
commit053930ffc41ba33fe7ce26bde7097951fe0b8462 (patch)
treedd1af5cb63bb465d0a639ee880d28a60271bb73b /src/net.h
parent22e0b35676230961aeb848a4f5c6b007cb8a43c9 (diff)
Avoid recalculating vchKeyedNetGroup in eviction logic.
Lazy calculate vchKeyedNetGroup in CNode::GetKeyedNetGroup.
Diffstat (limited to 'src/net.h')
-rw-r--r--src/net.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/net.h b/src/net.h
index 403653e8c8..019a3f7ee3 100644
--- a/src/net.h
+++ b/src/net.h
@@ -9,6 +9,8 @@
#include "amount.h"
#include "bloom.h"
#include "compat.h"
+#include "crypto/common.h"
+#include "crypto/sha256.h"
#include "limitedmap.h"
#include "netbase.h"
#include "protocol.h"
@@ -362,6 +364,8 @@ public:
CBloomFilter* pfilter;
int nRefCount;
NodeId id;
+
+ std::vector<unsigned char> vchKeyedNetGroup;
protected:
// Denial-of-service detection/prevention
@@ -450,6 +454,22 @@ private:
CNode(const CNode&);
void operator=(const CNode&);
+ void CalculateKeyedNetGroup() {
+ static std::vector<unsigned char> vchSecretKey;
+ if (vchSecretKey.empty()) {
+ vchSecretKey.resize(32, 0);
+ GetRandBytes(vchSecretKey.data(), vchSecretKey.size());
+ }
+
+ std::vector<unsigned char> vchNetGroup(this->addr.GetGroup());
+
+ CSHA256 hash;
+ hash.Write(begin_ptr(vchNetGroup), vchNetGroup.size());
+ hash.Write(begin_ptr(vchSecretKey), vchSecretKey.size());
+
+ vchKeyedNetGroup.resize(32, 0);
+ hash.Finalize(begin_ptr(vchKeyedNetGroup));
+ }
public:
NodeId GetId() const {