| 352 | } |
| 353 | |
| 354 | bool InitHTTPServer() |
| 355 | { |
| 356 | if (!InitHTTPAllowList()) |
| 357 | return false; |
| 358 | |
| 359 | if (gArgs.GetBoolArg("-rpcssl", false)) { |
| 360 | uiInterface.ThreadSafeMessageBox( |
| 361 | "SSL mode for RPC (-rpcssl) is no longer supported.", |
| 362 | "", CClientUIInterface::MSG_ERROR); |
| 363 | return false; |
| 364 | } |
| 365 | |
| 366 | // Redirect libevent's logging to our own log |
| 367 | event_set_log_callback(&libevent_log_cb); |
| 368 | // Update libevent's log handling. Returns false if our version of |
| 369 | // libevent doesn't support debug logging, in which case we should |
| 370 | // clear the BCLog::LIBEVENT flag. |
| 371 | if (!UpdateHTTPServerLogging(g_logger->WillLogCategory(BCLog::LIBEVENT))) { |
| 372 | g_logger->DisableCategory(BCLog::LIBEVENT); |
| 373 | } |
| 374 | |
| 375 | #ifdef WIN32 |
| 376 | evthread_use_windows_threads(); |
| 377 | #else |
| 378 | evthread_use_pthreads(); |
| 379 | #endif |
| 380 | |
| 381 | raii_event_base base_ctr = obtain_event_base(); |
| 382 | |
| 383 | /* Create a new evhttp object to handle requests. */ |
| 384 | raii_evhttp http_ctr = obtain_evhttp(base_ctr.get()); |
| 385 | struct evhttp* http = http_ctr.get(); |
| 386 | if (!http) { |
| 387 | LogPrintf("couldn't create evhttp. Exiting.\n"); |
| 388 | return false; |
| 389 | } |
| 390 | |
| 391 | evhttp_set_timeout(http, gArgs.GetArg("-rpcservertimeout", DEFAULT_HTTP_SERVER_TIMEOUT)); |
| 392 | evhttp_set_max_headers_size(http, MAX_HEADERS_SIZE); |
| 393 | evhttp_set_max_body_size(http, MAX_SIZE); |
| 394 | evhttp_set_gencb(http, http_request_cb, nullptr); |
| 395 | |
| 396 | if (!HTTPBindAddresses(http)) { |
| 397 | LogPrintf("Unable to bind any endpoint for RPC server\n"); |
| 398 | return false; |
| 399 | } |
| 400 | |
| 401 | LogPrint(BCLog::HTTP, "Initialized HTTP server\n"); |
| 402 | int workQueueDepth = std::max((long)gArgs.GetArg("-rpcworkqueue", DEFAULT_HTTP_WORKQUEUE), 1L); |
| 403 | LogPrintf("HTTP: creating work queue of depth %d\n", workQueueDepth); |
| 404 | |
| 405 | workQueue = new WorkQueue<HTTPClosure>(workQueueDepth); |
| 406 | // transfer ownership to eventBase/HTTP via .release() |
| 407 | eventBase = base_ctr.release(); |
| 408 | eventHTTP = http_ctr.release(); |
| 409 | return true; |
| 410 | } |
| 411 |
no test coverage detected