mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
p2p/enode: implement dynamic FairMix timeouts
This commit is contained in:
parent
70360e25fe
commit
4387dcd2a8
1 changed files with 6 additions and 3 deletions
|
|
@ -144,8 +144,9 @@ type FairMix struct {
|
|||
}
|
||||
|
||||
type mixSource struct {
|
||||
it Iterator
|
||||
next chan *Node
|
||||
it Iterator
|
||||
next chan *Node
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
// NewFairMix creates a mixer.
|
||||
|
|
@ -172,7 +173,7 @@ func (m *FairMix) AddSource(it Iterator) {
|
|||
return
|
||||
}
|
||||
m.wg.Add(1)
|
||||
source := &mixSource{it, make(chan *Node)}
|
||||
source := &mixSource{it, make(chan *Node), m.timeout}
|
||||
m.sources = append(m.sources, source)
|
||||
go m.runSource(m.closed, source)
|
||||
}
|
||||
|
|
@ -215,11 +216,13 @@ func (m *FairMix) Next() bool {
|
|||
case n, ok := <-source.next:
|
||||
if ok {
|
||||
m.cur = n
|
||||
source.timeout = m.timeout
|
||||
return true
|
||||
}
|
||||
// This source has ended.
|
||||
m.deleteSource(source)
|
||||
case <-timeout:
|
||||
source.timeout /= 2
|
||||
return m.nextFromAny()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue