Author

Topic: src/httpserver.h (Read 84 times)

staff
Activity: 3458
Merit: 6793
Just writing some code
August 12, 2021, 12:03:17 PM
#3
Not everything has to be object oriented. There's no point in having a class when there are no variables that those functions are managing, and there's never a need to make multiple of them.
legendary
Activity: 3500
Merit: 6320
Crypto Swap Exchange
August 12, 2021, 11:47:13 AM
#2
Could be talking out my ass here, but IIRC there are a lot of things / db calls in core that are done sequentially.
So if you are running multiple RPC servers things could get messy since you could in theory try to do things that may step on each other.

There might be another reason but that jumps out at me. Could be 100% wrong....

-Dave


legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
August 12, 2021, 11:33:28 AM
#1
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:

Code:
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 Smiley
Jump to: