DialSeeds takes an AddrBook
This commit is contained in:
parent
cfc7fed31c
commit
1208296dc0
|
@ -1,5 +1,5 @@
|
||||||
hash: 41f8fec708e98b7f8c4804be46008493199fa45e89b2d5dc237fd65fe431c62f
|
hash: 41f8fec708e98b7f8c4804be46008493199fa45e89b2d5dc237fd65fe431c62f
|
||||||
updated: 2017-03-05T00:18:48.136517571-05:00
|
updated: 2017-03-05T22:59:46.61454297-05:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/btcsuite/btcd
|
- name: github.com/btcsuite/btcd
|
||||||
version: d06c0bb181529331be8f8d9350288c420d9e60e4
|
version: d06c0bb181529331be8f8d9350288c420d9e60e4
|
||||||
|
@ -101,7 +101,7 @@ imports:
|
||||||
- name: github.com/tendermint/go-merkle
|
- name: github.com/tendermint/go-merkle
|
||||||
version: 714d4d04557fd068a7c2a1748241ce8428015a96
|
version: 714d4d04557fd068a7c2a1748241ce8428015a96
|
||||||
- name: github.com/tendermint/go-p2p
|
- name: github.com/tendermint/go-p2p
|
||||||
version: 56eebb95eede5f7cf742ecaefa83bed884df99ec
|
version: beb3eda438fbbfc3b566ead4be5705474a12e50a
|
||||||
subpackages:
|
subpackages:
|
||||||
- upnp
|
- upnp
|
||||||
- name: github.com/tendermint/go-rpc
|
- name: github.com/tendermint/go-rpc
|
||||||
|
|
42
node/node.go
42
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 seeds exist, add them to the address book and dial out
|
||||||
if n.config.GetString("seeds") != "" {
|
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
|
// 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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,13 +230,6 @@ func (n *Node) OnStart() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) RunForever() {
|
|
||||||
// Sleep forever and then...
|
|
||||||
cmn.TrapSignal(func() {
|
|
||||||
n.Stop()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *Node) OnStop() {
|
func (n *Node) OnStop() {
|
||||||
n.BaseService.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.
|
// Add the event switch to reactors, mempool, etc.
|
||||||
func SetEventSwitch(evsw types.EventSwitch, eventables ...types.Eventable) {
|
func SetEventSwitch(evsw types.EventSwitch, eventables ...types.Eventable) {
|
||||||
for _, e := range eventables {
|
for _, e := range eventables {
|
||||||
|
@ -296,6 +277,7 @@ func (n *Node) ConfigureRPC() {
|
||||||
rpccore.SetSwitch(n.sw)
|
rpccore.SetSwitch(n.sw)
|
||||||
rpccore.SetPubKey(n.privValidator.PubKey)
|
rpccore.SetPubKey(n.privValidator.PubKey)
|
||||||
rpccore.SetGenesisDoc(n.genesisDoc)
|
rpccore.SetGenesisDoc(n.genesisDoc)
|
||||||
|
rpccore.SetAddrBook(n.addrBook)
|
||||||
rpccore.SetProxyAppQuery(n.proxyApp.Query())
|
rpccore.SetProxyAppQuery(n.proxyApp.Query())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,8 +392,8 @@ func (n *Node) NodeInfo() *p2p.NodeInfo {
|
||||||
return n.sw.NodeInfo()
|
return n.sw.NodeInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) DialSeeds(seeds []string) {
|
func (n *Node) DialSeeds(seeds []string) error {
|
||||||
n.sw.DialSeeds(seeds)
|
return n.sw.DialSeeds(n.addrBook, seeds)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defaults to tcp
|
// Defaults to tcp
|
||||||
|
|
|
@ -32,7 +32,8 @@ func NetInfo() (*ctypes.ResultNetInfo, error) {
|
||||||
// Dial given list of seeds
|
// Dial given list of seeds
|
||||||
func UnsafeDialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
|
func UnsafeDialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
|
||||||
// starts go routines to dial each seed after random delays
|
// 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
|
return &ctypes.ResultDialSeeds{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ type P2P interface {
|
||||||
NumPeers() (outbound, inbound, dialig int)
|
NumPeers() (outbound, inbound, dialig int)
|
||||||
NodeInfo() *p2p.NodeInfo
|
NodeInfo() *p2p.NodeInfo
|
||||||
IsListening() bool
|
IsListening() bool
|
||||||
DialSeeds([]string) error
|
DialSeeds(*p2p.AddrBook, []string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
|
@ -42,8 +42,9 @@ var (
|
||||||
p2pSwitch P2P
|
p2pSwitch P2P
|
||||||
|
|
||||||
// objects
|
// objects
|
||||||
pubKey crypto.PubKey
|
pubKey crypto.PubKey
|
||||||
genDoc *types.GenesisDoc // cache the genesis structure
|
genDoc *types.GenesisDoc // cache the genesis structure
|
||||||
|
addrBook *p2p.AddrBook
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetConfig(c cfg.Config) {
|
func SetConfig(c cfg.Config) {
|
||||||
|
@ -78,6 +79,10 @@ func SetGenesisDoc(doc *types.GenesisDoc) {
|
||||||
genDoc = doc
|
genDoc = doc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetAddrBook(book *p2p.AddrBook) {
|
||||||
|
addrBook = book
|
||||||
|
}
|
||||||
|
|
||||||
func SetProxyAppQuery(appConn proxy.AppConnQuery) {
|
func SetProxyAppQuery(appConn proxy.AppConnQuery) {
|
||||||
proxyAppQuery = appConn
|
proxyAppQuery = appConn
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue