MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / InitHTTPServer

Function InitHTTPServer

src/httpserver.cpp:1213–1256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1211}
1212
1213bool InitHTTPServer()
1214{
1215 if (!InitHTTPAllowList()) {
1216 return false;
1217 }
1218
1219 // Create HTTPServer
1220 g_http_server = std::make_unique<HTTPServer>(MaybeDispatchRequestToWorker);
1221
1222 g_http_server->SetServerTimeout(std::chrono::seconds(gArgs.GetIntArg("-rpcservertimeout", DEFAULT_HTTP_SERVER_TIMEOUT)));
1223
1224 // Bind HTTP server to specified addresses
1225 std::vector<std::pair<std::string, uint16_t>> endpoints{GetBindAddresses()};
1226 bool bind_success{false};
1227 for (const auto& [address_string, port] : endpoints) {
1228 LogInfo("Binding RPC on address %s port %i", address_string, port);
1229 const std::optional<CService> addr{Lookup(address_string, port, false)};
1230 if (addr) {
1231 if (addr->IsBindAny()) {
1232 LogWarning("The RPC server is not safe to expose to untrusted networks such as the public internet");
1233 }
1234 auto result{g_http_server->BindAndStartListening(addr.value())};
1235 if (!result) {
1236 LogWarning("Binding RPC on address %s failed: %s", addr->ToStringAddrPort(), result.error());
1237 } else {
1238 bind_success = true;
1239 }
1240 } else {
1241 LogWarning("Could not bind RPC on address %s port %i: Address lookup failed.", address_string, port);
1242 }
1243 }
1244
1245 if (!bind_success) {
1246 LogError("Unable to bind any endpoint for RPC server");
1247 return false;
1248 }
1249
1250 LogDebug(BCLog::HTTP, "Initialized HTTP server");
1251
1252 g_max_queue_depth = std::max(gArgs.GetArg<int>("-rpcworkqueue", DEFAULT_HTTP_WORKQUEUE), 1);
1253 LogDebug(BCLog::HTTP, "set work queue of depth %d\n", g_max_queue_depth);
1254
1255 return true;
1256}
1257
1258void StartHTTPServer()
1259{

Callers 1

AppInitServersFunction · 0.85

Calls 9

InitHTTPAllowListFunction · 0.85
GetBindAddressesFunction · 0.85
LookupFunction · 0.85
SetServerTimeoutMethod · 0.80
IsBindAnyMethod · 0.80
BindAndStartListeningMethod · 0.80
ToStringAddrPortMethod · 0.80
valueMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected