Browse Source

DialSeeds takes an AddrBook

pull/426/head
Ethan Buchman 7 years ago
parent
commit
1208296dc0
4 changed files with 24 additions and 36 deletions
  1. +2
    -2
      glide.lock
  2. +12
    -30
      node/node.go
  3. +2
    -1
      rpc/core/net.go
  4. +8
    -3
      rpc/core/pipe.go

+ 2
- 2
glide.lock View File

@ -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


+ 12
- 30
node/node.go View File

@ -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


+ 2
- 1
rpc/core/net.go View File

@ -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
}


+ 8
- 3
rpc/core/pipe.go View File

@ -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
}

Loading…
Cancel
Save