From c8130df1d9dcc504244a49cbb12aa4c2848e5de2 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Tue, 6 Dec 2016 06:16:53 +0100 Subject: les: using random request IDs --- les/odr.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'les/odr.go') diff --git a/les/odr.go b/les/odr.go index 10ef928df..4bfbdcb4d 100644 --- a/les/odr.go +++ b/les/odr.go @@ -17,6 +17,8 @@ package les import ( + "crypto/rand" + "encoding/binary" "sync" "time" @@ -50,7 +52,6 @@ type LesOdr struct { mlock, clock sync.Mutex sentReqs map[uint64]*sentReq serverPool odrPeerSelector - lastReqID uint64 } func NewLesOdr(db ethdb.Database) *LesOdr { @@ -167,7 +168,7 @@ func (self *LesOdr) networkRequest(ctx context.Context, lreq LesOdrRequest) erro sentTo: make(map[*peer]chan struct{}), answered: answered, // reply delivered by any peer } - reqID := self.getNextReqID() + reqID := getNextReqID() self.mlock.Lock() self.sentReqs[reqID] = req self.mlock.Unlock() @@ -236,10 +237,8 @@ func (self *LesOdr) Retrieve(ctx context.Context, req light.OdrRequest) (err err return } -func (self *LesOdr) getNextReqID() uint64 { - self.clock.Lock() - defer self.clock.Unlock() - - self.lastReqID++ - return self.lastReqID +func getNextReqID() uint64 { + var rnd [8]byte + rand.Read(rnd[:]) + return binary.BigEndian.Uint64(rnd[:]) } -- cgit