diff --git a/addrmanager.go b/addrmanager.go index 3a90fa4c..d50c88c5 100644 --- a/addrmanager.go +++ b/addrmanager.go @@ -144,8 +144,8 @@ func chance(ka *knownAddress) float64 { c := 1.0 now := time.Now() - var lastSeen float64 = 0.0 - var lastTry float64 = 0.0 + var lastSeen float64 + var lastTry float64 if !ka.na.Timestamp.After(now) { var dur time.Duration if ka.na.Timestamp.IsZero() { @@ -462,7 +462,7 @@ func (a *AddrManager) AddressCacheFlat() []string { a.mtx.Lock() defer a.mtx.Unlock() - for k, _ := range a.addrNew { + for k := range a.addrNew { allAddr = append(allAddr, k) } diff --git a/btcd.go b/btcd.go index e04e67e0..c3da510d 100644 --- a/btcd.go +++ b/btcd.go @@ -25,7 +25,7 @@ const ( ) var ( - log seelog.LoggerInterface = seelog.Disabled + log = seelog.Disabled cfg *config ) diff --git a/config.go b/config.go index 125d6584..5b782ff2 100644 --- a/config.go +++ b/config.go @@ -5,7 +5,6 @@ package main import ( - "errors" "fmt" "github.com/conformal/btcdb" _ "github.com/conformal/btcdb/ldb" @@ -51,10 +50,10 @@ type config struct { MaxPeers int `long:"maxpeers" description:"Max number of inbound and outbound peers"` BanDuration time.Duration `long:"banduration" description:"How long to ban misbehaving peers. Valid time units are {s, m, h}. Minimum 1 second"` VerifyDisabled bool `long:"noverify" description:"Disable block/transaction verification -- WARNING: This option can be dangerous and is for development use only"` - RpcUser string `short:"u" long:"rpcuser" description:"Username for RPC connections"` - RpcPass string `short:"P" long:"rpcpass" description:"Password for RPC connections"` - RpcPort string `short:"r" long:"rpcport" description:"Listen for JSON/RPC messages on this port"` - DisableRpc bool `long:"norpc" description:"Disable built-in RPC server -- NOTE: The RPC server is disabled by default if no rpcuser/rpcpass is specified"` + RPCUser string `short:"u" long:"rpcuser" description:"Username for RPC connections"` + RPCPass string `short:"P" long:"rpcpass" description:"Password for RPC connections"` + RPCPort string `short:"r" long:"rpcport" description:"Listen for JSON/RPC messages on this port"` + DisableRPC bool `long:"norpc" description:"Disable built-in RPC server -- NOTE: The RPC server is disabled by default if no rpcuser/rpcpass is specified"` DisableDNSSeed bool `long:"nodnsseed" description:"Disable DNS seeding for peers"` Proxy string `long:"proxy" description:"Connect via SOCKS5 proxy (eg. 127.0.0.1:9050)"` ProxyUser string `long:"proxyuser" description:"Username for proxy server"` @@ -173,8 +172,8 @@ func updateConfigWithActiveParams(cfg *config) { cfg.Port = activeNetParams.listenPort } - if cfg.RpcPort == netParams(defaultBtcnet).rpcPort { - cfg.RpcPort = activeNetParams.rpcPort + if cfg.RPCPort == netParams(defaultBtcnet).rpcPort { + cfg.RPCPort = activeNetParams.rpcPort } } @@ -205,7 +204,7 @@ func loadConfig() (*config, []string, error) { cfg := config{ DebugLevel: defaultLogLevel, Port: netParams(defaultBtcnet).listenPort, - RpcPort: netParams(defaultBtcnet).rpcPort, + RPCPort: netParams(defaultBtcnet).rpcPort, MaxPeers: defaultMaxPeers, BanDuration: defaultBanDuration, ConfigFile: defaultConfigFile, @@ -263,7 +262,7 @@ func loadConfig() (*config, []string, error) { if cfg.TestNet3 && cfg.RegressionTest { str := "%s: The testnet and regtest params can't be used " + "together -- choose one of the two" - err := errors.New(fmt.Sprintf(str, "loadConfig")) + err := fmt.Errorf(str, "loadConfig") fmt.Fprintln(os.Stderr, err) parser.WriteHelp(os.Stderr) return nil, nil, err @@ -281,7 +280,7 @@ func loadConfig() (*config, []string, error) { // Validate debug log level. if !validLogLevel(cfg.DebugLevel) { str := "%s: The specified debug level [%v] is invalid" - err := errors.New(fmt.Sprintf(str, "loadConfig", cfg.DebugLevel)) + err := fmt.Errorf(str, "loadConfig", cfg.DebugLevel) fmt.Fprintln(os.Stderr, err) parser.WriteHelp(os.Stderr) return nil, nil, err @@ -291,8 +290,7 @@ func loadConfig() (*config, []string, error) { if !validDbType(cfg.DbType) { str := "%s: The specified database type [%v] is invalid -- " + "supported types %v" - err := errors.New(fmt.Sprintf(str, "loadConfig", cfg.DbType, - knownDbTypes)) + err := fmt.Errorf(str, "loadConfig", cfg.DbType, knownDbTypes) fmt.Fprintln(os.Stderr, err) parser.WriteHelp(os.Stderr) return nil, nil, err @@ -303,7 +301,7 @@ func loadConfig() (*config, []string, error) { profilePort, err := strconv.Atoi(cfg.Profile) if err != nil || profilePort < 1024 || profilePort > 65535 { str := "%s: The profile port must be between 1024 and 65535" - err := errors.New(fmt.Sprintf(str, "loadConfig")) + err := fmt.Errorf(str, "loadConfig") fmt.Fprintln(os.Stderr, err) parser.WriteHelp(os.Stderr) return nil, nil, err @@ -322,7 +320,7 @@ func loadConfig() (*config, []string, error) { // Don't allow ban durations that are too short. if cfg.BanDuration < time.Duration(time.Second) { str := "%s: The banduration option may not be less than 1s -- parsed [%v]" - err := errors.New(fmt.Sprintf(str, "loadConfig", cfg.BanDuration)) + err := fmt.Errorf(str, "loadConfig", cfg.BanDuration) fmt.Fprintln(os.Stderr, err) parser.WriteHelp(os.Stderr) return nil, nil, err @@ -332,7 +330,7 @@ func loadConfig() (*config, []string, error) { if len(cfg.AddPeers) > 0 && len(cfg.ConnectPeers) > 0 { str := "%s: the --addpeer and --connect options can not be " + "mixed" - err := errors.New(fmt.Sprintf(str, "loadConfig")) + err := fmt.Errorf(str, "loadConfig") fmt.Fprintln(os.Stderr, err) parser.WriteHelp(os.Stderr) return nil, nil, err @@ -341,7 +339,7 @@ func loadConfig() (*config, []string, error) { // --tor requires --proxy to be set. if cfg.UseTor && cfg.Proxy == "" { str := "%s: the --tor option requires --proxy to be set" - err := errors.New(fmt.Sprintf(str, "loadConfig")) + err := fmt.Errorf(str, "loadConfig") fmt.Fprintln(os.Stderr, err) parser.WriteHelp(os.Stderr) return nil, nil, err @@ -359,8 +357,8 @@ func loadConfig() (*config, []string, error) { } // The RPC server is disabled if no username or password is provided. - if cfg.RpcUser == "" || cfg.RpcPass == "" { - cfg.DisableRpc = true + if cfg.RPCUser == "" || cfg.RPCPass == "" { + cfg.DisableRPC = true } // Add default port to all added peer addresses if needed and remove diff --git a/rpcserver.go b/rpcserver.go index d4552730..5bf44052 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -40,7 +40,7 @@ func (s *rpcServer) Start() { log.Trace("[RPCS] Starting RPC server") http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - jsonRpcRead(w, r, s) + jsonRPCRead(w, r, s) }) httpServer := &http.Server{} for _, listener := range s.listeners { @@ -75,15 +75,15 @@ func (s *rpcServer) Stop() error { return nil } -// newRpcServer returns a new instance of the rpcServer struct. -func newRpcServer(s *server) (*rpcServer, error) { +// newRPCServer returns a new instance of the rpcServer struct. +func newRPCServer(s *server) (*rpcServer, error) { rpc := rpcServer{ server: s, } // Get values from config - rpc.rpcport = cfg.RpcPort - rpc.username = cfg.RpcUser - rpc.password = cfg.RpcPass + rpc.rpcport = cfg.RPCPort + rpc.username = cfg.RPCUser + rpc.password = cfg.RPCPass // IPv4 listener. var listeners []net.Listener @@ -108,9 +108,9 @@ func newRpcServer(s *server) (*rpcServer, error) { return &rpc, err } -// jsonRpcRead is the main function that handles reading messages, getting +// jsonRPCRead is the main function that handles reading messages, getting // the data the message requests, and writing the reply. -func jsonRpcRead(w http.ResponseWriter, r *http.Request, s *rpcServer) { +func jsonRPCRead(w http.ResponseWriter, r *http.Request, s *rpcServer) { _ = spew.Dump r.Close = true if s.shutdown == true { diff --git a/server.go b/server.go index dc653efc..fe21d8d6 100644 --- a/server.go +++ b/server.go @@ -239,7 +239,7 @@ func (s *server) peerHandler() { if cfg.MaxPeers < maxOutbound { maxOutbound = cfg.MaxPeers } - var wakeupTimer *time.Timer = nil + var wakeupTimer *time.Timer // Do initial DNS seeding to populate address manager. if !cfg.DisableDNSSeed { @@ -481,7 +481,7 @@ func (s *server) Start() { go s.peerHandler() // Start the RPC server if it's not disabled. - if !cfg.DisableRpc { + if !cfg.DisableRPC { s.rpcServer.Start() } @@ -509,7 +509,7 @@ func (s *server) Stop() error { } // Shutdown the RPC server if it's not disabled. - if !cfg.DisableRpc { + if !cfg.DisableRPC { s.rpcServer.Stop() } @@ -615,7 +615,7 @@ func newServer(addr string, db btcdb.Db, btcnet btcwire.BitcoinNet) (*server, er } log.Infof("[BMGR] Block index generation complete") - if !cfg.DisableRpc { + if !cfg.DisableRPC { s.rpcServer, err = newRpcServer(&s) if err != nil { return nil, err