Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2p: dial using node iterator #20132

Merged
merged 17 commits into from
Oct 29, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions p2p/enode/iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
karalabe marked this conversation as resolved.
Show resolved Hide resolved
return m.nextFromAny()
fjl marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down