From 3a6525eaf891459f6a50de7fe954908a76f249bd Mon Sep 17 00:00:00 2001 From: tau3 Date: Wed, 19 Feb 2020 21:31:50 +0400 Subject: [PATCH] set hashkey only once in addrbook --- p2p/pex/addrbook.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/p2p/pex/addrbook.go b/p2p/pex/addrbook.go index 8f82331a1..c470071cd 100644 --- a/p2p/pex/addrbook.go +++ b/p2p/pex/addrbook.go @@ -99,6 +99,15 @@ type addrBook struct { wg sync.WaitGroup } +var hashKey []byte + +func init() { + highwayKeyLength := 32 + hashKey = make([]byte, highwayKeyLength) + rand.Seed(time.Now().UnixNano()) + rand.Read(hashKey) +} + // NewAddrBook creates a new address book. // Use Start to begin processing asynchronous address updates. func NewAddrBook(filePath string, routabilityStrict bool) *addrBook { @@ -843,10 +852,7 @@ func (a *addrBook) groupKey(na *p2p.NetAddress) string { // hash function calculates hash and returns the resulting bytes. func hash(b []byte) ([]byte, error) { - highwayKeyLength := 32 - key := make([]byte, highwayKeyLength) - rand.Read(key) - hasher, err := highwayhash.New64(key) + hasher, err := highwayhash.New64(hashKey) if err != nil { return nil, err }