http: switch servers from libevent to bitcoin

This commit is contained in:
Matthew Zipkin
2025-01-15 15:44:16 -05:00
parent cbb8d1fb33
commit 21c7542cf8
8 changed files with 44 additions and 58 deletions

View File

@@ -61,7 +61,7 @@ static constexpr auto SELECT_TIMEOUT{50ms};
static constexpr int SOCKET_OPTION_TRUE{1};
using common::InvalidPortErrMsg;
using http_libevent::HTTPRequest;
using http_bitcoin::HTTPRequest;
/** Maximum size of http request (request line + headers) */
static const size_t MAX_HEADERS_SIZE = 8192;
@@ -217,9 +217,6 @@ static void MaybeDispatchRequestToWorker(std::shared_ptr<HTTPRequest> hreq)
return;
}
LogDebug(BCLog::HTTP, "Received a %s request for %s from %s\n",
RequestMethodString(hreq->GetRequestMethod()), SanitizeString(hreq->GetURI(), SAFE_CHARS_URI).substr(0, 100), hreq->GetPeer().ToStringAddrPort());
// Find registered handler for prefix
std::string strURI = hreq->GetURI();
std::string path;
@@ -308,8 +305,12 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
}
}
}
auto hreq{std::make_shared<HTTPRequest>(req, *static_cast<const util::SignalInterrupt*>(arg))};
MaybeDispatchRequestToWorker(std::move(hreq));
auto hreq{std::make_shared<http_libevent::HTTPRequest>(req, *static_cast<const util::SignalInterrupt*>(arg))};
// Disabled now that http_libevent is deprecated, or code won't compile.
// This line is currently unreachable and will be cleaned up in a future commit.
// MaybeDispatchRequestToWorker(std::move(hreq));
Assume(false);
}
/** Callback to reject HTTP requests after shutdown. */
@@ -319,7 +320,6 @@ static void http_reject_request_cb(struct evhttp_request* req, void*)
evhttp_send_error(req, HTTP_SERVUNAVAIL, nullptr);
}
/// \anchor http
/** Event dispatcher thread */
static void ThreadHTTP(struct event_base* base)
{
@@ -1424,6 +1424,7 @@ HTTPServer::IOReadiness HTTPServer::GenerateWaitSockets() const
return io_readiness;
}
/// \anchor http
void HTTPServer::ThreadSocketHandler()
{
while (!m_interrupt_net) {
@@ -1685,8 +1686,8 @@ bool InitHTTPServer()
return false;
}
// Create HTTPServer, using a dummy request handler just for this commit
g_http_server = std::make_unique<HTTPServer>([&](std::unique_ptr<HTTPRequest> req){});
// Create HTTPServer
g_http_server = std::make_unique<HTTPServer>(MaybeDispatchRequestToWorker);
g_http_server->SetServerTimeout(std::chrono::seconds(gArgs.GetIntArg("-rpcservertimeout", DEFAULT_HTTP_SERVER_TIMEOUT)));