aboutsummaryrefslogtreecommitdiffstats
path: root/les
diff options
context:
space:
mode:
authorZsolt Felfoldi <zsfelfoldi@gmail.com>2016-12-06 13:16:53 +0800
committerZsolt Felfoldi <zsfelfoldi@gmail.com>2016-12-10 16:53:25 +0800
commitc8130df1d9dcc504244a49cbb12aa4c2848e5de2 (patch)
tree172e9af96668feb822d67fedc28771d7671c9e7d /les
parentaf8a742d00f9d47b832f6f2d50a8e1c89bbf8441 (diff)
downloadgo-tangerine-c8130df1d9dcc504244a49cbb12aa4c2848e5de2.tar
go-tangerine-c8130df1d9dcc504244a49cbb12aa4c2848e5de2.tar.gz
go-tangerine-c8130df1d9dcc504244a49cbb12aa4c2848e5de2.tar.bz2
go-tangerine-c8130df1d9dcc504244a49cbb12aa4c2848e5de2.tar.lz
go-tangerine-c8130df1d9dcc504244a49cbb12aa4c2848e5de2.tar.xz
go-tangerine-c8130df1d9dcc504244a49cbb12aa4c2848e5de2.tar.zst
go-tangerine-c8130df1d9dcc504244a49cbb12aa4c2848e5de2.zip
les: using random request IDs
Diffstat (limited to 'les')
-rw-r--r--les/fetcher.go2
-rw-r--r--les/handler.go4
-rw-r--r--les/odr.go15
3 files changed, 10 insertions, 11 deletions
diff --git a/les/fetcher.go b/les/fetcher.go
index 0c8be9e2a..00cb31dfb 100644
--- a/les/fetcher.go
+++ b/les/fetcher.go
@@ -350,7 +350,7 @@ func (f *lightFetcher) request(p *peer, n *fetcherTreeNode, amount uint64) (uint
return 0, false
}
- reqID := f.odr.getNextReqID()
+ reqID := getNextReqID()
n.requested = true
cost := p.GetRequestCost(GetBlockHeadersMsg, int(amount))
p.fcServer.SendRequest(reqID, cost)
diff --git a/les/handler.go b/les/handler.go
index 4535aaeb9..3fc80e19a 100644
--- a/les/handler.go
+++ b/les/handler.go
@@ -338,13 +338,13 @@ func (pm *ProtocolManager) handle(p *peer) error {
glog.V(logger.Debug).Infof("LES: register peer %v", p.id)
if pm.lightSync {
requestHeadersByHash := func(origin common.Hash, amount int, skip int, reverse bool) error {
- reqID := pm.odr.getNextReqID()
+ reqID := getNextReqID()
cost := p.GetRequestCost(GetBlockHeadersMsg, amount)
p.fcServer.SendRequest(reqID, cost)
return p.RequestHeadersByHash(reqID, cost, origin, amount, skip, reverse)
}
requestHeadersByNumber := func(origin uint64, amount int, skip int, reverse bool) error {
- reqID := pm.odr.getNextReqID()
+ reqID := getNextReqID()
cost := p.GetRequestCost(GetBlockHeadersMsg, amount)
p.fcServer.SendRequest(reqID, cost)
return p.RequestHeadersByNumber(reqID, cost, origin, amount, skip, reverse)
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[:])
}