2011-05-14 20:10:21 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2019-01-25 01:54:46 +01:00
|
|
|
// Copyright (c) 2009-2019 The Bitcoin Core developers
|
2014-10-30 03:14:08 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 16:02:28 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2011-05-14 20:10:21 +02:00
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <rpc/server.h>
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <fs.h>
|
2017-09-20 03:12:25 +02:00
|
|
|
#include <key_io.h>
|
2018-11-06 16:40:50 +01:00
|
|
|
#include <rpc/util.h>
|
2018-05-16 21:17:40 +02:00
|
|
|
#include <shutdown.h>
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <sync.h>
|
2018-10-23 00:51:11 +02:00
|
|
|
#include <util/strencodings.h>
|
2018-11-06 16:40:50 +01:00
|
|
|
#include <util/system.h>
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2014-10-19 10:46:17 +02:00
|
|
|
#include <boost/signals2/signal.hpp>
|
2017-02-03 17:23:01 +01:00
|
|
|
#include <boost/algorithm/string/classification.hpp>
|
|
|
|
#include <boost/algorithm/string/split.hpp>
|
2014-08-20 21:15:16 +02:00
|
|
|
|
2016-07-18 11:26:21 +02:00
|
|
|
#include <memory> // for unique_ptr
|
2016-09-25 20:42:49 +02:00
|
|
|
#include <unordered_map>
|
2016-07-18 11:26:21 +02:00
|
|
|
|
2014-10-29 18:08:31 +01:00
|
|
|
static CCriticalSection cs_rpcWarmup;
|
2018-12-18 10:21:06 +01:00
|
|
|
static std::atomic<bool> g_rpc_running{false};
|
2018-04-29 22:29:26 +02:00
|
|
|
static bool fRPCInWarmup GUARDED_BY(cs_rpcWarmup) = true;
|
|
|
|
static std::string rpcWarmupStatus GUARDED_BY(cs_rpcWarmup) = "RPC server started";
|
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
|
|
|
/* Timer-creating functions */
|
2017-08-07 07:36:37 +02:00
|
|
|
static RPCTimerInterface* timerInterface = nullptr;
|
2016-07-18 11:26:21 +02:00
|
|
|
/* Map of name to timer. */
|
|
|
|
static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers;
|
2017-07-31 17:46:13 +02:00
|
|
|
static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler);
|
2012-04-15 02:35:58 +02:00
|
|
|
|
2019-01-02 13:34:39 +01:00
|
|
|
struct RPCCommandExecutionInfo
|
|
|
|
{
|
|
|
|
std::string method;
|
|
|
|
int64_t start;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RPCServerInfo
|
|
|
|
{
|
|
|
|
Mutex mutex;
|
|
|
|
std::list<RPCCommandExecutionInfo> active_commands GUARDED_BY(mutex);
|
|
|
|
};
|
|
|
|
|
|
|
|
static RPCServerInfo g_rpc_server_info;
|
|
|
|
|
|
|
|
struct RPCCommandExecution
|
|
|
|
{
|
|
|
|
std::list<RPCCommandExecutionInfo>::iterator it;
|
|
|
|
explicit RPCCommandExecution(const std::string& method)
|
|
|
|
{
|
|
|
|
LOCK(g_rpc_server_info.mutex);
|
2019-01-25 01:54:46 +01:00
|
|
|
it = g_rpc_server_info.active_commands.insert(g_rpc_server_info.active_commands.end(), {method, GetTimeMicros()});
|
2019-01-02 13:34:39 +01:00
|
|
|
}
|
|
|
|
~RPCCommandExecution()
|
|
|
|
{
|
|
|
|
LOCK(g_rpc_server_info.mutex);
|
|
|
|
g_rpc_server_info.active_commands.erase(it);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-19 10:46:17 +02:00
|
|
|
static struct CRPCSignals
|
|
|
|
{
|
|
|
|
boost::signals2::signal<void ()> Started;
|
|
|
|
boost::signals2::signal<void ()> Stopped;
|
|
|
|
} g_rpcSignals;
|
|
|
|
|
2017-05-13 17:52:14 +02:00
|
|
|
void RPCServer::OnStarted(std::function<void ()> slot)
|
2014-10-19 10:46:17 +02:00
|
|
|
{
|
|
|
|
g_rpcSignals.Started.connect(slot);
|
|
|
|
}
|
|
|
|
|
2017-05-13 17:52:14 +02:00
|
|
|
void RPCServer::OnStopped(std::function<void ()> slot)
|
2014-10-19 10:46:17 +02:00
|
|
|
{
|
|
|
|
g_rpcSignals.Stopped.connect(slot);
|
|
|
|
}
|
|
|
|
|
2016-12-29 14:05:51 +01:00
|
|
|
std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest& helpreq) const
|
2011-05-14 20:10:21 +02:00
|
|
|
{
|
2017-01-04 05:22:19 +01:00
|
|
|
std::string strRet;
|
|
|
|
std::string category;
|
2017-07-31 17:46:13 +02:00
|
|
|
std::set<intptr_t> setDone;
|
2017-01-04 05:22:19 +01:00
|
|
|
std::vector<std::pair<std::string, const CRPCCommand*> > vCommands;
|
2014-07-15 21:38:52 +02:00
|
|
|
|
2017-06-04 22:02:43 +02:00
|
|
|
for (const auto& entry : mapCommands)
|
2017-07-31 17:46:13 +02:00
|
|
|
vCommands.push_back(make_pair(entry.second.front()->category + entry.first, entry.second.front()));
|
2014-07-15 21:38:52 +02:00
|
|
|
sort(vCommands.begin(), vCommands.end());
|
|
|
|
|
2016-12-29 14:05:51 +01:00
|
|
|
JSONRPCRequest jreq(helpreq);
|
|
|
|
jreq.fHelp = true;
|
|
|
|
jreq.params = UniValue();
|
|
|
|
|
2017-06-02 03:28:42 +02:00
|
|
|
for (const std::pair<std::string, const CRPCCommand*>& command : vCommands)
|
2011-05-14 20:10:21 +02:00
|
|
|
{
|
2014-07-15 21:38:52 +02:00
|
|
|
const CRPCCommand *pcmd = command.second;
|
2017-01-04 05:22:19 +01:00
|
|
|
std::string strMethod = pcmd->name;
|
2014-11-26 16:33:18 +01:00
|
|
|
if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand)
|
2011-05-14 20:10:21 +02:00
|
|
|
continue;
|
2016-12-29 14:05:51 +01:00
|
|
|
jreq.strMethod = strMethod;
|
2011-05-14 20:10:21 +02:00
|
|
|
try
|
|
|
|
{
|
2017-07-31 17:46:13 +02:00
|
|
|
UniValue unused_result;
|
|
|
|
if (setDone.insert(pcmd->unique_id).second)
|
|
|
|
pcmd->actor(jreq, unused_result, true /* last_handler */);
|
2011-05-14 20:10:21 +02:00
|
|
|
}
|
2014-12-07 13:29:06 +01:00
|
|
|
catch (const std::exception& e)
|
2011-05-14 20:10:21 +02:00
|
|
|
{
|
|
|
|
// Help text is returned in an exception
|
2017-01-04 05:22:19 +01:00
|
|
|
std::string strHelp = std::string(e.what());
|
2011-05-14 20:10:21 +02:00
|
|
|
if (strCommand == "")
|
2014-07-15 21:38:52 +02:00
|
|
|
{
|
2017-01-04 05:22:19 +01:00
|
|
|
if (strHelp.find('\n') != std::string::npos)
|
2011-05-14 20:10:21 +02:00
|
|
|
strHelp = strHelp.substr(0, strHelp.find('\n'));
|
2014-07-15 21:38:52 +02:00
|
|
|
|
|
|
|
if (category != pcmd->category)
|
|
|
|
{
|
|
|
|
if (!category.empty())
|
|
|
|
strRet += "\n";
|
|
|
|
category = pcmd->category;
|
2018-07-25 11:45:07 +02:00
|
|
|
strRet += "== " + Capitalize(category) + " ==\n";
|
2014-07-15 21:38:52 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-14 20:10:21 +02:00
|
|
|
strRet += strHelp + "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (strRet == "")
|
2014-01-16 16:15:27 +01:00
|
|
|
strRet = strprintf("help: unknown command: %s\n", strCommand);
|
2011-05-14 20:10:21 +02:00
|
|
|
strRet = strRet.substr(0,strRet.size()-1);
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2016-09-22 09:46:41 +02:00
|
|
|
UniValue help(const JSONRPCRequest& jsonRequest)
|
2012-04-18 22:42:17 +02:00
|
|
|
{
|
2016-09-22 09:46:41 +02:00
|
|
|
if (jsonRequest.fHelp || jsonRequest.params.size() > 1)
|
2017-01-04 05:22:19 +01:00
|
|
|
throw std::runtime_error(
|
2018-10-20 14:19:44 +02:00
|
|
|
RPCHelpMan{"help",
|
|
|
|
"\nList all commands, or get help for a specified command.\n",
|
|
|
|
{
|
2018-12-10 22:56:51 +01:00
|
|
|
{"command", RPCArg::Type::STR, /* default */ "all commands", "The command to get help on"},
|
2018-12-21 18:29:36 +01:00
|
|
|
},
|
|
|
|
RPCResult{
|
2013-10-29 12:29:44 +01:00
|
|
|
"\"text\" (string) The help text\n"
|
2018-12-21 18:29:36 +01:00
|
|
|
},
|
|
|
|
RPCExamples{""},
|
|
|
|
}.ToString()
|
2013-10-29 12:29:44 +01:00
|
|
|
);
|
2012-04-18 22:42:17 +02:00
|
|
|
|
2017-01-04 05:22:19 +01:00
|
|
|
std::string strCommand;
|
2016-09-22 09:46:41 +02:00
|
|
|
if (jsonRequest.params.size() > 0)
|
|
|
|
strCommand = jsonRequest.params[0].get_str();
|
2012-04-18 22:42:17 +02:00
|
|
|
|
2016-12-29 14:05:51 +01:00
|
|
|
return tableRPC.help(strCommand, jsonRequest);
|
2012-04-18 22:42:17 +02:00
|
|
|
}
|
|
|
|
|
2011-05-14 20:10:21 +02:00
|
|
|
|
2016-09-22 09:46:41 +02:00
|
|
|
UniValue stop(const JSONRPCRequest& jsonRequest)
|
2011-05-14 20:10:21 +02:00
|
|
|
{
|
2013-01-20 18:50:30 +01:00
|
|
|
// Accept the deprecated and ignored 'detach' boolean argument
|
2018-11-20 18:52:15 +01:00
|
|
|
// Also accept the hidden 'wait' integer argument (milliseconds)
|
|
|
|
// For instance, 'stop 1000' makes the call wait 1 second before returning
|
|
|
|
// to the client (intended for testing)
|
2016-09-22 09:46:41 +02:00
|
|
|
if (jsonRequest.fHelp || jsonRequest.params.size() > 1)
|
2017-01-04 05:22:19 +01:00
|
|
|
throw std::runtime_error(
|
2018-10-20 14:19:44 +02:00
|
|
|
RPCHelpMan{"stop",
|
2018-12-21 18:29:36 +01:00
|
|
|
"\nStop Bitcoin server.",
|
|
|
|
{},
|
|
|
|
RPCResults{},
|
|
|
|
RPCExamples{""},
|
|
|
|
}.ToString());
|
2015-09-24 17:29:22 +02:00
|
|
|
// Event loop will exit after current HTTP requests have been handled, so
|
|
|
|
// this reply will get back to the client.
|
2012-06-11 07:40:14 +02:00
|
|
|
StartShutdown();
|
2018-11-20 18:52:15 +01:00
|
|
|
if (jsonRequest.params[0].isNum()) {
|
|
|
|
MilliSleep(jsonRequest.params[0].get_int());
|
|
|
|
}
|
2012-05-13 16:09:14 +02:00
|
|
|
return "Bitcoin server stopping";
|
2011-05-14 20:10:21 +02:00
|
|
|
}
|
|
|
|
|
2018-05-02 17:14:48 +02:00
|
|
|
static UniValue uptime(const JSONRPCRequest& jsonRequest)
|
2017-05-14 20:18:26 +02:00
|
|
|
{
|
2018-11-13 19:42:36 +01:00
|
|
|
if (jsonRequest.fHelp || jsonRequest.params.size() > 0)
|
2017-05-14 20:18:26 +02:00
|
|
|
throw std::runtime_error(
|
2018-10-20 14:19:44 +02:00
|
|
|
RPCHelpMan{"uptime",
|
2018-12-21 18:29:36 +01:00
|
|
|
"\nReturns the total uptime of the server.\n",
|
|
|
|
{},
|
|
|
|
RPCResult{
|
2017-05-14 20:18:26 +02:00
|
|
|
"ttt (numeric) The number of seconds that the server has been running\n"
|
2018-12-21 18:29:36 +01:00
|
|
|
},
|
|
|
|
RPCExamples{
|
|
|
|
HelpExampleCli("uptime", "")
|
2017-05-14 20:18:26 +02:00
|
|
|
+ HelpExampleRpc("uptime", "")
|
2018-12-21 18:29:36 +01:00
|
|
|
},
|
|
|
|
}.ToString());
|
2017-05-14 20:18:26 +02:00
|
|
|
|
|
|
|
return GetTime() - GetStartupTime();
|
|
|
|
}
|
|
|
|
|
2018-12-14 16:53:59 +01:00
|
|
|
static UniValue getrpcinfo(const JSONRPCRequest& request)
|
|
|
|
{
|
|
|
|
if (request.fHelp || request.params.size() > 0) {
|
|
|
|
throw std::runtime_error(
|
|
|
|
RPCHelpMan{"getrpcinfo",
|
2018-12-21 18:29:36 +01:00
|
|
|
"\nReturns details of the RPC server.\n",
|
|
|
|
{},
|
2019-04-05 09:04:34 +02:00
|
|
|
RPCResult{
|
|
|
|
"{\n"
|
|
|
|
" \"active_commands\" (array) All active commands\n"
|
|
|
|
" [\n"
|
|
|
|
" { (object) Information about an active command\n"
|
|
|
|
" \"method\" (string) The name of the RPC command \n"
|
|
|
|
" \"duration\" (numeric) The running time in microseconds\n"
|
|
|
|
" },...\n"
|
|
|
|
" ]\n"
|
|
|
|
"}\n"
|
|
|
|
},
|
|
|
|
RPCExamples{
|
|
|
|
HelpExampleCli("getrpcinfo", "")
|
|
|
|
+ HelpExampleRpc("getrpcinfo", "")},
|
2018-12-21 18:29:36 +01:00
|
|
|
}.ToString()
|
2018-12-14 16:53:59 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOCK(g_rpc_server_info.mutex);
|
|
|
|
UniValue active_commands(UniValue::VARR);
|
|
|
|
for (const RPCCommandExecutionInfo& info : g_rpc_server_info.active_commands) {
|
|
|
|
UniValue entry(UniValue::VOBJ);
|
|
|
|
entry.pushKV("method", info.method);
|
|
|
|
entry.pushKV("duration", GetTimeMicros() - info.start);
|
|
|
|
active_commands.push_back(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
UniValue result(UniValue::VOBJ);
|
|
|
|
result.pushKV("active_commands", active_commands);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-08-20 14:19:43 +02:00
|
|
|
// clang-format off
|
2012-04-21 01:37:34 +02:00
|
|
|
static const CRPCCommand vRPCCommands[] =
|
2017-06-09 02:38:23 +02:00
|
|
|
{ // category name actor (function) argNames
|
|
|
|
// --------------------- ------------------------ ----------------------- ----------
|
2014-03-26 12:26:43 +01:00
|
|
|
/* Overall control/query calls */
|
2018-12-14 16:53:59 +01:00
|
|
|
{ "control", "getrpcinfo", &getrpcinfo, {} },
|
2017-06-09 02:38:23 +02:00
|
|
|
{ "control", "help", &help, {"command"} },
|
2018-11-20 18:52:15 +01:00
|
|
|
{ "control", "stop", &stop, {"wait"} },
|
2017-06-09 02:38:23 +02:00
|
|
|
{ "control", "uptime", &uptime, {} },
|
2011-05-14 20:10:21 +02:00
|
|
|
};
|
2018-08-20 14:19:43 +02:00
|
|
|
// clang-format on
|
2011-05-14 20:10:21 +02:00
|
|
|
|
2012-04-18 22:42:17 +02:00
|
|
|
CRPCTable::CRPCTable()
|
2012-04-15 05:55:05 +02:00
|
|
|
{
|
|
|
|
unsigned int vcidx;
|
|
|
|
for (vcidx = 0; vcidx < (sizeof(vRPCCommands) / sizeof(vRPCCommands[0])); vcidx++)
|
|
|
|
{
|
2012-04-21 01:37:34 +02:00
|
|
|
const CRPCCommand *pcmd;
|
2011-05-14 20:10:21 +02:00
|
|
|
|
2012-04-15 05:55:05 +02:00
|
|
|
pcmd = &vRPCCommands[vcidx];
|
2017-07-31 17:46:13 +02:00
|
|
|
mapCommands[pcmd->name].push_back(pcmd);
|
2012-04-15 05:55:05 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-14 20:10:21 +02:00
|
|
|
|
2016-01-07 08:33:49 +01:00
|
|
|
bool CRPCTable::appendCommand(const std::string& name, const CRPCCommand* pcmd)
|
|
|
|
{
|
|
|
|
if (IsRPCRunning())
|
|
|
|
return false;
|
|
|
|
|
2017-07-31 17:46:13 +02:00
|
|
|
mapCommands[name].push_back(pcmd);
|
2016-01-07 08:33:49 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-31 17:46:13 +02:00
|
|
|
bool CRPCTable::removeCommand(const std::string& name, const CRPCCommand* pcmd)
|
|
|
|
{
|
|
|
|
auto it = mapCommands.find(name);
|
|
|
|
if (it != mapCommands.end()) {
|
|
|
|
auto new_end = std::remove(it->second.begin(), it->second.end(), pcmd);
|
|
|
|
if (it->second.end() != new_end) {
|
|
|
|
it->second.erase(new_end, it->second.end());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-27 08:22:42 +02:00
|
|
|
void StartRPC()
|
2011-08-10 13:53:13 +02:00
|
|
|
{
|
2016-12-25 21:19:40 +01:00
|
|
|
LogPrint(BCLog::RPC, "Starting RPC\n");
|
2018-12-18 10:21:06 +01:00
|
|
|
g_rpc_running = true;
|
2014-10-19 10:46:17 +02:00
|
|
|
g_rpcSignals.Started();
|
2013-03-07 04:31:26 +01:00
|
|
|
}
|
|
|
|
|
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
|
|
|
void InterruptRPC()
|
2014-01-17 16:32:35 +01:00
|
|
|
{
|
2016-12-25 21:19:40 +01:00
|
|
|
LogPrint(BCLog::RPC, "Interrupting RPC\n");
|
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
|
|
|
// Interrupt e.g. running longpolls
|
2018-12-18 10:21:06 +01:00
|
|
|
g_rpc_running = false;
|
2014-01-17 16:32:35 +01:00
|
|
|
}
|
|
|
|
|
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
|
|
|
void StopRPC()
|
2013-03-07 04:31:26 +01:00
|
|
|
{
|
2016-12-25 21:19:40 +01:00
|
|
|
LogPrint(BCLog::RPC, "Stopping RPC\n");
|
2013-05-07 16:47:00 +02:00
|
|
|
deadlineTimers.clear();
|
2017-03-28 08:20:08 +02:00
|
|
|
DeleteAuthCookie();
|
2014-10-19 10:46:17 +02:00
|
|
|
g_rpcSignals.Stopped();
|
2012-04-15 02:35:58 +02:00
|
|
|
}
|
|
|
|
|
2012-05-13 06:43:24 +02:00
|
|
|
bool IsRPCRunning()
|
|
|
|
{
|
2018-12-18 10:21:06 +01:00
|
|
|
return g_rpc_running;
|
2012-05-13 06:43:24 +02:00
|
|
|
}
|
|
|
|
|
2014-10-29 18:08:31 +01:00
|
|
|
void SetRPCWarmupStatus(const std::string& newStatus)
|
|
|
|
{
|
|
|
|
LOCK(cs_rpcWarmup);
|
|
|
|
rpcWarmupStatus = newStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetRPCWarmupFinished()
|
|
|
|
{
|
|
|
|
LOCK(cs_rpcWarmup);
|
|
|
|
assert(fRPCInWarmup);
|
|
|
|
fRPCInWarmup = false;
|
|
|
|
}
|
|
|
|
|
2014-11-26 13:51:02 +01:00
|
|
|
bool RPCIsInWarmup(std::string *outStatus)
|
|
|
|
{
|
|
|
|
LOCK(cs_rpcWarmup);
|
|
|
|
if (outStatus)
|
|
|
|
*outStatus = rpcWarmupStatus;
|
|
|
|
return fRPCInWarmup;
|
|
|
|
}
|
|
|
|
|
2016-09-22 09:46:41 +02:00
|
|
|
void JSONRPCRequest::parse(const UniValue& valRequest)
|
2012-06-27 19:47:02 +02:00
|
|
|
{
|
|
|
|
// Parse request
|
2014-08-20 21:15:16 +02:00
|
|
|
if (!valRequest.isObject())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_REQUEST, "Invalid Request object");
|
2015-05-18 14:02:18 +02:00
|
|
|
const UniValue& request = valRequest.get_obj();
|
2012-06-27 19:47:02 +02:00
|
|
|
|
|
|
|
// Parse id now so errors from here on will have the id
|
|
|
|
id = find_value(request, "id");
|
|
|
|
|
|
|
|
// Parse method
|
2015-05-13 21:29:19 +02:00
|
|
|
UniValue valMethod = find_value(request, "method");
|
2014-08-20 21:15:16 +02:00
|
|
|
if (valMethod.isNull())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_REQUEST, "Missing method");
|
2014-08-20 21:15:16 +02:00
|
|
|
if (!valMethod.isStr())
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_REQUEST, "Method must be a string");
|
2012-06-27 19:47:02 +02:00
|
|
|
strMethod = valMethod.get_str();
|
2018-03-25 20:25:09 +02:00
|
|
|
if (fLogIPs)
|
|
|
|
LogPrint(BCLog::RPC, "ThreadRPCServer method=%s user=%s peeraddr=%s\n", SanitizeString(strMethod),
|
|
|
|
this->authUser, this->peerAddr);
|
|
|
|
else
|
|
|
|
LogPrint(BCLog::RPC, "ThreadRPCServer method=%s user=%s\n", SanitizeString(strMethod), this->authUser);
|
2012-06-27 19:47:02 +02:00
|
|
|
|
|
|
|
// Parse params
|
2015-05-13 21:29:19 +02:00
|
|
|
UniValue valParams = find_value(request, "params");
|
2016-09-25 20:42:49 +02:00
|
|
|
if (valParams.isArray() || valParams.isObject())
|
|
|
|
params = valParams;
|
2014-08-20 21:15:16 +02:00
|
|
|
else if (valParams.isNull())
|
2015-05-18 14:02:18 +02:00
|
|
|
params = UniValue(UniValue::VARR);
|
2012-06-27 19:47:02 +02:00
|
|
|
else
|
2016-09-25 20:42:49 +02:00
|
|
|
throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array or object");
|
2012-06-27 19:47:02 +02:00
|
|
|
}
|
|
|
|
|
2017-08-11 17:25:06 +02:00
|
|
|
bool IsDeprecatedRPCEnabled(const std::string& method)
|
|
|
|
{
|
|
|
|
const std::vector<std::string> enabled_methods = gArgs.GetArgs("-deprecatedrpc");
|
|
|
|
|
|
|
|
return find(enabled_methods.begin(), enabled_methods.end(), method) != enabled_methods.end();
|
|
|
|
}
|
|
|
|
|
2017-09-07 23:20:26 +02:00
|
|
|
static UniValue JSONRPCExecOne(JSONRPCRequest jreq, const UniValue& req)
|
2012-06-24 08:01:28 +02:00
|
|
|
{
|
2015-05-10 14:48:35 +02:00
|
|
|
UniValue rpc_result(UniValue::VOBJ);
|
2012-06-24 08:01:28 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
jreq.parse(req);
|
|
|
|
|
2016-09-22 09:46:41 +02:00
|
|
|
UniValue result = tableRPC.execute(jreq);
|
2014-08-20 21:15:16 +02:00
|
|
|
rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id);
|
2012-06-24 08:01:28 +02:00
|
|
|
}
|
2015-05-18 14:02:18 +02:00
|
|
|
catch (const UniValue& objError)
|
2012-06-24 08:01:28 +02:00
|
|
|
{
|
2014-08-20 21:15:16 +02:00
|
|
|
rpc_result = JSONRPCReplyObj(NullUniValue, objError, jreq.id);
|
2012-06-24 08:01:28 +02:00
|
|
|
}
|
2014-12-07 13:29:06 +01:00
|
|
|
catch (const std::exception& e)
|
2012-06-24 08:01:28 +02:00
|
|
|
{
|
2014-08-20 21:15:16 +02:00
|
|
|
rpc_result = JSONRPCReplyObj(NullUniValue,
|
2012-10-04 09:34:44 +02:00
|
|
|
JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id);
|
2012-06-24 08:01:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return rpc_result;
|
|
|
|
}
|
|
|
|
|
2017-09-07 23:20:26 +02:00
|
|
|
std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq)
|
2012-06-24 08:01:28 +02:00
|
|
|
{
|
2015-06-02 11:41:00 +02:00
|
|
|
UniValue ret(UniValue::VARR);
|
2012-06-24 08:01:28 +02:00
|
|
|
for (unsigned int reqIdx = 0; reqIdx < vReq.size(); reqIdx++)
|
2017-09-07 23:20:26 +02:00
|
|
|
ret.push_back(JSONRPCExecOne(jreq, vReq[reqIdx]));
|
2012-06-24 08:01:28 +02:00
|
|
|
|
2014-08-20 21:15:16 +02:00
|
|
|
return ret.write() + "\n";
|
2012-06-24 08:01:28 +02:00
|
|
|
}
|
|
|
|
|
2016-09-25 20:42:49 +02:00
|
|
|
/**
|
|
|
|
* Process named arguments into a vector of positional arguments, based on the
|
|
|
|
* passed-in specification for the RPC call's arguments.
|
|
|
|
*/
|
|
|
|
static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, const std::vector<std::string>& argNames)
|
|
|
|
{
|
|
|
|
JSONRPCRequest out = in;
|
|
|
|
out.params = UniValue(UniValue::VARR);
|
|
|
|
// Build a map of parameters, and remove ones that have been processed, so that we can throw a focused error if
|
|
|
|
// there is an unknown one.
|
|
|
|
const std::vector<std::string>& keys = in.params.getKeys();
|
|
|
|
const std::vector<UniValue>& values = in.params.getValues();
|
|
|
|
std::unordered_map<std::string, const UniValue*> argsIn;
|
|
|
|
for (size_t i=0; i<keys.size(); ++i) {
|
|
|
|
argsIn[keys[i]] = &values[i];
|
|
|
|
}
|
|
|
|
// Process expected parameters.
|
|
|
|
int hole = 0;
|
2017-02-03 17:23:01 +01:00
|
|
|
for (const std::string &argNamePattern: argNames) {
|
|
|
|
std::vector<std::string> vargNames;
|
|
|
|
boost::algorithm::split(vargNames, argNamePattern, boost::algorithm::is_any_of("|"));
|
|
|
|
auto fr = argsIn.end();
|
|
|
|
for (const std::string & argName : vargNames) {
|
|
|
|
fr = argsIn.find(argName);
|
|
|
|
if (fr != argsIn.end()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-25 20:42:49 +02:00
|
|
|
if (fr != argsIn.end()) {
|
|
|
|
for (int i = 0; i < hole; ++i) {
|
|
|
|
// Fill hole between specified parameters with JSON nulls,
|
|
|
|
// but not at the end (for backwards compatibility with calls
|
|
|
|
// that act based on number of specified parameters).
|
|
|
|
out.params.push_back(UniValue());
|
|
|
|
}
|
|
|
|
hole = 0;
|
|
|
|
out.params.push_back(*fr->second);
|
|
|
|
argsIn.erase(fr);
|
|
|
|
} else {
|
|
|
|
hole += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If there are still arguments in the argsIn map, this is an error.
|
|
|
|
if (!argsIn.empty()) {
|
|
|
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown named parameter " + argsIn.begin()->first);
|
|
|
|
}
|
|
|
|
// Return request with named arguments transformed to positional arguments
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2016-09-22 09:46:41 +02:00
|
|
|
UniValue CRPCTable::execute(const JSONRPCRequest &request) const
|
2012-04-09 21:07:25 +02:00
|
|
|
{
|
2015-07-02 03:34:31 +02:00
|
|
|
// Return immediately if in warmup
|
|
|
|
{
|
|
|
|
LOCK(cs_rpcWarmup);
|
|
|
|
if (fRPCInWarmup)
|
|
|
|
throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
|
|
|
|
}
|
|
|
|
|
2012-04-09 21:07:25 +02:00
|
|
|
// Find method
|
2017-07-31 17:46:13 +02:00
|
|
|
auto it = mapCommands.find(request.strMethod);
|
|
|
|
if (it != mapCommands.end()) {
|
|
|
|
UniValue result;
|
|
|
|
for (const auto& command : it->second) {
|
|
|
|
if (ExecuteCommand(*command, request, result, &command == &it->second.back())) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
|
|
|
|
}
|
2011-05-14 20:10:21 +02:00
|
|
|
|
2017-07-31 17:46:13 +02:00
|
|
|
static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler)
|
|
|
|
{
|
2012-04-09 21:07:25 +02:00
|
|
|
try
|
|
|
|
{
|
2019-01-02 13:34:39 +01:00
|
|
|
RPCCommandExecution execution(request.strMethod);
|
2016-09-25 20:42:49 +02:00
|
|
|
// Execute, convert arguments to array if necessary
|
|
|
|
if (request.params.isObject()) {
|
2017-07-31 17:46:13 +02:00
|
|
|
return command.actor(transformNamedArguments(request, command.argNames), result, last_handler);
|
2016-09-25 20:42:49 +02:00
|
|
|
} else {
|
2017-07-31 17:46:13 +02:00
|
|
|
return command.actor(request, result, last_handler);
|
2016-09-25 20:42:49 +02:00
|
|
|
}
|
2012-04-09 21:07:25 +02:00
|
|
|
}
|
2014-12-07 13:29:06 +01:00
|
|
|
catch (const std::exception& e)
|
2012-04-09 21:07:25 +02:00
|
|
|
{
|
2012-10-04 09:34:44 +02:00
|
|
|
throw JSONRPCError(RPC_MISC_ERROR, e.what());
|
2012-04-09 21:07:25 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-14 20:10:21 +02:00
|
|
|
|
2016-02-27 04:57:12 +01:00
|
|
|
std::vector<std::string> CRPCTable::listCommands() const
|
|
|
|
{
|
|
|
|
std::vector<std::string> commandList;
|
2018-10-17 17:12:28 +02:00
|
|
|
for (const auto& i : mapCommands) commandList.emplace_back(i.first);
|
2016-02-27 04:57:12 +01:00
|
|
|
return commandList;
|
|
|
|
}
|
|
|
|
|
2016-01-08 11:03:52 +01:00
|
|
|
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)
|
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
|
|
|
{
|
2016-01-08 11:03:52 +01:00
|
|
|
if (!timerInterface)
|
|
|
|
timerInterface = iface;
|
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
|
|
|
}
|
|
|
|
|
2016-01-08 11:03:52 +01:00
|
|
|
void RPCSetTimerInterface(RPCTimerInterface *iface)
|
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
|
|
|
{
|
2016-01-08 11:03:52 +01:00
|
|
|
timerInterface = iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RPCUnsetTimerInterface(RPCTimerInterface *iface)
|
|
|
|
{
|
|
|
|
if (timerInterface == iface)
|
2017-08-07 07:36:37 +02:00
|
|
|
timerInterface = nullptr;
|
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
|
|
|
}
|
|
|
|
|
2018-09-13 19:36:41 +02:00
|
|
|
void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nSeconds)
|
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
|
|
|
{
|
2016-01-08 11:03:52 +01:00
|
|
|
if (!timerInterface)
|
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
|
|
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "No timer handler registered for RPC");
|
|
|
|
deadlineTimers.erase(name);
|
2016-12-25 21:19:40 +01:00
|
|
|
LogPrint(BCLog::RPC, "queue run of timer %s in %i seconds (using %s)\n", name, nSeconds, timerInterface->Name());
|
2016-07-19 01:15:59 +02:00
|
|
|
deadlineTimers.emplace(name, std::unique_ptr<RPCTimerBase>(timerInterface->NewTimer(func, nSeconds*1000)));
|
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.
- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.
- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral
- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.
- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.
By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.
What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.
Configuration options:
- `-rpcthreads`: repurposed as "number of work handler threads". Still
defaults to 4.
- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.
- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.
- `-debug=http`: low-level http activity logging
2015-01-23 07:53:17 +01:00
|
|
|
}
|
|
|
|
|
2016-11-20 15:54:51 +01:00
|
|
|
int RPCSerializationFlags()
|
|
|
|
{
|
|
|
|
int flag = 0;
|
2017-08-01 21:17:40 +02:00
|
|
|
if (gArgs.GetArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) == 0)
|
2016-11-20 15:54:51 +01:00
|
|
|
flag |= SERIALIZE_TRANSACTION_NO_WITNESS;
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2016-01-07 08:33:49 +01:00
|
|
|
CRPCTable tableRPC;
|