OSDN Git Service

Support custom node alias (#1677)
authoryahtoo <yahtoo.ma@gmail.com>
Mon, 8 Apr 2019 07:35:11 +0000 (15:35 +0800)
committerPaladz <yzhu101@uottawa.ca>
Mon, 8 Apr 2019 07:35:11 +0000 (15:35 +0800)
* Support custom node alias

* fix review bug

config/config.go
config/toml.go
p2p/node_info.go

index 4e66838..03829b8 100644 (file)
@@ -87,6 +87,9 @@ type BaseConfig struct {
        // This should be set in viper so it can unmarshal into this struct
        RootDir string `mapstructure:"home"`
 
+       //The alias of the node
+       NodeAlias string `mapstructure:"node_alias"`
+
        //The ID of the network to json
        ChainID string `mapstructure:"chain_id"`
 
@@ -127,6 +130,7 @@ func DefaultBaseConfig() BaseConfig {
                DBBackend:         "leveldb",
                DBPath:            "data",
                KeysPath:          "keystore",
+               NodeAlias:         "",
        }
 }
 
index 6ecce31..f056b56 100644 (file)
@@ -24,6 +24,7 @@ var defaultConfigTmpl = `# This is a TOML config file.
 fast_sync = true
 db_backend = "leveldb"
 api_addr = "0.0.0.0:9888"
+node_alias = ""
 `
 
 var mainNetConfigTmpl = `chain_id = "mainnet"
index 0c19110..a04c617 100644 (file)
@@ -22,17 +22,23 @@ type NodeInfo struct {
        RemoteAddr string               `json:"remote_addr"`
        ListenAddr string               `json:"listen_addr"`
        Version    string               `json:"version"` // major.minor.revision
-       Other      []string             `json:"other"`   // other application specific data
+       // other application specific data
+       //field 0: node service flags. field 1: node alias.
+       Other []string `json:"other"`
 }
 
 func NewNodeInfo(config *cfg.Config, pubkey crypto.PubKeyEd25519, listenAddr string) *NodeInfo {
+       other := []string{strconv.FormatUint(uint64(consensus.DefaultServices), 10)}
+       if config.NodeAlias != "" {
+               other = append(other, config.NodeAlias)
+       }
        return &NodeInfo{
                PubKey:     pubkey,
                Moniker:    config.Moniker,
                Network:    config.ChainID,
                ListenAddr: listenAddr,
                Version:    version.Version,
-               Other:      []string{strconv.FormatUint(uint64(consensus.DefaultServices), 10)},
+               Other:      other,
        }
 }