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

Function InitHTTPServer

src/httpserver.cpp:336–400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334}
335
336bool InitHTTPServer()
337{
338 struct evhttp* http = 0;
339 struct event_base* base = 0;
340
341 if (!InitHTTPAllowList())
342 return false;
343
344 if (GetBoolArg("-rpcssl", false)) {
345 uiInterface.ThreadSafeMessageBox(
346 "SSL mode for RPC (-rpcssl) is no longer supported.",
347 "", CClientUIInterface::MSG_ERROR);
348 return false;
349 }
350
351 // Redirect libevent's logging to our own log
352 event_set_log_callback(&libevent_log_cb);
353#if LIBEVENT_VERSION_NUMBER >= 0x02010100
354 // If -debug=libevent, set full libevent debugging.
355 // Otherwise, disable all libevent debugging.
356 if (LogAcceptCategory("libevent"))
357 event_enable_debug_logging(EVENT_DBG_ALL);
358 else
359 event_enable_debug_logging(EVENT_DBG_NONE);
360#endif
361#ifdef WIN32
362 evthread_use_windows_threads();
363#else
364 evthread_use_pthreads();
365#endif
366
367 base = event_base_new(); // XXX RAII
368 if (!base) {
369 LogPrintf("Couldn't create an event_base: exiting\n");
370 return false;
371 }
372
373 /* Create a new evhttp object to handle requests. */
374 http = evhttp_new(base); // XXX RAII
375 if (!http) {
376 LogPrintf("couldn't create evhttp. Exiting.\n");
377 event_base_free(base);
378 return false;
379 }
380
381 evhttp_set_timeout(http, GetArg("-rpcservertimeout", DEFAULT_HTTP_SERVER_TIMEOUT));
382 evhttp_set_max_body_size(http, MAX_SIZE);
383 evhttp_set_gencb(http, http_request_cb, NULL);
384
385 if (!HTTPBindAddresses(http)) {
386 LogPrintf("Unable to bind any endpoint for RPC server\n");
387 evhttp_free(http);
388 event_base_free(base);
389 return false;
390 }
391
392 LogPrint("http", "Initialized HTTP server\n");
393 int workQueueDepth = std::max((long)GetArg("-rpcworkqueue", DEFAULT_HTTP_WORKQUEUE), 1L);

Callers 1

AppInitServersFunction · 0.85

Calls 5

InitHTTPAllowListFunction · 0.85
GetBoolArgFunction · 0.85
LogAcceptCategoryFunction · 0.85
GetArgFunction · 0.85
HTTPBindAddressesFunction · 0.85

Tested by

no test coverage detected