From 7d35bc9460358357a16d8376460e3dd8b09178a1 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 18 Feb 2014 21:05:42 -0600 Subject: [PATCH] Add --rpcmaxwebsockets option with default of 25. This commit adds a new configuration option, --rpcmaxwebsockets, to limit the number of max RPC websocket clients that are served concurrently. --- config.go | 45 ++++++++++++++++++++++++--------------------- doc.go | 2 ++ rpcwebsocket.go | 7 ++----- sample-btcd.conf | 3 +++ 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/config.go b/config.go index f0cfcd33..1ebaa670 100644 --- a/config.go +++ b/config.go @@ -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 ( @@ -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"` @@ -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. diff --git a/doc.go b/doc.go index 8a8730cc..f507c698 100644 --- a/doc.go +++ b/doc.go @@ -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 diff --git a/rpcwebsocket.go b/rpcwebsocket.go index f6d9af20..7c01c6ab 100644 --- a/rpcwebsocket.go +++ b/rpcwebsocket.go @@ -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 @@ -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 diff --git a/sample-btcd.conf b/sample-btcd.conf index 8a8314fd..6eab03f9 100644 --- a/sample-btcd.conf +++ b/sample-btcd.conf @@ -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.