Browse Source

p2p/pex: consult seeds in crawlPeersRoutine (#3647)

* p2p/pex: consult seeds in crawlPeersRoutine

This changeset alters the startup behavior for crawlPeersRoutine. Previously
the routine would crawl a random selection of peers on startup. For a
new seed node, there are no peers. As a result, new seed nodes are unable
to bootstrap themselves with a list of peers until another node with a list
of peers connects to the seed. If this node relies on the seed node for peers,
then the two will not discover more peers.

This changeset makes the startup behavior for crawlPeersRoutine connect to
any seed nodes. Upon connecting, a request for peers will be sent to the seed node
thus helping bootstrap our seed node.

* p2p/pex: Adjust error message for no peers

Co-Authored-By: Ethan Buchman <ethan@coinculture.info>
pull/3675/head
Roman Shtylman 5 years ago
committed by Ethan Buchman
parent
commit
f1f243d749
1 changed files with 9 additions and 4 deletions
  1. +9
    -4
      p2p/pex/pex_reactor.go

+ 9
- 4
p2p/pex/pex_reactor.go View File

@ -145,7 +145,7 @@ func (r *PEXReactor) OnStart() error {
if err != nil {
return err
} else if numOnline == 0 && r.book.Empty() {
return errors.New("Address book is empty, and could not connect to any seed nodes")
return errors.New("Address book is empty and couldn't resolve any seed nodes")
}
r.seedAddrs = seedAddrs
@ -573,7 +573,7 @@ func (r *PEXReactor) checkSeeds() (numOnline int, netAddrs []*p2p.NetAddress, er
return 0, nil, errors.Wrap(e, "seed node configuration has error")
}
}
return
return numOnline, netAddrs, nil
}
// randomly dial seeds until we connect to one or exhaust them
@ -608,8 +608,13 @@ func (r *PEXReactor) AttemptsToDial(addr *p2p.NetAddress) int {
// Seed/Crawler Mode causes this node to quickly disconnect
// from peers, except other seed nodes.
func (r *PEXReactor) crawlPeersRoutine() {
// Do an initial crawl
r.crawlPeers(r.book.GetSelection())
// If we have any seed nodes, consult them first
if len(r.seedAddrs) > 0 {
r.dialSeeds()
} else {
// Do an initial crawl
r.crawlPeers(r.book.GetSelection())
}
// Fire periodically
ticker := time.NewTicker(crawlPeerPeriod)


Loading…
Cancel
Save