2011-05-14 20:10:21 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2020-01-15 02:17:38 +07:00
|
|
|
// Copyright (c) 2009-2020 The Bitcoin Core developers
|
2014-10-30 10:14:08 +08:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 22:02:28 +08:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2011-05-14 20:10:21 +02:00
|
|
|
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <rpc/server.h>
|
2013-04-13 00:13:08 -05:00
|
|
|
|
2018-11-06 10:40:50 -05:00
|
|
|
#include <rpc/util.h>
|
2018-05-16 19:17:40 +00:00
|
|
|
#include <shutdown.h>
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <sync.h>
|
2018-10-22 15:51:11 -07:00
|
|
|
#include <util/strencodings.h>
|
2018-11-06 10:40:50 -05:00
|
|
|
#include <util/system.h>
|
2013-04-13 00:13:08 -05:00
|
|
|
|
2017-02-03 16:23:01 +00:00
|
|
|
#include <boost/algorithm/string/classification.hpp>
|
|
|
|
#include <boost/algorithm/string/split.hpp>
|
2020-05-22 15:38:48 -04:00
|
|
|
#include <boost/signals2/signal.hpp>
|
2014-08-20 15:15:16 -04:00
|
|
|
|
2020-03-27 20:29:20 +02:00
|
|
|
#include <cassert>
|
2016-07-18 12:26:21 +03:00
|
|
|
#include <memory> // for unique_ptr
|
2020-03-27 20:29:20 +02:00
|
|
|
#include <mutex>
|
2016-09-25 20:42:49 +02:00
|
|
|
#include <unordered_map>
|
2016-07-18 12:26:21 +03:00
|
|
|
|
2020-06-28 09:54:17 +03:00
|
|
|
static Mutex g_rpc_warmup_mutex;
|
2018-12-18 10:21:06 +01:00
|
|
|
static std::atomic<bool> g_rpc_running{false};
|
2020-06-28 09:54:17 +03:00
|
|
|
static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true;
|
|
|
|
static std::string rpcWarmupStatus GUARDED_BY(g_rpc_warmup_mutex) = "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 12:26:21 +03:00
|
|
|
/* Map of name to timer. */
|
2020-04-29 10:40:39 +01:00
|
|
|
static Mutex g_deadline_timers_mutex;
|
|
|
|
static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers GUARDED_BY(g_deadline_timers_mutex);
|
2017-07-31 11:46:13 -04:00
|
|
|
static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler);
|
2012-04-14 20:35:58 -04:00
|
|
|
|
2019-01-02 12:34:39 +00: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-24 19:54:46 -05:00
|
|
|
it = g_rpc_server_info.active_commands.insert(g_rpc_server_info.active_commands.end(), {method, GetTimeMicros()});
|
2019-01-02 12:34:39 +00:00
|
|
|
}
|
|
|
|
~RPCCommandExecution()
|
|
|
|
{
|
|
|
|
LOCK(g_rpc_server_info.mutex);
|
|
|
|
g_rpc_server_info.active_commands.erase(it);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-19 04:46:17 -04: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 04:46:17 -04:00
|
|
|
{
|
|
|
|
g_rpcSignals.Started.connect(slot);
|
|
|
|
}
|
|
|
|
|
2017-05-13 17:52:14 +02:00
|
|
|
void RPCServer::OnStopped(std::function<void ()> slot)
|
2014-10-19 04:46:17 -04:00
|
|
|
{
|
|
|
|
g_rpcSignals.Stopped.connect(slot);
|
|
|
|
}
|
|
|
|
|
2016-12-29 13:05:51 +00:00
|
|
|
std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest& helpreq) const
|
2011-05-14 20:10:21 +02:00
|
|
|
{
|
2017-01-04 13:22:19 +09:00
|
|
|
std::string strRet;
|
|
|
|
std::string category;
|
2017-07-31 11:46:13 -04:00
|
|
|
std::set<intptr_t> setDone;
|
2017-01-04 13:22:19 +09: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 11:46:13 -04: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());
|
|
|
|
|
2020-12-01 00:36:36 +01:00
|
|
|
JSONRPCRequest jreq = helpreq;
|
2021-01-29 18:09:46 -05:00
|
|
|
jreq.mode = JSONRPCRequest::GET_HELP;
|
2016-12-29 13:05:51 +00:00
|
|
|
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 13:22:19 +09: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 13:05:51 +00:00
|
|
|
jreq.strMethod = strMethod;
|
2011-05-14 20:10:21 +02:00
|
|
|
try
|
|
|
|
{
|
2017-07-31 11:46:13 -04: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 13:22:19 +09: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 13:22:19 +09: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;
|
|
|
|
}
|
|
|
|
|
2020-06-26 14:12:46 -04:00
|
|
|
static RPCHelpMan help()
|
2012-04-18 22:42:17 +02:00
|
|
|
{
|
2020-06-26 14:12:46 -04:00
|
|
|
return RPCHelpMan{"help",
|
2018-10-20 08:19:44 -04:00
|
|
|
"\nList all commands, or get help for a specified command.\n",
|
|
|
|
{
|
2021-04-14 15:01:00 +01:00
|
|
|
{"command", RPCArg::Type::STR, RPCArg::DefaultHint{"all commands"}, "The command to get help on"},
|
2018-12-21 12:29:36 -05:00
|
|
|
},
|
2020-11-23 10:41:27 +01:00
|
|
|
{
|
|
|
|
RPCResult{RPCResult::Type::STR, "", "The help text"},
|
|
|
|
RPCResult{RPCResult::Type::ANY, "", ""},
|
2018-12-21 12:29:36 -05:00
|
|
|
},
|
|
|
|
RPCExamples{""},
|
2020-06-26 14:12:46 -04:00
|
|
|
[&](const RPCHelpMan& self, const JSONRPCRequest& jsonRequest) -> UniValue
|
|
|
|
{
|
2017-01-04 13:22:19 +09:00
|
|
|
std::string strCommand;
|
2021-01-12 06:28:13 +01:00
|
|
|
if (jsonRequest.params.size() > 0) {
|
2016-09-22 09:46:41 +02:00
|
|
|
strCommand = jsonRequest.params[0].get_str();
|
2021-01-12 06:28:13 +01:00
|
|
|
}
|
|
|
|
if (strCommand == "dump_all_command_conversions") {
|
|
|
|
// Used for testing only, undocumented
|
2021-01-29 18:15:48 -05:00
|
|
|
return tableRPC.dumpArgMap(jsonRequest);
|
2021-01-12 06:28:13 +01:00
|
|
|
}
|
2012-04-18 22:42:17 +02:00
|
|
|
|
2016-12-29 13:05:51 +00:00
|
|
|
return tableRPC.help(strCommand, jsonRequest);
|
2020-06-26 14:12:46 -04:00
|
|
|
},
|
|
|
|
};
|
2012-04-18 22:42:17 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 14:12:46 -04:00
|
|
|
static RPCHelpMan stop()
|
2011-05-14 20:10:21 +02:00
|
|
|
{
|
2020-03-13 14:40:53 -04:00
|
|
|
static const std::string RESULT{PACKAGE_NAME " stopping"};
|
2020-06-26 14:12:46 -04:00
|
|
|
return RPCHelpMan{"stop",
|
2018-11-20 17:52:15 +00: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)
|
2019-07-27 16:28:48 +02:00
|
|
|
"\nRequest a graceful shutdown of " PACKAGE_NAME ".",
|
2020-06-26 14:12:46 -04:00
|
|
|
{
|
|
|
|
{"wait", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "how long to wait in ms", "", {}, /* hidden */ true},
|
|
|
|
},
|
2020-03-13 14:40:53 -04:00
|
|
|
RPCResult{RPCResult::Type::STR, "", "A string with the content '" + RESULT + "'"},
|
2018-12-21 12:29:36 -05:00
|
|
|
RPCExamples{""},
|
2020-06-26 14:12:46 -04:00
|
|
|
[&](const RPCHelpMan& self, const JSONRPCRequest& jsonRequest) -> UniValue
|
|
|
|
{
|
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 17:52:15 +00:00
|
|
|
if (jsonRequest.params[0].isNum()) {
|
2020-02-21 09:20:51 -08:00
|
|
|
UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].get_int()});
|
2018-11-20 17:52:15 +00:00
|
|
|
}
|
2020-03-13 14:40:53 -04:00
|
|
|
return RESULT;
|
2020-06-26 14:12:46 -04:00
|
|
|
},
|
|
|
|
};
|
2011-05-14 20:10:21 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 14:12:46 -04:00
|
|
|
static RPCHelpMan uptime()
|
2017-05-14 19:18:26 +01:00
|
|
|
{
|
2020-06-26 14:12:46 -04:00
|
|
|
return RPCHelpMan{"uptime",
|
2018-12-21 12:29:36 -05:00
|
|
|
"\nReturns the total uptime of the server.\n",
|
|
|
|
{},
|
|
|
|
RPCResult{
|
2020-01-10 00:00:57 +07:00
|
|
|
RPCResult::Type::NUM, "", "The number of seconds that the server has been running"
|
2018-12-21 12:29:36 -05:00
|
|
|
},
|
|
|
|
RPCExamples{
|
|
|
|
HelpExampleCli("uptime", "")
|
2017-05-14 19:18:26 +01:00
|
|
|
+ HelpExampleRpc("uptime", "")
|
2018-12-21 12:29:36 -05:00
|
|
|
},
|
2020-06-26 14:12:46 -04:00
|
|
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
|
|
|
{
|
2017-05-14 19:18:26 +01:00
|
|
|
return GetTime() - GetStartupTime();
|
|
|
|
}
|
2020-06-26 14:12:46 -04:00
|
|
|
};
|
|
|
|
}
|
2017-05-14 19:18:26 +01:00
|
|
|
|
2020-06-26 14:12:46 -04:00
|
|
|
static RPCHelpMan getrpcinfo()
|
2018-12-14 15:53:59 +00:00
|
|
|
{
|
2020-06-26 14:12:46 -04:00
|
|
|
return RPCHelpMan{"getrpcinfo",
|
2018-12-21 12:29:36 -05:00
|
|
|
"\nReturns details of the RPC server.\n",
|
|
|
|
{},
|
2019-04-05 02:04:34 -05:00
|
|
|
RPCResult{
|
2020-01-10 00:00:57 +07:00
|
|
|
RPCResult::Type::OBJ, "", "",
|
|
|
|
{
|
|
|
|
{RPCResult::Type::ARR, "active_commands", "All active commands",
|
|
|
|
{
|
|
|
|
{RPCResult::Type::OBJ, "", "Information about an active command",
|
|
|
|
{
|
|
|
|
{RPCResult::Type::STR, "method", "The name of the RPC command"},
|
|
|
|
{RPCResult::Type::NUM, "duration", "The running time in microseconds"},
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
{RPCResult::Type::STR, "logpath", "The complete file path to the debug log"},
|
|
|
|
}
|
2019-04-05 02:04:34 -05:00
|
|
|
},
|
|
|
|
RPCExamples{
|
|
|
|
HelpExampleCli("getrpcinfo", "")
|
|
|
|
+ HelpExampleRpc("getrpcinfo", "")},
|
2020-06-26 14:12:46 -04:00
|
|
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
|
|
|
{
|
2018-12-14 15:53:59 +00: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);
|
|
|
|
|
2019-05-16 23:01:00 +02:00
|
|
|
const std::string path = LogInstance().m_file_path.string();
|
|
|
|
UniValue log_path(UniValue::VSTR, path);
|
|
|
|
result.pushKV("logpath", log_path);
|
|
|
|
|
2018-12-14 15:53:59 +00:00
|
|
|
return result;
|
|
|
|
}
|
2020-06-26 14:12:46 -04:00
|
|
|
};
|
|
|
|
}
|
2018-12-14 15:53:59 +00:00
|
|
|
|
2018-08-20 14:19:43 +02:00
|
|
|
// clang-format off
|
2012-04-21 01:37:34 +02:00
|
|
|
static const CRPCCommand vRPCCommands[] =
|
2021-01-12 06:41:46 +01:00
|
|
|
{ // category actor (function)
|
|
|
|
// --------------------- -----------------------
|
2014-03-26 12:26:43 +01:00
|
|
|
/* Overall control/query calls */
|
2021-01-12 06:41:46 +01:00
|
|
|
{ "control", &getrpcinfo, },
|
|
|
|
{ "control", &help, },
|
|
|
|
{ "control", &stop, },
|
|
|
|
{ "control", &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-14 23:55:05 -04:00
|
|
|
{
|
2020-07-15 21:29:41 +02:00
|
|
|
for (const auto& c : vRPCCommands) {
|
|
|
|
appendCommand(c.name, &c);
|
2012-04-14 23:55:05 -04:00
|
|
|
}
|
|
|
|
}
|
2011-05-14 20:10:21 +02:00
|
|
|
|
2020-08-14 10:15:30 +02:00
|
|
|
void CRPCTable::appendCommand(const std::string& name, const CRPCCommand* pcmd)
|
2016-01-07 08:33:49 +01:00
|
|
|
{
|
2020-08-14 10:15:30 +02:00
|
|
|
CHECK_NONFATAL(!IsRPCRunning()); // Only add commands before rpc is running
|
2016-01-07 08:33:49 +01:00
|
|
|
|
2017-07-31 11:46:13 -04:00
|
|
|
mapCommands[name].push_back(pcmd);
|
2016-01-07 08:33:49 +01:00
|
|
|
}
|
|
|
|
|
2017-07-31 11:46:13 -04: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 20:19:40 +00:00
|
|
|
LogPrint(BCLog::RPC, "Starting RPC\n");
|
2018-12-18 10:21:06 +01:00
|
|
|
g_rpc_running = true;
|
2014-10-19 04:46:17 -04:00
|
|
|
g_rpcSignals.Started();
|
2013-03-06 22:31:26 -05: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
|
|
|
{
|
2020-05-29 17:21:56 -04:00
|
|
|
static std::once_flag g_rpc_interrupt_flag;
|
2020-03-27 20:29:20 +02:00
|
|
|
// This function could be called twice if the GUI has been started with -server=1.
|
|
|
|
std::call_once(g_rpc_interrupt_flag, []() {
|
|
|
|
LogPrint(BCLog::RPC, "Interrupting RPC\n");
|
|
|
|
// Interrupt e.g. running longpolls
|
|
|
|
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-06 22:31:26 -05:00
|
|
|
{
|
2020-05-29 17:21:56 -04:00
|
|
|
static std::once_flag g_rpc_stop_flag;
|
2020-03-27 20:29:20 +02:00
|
|
|
// This function could be called twice if the GUI has been started with -server=1.
|
|
|
|
assert(!g_rpc_running);
|
|
|
|
std::call_once(g_rpc_stop_flag, []() {
|
|
|
|
LogPrint(BCLog::RPC, "Stopping RPC\n");
|
|
|
|
WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear());
|
|
|
|
DeleteAuthCookie();
|
|
|
|
g_rpcSignals.Stopped();
|
|
|
|
});
|
2012-04-14 20:35:58 -04:00
|
|
|
}
|
|
|
|
|
2012-05-13 04:43:24 +00:00
|
|
|
bool IsRPCRunning()
|
|
|
|
{
|
2018-12-18 10:21:06 +01:00
|
|
|
return g_rpc_running;
|
2012-05-13 04:43:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-22 15:38:48 -04:00
|
|
|
void RpcInterruptionPoint()
|
|
|
|
{
|
|
|
|
if (!IsRPCRunning()) throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
|
|
|
|
}
|
|
|
|
|
2014-10-29 18:08:31 +01:00
|
|
|
void SetRPCWarmupStatus(const std::string& newStatus)
|
|
|
|
{
|
2020-06-28 09:54:17 +03:00
|
|
|
LOCK(g_rpc_warmup_mutex);
|
2014-10-29 18:08:31 +01:00
|
|
|
rpcWarmupStatus = newStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetRPCWarmupFinished()
|
|
|
|
{
|
2020-06-28 09:54:17 +03:00
|
|
|
LOCK(g_rpc_warmup_mutex);
|
2014-10-29 18:08:31 +01:00
|
|
|
assert(fRPCInWarmup);
|
|
|
|
fRPCInWarmup = false;
|
|
|
|
}
|
|
|
|
|
2014-11-26 13:51:02 +01:00
|
|
|
bool RPCIsInWarmup(std::string *outStatus)
|
|
|
|
{
|
2020-06-28 09:54:17 +03:00
|
|
|
LOCK(g_rpc_warmup_mutex);
|
2014-11-26 13:51:02 +01:00
|
|
|
if (outStatus)
|
|
|
|
*outStatus = rpcWarmupStatus;
|
|
|
|
return fRPCInWarmup;
|
|
|
|
}
|
|
|
|
|
2017-08-11 11:25:06 -04: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 17:20:26 -04:00
|
|
|
static UniValue JSONRPCExecOne(JSONRPCRequest jreq, const UniValue& req)
|
2012-06-24 02:01:28 -04:00
|
|
|
{
|
2015-05-10 14:48:35 +02:00
|
|
|
UniValue rpc_result(UniValue::VOBJ);
|
2012-06-24 02:01:28 -04:00
|
|
|
|
|
|
|
try {
|
|
|
|
jreq.parse(req);
|
|
|
|
|
2016-09-22 09:46:41 +02:00
|
|
|
UniValue result = tableRPC.execute(jreq);
|
2014-08-20 15:15:16 -04:00
|
|
|
rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id);
|
2012-06-24 02:01:28 -04:00
|
|
|
}
|
2015-05-18 14:02:18 +02:00
|
|
|
catch (const UniValue& objError)
|
2012-06-24 02:01:28 -04:00
|
|
|
{
|
2014-08-20 15:15:16 -04:00
|
|
|
rpc_result = JSONRPCReplyObj(NullUniValue, objError, jreq.id);
|
2012-06-24 02:01:28 -04:00
|
|
|
}
|
2014-12-07 13:29:06 +01:00
|
|
|
catch (const std::exception& e)
|
2012-06-24 02:01:28 -04:00
|
|
|
{
|
2014-08-20 15:15:16 -04:00
|
|
|
rpc_result = JSONRPCReplyObj(NullUniValue,
|
2012-10-04 09:34:44 +02:00
|
|
|
JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id);
|
2012-06-24 02:01:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rpc_result;
|
|
|
|
}
|
|
|
|
|
2017-09-07 17:20:26 -04:00
|
|
|
std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq)
|
2012-06-24 02:01:28 -04:00
|
|
|
{
|
2015-06-02 11:41:00 +02:00
|
|
|
UniValue ret(UniValue::VARR);
|
2012-06-24 02:01:28 -04:00
|
|
|
for (unsigned int reqIdx = 0; reqIdx < vReq.size(); reqIdx++)
|
2017-09-07 17:20:26 -04:00
|
|
|
ret.push_back(JSONRPCExecOne(jreq, vReq[reqIdx]));
|
2012-06-24 02:01:28 -04:00
|
|
|
|
2014-08-20 15:15:16 -04:00
|
|
|
return ret.write() + "\n";
|
2012-06-24 02:01:28 -04: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 16:23:01 +00: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;
|
|
|
|
}
|
|
|
|
|
2021-01-29 18:12:19 -05:00
|
|
|
static bool ExecuteCommands(const std::vector<const CRPCCommand*>& commands, const JSONRPCRequest& request, UniValue& result)
|
|
|
|
{
|
|
|
|
for (const auto& command : commands) {
|
|
|
|
if (ExecuteCommand(*command, request, result, &command == &commands.back())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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-01 21:34:31 -04:00
|
|
|
// Return immediately if in warmup
|
|
|
|
{
|
2020-06-28 09:54:17 +03:00
|
|
|
LOCK(g_rpc_warmup_mutex);
|
2015-07-01 21:34:31 -04:00
|
|
|
if (fRPCInWarmup)
|
|
|
|
throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
|
|
|
|
}
|
|
|
|
|
2012-04-09 21:07:25 +02:00
|
|
|
// Find method
|
2017-07-31 11:46:13 -04:00
|
|
|
auto it = mapCommands.find(request.strMethod);
|
|
|
|
if (it != mapCommands.end()) {
|
|
|
|
UniValue result;
|
2021-01-29 18:12:19 -05:00
|
|
|
if (ExecuteCommands(it->second, request, result)) {
|
|
|
|
return result;
|
2017-07-31 11:46:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
|
|
|
|
}
|
2011-05-14 20:10:21 +02:00
|
|
|
|
2017-07-31 11:46:13 -04: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 12:34:39 +00: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 11:46:13 -04:00
|
|
|
return command.actor(transformNamedArguments(request, command.argNames), result, last_handler);
|
2016-09-25 20:42:49 +02:00
|
|
|
} else {
|
2017-07-31 11:46:13 -04: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 11:57:12 +08:00
|
|
|
std::vector<std::string> CRPCTable::listCommands() const
|
|
|
|
{
|
|
|
|
std::vector<std::string> commandList;
|
2018-10-17 23:12:28 +08:00
|
|
|
for (const auto& i : mapCommands) commandList.emplace_back(i.first);
|
2016-02-27 11:57:12 +08:00
|
|
|
return commandList;
|
|
|
|
}
|
|
|
|
|
2021-01-29 18:15:48 -05:00
|
|
|
UniValue CRPCTable::dumpArgMap(const JSONRPCRequest& args_request) const
|
2021-01-12 06:28:13 +01:00
|
|
|
{
|
2020-12-01 00:36:36 +01:00
|
|
|
JSONRPCRequest request = args_request;
|
2021-01-29 18:15:48 -05:00
|
|
|
request.mode = JSONRPCRequest::GET_ARGS;
|
|
|
|
|
2021-01-12 06:28:13 +01:00
|
|
|
UniValue ret{UniValue::VARR};
|
|
|
|
for (const auto& cmd : mapCommands) {
|
2021-01-29 18:15:48 -05:00
|
|
|
UniValue result;
|
|
|
|
if (ExecuteCommands(cmd.second, request, result)) {
|
|
|
|
for (const auto& values : result.getValues()) {
|
|
|
|
ret.push_back(values);
|
|
|
|
}
|
2021-01-12 06:28:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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 10:36:41 -07: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");
|
2020-04-29 10:40:39 +01:00
|
|
|
LOCK(g_deadline_timers_mutex);
|
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
|
|
|
deadlineTimers.erase(name);
|
2016-12-25 20:19:40 +00:00
|
|
|
LogPrint(BCLog::RPC, "queue run of timer %s in %i seconds (using %s)\n", name, nSeconds, timerInterface->Name());
|
2016-07-19 02:15:59 +03: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 09:54:51 -05:00
|
|
|
int RPCSerializationFlags()
|
|
|
|
{
|
|
|
|
int flag = 0;
|
2019-08-22 21:40:41 -04:00
|
|
|
if (gArgs.GetIntArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) == 0)
|
2016-11-20 09:54:51 -05:00
|
|
|
flag |= SERIALIZE_TRANSACTION_NO_WITNESS;
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2016-01-07 08:33:49 +01:00
|
|
|
CRPCTable tableRPC;
|