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
|
|
@ -146,6 +146,7 @@ type FairMix struct {
|
||||||
type mixSource struct {
|
type mixSource struct {
|
||||||
it Iterator
|
it Iterator
|
||||||
next chan *Node
|
next chan *Node
|
||||||
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFairMix creates a mixer.
|
// NewFairMix creates a mixer.
|
||||||
|
|
@ -172,7 +173,7 @@ func (m *FairMix) AddSource(it Iterator) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.wg.Add(1)
|
m.wg.Add(1)
|
||||||
source := &mixSource{it, make(chan *Node)}
|
source := &mixSource{it, make(chan *Node), m.timeout}
|
||||||
m.sources = append(m.sources, source)
|
m.sources = append(m.sources, source)
|
||||||
go m.runSource(m.closed, source)
|
go m.runSource(m.closed, source)
|
||||||
}
|
}
|
||||||
|
|
@ -215,11 +216,13 @@ func (m *FairMix) Next() bool {
|
||||||
case n, ok := <-source.next:
|
case n, ok := <-source.next:
|
||||||
if ok {
|
if ok {
|
||||||
m.cur = n
|
m.cur = n
|
||||||
|
source.timeout = m.timeout
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// This source has ended.
|
// This source has ended.
|
||||||
m.deleteSource(source)
|
m.deleteSource(source)
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
|
source.timeout /= 2
|
||||||
return m.nextFromAny()
|
return m.nextFromAny()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue