Bitcoin Core 31.99.0
P2P Digital Currency
Classes | Namespaces | Functions | Variables
httpserver.cpp File Reference
#include <bitcoin-build-config.h>
#include <httpserver.h>
#include <chainparamsbase.h>
#include <common/args.h>
#include <common/messages.h>
#include <common/url.h>
#include <compat/compat.h>
#include <logging.h>
#include <netbase.h>
#include <node/interface_ui.h>
#include <rpc/protocol.h>
#include <span.h>
#include <sync.h>
#include <util/check.h>
#include <util/signalinterrupt.h>
#include <util/sock.h>
#include <util/strencodings.h>
#include <util/thread.h>
#include <util/threadnames.h>
#include <util/threadpool.h>
#include <util/time.h>
#include <util/translation.h>
#include <condition_variable>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <memory>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <thread>
#include <unordered_map>
#include <vector>
#include <sys/types.h>
#include <sys/stat.h>
Include dependency graph for httpserver.cpp:

Go to the source code of this file.

Classes

struct  HTTPPathHandler
 

Namespaces

namespace  http_bitcoin
 

Functions

static std::vector< HTTPPathHandler > pathHandlers GUARDED_BY (g_httppathhandlers_mutex)
 
static bool ClientAllowed (const CNetAddr &netaddr)
 Check if a network address is allowed to access the HTTP server. More...
 
static bool InitHTTPAllowList ()
 Initialize ACL list for HTTP server. More...
 
std::string_view RequestMethodString (HTTPRequestMethod m)
 HTTP request method as string - use for logging only. More...
 
static void MaybeDispatchRequestToWorker (std::shared_ptr< HTTPRequest > hreq)
 
static void RejectRequest (std::unique_ptr< http_bitcoin::HTTPRequest > hreq)
 
static std::vector< std::pair< std::string, uint16_t > > GetBindAddresses ()
 
void RegisterHTTPHandler (const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
 Register handler for prefix. More...
 
void UnregisterHTTPHandler (const std::string &prefix, bool exactMatch)
 Unregister handler for prefix. More...
 
std::optional< std::string > http_bitcoin::GetQueryParameterFromUri (const std::string_view uri, const std::string_view key)
 
bool http_bitcoin::InitHTTPServer ()
 Initialize HTTP server. More...
 
void http_bitcoin::StartHTTPServer ()
 Start HTTP server. More...
 
void http_bitcoin::InterruptHTTPServer ()
 Interrupt HTTP server threads. More...
 
void http_bitcoin::StopHTTPServer ()
 Stop HTTP server. More...
 

Variables

static constexpr auto SELECT_TIMEOUT {50ms}
 The set of sockets cannot be modified while waiting, so the sleep time needs to be small to avoid new sockets stalling. More...
 
static constexpr int SOCKET_OPTION_TRUE {1}
 Explicit alias for setting socket option methods. More...
 
static std::unique_ptr< http_bitcoin::HTTPServerg_http_server {nullptr}
 HTTP module state. More...
 
static std::vector< CSubNetrpc_allow_subnets
 List of subnets to allow RPC connections from. More...
 
static GlobalMutex g_httppathhandlers_mutex
 Handlers for (sub)paths. More...
 
static ThreadPool g_threadpool_http ("http")
 Http thread pool - future: encapsulate in HttpContext More...
 
static int g_max_queue_depth {100}
 

Function Documentation

◆ ClientAllowed()

static bool ClientAllowed ( const CNetAddr netaddr)
static

Check if a network address is allowed to access the HTTP server.

Definition at line 81 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBindAddresses()

static std::vector< std::pair< std::string, uint16_t > > GetBindAddresses ( )
static

Definition at line 208 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GUARDED_BY()

static std::vector< HTTPPathHandler > pathHandlers GUARDED_BY ( g_httppathhandlers_mutex  )
static

◆ InitHTTPAllowList()

static bool InitHTTPAllowList ( )
static

Initialize ACL list for HTTP server.

Definition at line 92 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MaybeDispatchRequestToWorker()

static void MaybeDispatchRequestToWorker ( std::shared_ptr< HTTPRequest hreq)
static

Definition at line 128 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterHTTPHandler()

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 241 of file httpserver.cpp.

Here is the caller graph for this function:

◆ RejectRequest()

static void RejectRequest ( std::unique_ptr< http_bitcoin::HTTPRequest hreq)
static

Definition at line 202 of file httpserver.cpp.

Here is the caller graph for this function:

◆ RequestMethodString()

std::string_view RequestMethodString ( HTTPRequestMethod  m)

HTTP request method as string - use for logging only.

Definition at line 115 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnregisterHTTPHandler()

void UnregisterHTTPHandler ( const std::string &  prefix,
bool  exactMatch 
)

Unregister handler for prefix.

Definition at line 248 of file httpserver.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ g_http_server

std::unique_ptr<http_bitcoin::HTTPServer> g_http_server {nullptr}
static

HTTP module state.

Definition at line 69 of file httpserver.cpp.

◆ g_httppathhandlers_mutex

GlobalMutex g_httppathhandlers_mutex
static

Handlers for (sub)paths.

Definition at line 73 of file httpserver.cpp.

◆ g_max_queue_depth

int g_max_queue_depth {100}
static

Definition at line 78 of file httpserver.cpp.

◆ g_threadpool_http

ThreadPool g_threadpool_http("http") ( "http"  )
static

Http thread pool - future: encapsulate in HttpContext

◆ rpc_allow_subnets

std::vector<CSubNet> rpc_allow_subnets
static

List of subnets to allow RPC connections from.

Definition at line 71 of file httpserver.cpp.

◆ SELECT_TIMEOUT

constexpr auto SELECT_TIMEOUT {50ms}
staticconstexpr

The set of sockets cannot be modified while waiting, so the sleep time needs to be small to avoid new sockets stalling.

Definition at line 48 of file httpserver.cpp.

◆ SOCKET_OPTION_TRUE

constexpr int SOCKET_OPTION_TRUE {1}
staticconstexpr

Explicit alias for setting socket option methods.

Definition at line 51 of file httpserver.cpp.