Address some minor things reported by golint.

This commit is contained in:
Dave Collins 2013-09-18 00:36:40 -05:00
parent 3ca1e82f66
commit a5cc716940
5 changed files with 32 additions and 34 deletions

View file

@ -144,8 +144,8 @@ func chance(ka *knownAddress) float64 {
c := 1.0 c := 1.0
now := time.Now() now := time.Now()
var lastSeen float64 = 0.0 var lastSeen float64
var lastTry float64 = 0.0 var lastTry float64
if !ka.na.Timestamp.After(now) { if !ka.na.Timestamp.After(now) {
var dur time.Duration var dur time.Duration
if ka.na.Timestamp.IsZero() { if ka.na.Timestamp.IsZero() {
@ -462,7 +462,7 @@ func (a *AddrManager) AddressCacheFlat() []string {
a.mtx.Lock() a.mtx.Lock()
defer a.mtx.Unlock() defer a.mtx.Unlock()
for k, _ := range a.addrNew { for k := range a.addrNew {
allAddr = append(allAddr, k) allAddr = append(allAddr, k)
} }

View file

@ -25,7 +25,7 @@ const (
) )
var ( var (
log seelog.LoggerInterface = seelog.Disabled log = seelog.Disabled
cfg *config cfg *config
) )

View file

@ -5,7 +5,6 @@
package main package main
import ( import (
"errors"
"fmt" "fmt"
"github.com/conformal/btcdb" "github.com/conformal/btcdb"
_ "github.com/conformal/btcdb/ldb" _ "github.com/conformal/btcdb/ldb"
@ -51,10 +50,10 @@ type config struct {
MaxPeers int `long:"maxpeers" description:"Max number of inbound and outbound peers"` 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"` 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"` 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"` RPCUser string `short:"u" long:"rpcuser" description:"Username for RPC connections"`
RpcPass string `short:"P" long:"rpcpass" description:"Password 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"` 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"` 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"` 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)"` Proxy string `long:"proxy" description:"Connect via SOCKS5 proxy (eg. 127.0.0.1:9050)"`
ProxyUser string `long:"proxyuser" description:"Username for proxy server"` ProxyUser string `long:"proxyuser" description:"Username for proxy server"`
@ -173,8 +172,8 @@ func updateConfigWithActiveParams(cfg *config) {
cfg.Port = activeNetParams.listenPort cfg.Port = activeNetParams.listenPort
} }
if cfg.RpcPort == netParams(defaultBtcnet).rpcPort { if cfg.RPCPort == netParams(defaultBtcnet).rpcPort {
cfg.RpcPort = activeNetParams.rpcPort cfg.RPCPort = activeNetParams.rpcPort
} }
} }
@ -205,7 +204,7 @@ func loadConfig() (*config, []string, error) {
cfg := config{ cfg := config{
DebugLevel: defaultLogLevel, DebugLevel: defaultLogLevel,
Port: netParams(defaultBtcnet).listenPort, Port: netParams(defaultBtcnet).listenPort,
RpcPort: netParams(defaultBtcnet).rpcPort, RPCPort: netParams(defaultBtcnet).rpcPort,
MaxPeers: defaultMaxPeers, MaxPeers: defaultMaxPeers,
BanDuration: defaultBanDuration, BanDuration: defaultBanDuration,
ConfigFile: defaultConfigFile, ConfigFile: defaultConfigFile,
@ -263,7 +262,7 @@ func loadConfig() (*config, []string, error) {
if cfg.TestNet3 && cfg.RegressionTest { if cfg.TestNet3 && cfg.RegressionTest {
str := "%s: The testnet and regtest params can't be used " + str := "%s: The testnet and regtest params can't be used " +
"together -- choose one of the two" "together -- choose one of the two"
err := errors.New(fmt.Sprintf(str, "loadConfig")) err := fmt.Errorf(str, "loadConfig")
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
parser.WriteHelp(os.Stderr) parser.WriteHelp(os.Stderr)
return nil, nil, err return nil, nil, err
@ -281,7 +280,7 @@ func loadConfig() (*config, []string, error) {
// Validate debug log level. // Validate debug log level.
if !validLogLevel(cfg.DebugLevel) { if !validLogLevel(cfg.DebugLevel) {
str := "%s: The specified debug level [%v] is invalid" 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) fmt.Fprintln(os.Stderr, err)
parser.WriteHelp(os.Stderr) parser.WriteHelp(os.Stderr)
return nil, nil, err return nil, nil, err
@ -291,8 +290,7 @@ func loadConfig() (*config, []string, error) {
if !validDbType(cfg.DbType) { if !validDbType(cfg.DbType) {
str := "%s: The specified database type [%v] is invalid -- " + str := "%s: The specified database type [%v] is invalid -- " +
"supported types %v" "supported types %v"
err := errors.New(fmt.Sprintf(str, "loadConfig", cfg.DbType, err := fmt.Errorf(str, "loadConfig", cfg.DbType, knownDbTypes)
knownDbTypes))
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
parser.WriteHelp(os.Stderr) parser.WriteHelp(os.Stderr)
return nil, nil, err return nil, nil, err
@ -303,7 +301,7 @@ func loadConfig() (*config, []string, error) {
profilePort, err := strconv.Atoi(cfg.Profile) profilePort, err := strconv.Atoi(cfg.Profile)
if err != nil || profilePort < 1024 || profilePort > 65535 { if err != nil || profilePort < 1024 || profilePort > 65535 {
str := "%s: The profile port must be between 1024 and 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) fmt.Fprintln(os.Stderr, err)
parser.WriteHelp(os.Stderr) parser.WriteHelp(os.Stderr)
return nil, nil, err return nil, nil, err
@ -322,7 +320,7 @@ func loadConfig() (*config, []string, error) {
// Don't allow ban durations that are too short. // Don't allow ban durations that are too short.
if cfg.BanDuration < time.Duration(time.Second) { if cfg.BanDuration < time.Duration(time.Second) {
str := "%s: The banduration option may not be less than 1s -- parsed [%v]" 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) fmt.Fprintln(os.Stderr, err)
parser.WriteHelp(os.Stderr) parser.WriteHelp(os.Stderr)
return nil, nil, err return nil, nil, err
@ -332,7 +330,7 @@ func loadConfig() (*config, []string, error) {
if len(cfg.AddPeers) > 0 && len(cfg.ConnectPeers) > 0 { if len(cfg.AddPeers) > 0 && len(cfg.ConnectPeers) > 0 {
str := "%s: the --addpeer and --connect options can not be " + str := "%s: the --addpeer and --connect options can not be " +
"mixed" "mixed"
err := errors.New(fmt.Sprintf(str, "loadConfig")) err := fmt.Errorf(str, "loadConfig")
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
parser.WriteHelp(os.Stderr) parser.WriteHelp(os.Stderr)
return nil, nil, err return nil, nil, err
@ -341,7 +339,7 @@ func loadConfig() (*config, []string, error) {
// --tor requires --proxy to be set. // --tor requires --proxy to be set.
if cfg.UseTor && cfg.Proxy == "" { if cfg.UseTor && cfg.Proxy == "" {
str := "%s: the --tor option requires --proxy to be set" 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) fmt.Fprintln(os.Stderr, err)
parser.WriteHelp(os.Stderr) parser.WriteHelp(os.Stderr)
return nil, nil, err 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. // The RPC server is disabled if no username or password is provided.
if cfg.RpcUser == "" || cfg.RpcPass == "" { if cfg.RPCUser == "" || cfg.RPCPass == "" {
cfg.DisableRpc = true cfg.DisableRPC = true
} }
// Add default port to all added peer addresses if needed and remove // Add default port to all added peer addresses if needed and remove

View file

@ -40,7 +40,7 @@ func (s *rpcServer) Start() {
log.Trace("[RPCS] Starting RPC server") log.Trace("[RPCS] Starting RPC server")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
jsonRpcRead(w, r, s) jsonRPCRead(w, r, s)
}) })
httpServer := &http.Server{} httpServer := &http.Server{}
for _, listener := range s.listeners { for _, listener := range s.listeners {
@ -75,15 +75,15 @@ func (s *rpcServer) Stop() error {
return nil return nil
} }
// newRpcServer returns a new instance of the rpcServer struct. // newRPCServer returns a new instance of the rpcServer struct.
func newRpcServer(s *server) (*rpcServer, error) { func newRPCServer(s *server) (*rpcServer, error) {
rpc := rpcServer{ rpc := rpcServer{
server: s, server: s,
} }
// Get values from config // Get values from config
rpc.rpcport = cfg.RpcPort rpc.rpcport = cfg.RPCPort
rpc.username = cfg.RpcUser rpc.username = cfg.RPCUser
rpc.password = cfg.RpcPass rpc.password = cfg.RPCPass
// IPv4 listener. // IPv4 listener.
var listeners []net.Listener var listeners []net.Listener
@ -108,9 +108,9 @@ func newRpcServer(s *server) (*rpcServer, error) {
return &rpc, err 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. // 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 _ = spew.Dump
r.Close = true r.Close = true
if s.shutdown == true { if s.shutdown == true {

View file

@ -239,7 +239,7 @@ func (s *server) peerHandler() {
if cfg.MaxPeers < maxOutbound { if cfg.MaxPeers < maxOutbound {
maxOutbound = cfg.MaxPeers maxOutbound = cfg.MaxPeers
} }
var wakeupTimer *time.Timer = nil var wakeupTimer *time.Timer
// Do initial DNS seeding to populate address manager. // Do initial DNS seeding to populate address manager.
if !cfg.DisableDNSSeed { if !cfg.DisableDNSSeed {
@ -481,7 +481,7 @@ func (s *server) Start() {
go s.peerHandler() go s.peerHandler()
// Start the RPC server if it's not disabled. // Start the RPC server if it's not disabled.
if !cfg.DisableRpc { if !cfg.DisableRPC {
s.rpcServer.Start() s.rpcServer.Start()
} }
@ -509,7 +509,7 @@ func (s *server) Stop() error {
} }
// Shutdown the RPC server if it's not disabled. // Shutdown the RPC server if it's not disabled.
if !cfg.DisableRpc { if !cfg.DisableRPC {
s.rpcServer.Stop() 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") log.Infof("[BMGR] Block index generation complete")
if !cfg.DisableRpc { if !cfg.DisableRPC {
s.rpcServer, err = newRpcServer(&s) s.rpcServer, err = newRpcServer(&s)
if err != nil { if err != nil {
return nil, err return nil, err