diff options
author | Zsolt Felfoldi <zsfelfoldi@gmail.com> | 2016-12-10 13:50:36 +0800 |
---|---|---|
committer | Zsolt Felfoldi <zsfelfoldi@gmail.com> | 2016-12-10 16:53:25 +0800 |
commit | f12f8a6c14dbaf6e6531cea1b0cf169b851e1894 (patch) | |
tree | 41f0d7dd9f5fe21cbb8615a59cc08b9594f83770 /les/peer.go | |
parent | c57c54ce96628aeb6345776310123a80593f0143 (diff) | |
download | go-tangerine-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.tar go-tangerine-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.tar.gz go-tangerine-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.tar.bz2 go-tangerine-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.tar.lz go-tangerine-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.tar.xz go-tangerine-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.tar.zst go-tangerine-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.zip |
les, light: add block availability check for ODR requests
Diffstat (limited to 'les/peer.go')
-rw-r--r-- | les/peer.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/les/peer.go b/les/peer.go index 8ebbe3511..0a8db4975 100644 --- a/les/peer.go +++ b/les/peer.go @@ -57,6 +57,7 @@ type peer struct { announceChn chan announceData poolEntry *poolEntry + hasBlock func(common.Hash, uint64) bool fcClient *flowcontrol.ClientNode // nil if the peer is server only fcServer *flowcontrol.ServerNode // nil if the peer is client only @@ -135,6 +136,9 @@ func sendResponse(w p2p.MsgWriter, msgcode, reqID, bv uint64, data interface{}) } func (p *peer) GetRequestCost(msgcode uint64, amount int) uint64 { + p.lock.RLock() + defer p.lock.RUnlock() + cost := p.fcCosts[msgcode].baseCost + p.fcCosts[msgcode].reqCost*uint64(amount) if cost > p.fcServerParams.BufLimit { cost = p.fcServerParams.BufLimit @@ -142,6 +146,14 @@ func (p *peer) GetRequestCost(msgcode uint64, amount int) uint64 { return cost } +// HasBlock checks if the peer has a given block +func (p *peer) HasBlock(hash common.Hash, number uint64) bool { + p.lock.RLock() + hashBlock := p.hasBlock + p.lock.RUnlock() + return hashBlock != nil && hashBlock(hash, number) +} + // SendAnnounce announces the availability of a number of blocks through // a hash notification. func (p *peer) SendAnnounce(request announceData) error { |