aboutsummaryrefslogtreecommitdiff
path: root/src/rpcserver.cpp
diff options
context:
space:
mode:
authorDaniel Kraft <d@domob.eu>2014-10-29 18:08:31 +0100
committerDaniel Kraft <d@domob.eu>2014-11-04 16:01:09 +0100
commitaf82884ab7c485c8b4c5ac93c308127c39c196be (patch)
tree766428da14b53e4902c87fd3fb05a1c0d1acd87a /src/rpcserver.cpp
parentbe32b5212b6ab4460080ec5ff55e2bf882259e5e (diff)
Add "warmup mode" for RPC server.
Start the RPC server before doing all the (expensive) startup initialisations like loading the block index. Until the node is ready, return all calls immediately with a new error signalling "in warmup" with an appropriate status message (similar to the init message). This is useful for RPC clients to know that the server is there (e. g., they don't have to start it) but not yet available. It is used in Namecoin and Huntercoin already for some time, and there exists a UI hooked onto the RPC interface that actively uses this to its advantage.
Diffstat (limited to 'src/rpcserver.cpp')
-rw-r--r--src/rpcserver.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp
index 08ed73f6de..cc80887ba4 100644
--- a/src/rpcserver.cpp
+++ b/src/rpcserver.cpp
@@ -34,6 +34,10 @@ using namespace std;
static std::string strRPCUserColonPass;
static bool fRPCRunning = false;
+static bool fRPCInWarmup = true;
+static std::string rpcWarmupStatus("RPC server started");
+static CCriticalSection cs_rpcWarmup;
+
//! These are created by StartRPCThreads, destroyed in StopRPCThreads
static asio::io_service* rpc_io_service = NULL;
static map<string, boost::shared_ptr<deadline_timer> > deadlineTimers;
@@ -744,6 +748,19 @@ bool IsRPCRunning()
return fRPCRunning;
}
+void SetRPCWarmupStatus(const std::string& newStatus)
+{
+ LOCK(cs_rpcWarmup);
+ rpcWarmupStatus = newStatus;
+}
+
+void SetRPCWarmupFinished()
+{
+ LOCK(cs_rpcWarmup);
+ assert(fRPCInWarmup);
+ fRPCInWarmup = false;
+}
+
void RPCRunHandler(const boost::system::error_code& err, boost::function<void(void)> func)
{
if (!err)
@@ -870,6 +887,13 @@ static bool HTTPReq_JSONRPC(AcceptedConnection *conn,
if (!read_string(strRequest, valRequest))
throw JSONRPCError(RPC_PARSE_ERROR, "Parse error");
+ // Return immediately if in warmup
+ {
+ LOCK(cs_rpcWarmup);
+ if (fRPCInWarmup)
+ throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
+ }
+
string strReply;
// singleton request