diff options
author | Felix Lange <fjl@twurst.com> | 2016-11-09 08:04:36 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-11-09 09:18:48 +0800 |
commit | 0f19cbc6e5b842fb271eedeed47f433d0c63ff2e (patch) | |
tree | 86eb4ccccf527f9a4c3be183fbfa59b8449ddd74 /p2p/discv5/ticket.go | |
parent | 49da42983af7a775695166689e5bf701bcec4f81 (diff) | |
download | dexon-0f19cbc6e5b842fb271eedeed47f433d0c63ff2e.tar dexon-0f19cbc6e5b842fb271eedeed47f433d0c63ff2e.tar.gz dexon-0f19cbc6e5b842fb271eedeed47f433d0c63ff2e.tar.bz2 dexon-0f19cbc6e5b842fb271eedeed47f433d0c63ff2e.tar.lz dexon-0f19cbc6e5b842fb271eedeed47f433d0c63ff2e.tar.xz dexon-0f19cbc6e5b842fb271eedeed47f433d0c63ff2e.tar.zst dexon-0f19cbc6e5b842fb271eedeed47f433d0c63ff2e.zip |
p2p/discv5: fix build with Go 1.5, delete package testimg
Diffstat (limited to 'p2p/discv5/ticket.go')
-rw-r--r-- | p2p/discv5/ticket.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/p2p/discv5/ticket.go b/p2p/discv5/ticket.go index e256d7679..3f9711ec0 100644 --- a/p2p/discv5/ticket.go +++ b/p2p/discv5/ticket.go @@ -766,10 +766,26 @@ func (r *topicRadius) targetForBucket(bucket int) common.Hash { prefix := r.topicHashPrefix ^ xor var target common.Hash binary.BigEndian.PutUint64(target[0:8], prefix) - rand.Read(target[8:]) + globalRandRead(target[8:]) return target } +// package rand provides a Read function in Go 1.6 and later, but +// we can't use it yet because we still support Go 1.5. +func globalRandRead(b []byte) { + pos := 0 + val := 0 + for n := 0; n < len(b); n++ { + if pos == 0 { + val = rand.Int() + pos = 7 + } + b[n] = byte(val) + val >>= 8 + pos-- + } +} + func (r *topicRadius) isInRadius(addrHash common.Hash) bool { nodePrefix := binary.BigEndian.Uint64(addrHash[0:8]) dist := nodePrefix ^ r.topicHashPrefix @@ -926,7 +942,7 @@ func (r *topicRadius) nextTarget(forceRegular bool) lookupInfo { prefix := r.topicHashPrefix ^ rnd var target common.Hash binary.BigEndian.PutUint64(target[0:8], prefix) - rand.Read(target[8:]) + globalRandRead(target[8:]) return lookupInfo{target: target, topic: r.topic, radiusLookup: false} } |