mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
try to connect through addrbook before requesting peers from seeds
we only use seeds if we can’t connect to peers in the addrbook. Refs #864
This commit is contained in:
parent
c521f385a6
commit
179d6062e4
36
node/node.go
36
node/node.go
@ -8,6 +8,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
abci "github.com/tendermint/abci/types"
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
@ -379,19 +380,42 @@ func (n *Node) OnStart() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// If seeds exist, add them to the address book and dial out
|
||||
if n.config.P2P.Seeds != "" {
|
||||
// dial out
|
||||
seeds := strings.Split(n.config.P2P.Seeds, ",")
|
||||
if err := n.DialSeeds(seeds); err != nil {
|
||||
err = n.dialSeedsIfAddrBookIsEmptyOrPEXFailedToConnect()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// start tx indexer
|
||||
return n.indexerService.Start()
|
||||
}
|
||||
|
||||
func (n *Node) dialSeedsIfAddrBookIsEmptyOrPEXFailedToConnect() error {
|
||||
if n.config.P2P.Seeds == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
seeds := strings.Split(n.config.P2P.Seeds, ",")
|
||||
|
||||
// prefer peers from address book
|
||||
if n.config.P2P.PexReactor && n.addrBook.Size() > 0 {
|
||||
// give some time to PexReactor to connect us to other peers
|
||||
const fallbackToSeedsAfterSec = 30 * time.Second
|
||||
go func() {
|
||||
time.Sleep(fallbackToSeedsAfterSec)
|
||||
// fallback to dialing seeds if for some reason we can't connect to any
|
||||
// peers
|
||||
outbound, inbound, _ := n.sw.NumPeers()
|
||||
if n.IsRunning() && outbound+inbound == 0 {
|
||||
n.DialSeeds(seeds)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
// add seeds to the address book and dial out
|
||||
return n.DialSeeds(seeds)
|
||||
}
|
||||
|
||||
// OnStop stops the Node. It implements cmn.Service.
|
||||
func (n *Node) OnStop() {
|
||||
n.BaseService.OnStop()
|
||||
|
Loading…
x
Reference in New Issue
Block a user