MCPcopy Create free account
hub / github.com/ElementsProject/elements / InitHTTPServer

Function InitHTTPServer

src/httpserver.cpp:356–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

AppInitServersFunction · 0.85

Calls 10

InitHTTPAllowListFunction · 0.85
UpdateHTTPServerLoggingFunction · 0.85
obtain_event_baseFunction · 0.85
obtain_evhttpFunction · 0.85
HTTPBindAddressesFunction · 0.85
WillLogCategoryMethod · 0.80
DisableCategoryMethod · 0.80
GetIntArgMethod · 0.80
releaseMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected