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.
This commit is contained in:
parent
54203d7db0
commit
7d35bc9460
4 changed files with 31 additions and 26 deletions
|
@ -34,6 +34,7 @@ const (
|
||||||
defaultMaxPeers = 125
|
defaultMaxPeers = 125
|
||||||
defaultBanDuration = time.Hour * 24
|
defaultBanDuration = time.Hour * 24
|
||||||
defaultMaxRPCClients = 10
|
defaultMaxRPCClients = 10
|
||||||
|
defaultMaxRPCWebsockets = 25
|
||||||
defaultVerifyEnabled = false
|
defaultVerifyEnabled = false
|
||||||
defaultDbType = "leveldb"
|
defaultDbType = "leveldb"
|
||||||
)
|
)
|
||||||
|
@ -73,6 +74,7 @@ type config struct {
|
||||||
RPCCert string `long:"rpccert" description:"File containing the certificate file"`
|
RPCCert string `long:"rpccert" description:"File containing the certificate file"`
|
||||||
RPCKey string `long:"rpckey" description:"File containing the certificate key"`
|
RPCKey string `long:"rpckey" description:"File containing the certificate key"`
|
||||||
RPCMaxClients int `long:"rpcmaxclients" description:"Max number of RPC clients for standard connections"`
|
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"`
|
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"`
|
||||||
ExternalIPs []string `long:"externalip" description:"Add an ip to the list of local addresses we claim to listen on to peers"`
|
ExternalIPs []string `long:"externalip" description:"Add an ip to the list of local addresses we claim to listen on to peers"`
|
||||||
|
@ -285,6 +287,7 @@ func loadConfig() (*config, []string, error) {
|
||||||
MaxPeers: defaultMaxPeers,
|
MaxPeers: defaultMaxPeers,
|
||||||
BanDuration: defaultBanDuration,
|
BanDuration: defaultBanDuration,
|
||||||
RPCMaxClients: defaultMaxRPCClients,
|
RPCMaxClients: defaultMaxRPCClients,
|
||||||
|
RPCMaxWebsockets: defaultMaxRPCWebsockets,
|
||||||
DataDir: defaultDataDir,
|
DataDir: defaultDataDir,
|
||||||
LogDir: defaultLogDir,
|
LogDir: defaultLogDir,
|
||||||
DbType: defaultDbType,
|
DbType: defaultDbType,
|
||||||
|
|
2
doc.go
2
doc.go
|
@ -43,6 +43,8 @@ Application Options:
|
||||||
--rpckey= File containing the certificate key
|
--rpckey= File containing the certificate key
|
||||||
--rpcmaxclients= Max number of RPC clients for standard connections
|
--rpcmaxclients= Max number of RPC clients for standard connections
|
||||||
(10)
|
(10)
|
||||||
|
--rpcmaxwebsockets= Max number of RPC clients for standard connections
|
||||||
|
(25)
|
||||||
--norpc Disable built-in RPC server -- NOTE: The RPC server
|
--norpc Disable built-in RPC server -- NOTE: The RPC server
|
||||||
is disabled by default if no rpcuser/rpcpass is
|
is disabled by default if no rpcuser/rpcpass is
|
||||||
specified
|
specified
|
||||||
|
|
|
@ -26,9 +26,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// TODO(davec): This should be a config option.
|
|
||||||
maxWebsocketClients = 10
|
|
||||||
|
|
||||||
// websocketSendBufferSize is the number of elements the send channel
|
// websocketSendBufferSize is the number of elements the send channel
|
||||||
// can queue before blocking. Note that this only applies to requests
|
// can queue before blocking. Note that this only applies to requests
|
||||||
// handled directly in the websocket client input handler or the async
|
// 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.
|
// Limit max number of websocket clients.
|
||||||
rpcsLog.Infof("New websocket client %s", remoteAddr)
|
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] - "+
|
rpcsLog.Infof("Max websocket clients exceeded [%d] - "+
|
||||||
"disconnecting client %s", maxWebsocketClients,
|
"disconnecting client %s", cfg.RPCMaxWebsockets,
|
||||||
remoteAddr)
|
remoteAddr)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return
|
return
|
||||||
|
|
|
@ -146,6 +146,9 @@
|
||||||
; Specify the maximum number of concurrent RPC clients for standard connections.
|
; Specify the maximum number of concurrent RPC clients for standard connections.
|
||||||
; rpcmaxclients=10
|
; 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
|
; 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
|
; rpcpass are specified above. This allows one to quickly disable the RPC
|
||||||
; server without having to remove credentials from the config file.
|
; server without having to remove credentials from the config file.
|
||||||
|
|
Loading…
Add table
Reference in a new issue