Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/server.cpp
// Copyright (c) 2010 Satoshi Nakamoto | // Copyright (c) 2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2018-2019 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 "rpc/server.h" | #include "rpc/server.h" | ||||
#include "base58.h" | #include "base58.h" | ||||
#include "config.h" | #include "config.h" | ||||
#include "fs.h" | #include "fs.h" | ||||
Show All 23 Lines | |||||
/* Timer-creating functions */ | /* Timer-creating functions */ | ||||
static RPCTimerInterface *timerInterface = nullptr; | static RPCTimerInterface *timerInterface = nullptr; | ||||
/* Map of name to timer. */ | /* Map of name to timer. */ | ||||
static std::map<std::string, std::unique_ptr<RPCTimerBase>> deadlineTimers; | static std::map<std::string, std::unique_ptr<RPCTimerBase>> deadlineTimers; | ||||
UniValue RPCServer::ExecuteCommand(Config &config, | UniValue RPCServer::ExecuteCommand(Config &config, | ||||
const JSONRPCRequest &request) const { | const JSONRPCRequest &request) const { | ||||
// Return immediately if in warmup | // Return immediately if in warmup | ||||
// This is retained from the old RPC implementation because a lot of state | |||||
// is set during warmup that RPC commands may depend on. This can be | |||||
// safely removed once global variable usage has been eliminated. | |||||
{ | { | ||||
LOCK(cs_rpcWarmup); | LOCK(cs_rpcWarmup); | ||||
if (fRPCInWarmup) { | if (fRPCInWarmup) { | ||||
throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus); | throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus); | ||||
} | } | ||||
} | } | ||||
// TODO Only call tableRPC.execute() if no context-sensitive RPC command | std::string commandName = request.strMethod; | ||||
// exists | { | ||||
auto commandsReadView = commands.getReadView(); | |||||
auto iter = commandsReadView->find(commandName); | |||||
if (iter != commandsReadView.end()) { | |||||
return iter->second.get()->Execute(request.params); | |||||
} | |||||
} | |||||
// TODO Remove the below call to tableRPC.execute() and only call it for | |||||
// context-free RPC commands via an implementation of RPCCommand. | |||||
// Check if context-free RPC method is valid and execute it | // Check if context-free RPC method is valid and execute it | ||||
return tableRPC.execute(config, request); | return tableRPC.execute(config, request); | ||||
} | } | ||||
void RPCServer::RegisterCommand(std::unique_ptr<RPCCommand> command) { | |||||
if (command != nullptr) { | |||||
commands.getWriteView()->insert( | |||||
std::make_pair(command->GetName(), std::move(command))); | |||||
} | |||||
} | |||||
static struct CRPCSignals { | static struct CRPCSignals { | ||||
boost::signals2::signal<void()> Started; | boost::signals2::signal<void()> Started; | ||||
boost::signals2::signal<void()> Stopped; | boost::signals2::signal<void()> Stopped; | ||||
boost::signals2::signal<void(const ContextFreeRPCCommand &)> PreCommand; | boost::signals2::signal<void(const ContextFreeRPCCommand &)> PreCommand; | ||||
} g_rpcSignals; | } g_rpcSignals; | ||||
void RPCServerSignals::OnStarted(std::function<void()> slot) { | void RPCServerSignals::OnStarted(std::function<void()> slot) { | ||||
g_rpcSignals.Started.connect(slot); | g_rpcSignals.Started.connect(slot); | ||||
▲ Show 20 Lines • Show All 527 Lines • Show Last 20 Lines |