Use 64-bit SipHash of netgroups in eviction

This commit is contained in:
Pieter Wuille
2016-05-25 15:38:32 +02:00
committed by lateminer
parent 02cfe3c9e8
commit a1d4facb14
2 changed files with 29 additions and 32 deletions

View File

@@ -9,8 +9,6 @@
#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"
@@ -336,7 +334,7 @@ public:
int64_t nLastRecv;
int64_t nTimeConnected;
int64_t nTimeOffset;
CAddress addr;
const CAddress addr;
std::string addrName;
CService addrLocal;
int nVersion;
@@ -364,7 +362,7 @@ public:
int nRefCount;
NodeId id;
std::vector<unsigned char> vchKeyedNetGroup;
const uint64_t nKeyedNetGroup;
protected:
// Denial-of-service detection/prevention
@@ -450,22 +448,8 @@ 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());
}
static uint64_t CalculateKeyedNetGroup(const CAddress& ad);
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 {