Bitcoin Forum
June 18, 2024, 07:53:58 AM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: src/httpserver.h  (Read 64 times)
NotATether (OP)
Legendary
*
Offline Offline

Activity: 1638
Merit: 6898


bitcoincleanup.com / bitmixlist.org


View Profile WWW
August 12, 2021, 04:33:28 PM
 #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

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
DaveF
Legendary
*
Offline Offline

Activity: 3514
Merit: 6350


Crypto Swap Exchange


View Profile WWW
August 12, 2021, 04:47:13 PM
 #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



█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3430
Merit: 6709


Just writing some code


View Profile WWW
August 12, 2021, 05:03:17 PM
Merited by NotATether (2)
 #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.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!