Wouldn't it make sense to enclose all the HTTP RPC Server stuff in its own class instead of littering the global namespace? It would allow multiple RPC servers to run at once, instead of the current limit of just one right now.
Example: All this stuff can be moved into this new class:
class HTTPRPCServer final {
public:
HTTPRPCServer() {}
/** Initialize HTTP server.
* Call this before RegisterHTTPHandler or EventBase().
*/
bool InitHTTPServer();
/** Start HTTP server.
* This is separate from InitHTTPServer to give users race-condition-free time
* to register their handlers between InitHTTPServer and StartHTTPServer.
*/
void StartHTTPServer();
/** Interrupt HTTP server threads */
void InterruptHTTPServer();
/** Stop HTTP server */
void StopHTTPServer();
/** Change logging level for libevent. Removes BCLog::LIBEVENT from log categories if
* libevent doesn't support debug logging.*/
bool UpdateHTTPServerLogging(bool enable);
/** Register handler for prefix.
* If multiple handlers match a prefix, the first-registered one will
* be invoked.
*/
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler);
/** Unregister handler for prefix */
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch);
/** Return evhttp event base. This can be used by submodules to
* queue timers or custom events.
*/
struct event_base* EventBase();
}
And that's just for httpserver.h. In httprpc.cpp there are a ton of static globals that can also be moved in here.
True, I know Bitcoin Core doesn't have a need for simultaneous RPC servers, but I'm just nitpicking at the code architecture