MCPcopy Create free account
hub / github.com/LUX-Core/lux / InitHTTPServer

Function InitHTTPServer

src/httpserver.cpp:351–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349}
350
351bool InitHTTPServer()
352{
353 if (!InitHTTPAllowList())
354 return false;
355
356 if (GetBoolArg("-rpcssl", false)) {
357 uiInterface.ThreadSafeMessageBox(
358 "SSL mode for RPC (-rpcssl) is no longer supported.",
359 "", CClientUIInterface::MSG_ERROR);
360 return false;
361 }
362
363 // Redirect libevent's logging to our own log
364 event_set_log_callback(&libevent_log_cb);
365#if LIBEVENT_VERSION_NUMBER >= 0x02010100
366 // If -debug=libevent, set full libevent debugging.
367 // Otherwise, disable all libevent debugging.
368 if (LogAcceptCategory("libevent"))
369 event_enable_debug_logging(EVENT_DBG_ALL);
370 else
371 event_enable_debug_logging(EVENT_DBG_NONE);
372#endif
373#ifdef WIN32
374 evthread_use_windows_threads();
375#else
376 evthread_use_pthreads();
377#endif
378
379 raii_event_base base_ctr = obtain_event_base();
380
381 /* Create a new evhttp object to handle requests. */
382 raii_evhttp http_ctr = obtain_evhttp(base_ctr.get());
383 struct evhttp* http = http_ctr.get();
384 if (!http) {
385 LogPrintf("couldn't create evhttp. Exiting.\n");
386 return false;
387 }
388
389 evhttp_set_timeout(http, GetArg("-rpcservertimeout", DEFAULT_HTTP_SERVER_TIMEOUT));
390 evhttp_set_max_headers_size(http, MAX_HEADERS_SIZE);
391 evhttp_set_max_body_size(http, MAX_SIZE);
392 evhttp_set_gencb(http, http_request_cb, NULL);
393
394 if (!HTTPBindAddresses(http)) {
395 LogPrintf("Unable to bind any endpoint for RPC server\n");
396 return false;
397 }
398
399 LogPrint("http", "Initialized HTTP server\n");
400 int workQueueDepth = std::max((long)GetArg("-rpcworkqueue", DEFAULT_HTTP_WORKQUEUE), 1L);
401 LogPrintf("HTTP: creating work queue of depth %d\n", workQueueDepth);
402
403 workQueue = new WorkQueue<HTTPClosure>(workQueueDepth);
404 // transfer ownership to eventBase/HTTP via .release()
405 eventBase = base_ctr.release();
406 eventHTTP = http_ctr.release();
407 return true;
408}

Callers 1

AppInitServersFunction · 0.85

Calls 11

InitHTTPAllowListFunction · 0.85
GetBoolArgFunction · 0.85
LogAcceptCategoryFunction · 0.85
obtain_event_baseFunction · 0.85
obtain_evhttpFunction · 0.85
GetArgFunction · 0.85
HTTPBindAddressesFunction · 0.85
LogPrintFunction · 0.85
maxFunction · 0.85
getMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected