Bitcoin Core  0.20.99
P2P Digital Currency
server.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2020 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <rpc/server.h>
7 
8 #include <rpc/util.h>
9 #include <shutdown.h>
10 #include <sync.h>
11 #include <util/strencodings.h>
12 #include <util/system.h>
13 
14 #include <boost/algorithm/string/classification.hpp>
15 #include <boost/algorithm/string/split.hpp>
16 #include <boost/signals2/signal.hpp>
17 
18 #include <cassert>
19 #include <memory> // for unique_ptr
20 #include <mutex>
21 #include <unordered_map>
22 
24 static std::atomic<bool> g_rpc_running{false};
25 static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true;
26 static std::string rpcWarmupStatus GUARDED_BY(g_rpc_warmup_mutex) = "RPC server started";
27 /* Timer-creating functions */
29 /* Map of name to timer. */
31 static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers GUARDED_BY(g_deadline_timers_mutex);
32 static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler);
33 
35 {
36  std::string method;
37  int64_t start;
38 };
39 
41 {
43  std::list<RPCCommandExecutionInfo> active_commands GUARDED_BY(mutex);
44 };
45 
47 
49 {
50  std::list<RPCCommandExecutionInfo>::iterator it;
51  explicit RPCCommandExecution(const std::string& method)
52  {
53  LOCK(g_rpc_server_info.mutex);
54  it = g_rpc_server_info.active_commands.insert(g_rpc_server_info.active_commands.end(), {method, GetTimeMicros()});
55  }
57  {
58  LOCK(g_rpc_server_info.mutex);
59  g_rpc_server_info.active_commands.erase(it);
60  }
61 };
62 
63 static struct CRPCSignals
64 {
65  boost::signals2::signal<void ()> Started;
66  boost::signals2::signal<void ()> Stopped;
67 } g_rpcSignals;
68 
69 void RPCServer::OnStarted(std::function<void ()> slot)
70 {
71  g_rpcSignals.Started.connect(slot);
72 }
73 
74 void RPCServer::OnStopped(std::function<void ()> slot)
75 {
76  g_rpcSignals.Stopped.connect(slot);
77 }
78 
79 std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest& helpreq) const
80 {
81  std::string strRet;
82  std::string category;
83  std::set<intptr_t> setDone;
84  std::vector<std::pair<std::string, const CRPCCommand*> > vCommands;
85 
86  for (const auto& entry : mapCommands)
87  vCommands.push_back(make_pair(entry.second.front()->category + entry.first, entry.second.front()));
88  sort(vCommands.begin(), vCommands.end());
89 
90  JSONRPCRequest jreq(helpreq);
91  jreq.fHelp = true;
92  jreq.params = UniValue();
93 
94  for (const std::pair<std::string, const CRPCCommand*>& command : vCommands)
95  {
96  const CRPCCommand *pcmd = command.second;
97  std::string strMethod = pcmd->name;
98  if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand)
99  continue;
100  jreq.strMethod = strMethod;
101  try
102  {
103  UniValue unused_result;
104  if (setDone.insert(pcmd->unique_id).second)
105  pcmd->actor(jreq, unused_result, true /* last_handler */);
106  }
107  catch (const std::exception& e)
108  {
109  // Help text is returned in an exception
110  std::string strHelp = std::string(e.what());
111  if (strCommand == "")
112  {
113  if (strHelp.find('\n') != std::string::npos)
114  strHelp = strHelp.substr(0, strHelp.find('\n'));
115 
116  if (category != pcmd->category)
117  {
118  if (!category.empty())
119  strRet += "\n";
120  category = pcmd->category;
121  strRet += "== " + Capitalize(category) + " ==\n";
122  }
123  }
124  strRet += strHelp + "\n";
125  }
126  }
127  if (strRet == "")
128  strRet = strprintf("help: unknown command: %s\n", strCommand);
129  strRet = strRet.substr(0,strRet.size()-1);
130  return strRet;
131 }
132 
133 static RPCHelpMan help()
134 {
135  return RPCHelpMan{"help",
136  "\nList all commands, or get help for a specified command.\n",
137  {
138  {"command", RPCArg::Type::STR, /* default */ "all commands", "The command to get help on"},
139  },
140  RPCResult{
141  RPCResult::Type::STR, "", "The help text"
142  },
143  RPCExamples{""},
144  [&](const RPCHelpMan& self, const JSONRPCRequest& jsonRequest) -> UniValue
145 {
146  std::string strCommand;
147  if (jsonRequest.params.size() > 0)
148  strCommand = jsonRequest.params[0].get_str();
149 
150  return tableRPC.help(strCommand, jsonRequest);
151 },
152  };
153 }
154 
155 static RPCHelpMan stop()
156 {
157  static const std::string RESULT{PACKAGE_NAME " stopping"};
158  return RPCHelpMan{"stop",
159  // Also accept the hidden 'wait' integer argument (milliseconds)
160  // For instance, 'stop 1000' makes the call wait 1 second before returning
161  // to the client (intended for testing)
162  "\nRequest a graceful shutdown of " PACKAGE_NAME ".",
163  {
164  {"wait", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "how long to wait in ms", "", {}, /* hidden */ true},
165  },
166  RPCResult{RPCResult::Type::STR, "", "A string with the content '" + RESULT + "'"},
167  RPCExamples{""},
168  [&](const RPCHelpMan& self, const JSONRPCRequest& jsonRequest) -> UniValue
169 {
170  // Event loop will exit after current HTTP requests have been handled, so
171  // this reply will get back to the client.
172  StartShutdown();
173  if (jsonRequest.params[0].isNum()) {
174  UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].get_int()});
175  }
176  return RESULT;
177 },
178  };
179 }
180 
182 {
183  return RPCHelpMan{"uptime",
184  "\nReturns the total uptime of the server.\n",
185  {},
186  RPCResult{
187  RPCResult::Type::NUM, "", "The number of seconds that the server has been running"
188  },
189  RPCExamples{
190  HelpExampleCli("uptime", "")
191  + HelpExampleRpc("uptime", "")
192  },
193  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
194 {
195  return GetTime() - GetStartupTime();
196 }
197  };
198 }
199 
201 {
202  return RPCHelpMan{"getrpcinfo",
203  "\nReturns details of the RPC server.\n",
204  {},
205  RPCResult{
206  RPCResult::Type::OBJ, "", "",
207  {
208  {RPCResult::Type::ARR, "active_commands", "All active commands",
209  {
210  {RPCResult::Type::OBJ, "", "Information about an active command",
211  {
212  {RPCResult::Type::STR, "method", "The name of the RPC command"},
213  {RPCResult::Type::NUM, "duration", "The running time in microseconds"},
214  }},
215  }},
216  {RPCResult::Type::STR, "logpath", "The complete file path to the debug log"},
217  }
218  },
219  RPCExamples{
220  HelpExampleCli("getrpcinfo", "")
221  + HelpExampleRpc("getrpcinfo", "")},
222  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
223 {
224  LOCK(g_rpc_server_info.mutex);
225  UniValue active_commands(UniValue::VARR);
226  for (const RPCCommandExecutionInfo& info : g_rpc_server_info.active_commands) {
227  UniValue entry(UniValue::VOBJ);
228  entry.pushKV("method", info.method);
229  entry.pushKV("duration", GetTimeMicros() - info.start);
230  active_commands.push_back(entry);
231  }
232 
233  UniValue result(UniValue::VOBJ);
234  result.pushKV("active_commands", active_commands);
235 
236  const std::string path = LogInstance().m_file_path.string();
237  UniValue log_path(UniValue::VSTR, path);
238  result.pushKV("logpath", log_path);
239 
240  return result;
241 }
242  };
243 }
244 
245 // clang-format off
246 static const CRPCCommand vRPCCommands[] =
247 { // category name actor (function) argNames
248  // --------------------- ------------------------ ----------------------- ----------
249  /* Overall control/query calls */
250  { "control", "getrpcinfo", &getrpcinfo, {} },
251  { "control", "help", &help, {"command"} },
252  { "control", "stop", &stop, {"wait"} },
253  { "control", "uptime", &uptime, {} },
254 };
255 // clang-format on
256 
258 {
259  for (const auto& c : vRPCCommands) {
260  appendCommand(c.name, &c);
261  }
262 }
263 
264 void CRPCTable::appendCommand(const std::string& name, const CRPCCommand* pcmd)
265 {
266  CHECK_NONFATAL(!IsRPCRunning()); // Only add commands before rpc is running
267 
268  mapCommands[name].push_back(pcmd);
269 }
270 
271 bool CRPCTable::removeCommand(const std::string& name, const CRPCCommand* pcmd)
272 {
273  auto it = mapCommands.find(name);
274  if (it != mapCommands.end()) {
275  auto new_end = std::remove(it->second.begin(), it->second.end(), pcmd);
276  if (it->second.end() != new_end) {
277  it->second.erase(new_end, it->second.end());
278  return true;
279  }
280  }
281  return false;
282 }
283 
284 void StartRPC()
285 {
286  LogPrint(BCLog::RPC, "Starting RPC\n");
287  g_rpc_running = true;
289 }
290 
292 {
293  static std::once_flag g_rpc_interrupt_flag;
294  // This function could be called twice if the GUI has been started with -server=1.
295  std::call_once(g_rpc_interrupt_flag, []() {
296  LogPrint(BCLog::RPC, "Interrupting RPC\n");
297  // Interrupt e.g. running longpolls
298  g_rpc_running = false;
299  });
300 }
301 
302 void StopRPC()
303 {
304  static std::once_flag g_rpc_stop_flag;
305  // This function could be called twice if the GUI has been started with -server=1.
306  assert(!g_rpc_running);
307  std::call_once(g_rpc_stop_flag, []() {
308  LogPrint(BCLog::RPC, "Stopping RPC\n");
309  WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear());
312  });
313 }
314 
316 {
317  return g_rpc_running;
318 }
319 
321 {
322  if (!IsRPCRunning()) throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
323 }
324 
325 void SetRPCWarmupStatus(const std::string& newStatus)
326 {
327  LOCK(g_rpc_warmup_mutex);
328  rpcWarmupStatus = newStatus;
329 }
330 
332 {
333  LOCK(g_rpc_warmup_mutex);
334  assert(fRPCInWarmup);
335  fRPCInWarmup = false;
336 }
337 
338 bool RPCIsInWarmup(std::string *outStatus)
339 {
340  LOCK(g_rpc_warmup_mutex);
341  if (outStatus)
342  *outStatus = rpcWarmupStatus;
343  return fRPCInWarmup;
344 }
345 
346 bool IsDeprecatedRPCEnabled(const std::string& method)
347 {
348  const std::vector<std::string> enabled_methods = gArgs.GetArgs("-deprecatedrpc");
349 
350  return find(enabled_methods.begin(), enabled_methods.end(), method) != enabled_methods.end();
351 }
352 
354 {
355  UniValue rpc_result(UniValue::VOBJ);
356 
357  try {
358  jreq.parse(req);
359 
360  UniValue result = tableRPC.execute(jreq);
361  rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id);
362  }
363  catch (const UniValue& objError)
364  {
365  rpc_result = JSONRPCReplyObj(NullUniValue, objError, jreq.id);
366  }
367  catch (const std::exception& e)
368  {
369  rpc_result = JSONRPCReplyObj(NullUniValue,
370  JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id);
371  }
372 
373  return rpc_result;
374 }
375 
376 std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq)
377 {
379  for (unsigned int reqIdx = 0; reqIdx < vReq.size(); reqIdx++)
380  ret.push_back(JSONRPCExecOne(jreq, vReq[reqIdx]));
381 
382  return ret.write() + "\n";
383 }
384 
389 static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, const std::vector<std::string>& argNames)
390 {
391  JSONRPCRequest out = in;
393  // Build a map of parameters, and remove ones that have been processed, so that we can throw a focused error if
394  // there is an unknown one.
395  const std::vector<std::string>& keys = in.params.getKeys();
396  const std::vector<UniValue>& values = in.params.getValues();
397  std::unordered_map<std::string, const UniValue*> argsIn;
398  for (size_t i=0; i<keys.size(); ++i) {
399  argsIn[keys[i]] = &values[i];
400  }
401  // Process expected parameters.
402  int hole = 0;
403  for (const std::string &argNamePattern: argNames) {
404  std::vector<std::string> vargNames;
405  boost::algorithm::split(vargNames, argNamePattern, boost::algorithm::is_any_of("|"));
406  auto fr = argsIn.end();
407  for (const std::string & argName : vargNames) {
408  fr = argsIn.find(argName);
409  if (fr != argsIn.end()) {
410  break;
411  }
412  }
413  if (fr != argsIn.end()) {
414  for (int i = 0; i < hole; ++i) {
415  // Fill hole between specified parameters with JSON nulls,
416  // but not at the end (for backwards compatibility with calls
417  // that act based on number of specified parameters).
418  out.params.push_back(UniValue());
419  }
420  hole = 0;
421  out.params.push_back(*fr->second);
422  argsIn.erase(fr);
423  } else {
424  hole += 1;
425  }
426  }
427  // If there are still arguments in the argsIn map, this is an error.
428  if (!argsIn.empty()) {
429  throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown named parameter " + argsIn.begin()->first);
430  }
431  // Return request with named arguments transformed to positional arguments
432  return out;
433 }
434 
436 {
437  // Return immediately if in warmup
438  {
439  LOCK(g_rpc_warmup_mutex);
440  if (fRPCInWarmup)
441  throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
442  }
443 
444  // Find method
445  auto it = mapCommands.find(request.strMethod);
446  if (it != mapCommands.end()) {
447  UniValue result;
448  for (const auto& command : it->second) {
449  if (ExecuteCommand(*command, request, result, &command == &it->second.back())) {
450  return result;
451  }
452  }
453  }
454  throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
455 }
456 
457 static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler)
458 {
459  try
460  {
461  RPCCommandExecution execution(request.strMethod);
462  // Execute, convert arguments to array if necessary
463  if (request.params.isObject()) {
464  return command.actor(transformNamedArguments(request, command.argNames), result, last_handler);
465  } else {
466  return command.actor(request, result, last_handler);
467  }
468  }
469  catch (const std::exception& e)
470  {
471  throw JSONRPCError(RPC_MISC_ERROR, e.what());
472  }
473 }
474 
475 std::vector<std::string> CRPCTable::listCommands() const
476 {
477  std::vector<std::string> commandList;
478  for (const auto& i : mapCommands) commandList.emplace_back(i.first);
479  return commandList;
480 }
481 
483 {
484  if (!timerInterface)
485  timerInterface = iface;
486 }
487 
489 {
490  timerInterface = iface;
491 }
492 
494 {
495  if (timerInterface == iface)
496  timerInterface = nullptr;
497 }
498 
499 void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nSeconds)
500 {
501  if (!timerInterface)
502  throw JSONRPCError(RPC_INTERNAL_ERROR, "No timer handler registered for RPC");
503  LOCK(g_deadline_timers_mutex);
504  deadlineTimers.erase(name);
505  LogPrint(BCLog::RPC, "queue run of timer %s in %i seconds (using %s)\n", name, nSeconds, timerInterface->Name());
506  deadlineTimers.emplace(name, std::unique_ptr<RPCTimerBase>(timerInterface->NewTimer(func, nSeconds*1000)));
507 }
508 
510 {
511  int flag = 0;
512  if (gArgs.GetArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) == 0)
514  return flag;
515 }
516 
bool isObject() const
Definition: univalue.h:84
std::string Capitalize(std::string str)
Capitalizes the first character of the given string.
RPC timer "driver".
Definition: server.h:60
static const int SERIALIZE_TRANSACTION_NO_WITNESS
A flag that is ORed into the protocol version to designate that a transaction should be (un)serialize...
Definition: transaction.h:23
std::string help(const std::string &name, const JSONRPCRequest &helpreq) const
Definition: server.cpp:79
std::string category
Definition: server.h:127
std::deque< CInv >::iterator it
const std::vector< UniValue > & getValues() const
static JSONRPCRequest transformNamedArguments(const JSONRPCRequest &in, const std::vector< std::string > &argNames)
Process named arguments into a vector of positional arguments, based on the passed-in specification f...
Definition: server.cpp:389
BCLog::Logger & LogInstance()
Definition: logging.cpp:14
RPC command dispatcher.
Definition: server.h:137
#define LogPrint(category,...)
Definition: logging.h:182
bool IsRPCRunning()
Query whether RPC is running.
Definition: server.cpp:315
void SetRPCWarmupStatus(const std::string &newStatus)
Set the RPC warmup status.
Definition: server.cpp:325
static const unsigned int DEFAULT_RPC_SERIALIZE_VERSION
Definition: server.h:20
Actor actor
Definition: server.h:129
fs::path m_file_path
Definition: logging.h:94
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:264
static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex)
#define CHECK_NONFATAL(condition)
Throw a NonFatalCheckError when the condition evaluates to false.
Definition: check.h:32
static std::atomic< bool > g_rpc_running
Definition: server.cpp:24
void OnStopped(std::function< void()> slot)
Definition: server.cpp:74
bool removeCommand(const std::string &name, const CRPCCommand *pcmd)
Definition: server.cpp:271
#define PACKAGE_NAME
void InterruptRPC()
Definition: server.cpp:291
const std::string & get_str() const
const std::vector< std::string > & getKeys() const
static const CRPCCommand vRPCCommands[]
Definition: server.cpp:246
void RPCRunLater(const std::string &name, std::function< void()> func, int64_t nSeconds)
Run func nSeconds from now.
Definition: server.cpp:499
Client still warming up.
Definition: protocol.h:49
std::string method
Definition: server.cpp:36
std::vector< std::string > argNames
Definition: server.h:130
Invalid, missing or duplicate parameter.
Definition: protocol.h:43
static RPCServerInfo g_rpc_server_info
Definition: server.cpp:46
static Mutex g_deadline_timers_mutex
Definition: server.cpp:30
void RPCUnsetTimerInterface(RPCTimerInterface *iface)
Unset factory function for timers.
Definition: server.cpp:493
void DeleteAuthCookie()
Delete RPC authentication cookie from disk.
Definition: request.cpp:124
static bool ExecuteCommand(const CRPCCommand &command, const JSONRPCRequest &request, UniValue &result, bool last_handler)
Definition: server.cpp:457
UniValue execute(const JSONRPCRequest &request) const
Execute a method.
Definition: server.cpp:435
boost::signals2::signal< void()> Stopped
Definition: server.cpp:66
std::string strMethod
Definition: request.h:35
void SetRPCWarmupFinished()
Definition: server.cpp:331
std::string name
Definition: server.h:128
CRPCTable tableRPC
Definition: server.cpp:517
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:51
bool push_back(const UniValue &val)
Definition: univalue.cpp:108
Mutex mutex
Definition: server.cpp:42
UniValue params
Definition: request.h:36
#define LOCK(cs)
Definition: sync.h:230
const char * name
Definition: rest.cpp:41
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:138
static RPCTimerInterface * timerInterface
Definition: server.cpp:28
boost::signals2::signal< void()> Started
Definition: server.cpp:65
std::string JSONRPCExecBatch(const JSONRPCRequest &jreq, const UniValue &vReq)
Definition: server.cpp:376
UniValue id
Definition: request.h:34
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
General application defined errors.
Definition: protocol.h:39
RPCCommandExecution(const std::string &method)
Definition: server.cpp:51
bool pushKV(const std::string &key, const UniValue &val)
Definition: univalue.cpp:133
void StartRPC()
Definition: server.cpp:284
static RPCHelpMan stop()
Definition: server.cpp:155
bool IsDeprecatedRPCEnabled(const std::string &method)
Definition: server.cpp:346
static UniValue JSONRPCExecOne(JSONRPCRequest jreq, const UniValue &req)
Definition: server.cpp:353
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:257
static struct CRPCSignals g_rpcSignals
Optional arg that is a named argument and has a default value of null.
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)
Set the factory function for timer, but only, if unset.
Definition: server.cpp:482
virtual RPCTimerBase * NewTimer(std::function< void()> &func, int64_t millis)=0
Factory function for timers.
int64_t GetTimeMicros()
Returns the system time (not mockable)
Definition: time.cpp:65
void parse(const UniValue &valRequest)
Definition: request.cpp:153
void StopRPC()
Definition: server.cpp:302
int64_t GetStartupTime()
Definition: system.cpp:1280
void UninterruptibleSleep(const std::chrono::microseconds &n)
Definition: time.cpp:19
int RPCSerializationFlags()
Definition: server.cpp:509
void RpcInterruptionPoint()
Throw JSONRPCError if RPC is not running.
Definition: server.cpp:320
static RPCHelpMan getrpcinfo()
Definition: server.cpp:200
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:466
void RPCSetTimerInterface(RPCTimerInterface *iface)
Set the factory function for timers.
Definition: server.cpp:488
UniValue JSONRPCReplyObj(const UniValue &result, const UniValue &error, const UniValue &id)
Definition: request.cpp:33
std::list< RPCCommandExecutionInfo >::iterator it
Definition: server.cpp:50
ArgsManager gArgs
Definition: system.cpp:76
static Mutex g_rpc_warmup_mutex
Definition: server.cpp:23
bool RPCIsInWarmup(std::string *outStatus)
Definition: server.cpp:338
const UniValue NullUniValue
Definition: univalue.cpp:13
void StartShutdown()
Definition: shutdown.cpp:12
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:133
virtual const char * Name()=0
Implementation name.
void OnStarted(std::function< void()> slot)
Definition: server.cpp:69
size_t size() const
Definition: univalue.h:68
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
Definition: system.cpp:361
intptr_t unique_id
Definition: server.h:131
int64_t GetTime()
Return system time (or mocked time, if set)
Definition: time.cpp:23
std::vector< std::string > listCommands() const
Returns a list of registered commands.
Definition: server.cpp:475
P2P client errors.
Definition: protocol.h:58
static RPCHelpMan help()
Definition: server.cpp:133
CRPCTable()
Definition: server.cpp:257
static RPCHelpMan uptime()
Definition: server.cpp:181