aboutsummaryrefslogtreecommitdiffstats
path: root/les/odr.go
diff options
context:
space:
mode:
authorZsolt Felfoldi <zsfelfoldi@gmail.com>2016-12-15 18:13:52 +0800
committerZsolt Felfoldi <zsfelfoldi@gmail.com>2017-01-06 11:34:31 +0800
commit93f9c023ccda2256079484d6c2a3159818ba6691 (patch)
treef2ed341904459184587ca1cc8667d8169761f752 /les/odr.go
parente0ee0cc66a4416edd47232649f4d4bca4a5e3c07 (diff)
downloadgo-tangerine-93f9c023ccda2256079484d6c2a3159818ba6691.tar.gz
go-tangerine-93f9c023ccda2256079484d6c2a3159818ba6691.tar.zst
go-tangerine-93f9c023ccda2256079484d6c2a3159818ba6691.zip
les: fixed selectPeer deadlock, improved request distribution
les/flowcontrol: using proper types for relative and absolute times
Diffstat (limited to 'les/odr.go')
-rw-r--r--les/odr.go10
1 files changed, 6 insertions, 4 deletions
diff --git a/les/odr.go b/les/odr.go
index 8878508c4..88c7d85a5 100644
--- a/les/odr.go
+++ b/les/odr.go
@@ -40,7 +40,7 @@ var (
type peerDropFn func(id string)
type odrPeerSelector interface {
- selectPeer(func(*peer) (bool, uint64)) *peer
+ selectPeerWait(uint64, func(*peer) (bool, time.Duration), <-chan struct{}) *peer
adjustResponseTime(*poolEntry, time.Duration, bool)
}
@@ -116,6 +116,7 @@ func (self *LesOdr) Deliver(peer *peer, msg *Msg) error {
if req.valFunc(self.db, msg) {
close(delivered)
req.lock.Lock()
+ delete(req.sentTo, peer)
if req.answered != nil {
close(req.answered)
req.answered = nil
@@ -150,6 +151,7 @@ func (self *LesOdr) requestPeer(req *sentReq, peer *peer, delivered, timeout cha
select {
case <-delivered:
case <-time.After(hardRequestTimeout):
+ glog.V(logger.Debug).Infof("ODR hard request timeout from peer %v", peer.id)
go self.removePeer(peer.id)
case <-self.stop:
return
@@ -187,12 +189,12 @@ func (self *LesOdr) networkRequest(ctx context.Context, lreq LesOdrRequest) erro
for {
var p *peer
if self.serverPool != nil {
- p = self.serverPool.selectPeer(func(p *peer) (bool, uint64) {
- if !lreq.CanSend(p) {
+ p = self.serverPool.selectPeerWait(reqID, func(p *peer) (bool, time.Duration) {
+ if _, ok := exclude[p]; ok || !lreq.CanSend(p) {
return false, 0
}
return true, p.fcServer.CanSend(lreq.GetCost(p))
- })
+ }, ctx.Done())
}
if p == nil {
select {