OSDN Git Service

Add RPC access auth config option on node start (#225)
authoryahtoo <yahtoo.ma@gmail.com>
Fri, 29 Dec 2017 07:45:57 +0000 (15:45 +0800)
committerPaladz <yzhu101@uottawa.ca>
Fri, 29 Dec 2017 07:45:57 +0000 (15:45 +0800)
cmd/bytomd/commands/run_node.go
config/config.go
node/node.go

index 835fe82..0d6302b 100755 (executable)
@@ -22,6 +22,8 @@ func init() {
        runNodeCmd.Flags().String("prof_laddr", config.ProfListenAddress, "Use http to profile bytomd programs")
        runNodeCmd.Flags().Bool("mining", config.Mining, "Enable mining")
 
+       runNodeCmd.Flags().Bool("auth.disable", config.Auth.Disable, "Disable rpc access authenticate")
+
        runNodeCmd.Flags().Bool("wallet.enable", config.Wallet.Enable, "Enable wallet")
 
        // p2p flags
index 54712c8..24dbb4a 100644 (file)
@@ -9,9 +9,10 @@ type Config struct {
        // Top level options use an anonymous struct
        BaseConfig `mapstructure:",squash"`
        // Options for services
-       RPC    *RPCConfig    `mapstructure:"rpc"`
-       P2P    *P2PConfig    `mapstructure:"p2p"`
-       Wallet *WalletConfig `mapstructure:"wallet"`
+       RPC    *RPCConfig     `mapstructure:"rpc"`
+       P2P    *P2PConfig     `mapstructure:"p2p"`
+       Wallet *WalletConfig  `mapstructure:"wallet"`
+       Auth   *RPCAuthConfig `mapstructure:"auth"`
 }
 
 func DefaultConfig() *Config {
@@ -20,6 +21,7 @@ func DefaultConfig() *Config {
                RPC:        DefaultRPCConfig(),
                P2P:        DefaultP2PConfig(),
                Wallet:     DefaultWalletConfig(),
+               Auth:       DefaultRPCAuthConfig(),
        }
 }
 
@@ -168,25 +170,25 @@ func TestRPCConfig() *RPCConfig {
 // P2PConfig
 
 type P2PConfig struct {
-       RootDir        string `mapstructure:"home"`
-       ListenAddress  string `mapstructure:"laddr"`
-       Seeds          string `mapstructure:"seeds"`
-       SkipUPNP       bool   `mapstructure:"skip_upnp"`
-       AddrBook       string `mapstructure:"addr_book_file"`
-       AddrBookStrict bool   `mapstructure:"addr_book_strict"`
-       PexReactor     bool   `mapstructure:"pex"`
-       MaxNumPeers    int    `mapstructure:"max_num_peers"`
-       HandshakeTimeout int `mapstructure:"handshake_timeout"`
-       DialTimeout      int `mapstructure:"dial_timeout"`
+       RootDir          string `mapstructure:"home"`
+       ListenAddress    string `mapstructure:"laddr"`
+       Seeds            string `mapstructure:"seeds"`
+       SkipUPNP         bool   `mapstructure:"skip_upnp"`
+       AddrBook         string `mapstructure:"addr_book_file"`
+       AddrBookStrict   bool   `mapstructure:"addr_book_strict"`
+       PexReactor       bool   `mapstructure:"pex"`
+       MaxNumPeers      int    `mapstructure:"max_num_peers"`
+       HandshakeTimeout int    `mapstructure:"handshake_timeout"`
+       DialTimeout      int    `mapstructure:"dial_timeout"`
 }
 
 func DefaultP2PConfig() *P2PConfig {
        return &P2PConfig{
-               ListenAddress:  "tcp://0.0.0.0:46656",
-               AddrBook:       "addrbook.json",
-               AddrBookStrict: true,
-               SkipUPNP:       false,
-               MaxNumPeers:    50,
+               ListenAddress:    "tcp://0.0.0.0:46656",
+               AddrBook:         "addrbook.json",
+               AddrBookStrict:   true,
+               SkipUPNP:         false,
+               MaxNumPeers:      50,
                HandshakeTimeout: 30,
                DialTimeout:      3,
        }
@@ -210,6 +212,16 @@ type WalletConfig struct {
        Enable bool `mapstructure:"enable"`
 }
 
+type RPCAuthConfig struct {
+       Disable bool `mapstructure:"disable"`
+}
+
+func DefaultRPCAuthConfig() *RPCAuthConfig {
+       return &RPCAuthConfig{
+               Disable: false,
+       }
+}
+
 func DefaultWalletConfig() *WalletConfig {
        return &WalletConfig{
                Enable: false,
index 4d984d6..ced1775 100755 (executable)
@@ -112,7 +112,10 @@ func rpcInit(h *bc.BlockchainReactor, config *cfg.Config, accessTokens *accessto
        mux.Handle("/", &coreHandler)
 
        var handler http.Handler = mux
-       handler = AuthHandler(handler, accessTokens)
+
+       if config.Auth.Disable == false {
+               handler = AuthHandler(handler, accessTokens)
+       }
        handler = RedirectHandler(handler)
 
        secureheader.DefaultConfig.PermitClearLoopback = true