OSDN Git Service

Added configure API address and test ok.
authorgguoss <1536310027@qq.com>
Wed, 30 Aug 2017 02:46:19 +0000 (10:46 +0800)
committergguoss <1536310027@qq.com>
Wed, 30 Aug 2017 02:46:19 +0000 (10:46 +0800)
cmd/bytom/commands/run_node.go
config/config.go
config/toml.go
node/node.go

index e1891b3..68e1903 100644 (file)
@@ -29,7 +29,6 @@ func init() {
 }
 
 func runNode(cmd *cobra.Command, args []string) error {
-
        genDocFile := config.GenesisFile()
        if !cmn.FileExists(genDocFile) {
                logger.Info(cmn.Fmt("Waiting for genesis file %v...", genDocFile))
index ff7105d..11d9bb7 100644 (file)
@@ -82,6 +82,8 @@ type BaseConfig struct {
 
        // Database directory
        DBPath string `mapstructure:"db_dir"`
+
+       ApiAddress string `mapstructure:"api_addr"`
 }
 
 func DefaultBaseConfig() BaseConfig {
index 1976e69..50262aa 100644 (file)
@@ -32,6 +32,7 @@ moniker = "__MONIKER__"
 fast_sync = true
 db_backend = "leveldb"
 log_level = "state:info,*:info"
+api_addr = "0.0.0.0:1999"
 
 [rpc]
 laddr = "tcp://0.0.0.0:46657"
@@ -48,16 +49,14 @@ func defaultConfig(moniker string) string {
 /****** these are for test settings ***********/
 
 func ResetTestRoot(testName string) *Config {
-       rootDir := os.ExpandEnv("$HOME/.tendermint_test")
+       rootDir := os.ExpandEnv("$HOME/.test")
        rootDir = filepath.Join(rootDir, testName)
-       // Remove ~/.tendermint_test_bak
        if cmn.FileExists(rootDir + "_bak") {
                err := os.RemoveAll(rootDir + "_bak")
                if err != nil {
                        cmn.PanicSanity(err.Error())
                }
        }
-       // Move ~/.tendermint_test to ~/.tendermint_test_bak
        if cmn.FileExists(rootDir) {
                err := os.Rename(rootDir, rootDir+"_bak")
                if err != nil {
@@ -94,6 +93,7 @@ moniker = "__MONIKER__"
 fast_sync = false
 db_backend = "memdb"
 log_level = "info"
+api_addr = "0.0.0.0:1999"
 
 [rpc]
 laddr = "tcp://0.0.0.0:36657"
index a6ad390..e36b48b 100644 (file)
@@ -67,7 +67,6 @@ type Node struct {
 var (
     // config vars
        rootCAs       = env.String("ROOT_CA_CERTS", "") // file path
-       listenAddr    = env.String("LISTEN", ":1999")
        splunkAddr    = os.Getenv("SPLUNKADDR")
        logFile       = os.Getenv("LOGFILE")
        logSize       = env.Int("LOGSIZE", 5e6) // 5MB
@@ -117,7 +116,7 @@ func (wh *waitHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
        wh.h.ServeHTTP(w, req)
 }
 
-func rpcInit(h *bc.BlockchainReactor) {
+func rpcInit(h *bc.BlockchainReactor, config *cfg.Config) {
        // The waitHandler accepts incoming requests, but blocks until its underlying
        // handler is set, when the second phase is complete.
        var coreHandler waitHandler
@@ -145,6 +144,7 @@ func rpcInit(h *bc.BlockchainReactor) {
                // https://github.com/golang/go/issues/17071
                TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){},
        }
+       listenAddr := env.String("LISTEN", config.ApiAddress)
        listener, _ := net.Listen("tcp", *listenAddr)
 
        // The `Serve` call has to happen in its own goroutine because
@@ -209,7 +209,7 @@ func NewNode(config *cfg.Config, logger log.Logger) *Node {
     bcReactor.SetLogger(logger.With("module", "blockchain"))
     sw.AddReactor("BLOCKCHAIN", bcReactor)
 
-       rpcInit(bcReactor)
+       rpcInit(bcReactor, config)
        // Optionally, start the pex reactor
        var addrBook *p2p.AddrBook
        if config.P2P.PexReactor {