aboutsummaryrefslogtreecommitdiffstats
path: root/les
diff options
context:
space:
mode:
authorZsolt Felfoldi <zsfelfoldi@gmail.com>2016-11-30 06:55:35 +0800
committerZsolt Felfoldi <zsfelfoldi@gmail.com>2016-12-08 20:38:15 +0800
commite67500aa15a2f51a96f0ae91ab3af898b81d82f2 (patch)
tree1406ba81a4fc59d775d1b44082af5a35401da7bf /les
parenta6d3bf6fc37571484ab4e174f1ca032b40bc16fb (diff)
downloadgo-tangerine-e67500aa15a2f51a96f0ae91ab3af898b81d82f2.tar
go-tangerine-e67500aa15a2f51a96f0ae91ab3af898b81d82f2.tar.gz
go-tangerine-e67500aa15a2f51a96f0ae91ab3af898b81d82f2.tar.bz2
go-tangerine-e67500aa15a2f51a96f0ae91ab3af898b81d82f2.tar.lz
go-tangerine-e67500aa15a2f51a96f0ae91ab3af898b81d82f2.tar.xz
go-tangerine-e67500aa15a2f51a96f0ae91ab3af898b81d82f2.tar.zst
go-tangerine-e67500aa15a2f51a96f0ae91ab3af898b81d82f2.zip
les: fixed light fetcher request ID matching
Diffstat (limited to 'les')
-rw-r--r--les/fetcher.go14
-rw-r--r--les/handler.go2
2 files changed, 11 insertions, 5 deletions
diff --git a/les/fetcher.go b/les/fetcher.go
index ae9bf8474..24cf51839 100644
--- a/les/fetcher.go
+++ b/les/fetcher.go
@@ -53,6 +53,7 @@ type fetchRequest struct {
type fetchResponse struct {
reqID uint64
headers []*types.Header
+ peer *peer
}
func newLightFetcher(pm *ProtocolManager) *lightFetcher {
@@ -148,8 +149,8 @@ func (f *lightFetcher) nextRequest() (*peer, *announceData) {
return bestPeer, res
}
-func (f *lightFetcher) deliverHeaders(reqID uint64, headers []*types.Header) {
- f.deliverChn <- fetchResponse{reqID: reqID, headers: headers}
+func (f *lightFetcher) deliverHeaders(peer *peer, reqID uint64, headers []*types.Header) {
+ f.deliverChn <- fetchResponse{reqID: reqID, headers: headers, peer: peer}
}
func (f *lightFetcher) requestedID(reqID uint64) bool {
@@ -280,11 +281,16 @@ func (f *lightFetcher) syncLoop() {
//fmt.Println("<-f.deliverChn", f.syncing)
f.reqMu.Lock()
req, ok := f.requested[resp.reqID]
- delete(f.requested, resp.reqID)
+ if ok && req.peer != resp.peer {
+ ok = false
+ }
+ if ok {
+ delete(f.requested, resp.reqID)
+ }
f.reqMu.Unlock()
if !ok || !(f.syncing || f.processResponse(req, resp)) {
//fmt.Println("processResponse fail")
- f.pm.removePeer(req.peer.id)
+ f.pm.removePeer(resp.peer.id)
}
case <-f.syncDone:
//fmt.Println("<-f.syncDone", f.syncing)
diff --git a/les/handler.go b/les/handler.go
index 2e6952d2f..f1a8bc62c 100644
--- a/les/handler.go
+++ b/les/handler.go
@@ -559,7 +559,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
p.fcServer.GotReply(resp.ReqID, resp.BV)
if pm.fetcher.requestedID(resp.ReqID) {
- pm.fetcher.deliverHeaders(resp.ReqID, resp.Headers)
+ pm.fetcher.deliverHeaders(p, resp.ReqID, resp.Headers)
} else {
err := pm.downloader.DeliverHeaders(p.id, resp.Headers)
if err != nil {