Skip to content

Commit

Permalink
Add --rpcmaxwebsockets option with default of 25.
Browse files Browse the repository at this point in the history
This commit adds a new configuration option, --rpcmaxwebsockets, to limit the
number of max RPC websocket clients that are served concurrently.
  • Loading branch information
davecgh committed Feb 19, 2014
1 parent 54203d7 commit 7d35bc9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
45 changes: 24 additions & 21 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ import (
)

const (
defaultConfigFilename = "btcd.conf"
defaultDataDirname = "data"
defaultLogLevel = "info"
defaultLogDirname = "logs"
defaultLogFilename = "btcd.log"
defaultBtcnet = btcwire.MainNet
defaultMaxPeers = 125
defaultBanDuration = time.Hour * 24
defaultMaxRPCClients = 10
defaultVerifyEnabled = false
defaultDbType = "leveldb"
defaultConfigFilename = "btcd.conf"
defaultDataDirname = "data"
defaultLogLevel = "info"
defaultLogDirname = "logs"
defaultLogFilename = "btcd.log"
defaultBtcnet = btcwire.MainNet
defaultMaxPeers = 125
defaultBanDuration = time.Hour * 24
defaultMaxRPCClients = 10
defaultMaxRPCWebsockets = 25
defaultVerifyEnabled = false
defaultDbType = "leveldb"
)

var (
Expand Down Expand Up @@ -73,6 +74,7 @@ type config struct {
RPCCert string `long:"rpccert" description:"File containing the certificate file"`
RPCKey string `long:"rpckey" description:"File containing the certificate key"`
RPCMaxClients int `long:"rpcmaxclients" description:"Max number of RPC clients for standard connections"`
RPCMaxWebsockets int `long:"rpcmaxwebsockets" description:"Max number of RPC websocket connections"`
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"`
ExternalIPs []string `long:"externalip" description:"Add an ip to the list of local addresses we claim to listen on to peers"`
Expand Down Expand Up @@ -280,16 +282,17 @@ func newConfigParser(cfg *config, so *serviceOptions, options flags.Options) *fl
func loadConfig() (*config, []string, error) {
// Default config.
cfg := config{
ConfigFile: defaultConfigFile,
DebugLevel: defaultLogLevel,
MaxPeers: defaultMaxPeers,
BanDuration: defaultBanDuration,
RPCMaxClients: defaultMaxRPCClients,
DataDir: defaultDataDir,
LogDir: defaultLogDir,
DbType: defaultDbType,
RPCKey: defaultRPCKeyFile,
RPCCert: defaultRPCCertFile,
ConfigFile: defaultConfigFile,
DebugLevel: defaultLogLevel,
MaxPeers: defaultMaxPeers,
BanDuration: defaultBanDuration,
RPCMaxClients: defaultMaxRPCClients,
RPCMaxWebsockets: defaultMaxRPCWebsockets,
DataDir: defaultDataDir,
LogDir: defaultLogDir,
DbType: defaultDbType,
RPCKey: defaultRPCKeyFile,
RPCCert: defaultRPCCertFile,
}

// Service options which are only added on Windows.
Expand Down
2 changes: 2 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Application Options:
--rpckey= File containing the certificate key
--rpcmaxclients= Max number of RPC clients for standard connections
(10)
--rpcmaxwebsockets= Max number of RPC clients for standard connections
(25)
--norpc Disable built-in RPC server -- NOTE: The RPC server
is disabled by default if no rpcuser/rpcpass is
specified
Expand Down
7 changes: 2 additions & 5 deletions rpcwebsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import (
)

const (
// TODO(davec): This should be a config option.
maxWebsocketClients = 10

// websocketSendBufferSize is the number of elements the send channel
// can queue before blocking. Note that this only applies to requests
// handled directly in the websocket client input handler or the async
Expand Down Expand Up @@ -79,9 +76,9 @@ func (s *rpcServer) WebsocketHandler(conn *websocket.Conn, remoteAddr string,

// Limit max number of websocket clients.
rpcsLog.Infof("New websocket client %s", remoteAddr)
if s.ntfnMgr.NumClients()+1 > maxWebsocketClients {
if s.ntfnMgr.NumClients()+1 > cfg.RPCMaxWebsockets {
rpcsLog.Infof("Max websocket clients exceeded [%d] - "+
"disconnecting client %s", maxWebsocketClients,
"disconnecting client %s", cfg.RPCMaxWebsockets,
remoteAddr)
conn.Close()
return
Expand Down
3 changes: 3 additions & 0 deletions sample-btcd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@
; Specify the maximum number of concurrent RPC clients for standard connections.
; rpcmaxclients=10

; Specify the maximum number of concurrent RPC websocket clients.
; rpcmaxwebsockets=25

; Use the following setting to disable the RPC server even if the rpcuser and
; rpcpass are specified above. This allows one to quickly disable the RPC
; server without having to remove credentials from the config file.
Expand Down

0 comments on commit 7d35bc9

Please sign in to comment.