Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (s *Ethereum) setupDiscovery() error {
if err != nil {
return err
}
s.discmix.AddSource(iter)
s.discmix.AddSource(iter, "DNSdiscEth")
}

// Add snap nodes from DNS.
Expand All @@ -487,14 +487,14 @@ func (s *Ethereum) setupDiscovery() error {
if err != nil {
return err
}
s.discmix.AddSource(iter)
s.discmix.AddSource(iter, "DNSdiscSnap")
}

// Add DHT nodes from discv5.
if s.p2pServer.DiscoveryV5() != nil {
filter := eth.NewNodeFilter(s.blockchain)
iter := enode.Filter(s.p2pServer.DiscoveryV5().RandomNodes(), filter)
s.discmix.AddSource(iter)
s.discmix.AddSource(iter, "DiscoveryV5")
}

return nil
Expand Down
8 changes: 6 additions & 2 deletions p2p/enode/iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ type mixSource struct {
it Iterator
next chan *Node
timeout time.Duration
name string
}

// NewFairMix creates a mixer.
Expand All @@ -167,15 +168,18 @@ func NewFairMix(timeout time.Duration) *FairMix {
}

// AddSource adds a source of nodes.
func (m *FairMix) AddSource(it Iterator) {
func (m *FairMix) AddSource(it Iterator, name ...string) {
m.mu.Lock()
defer m.mu.Unlock()

if m.closed == nil {
return
}
m.wg.Add(1)
source := &mixSource{it, make(chan *Node), m.timeout}
source := &mixSource{it, make(chan *Node), m.timeout, ""}
if len(name) > 0 {
source.name = name[0]
}
m.sources = append(m.sources, source)
go m.runSource(m.closed, source)
}
Expand Down
6 changes: 3 additions & 3 deletions p2p/enode/iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ func TestFairMix(t *testing.T) {

func testMixerFairness(t *testing.T) {
mix := NewFairMix(1 * time.Second)
mix.AddSource(&genIter{index: 1})
mix.AddSource(&genIter{index: 2})
mix.AddSource(&genIter{index: 3})
mix.AddSource(&genIter{index: 1}, "1")
mix.AddSource(&genIter{index: 2}, "2")
mix.AddSource(&genIter{index: 3}, "3")
defer mix.Close()

nodes := ReadNodes(mix, 500)
Expand Down
4 changes: 2 additions & 2 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func (srv *Server) setupDiscovery() error {
return err
}
srv.discv4 = ntab
srv.discmix.AddSource(ntab.RandomNodes())
srv.discmix.AddSource(ntab.RandomNodes(), "DiscoveryV4")
}
if srv.Config.DiscoveryV5 {
cfg := discover.Config{
Expand All @@ -498,7 +498,7 @@ func (srv *Server) setupDiscovery() error {
added := make(map[string]bool)
for _, proto := range srv.Protocols {
if proto.DialCandidates != nil && !added[proto.Name] {
srv.discmix.AddSource(proto.DialCandidates)
srv.discmix.AddSource(proto.DialCandidates, "DialCandidates-"+proto.Name)
added[proto.Name] = true
}
}
Expand Down