Browse Source

allow multiple seed nodes

pull/61/head
Ethan Buchman 10 years ago
committed by Jae Kwon
parent
commit
9892dfd0b3
4 changed files with 32 additions and 7 deletions
  1. +1
    -1
      blockchain/pool.go
  2. +2
    -1
      blockchain/reactor.go
  3. +7
    -3
      config/config.go
  4. +22
    -2
      node/node.go

+ 1
- 1
blockchain/pool.go View File

@ -21,7 +21,7 @@ const (
// numTotal = numPending + blocks in the pool we havnt synced yet
var (
requestTimeoutSeconds = time.Duration(1)
requestTimeoutSeconds = time.Duration(3)
)
/*


+ 2
- 1
blockchain/reactor.go View File

@ -24,7 +24,8 @@ const (
trySyncIntervalMS = 100
// stop syncing when last block's time is
// within this much of the system time.
stopSyncingDurationMinutes = 10
// stopSyncingDurationMinutes = 10
// ask for best height every 10s
statusUpdateIntervalSeconds = 10
// check if we should switch to consensus reactor


+ 7
- 3
config/config.go View File

@ -39,7 +39,11 @@ Moniker = "anonymous"
Network = "tendermint_testnet3"
ListenAddr = "0.0.0.0:46656"
# First node to connect to. Command-line overridable.
SeedNode = "188.166.55.222:46656"
SeedNode = ""
# Pool of seeds. Best to use these, and specify one on command line
# if needed to override
SeedNodes = ["navytoad.chaintest.net:46656", "whiteferret.chaintest.net:46656", "magentagriffin.chaintest.net:46656", "greensalamander.chaintest.net:46656", "blackshadow.chaintest.net:46656", "purpleanteater.chaintest.net:46656", "pinkpenguin.chaintest.net:46656", "polkapig.chaintest.net:46656", "128.199.230.153:8080"]
[DB]
# The only other available backend is "memdb"
@ -153,7 +157,7 @@ func Init(rootDir string) {
}
// Confused?
// app.Debug()
//app.Debug()
}
// Check if a file exists; if not, ensure the directory is made and write the file
@ -182,7 +186,7 @@ func ParseFlags(args []string) {
// Declare flags
flags.BoolVar(&printHelp, "help", false, "Print this help message.")
flags.String("listen_addr", app.GetString("ListenAddr"), "Listen address. (0.0.0.0:0 means any interface, any port)")
flags.String("seed_node", app.GetString("SeedNode"), "Address of seed node")
flags.String("seed_node", app.GetString("SeedNode"), "Address of seed nodes")
flags.String("rpc_http_listen_addr", app.GetString("RPC.HTTP.ListenAddr"), "RPC listen address. Port required")
flags.Bool("fast_sync", app.GetBool("FastSync"), "Fast blockchain syncing")
flags.String("log_stdout_level", app.GetString("Log.Stdout.Level"), "Stdout log level")


+ 22
- 2
node/node.go View File

@ -1,6 +1,7 @@
package node
import (
"math/rand"
"net"
"net/http"
"os"
@ -143,7 +144,26 @@ func (n *Node) AddListener(l p2p.Listener) {
}
func (n *Node) DialSeed() {
addr := p2p.NewNetAddressString(config.App().GetString("SeedNode"))
// if the single seed node is available, use only it
prioritySeed := config.App().GetString("SeedNode")
if prioritySeed != "" {
addr := p2p.NewNetAddressString(prioritySeed)
n.dialSeed(addr)
return
}
// permute the list, dial half of them
seeds := config.App().GetStringSlice("SeedNodes")
perm := rand.Perm(len(seeds))
// TODO: we shouldn't necessarily connect to all of them every time ...
for i := 0; i < len(perm); i++ {
j := perm[i]
addr := p2p.NewNetAddressString(seeds[j])
n.dialSeed(addr)
}
}
func (n *Node) dialSeed(addr *p2p.NetAddress) {
peer, err := n.sw.DialPeerWithAddress(addr)
if err != nil {
log.Error("Error dialing seed", "error", err)
@ -221,7 +241,7 @@ func RunNode() {
n.Start()
// If seedNode is provided by config, dial out.
if config.App().GetString("SeedNode") != "" {
if config.App().GetString("SeedNode") != "" || len(config.App().GetStringSlice("SeedNodes")) != 0 {
n.DialSeed()
}


Loading…
Cancel
Save