http: configure simultaneous connection limit with -rpcmaxconnections

This commit is contained in:
Matthew Zipkin
2026-07-09 11:18:20 -04:00
parent b3d6d2d1a7
commit cc2acebefb
5 changed files with 84 additions and 34 deletions

View File

@@ -44,7 +44,7 @@ inline constexpr int DEFAULT_HTTP_SERVER_TIMEOUT=30;
/**
* Maximum number of connected HTTP clients
*/
inline constexpr int MAX_HTTP_CONNECTIONS = 16;
inline constexpr int DEFAULT_MAX_HTTP_CONNECTIONS = 16;
enum class HTTPRequestMethod {
UNKNOWN,
@@ -316,6 +316,11 @@ public:
*/
void SetServerTimeout(std::chrono::seconds seconds) { m_rpcservertimeout = seconds; }
/**
* Set the maximum amount of connected HTTPClients (-rpcmaxconnections)
*/
void SetMaxConnections(int max_conn) { m_rpcmaxconnections = max_conn; }
/**
* Force-remove all remaining clients from m_connected without waiting for
* graceful disconnection. Must only be called after JoinSocketsThreads().
@@ -421,6 +426,11 @@ private:
*/
bool ClientAllowed(const CNetAddr& netaddr) const;
/**
* Maximum amount of concurrent connections
*/
int m_rpcmaxconnections{DEFAULT_MAX_HTTP_CONNECTIONS};
/**
* Accept a connection.
* @param[in] listen_sock Socket on which to accept the connection.