Bitcoin ABC 0.26.3
P2P Digital Currency
|
#include <httpserver.h>
#include <chainparamsbase.h>
#include <common/args.h>
#include <compat.h>
#include <config.h>
#include <logging.h>
#include <netbase.h>
#include <node/ui_interface.h>
#include <rpc/protocol.h>
#include <shutdown.h>
#include <sync.h>
#include <util/strencodings.h>
#include <util/threadnames.h>
#include <util/translation.h>
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#include <event2/keyvalq_struct.h>
#include <event2/thread.h>
#include <event2/util.h>
#include <support/events.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <memory>
Go to the source code of this file.
Classes | |
class | HTTPWorkItem |
HTTP request work item. More... | |
class | WorkQueue< WorkItem > |
Simple work queue for distributing work over multiple threads. More... | |
struct | HTTPPathHandler |
Macros | |
#define | EVENT_LOG_WARN _EVENT_LOG_WARN |
Functions | |
static bool | ClientAllowed (const CNetAddr &netaddr) |
Check if a network address is allowed to access the HTTP server. | |
static bool | InitHTTPAllowList () |
Initialize ACL list for HTTP server. | |
std::string | RequestMethodString (HTTPRequest::RequestMethod m) |
HTTP request method as string - use for logging only. | |
static void | http_request_cb (struct evhttp_request *req, void *arg) |
HTTP request callback. | |
static void | http_reject_request_cb (struct evhttp_request *req, void *) |
Callback to reject HTTP requests after shutdown. | |
static bool | ThreadHTTP (struct event_base *base) |
Event dispatcher thread. | |
static bool | HTTPBindAddresses (struct evhttp *http) |
Bind HTTP server to specified addresses. | |
static void | HTTPWorkQueueRun (WorkQueue< HTTPClosure > *queue, int worker_num) |
Simple wrapper to set thread name and run work queue. | |
static void | libevent_log_cb (int severity, const char *msg) |
libevent event log callback | |
bool | InitHTTPServer (Config &config) |
Initialize HTTP server. | |
bool | UpdateHTTPServerLogging (bool enable) |
Change logging level for libevent. | |
void | StartHTTPServer () |
Start HTTP server. | |
void | InterruptHTTPServer () |
Interrupt HTTP server threads. | |
void | StopHTTPServer () |
Stop HTTP server. | |
struct event_base * | EventBase () |
Return evhttp event base. | |
static void | httpevent_callback_fn (evutil_socket_t, short, void *data) |
void | RegisterHTTPHandler (const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler) |
Register handler for prefix. | |
void | UnregisterHTTPHandler (const std::string &prefix, bool exactMatch) |
Unregister handler for prefix. | |
Variables | |
static const size_t | MAX_HEADERS_SIZE = 8192 |
Maximum size of http request (request line + headers) | |
static const size_t | MIN_SUPPORTED_BODY_SIZE = 0x02000000 |
Maximum HTTP post body size. | |
static struct event_base * | eventBase = nullptr |
HTTP module state. | |
static struct evhttp * | eventHTTP = nullptr |
HTTP server. | |
static std::vector< CSubNet > | rpc_allow_subnets |
List of subnets to allow RPC connections from. | |
static WorkQueue< HTTPClosure > * | workQueue = nullptr |
Work queue for handling longer requests off the event loop thread. | |
static std::vector< HTTPPathHandler > | pathHandlers |
Handlers for (sub)paths. | |
static std::vector< evhttp_bound_socket * > | boundSockets |
Bound listening sockets. | |
static std::thread | g_thread_http |
static std::vector< std::thread > | g_thread_http_workers |
#define EVENT_LOG_WARN _EVENT_LOG_WARN |
Check if a network address is allowed to access the HTTP server.
Definition at line 148 of file httpserver.cpp.
struct event_base * EventBase | ( | ) |
Return evhttp event base.
This can be used by submodules to queue timers or custom events.
Definition at line 517 of file httpserver.cpp.
|
static |
Callback to reject HTTP requests after shutdown.
Definition at line 293 of file httpserver.cpp.
|
static |
HTTP request callback.
Definition at line 214 of file httpserver.cpp.
Bind HTTP server to specified addresses.
Definition at line 309 of file httpserver.cpp.
|
static |
Definition at line 521 of file httpserver.cpp.
|
static |
Simple wrapper to set thread name and run work queue.
Definition at line 363 of file httpserver.cpp.
Initialize ACL list for HTTP server.
Definition at line 161 of file httpserver.cpp.
Initialize HTTP server.
Call this before RegisterHTTPHandler or EventBase().
Definition at line 382 of file httpserver.cpp.
void InterruptHTTPServer | ( | ) |
Interrupt HTTP server threads.
Definition at line 472 of file httpserver.cpp.
libevent event log callback
Definition at line 369 of file httpserver.cpp.
void RegisterHTTPHandler | ( | const std::string & | prefix, |
bool | exactMatch, | ||
const HTTPRequestHandler & | handler | ||
) |
Register handler for prefix.
If multiple handlers match a prefix, the first-registered one will be invoked.
Definition at line 672 of file httpserver.cpp.
std::string RequestMethodString | ( | HTTPRequest::RequestMethod | m | ) |
HTTP request method as string - use for logging only.
Definition at line 196 of file httpserver.cpp.
void StartHTTPServer | ( | ) |
Start HTTP server.
This is separate from InitHTTPServer to give users race-condition-free time to register their handlers between InitHTTPServer and StartHTTPServer.
Definition at line 460 of file httpserver.cpp.
void StopHTTPServer | ( | ) |
Stop HTTP server.
Definition at line 483 of file httpserver.cpp.
|
static |
Event dispatcher thread.
Definition at line 299 of file httpserver.cpp.
Unregister handler for prefix.
Definition at line 679 of file httpserver.cpp.
Change logging level for libevent.
Removes BCLog::LIBEVENT from log categories if libevent doesn't support debug logging.
Definition at line 443 of file httpserver.cpp.
|
static |
Bound listening sockets.
Definition at line 145 of file httpserver.cpp.
|
static |
HTTP server.
Definition at line 137 of file httpserver.cpp.
|
static |
Definition at line 457 of file httpserver.cpp.
|
static |
Definition at line 458 of file httpserver.cpp.
|
static |
Maximum size of http request (request line + headers)
Definition at line 40 of file httpserver.cpp.
|
static |
Maximum HTTP post body size.
Twice the maximum block size is added to this value in practice.
Definition at line 46 of file httpserver.cpp.
|
static |
Handlers for (sub)paths.
Definition at line 143 of file httpserver.cpp.
|
static |
List of subnets to allow RPC connections from.
Definition at line 139 of file httpserver.cpp.
|
static |
Work queue for handling longer requests off the event loop thread.
Definition at line 141 of file httpserver.cpp.