Changeset View
Changeset View
Standalone View
Standalone View
src/httpserver.cpp
// Copyright (c) 2015-2016 The Bitcoin Core developers | // Copyright (c) 2015-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2018 The Bitcoin developers | // Copyright (c) 2018 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <httpserver.h> | #include <httpserver.h> | ||||
#include <chainparamsbase.h> | #include <chainparamsbase.h> | ||||
#include <compat.h> | #include <compat.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <logging.h> | |||||
#include <netbase.h> | #include <netbase.h> | ||||
#include <rpc/protocol.h> // For HTTP status codes | #include <rpc/protocol.h> // For HTTP status codes | ||||
#include <sync.h> | #include <sync.h> | ||||
#include <ui_interface.h> | #include <ui_interface.h> | ||||
#include <util.h> | #include <util.h> | ||||
#include <utilstrencodings.h> | #include <utilstrencodings.h> | ||||
#include <event2/buffer.h> | #include <event2/buffer.h> | ||||
▲ Show 20 Lines • Show All 348 Lines • ▼ Show 20 Lines | if (gArgs.GetBoolArg("-rpcssl", false)) { | ||||
uiInterface.ThreadSafeMessageBox( | uiInterface.ThreadSafeMessageBox( | ||||
"SSL mode for RPC (-rpcssl) is no longer supported.", "", | "SSL mode for RPC (-rpcssl) is no longer supported.", "", | ||||
CClientUIInterface::MSG_ERROR); | CClientUIInterface::MSG_ERROR); | ||||
return false; | return false; | ||||
} | } | ||||
// Redirect libevent's logging to our own log | // Redirect libevent's logging to our own log | ||||
event_set_log_callback(&libevent_log_cb); | event_set_log_callback(&libevent_log_cb); | ||||
#if LIBEVENT_VERSION_NUMBER >= 0x02010100 | // Update libevent's log handling. Returns false if our version of | ||||
// If -debug=libevent, set full libevent debugging. | // libevent doesn't support debug logging, in which case we should | ||||
// Otherwise, disable all libevent debugging. | // clear the BCLog::LIBEVENT flag. | ||||
if (LogAcceptCategory(BCLog::LIBEVENT)) { | if (!UpdateHTTPServerLogging( | ||||
event_enable_debug_logging(EVENT_DBG_ALL); | GetLogger().WillLogCategory(BCLog::LIBEVENT))) { | ||||
} else { | GetLogger().EnableCategory(BCLog::LIBEVENT); | ||||
event_enable_debug_logging(EVENT_DBG_NONE); | |||||
} | } | ||||
#endif | |||||
#ifdef WIN32 | #ifdef WIN32 | ||||
evthread_use_windows_threads(); | evthread_use_windows_threads(); | ||||
#else | #else | ||||
evthread_use_pthreads(); | evthread_use_pthreads(); | ||||
#endif | #endif | ||||
raii_event_base base_ctr = obtain_event_base(); | raii_event_base base_ctr = obtain_event_base(); | ||||
Show All 30 Lines | #endif | ||||
workQueue = new WorkQueue<HTTPClosure>(workQueueDepth); | workQueue = new WorkQueue<HTTPClosure>(workQueueDepth); | ||||
// transfer ownership to eventBase/HTTP via .release() | // transfer ownership to eventBase/HTTP via .release() | ||||
eventBase = base_ctr.release(); | eventBase = base_ctr.release(); | ||||
eventHTTP = http_ctr.release(); | eventHTTP = http_ctr.release(); | ||||
return true; | return true; | ||||
} | } | ||||
bool UpdateHTTPServerLogging(bool enable) { | |||||
#if LIBEVENT_VERSION_NUMBER >= 0x02010100 | |||||
if (enable) { | |||||
event_enable_debug_logging(EVENT_DBG_ALL); | |||||
} else { | |||||
event_enable_debug_logging(EVENT_DBG_NONE); | |||||
} | |||||
return true; | |||||
#else | |||||
// Can't update libevent logging if version < 02010100 | |||||
return false; | |||||
#endif | |||||
} | |||||
std::thread threadHTTP; | std::thread threadHTTP; | ||||
std::future<bool> threadResult; | std::future<bool> threadResult; | ||||
static std::vector<std::thread> g_thread_http_workers; | static std::vector<std::thread> g_thread_http_workers; | ||||
bool StartHTTPServer() { | bool StartHTTPServer() { | ||||
LogPrint(BCLog::HTTP, "Starting HTTP server\n"); | LogPrint(BCLog::HTTP, "Starting HTTP server\n"); | ||||
int rpcThreads = | int rpcThreads = | ||||
std::max((long)gArgs.GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L); | std::max((long)gArgs.GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L); | ||||
▲ Show 20 Lines • Show All 231 Lines • Show Last 20 Lines |