From 1208296dc0d1338359fc1a64ab5c47a3e894afd6 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 5 Mar 2017 23:13:34 -0500 Subject: [PATCH] DialSeeds takes an AddrBook --- glide.lock | 4 ++-- node/node.go | 42 ++++++++++++------------------------------ rpc/core/net.go | 3 ++- rpc/core/pipe.go | 11 ++++++++--- 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/glide.lock b/glide.lock index a3ce63dd8..216871f8c 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ hash: 41f8fec708e98b7f8c4804be46008493199fa45e89b2d5dc237fd65fe431c62f -updated: 2017-03-05T00:18:48.136517571-05:00 +updated: 2017-03-05T22:59:46.61454297-05:00 imports: - name: github.com/btcsuite/btcd version: d06c0bb181529331be8f8d9350288c420d9e60e4 @@ -101,7 +101,7 @@ imports: - name: github.com/tendermint/go-merkle version: 714d4d04557fd068a7c2a1748241ce8428015a96 - name: github.com/tendermint/go-p2p - version: 56eebb95eede5f7cf742ecaefa83bed884df99ec + version: beb3eda438fbbfc3b566ead4be5705474a12e50a subpackages: - upnp - name: github.com/tendermint/go-rpc diff --git a/node/node.go b/node/node.go index 2e8177661..f9c69c289 100644 --- a/node/node.go +++ b/node/node.go @@ -211,28 +211,9 @@ func (n *Node) OnStart() error { // If seeds exist, add them to the address book and dial out if n.config.GetString("seeds") != "" { - seeds := strings.Split(n.config.GetString("seeds"), ",") - - if n.config.GetBool("pex_reactor") { - // add seeds to `addrBook` to avoid losing - ourAddrS := n.NodeInfo().ListenAddr - ourAddr, _ := p2p.NewNetAddressString(ourAddrS) - for _, s := range seeds { - // do not add ourselves - if s == ourAddrS { - continue - } - - addr, err := p2p.NewNetAddressString(s) - if err != nil { - n.addrBook.AddAddress(addr, ourAddr) - } - } - n.addrBook.Save() - } - // dial out - if err := n.sw.DialSeeds(seeds); err != nil { + seeds := strings.Split(n.config.GetString("seeds"), ",") + if err := n.DialSeeds(seeds); err != nil { return err } } @@ -249,13 +230,6 @@ func (n *Node) OnStart() error { return nil } -func (n *Node) RunForever() { - // Sleep forever and then... - cmn.TrapSignal(func() { - n.Stop() - }) -} - func (n *Node) OnStop() { n.BaseService.OnStop() @@ -271,6 +245,13 @@ func (n *Node) OnStop() { } } +func (n *Node) RunForever() { + // Sleep forever and then... + cmn.TrapSignal(func() { + n.Stop() + }) +} + // Add the event switch to reactors, mempool, etc. func SetEventSwitch(evsw types.EventSwitch, eventables ...types.Eventable) { for _, e := range eventables { @@ -296,6 +277,7 @@ func (n *Node) ConfigureRPC() { rpccore.SetSwitch(n.sw) rpccore.SetPubKey(n.privValidator.PubKey) rpccore.SetGenesisDoc(n.genesisDoc) + rpccore.SetAddrBook(n.addrBook) rpccore.SetProxyAppQuery(n.proxyApp.Query()) } @@ -410,8 +392,8 @@ func (n *Node) NodeInfo() *p2p.NodeInfo { return n.sw.NodeInfo() } -func (n *Node) DialSeeds(seeds []string) { - n.sw.DialSeeds(seeds) +func (n *Node) DialSeeds(seeds []string) error { + return n.sw.DialSeeds(n.addrBook, seeds) } // Defaults to tcp diff --git a/rpc/core/net.go b/rpc/core/net.go index 3e9526d28..df491ba80 100644 --- a/rpc/core/net.go +++ b/rpc/core/net.go @@ -32,7 +32,8 @@ func NetInfo() (*ctypes.ResultNetInfo, error) { // Dial given list of seeds func UnsafeDialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) { // starts go routines to dial each seed after random delays - err := p2pSwitch.DialSeeds(seeds) + log.Info("DialSeeds", "addrBook", addrBook, "seeds", seeds) + err := p2pSwitch.DialSeeds(addrBook, seeds) return &ctypes.ResultDialSeeds{}, err } diff --git a/rpc/core/pipe.go b/rpc/core/pipe.go index fae2630cb..123b13dd8 100644 --- a/rpc/core/pipe.go +++ b/rpc/core/pipe.go @@ -24,7 +24,7 @@ type P2P interface { NumPeers() (outbound, inbound, dialig int) NodeInfo() *p2p.NodeInfo IsListening() bool - DialSeeds([]string) error + DialSeeds(*p2p.AddrBook, []string) error } //---------------------------------------------- @@ -42,8 +42,9 @@ var ( p2pSwitch P2P // objects - pubKey crypto.PubKey - genDoc *types.GenesisDoc // cache the genesis structure + pubKey crypto.PubKey + genDoc *types.GenesisDoc // cache the genesis structure + addrBook *p2p.AddrBook ) func SetConfig(c cfg.Config) { @@ -78,6 +79,10 @@ func SetGenesisDoc(doc *types.GenesisDoc) { genDoc = doc } +func SetAddrBook(book *p2p.AddrBook) { + addrBook = book +} + func SetProxyAppQuery(appConn proxy.AppConnQuery) { proxyAppQuery = appConn }