Skip to content

p2p: make dial faster by streamlined discovery process #31678

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

Closed
wants to merge 17 commits into from
Closed
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
Prev Previous commit
Next Next commit
p2p/enode: closed channel not needed in bufferIter
Signed-off-by: Csaba Kiraly <[email protected]>
  • Loading branch information
cskiraly committed Jun 1, 2025
commit 2a9b0605ee00e21a7fc06b99a9e43e20b88ad48f
16 changes: 2 additions & 14 deletions p2p/enode/iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ type BufferIter struct {
it Iterator
buffer chan *Node
head *Node
closed chan struct{}
closeOnce sync.Once
}

Expand All @@ -247,31 +246,21 @@ func NewBufferIter(it Iterator, size int) Iterator {
b := BufferIter{
it: it,
buffer: make(chan *Node, size),
head: nil,
closed: make(chan struct{}),
}

go func() {
// if the wrapped iterator ends, the buffer content will still be served.
defer close(b.buffer)
// If instead the bufferIterator is closed, we bail out of the loop.
for b.it.Next() {
select {
case b.buffer <- b.it.Node():
case <-b.closed:
return
}
b.buffer <- b.it.Node()
}
}()
return &b
}

func (b *BufferIter) Next() bool {
select {
case b.head = <-b.buffer:
case <-b.closed:
b.head = nil
}
b.head = <-b.buffer
return b.head != nil
}

Expand All @@ -282,7 +271,6 @@ func (b *BufferIter) Node() *Node {
func (b *BufferIter) Close() {
b.closeOnce.Do(func() {
b.it.Close()
close(b.closed)
// Wait for Next to terminate.
for range b.buffer {
}
Expand Down