10 #include <validation.h> 29 throw std::runtime_error(
30 "getconnectioncount\n" 31 "\nReturns the number of connections to other nodes.\n" 33 "n (numeric) The connection count\n" 48 throw std::runtime_error(
50 "\nRequests that a ping be sent to all other nodes, to measure ping time.\n" 51 "Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n" 52 "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.\n" 71 throw std::runtime_error(
73 "\nReturns data about each connected network node as a json array of objects.\n" 77 " \"id\": n, (numeric) Peer index\n" 78 " \"addr\":\"host:port\", (string) The IP address and port of the peer\n" 79 " \"addrbind\":\"ip:port\", (string) Bind address of the connection to the peer\n" 80 " \"addrlocal\":\"ip:port\", (string) Local address as reported by the peer\n" 81 " \"services\":\"xxxxxxxxxxxxxxxx\", (string) The services offered\n" 82 " \"relaytxes\":true|false, (boolean) Whether peer has asked us to relay transactions to it\n" 83 " \"lastsend\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n" 84 " \"lastrecv\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n" 85 " \"bytessent\": n, (numeric) The total bytes sent\n" 86 " \"bytesrecv\": n, (numeric) The total bytes received\n" 87 " \"conntime\": ttt, (numeric) The connection time in seconds since epoch (Jan 1 1970 GMT)\n" 88 " \"timeoffset\": ttt, (numeric) The time offset in seconds\n" 89 " \"pingtime\": n, (numeric) ping time (if available)\n" 90 " \"minping\": n, (numeric) minimum observed ping time (if any at all)\n" 91 " \"pingwait\": n, (numeric) ping wait (if non-zero)\n" 92 " \"version\": v, (numeric) The peer version, such as 7001\n" 93 " \"subver\": \"/Satoshi:0.8.5/\", (string) The string version\n" 94 " \"inbound\": true|false, (boolean) Inbound (true) or Outbound (false)\n" 95 " \"addnode\": true|false, (boolean) Whether connection was due to addnode and is using an addnode slot\n" 96 " \"startingheight\": n, (numeric) The starting height (block) of the peer\n" 97 " \"banscore\": n, (numeric) The ban score\n" 98 " \"synced_headers\": n, (numeric) The last header we have in common with this peer\n" 99 " \"synced_blocks\": n, (numeric) The last block we have in common with this peer\n" 101 " n, (numeric) The heights of blocks we're currently asking from this peer\n" 104 " \"whitelisted\": true|false, (boolean) Whether the peer is whitelisted\n" 105 " \"bytessent_per_msg\": {\n" 106 " \"addr\": n, (numeric) The total bytes sent aggregated by message type\n" 109 " \"bytesrecv_per_msg\": {\n" 110 " \"addr\": n, (numeric) The total bytes received aggregated by message type\n" 124 std::vector<CNodeStats> vstats;
135 if (!(stats.addrLocal.empty()))
137 if (stats.addrBind.IsValid())
147 if (stats.dPingTime > 0.0)
151 if (stats.dPingWait > 0.0)
160 obj.
push_back(
Pair(
"startingheight", stats.nStartingHeight));
174 for (
const mapMsgCmdSize::value_type &i : stats.mapSendBytesPerMsgCmd) {
181 for (
const mapMsgCmdSize::value_type &i : stats.mapRecvBytesPerMsgCmd) {
195 std::string strCommand;
199 (strCommand !=
"onetry" && strCommand !=
"add" && strCommand !=
"remove"))
200 throw std::runtime_error(
201 "addnode \"node\" \"add|remove|onetry\"\n" 202 "\nAttempts to add or remove a node from the addnode list.\n" 203 "Or try a connection to a node once.\n" 205 "1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n" 206 "2. \"command\" (string, required) 'add' to add a node to the list, 'remove' to remove a node from the list, 'onetry' to try a connection to the node once\n" 217 if (strCommand ==
"onetry")
220 g_connman->OpenNetworkConnection(addr,
false,
nullptr, strNode.c_str());
224 if (strCommand ==
"add")
229 else if(strCommand ==
"remove")
241 throw std::runtime_error(
242 "disconnectnode \"[address]\" [nodeid]\n" 243 "\nImmediately disconnects from the specified peer node.\n" 244 "\nStrictly one out of 'address' and 'nodeid' can be provided to identify the node.\n" 245 "\nTo disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid' argument only.\n" 247 "1. \"address\" (string, optional) The IP address/port of the node\n" 248 "2. \"nodeid\" (number, optional) The node ID (see getpeerinfo for node IDs)\n" 269 success =
g_connman->DisconnectNode(nodeid);
284 throw std::runtime_error(
285 "getaddednodeinfo ( \"node\" )\n" 286 "\nReturns information about the given added node, or all added nodes\n" 287 "(note that onetry addnodes are not listed here)\n" 289 "1. \"node\" (string, optional) If provided, return information about this specific node, otherwise all nodes are returned.\n" 293 " \"addednode\" : \"192.168.0.201\", (string) The node IP address or name (as provided to addnode)\n" 294 " \"connected\" : true|false, (boolean) If connected\n" 295 " \"addresses\" : [ (list of objects) Only when connected = true\n" 297 " \"address\" : \"192.168.0.201:8665\", (string) The fabcoin server IP and port we're connected to\n" 298 " \"connected\" : \"outbound\" (string) connection, inbound or outbound\n" 312 std::vector<AddedNodeInfo> vInfo =
g_connman->GetAddedNodeInfo();
318 vInfo.assign(1, info);
335 if (info.fConnected) {
337 address.
push_back(
Pair(
"address", info.resolvedAddress.ToString()));
338 address.
push_back(
Pair(
"connected", info.fInbound ?
"inbound" :
"outbound"));
351 throw std::runtime_error(
353 "\nReturns information about network traffic, including bytes in, bytes out,\n" 354 "and current time.\n" 357 " \"totalbytesrecv\": n, (numeric) Total bytes received\n" 358 " \"totalbytessent\": n, (numeric) Total bytes sent\n" 359 " \"timemillis\": t, (numeric) Current UNIX time in milliseconds\n" 360 " \"uploadtarget\":\n" 362 " \"timeframe\": n, (numeric) Length of the measuring timeframe in seconds\n" 363 " \"target\": n, (numeric) Target in bytes\n" 364 " \"target_reached\": true|false, (boolean) True if target is reached\n" 365 " \"serve_historical_blocks\": true|false, (boolean) True if serving historical blocks\n" 366 " \"bytes_left_in_cycle\": t, (numeric) Bytes left in current time cycle\n" 367 " \"time_left_in_cycle\": t (numeric) Seconds left in current time cycle\n" 417 throw std::runtime_error(
419 "Returns an object containing various state info regarding P2P networking.\n" 422 " \"version\": xxxxx, (numeric) the server version\n" 423 " \"subversion\": \"/Satoshi:x.x.x/\", (string) the server subversion string\n" 424 " \"protocolversion\": xxxxx, (numeric) the protocol version\n" 425 " \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the services we offer to the network\n" 426 " \"localrelay\": true|false, (bool) true if transaction relay is requested from peers\n" 427 " \"timeoffset\": xxxxx, (numeric) the time offset\n" 428 " \"connections\": xxxxx, (numeric) the number of connections\n" 429 " \"networkactive\": true|false, (bool) whether p2p networking is enabled\n" 430 " \"networks\": [ (array) information per network\n" 432 " \"name\": \"xxx\", (string) network (ipv4, ipv6 or onion)\n" 433 " \"limited\": true|false, (boolean) is the network limited using -onlynet?\n" 434 " \"reachable\": true|false, (boolean) is the network reachable?\n" 435 " \"proxy\": \"host:port\" (string) the proxy that is used for this network, or empty if none\n" 436 " \"proxy_randomize_credentials\": true|false, (string) Whether randomized credentials are used\n" 440 " \"relayfee\": x.xxxxxxxx, (numeric) minimum relay fee for transactions in " +
CURRENCY_UNIT +
"/kB\n" 441 " \"incrementalfee\": x.xxxxxxxx, (numeric) minimum fee increment for mempool limiting or BIP 125 replacement in " +
CURRENCY_UNIT +
"/kB\n" 442 " \"localaddresses\": [ (array) list of local addresses\n" 444 " \"address\": \"xxxx\", (string) network address\n" 445 " \"port\": xxx, (numeric) network port\n" 446 " \"score\": xxx (numeric) relative score\n" 450 " \"warnings\": \"...\" (string) any network warnings\n" 476 for (
const std::pair<CNetAddr, LocalServiceInfo> &item :
mapLocalHost)
492 std::string strCommand;
496 (strCommand !=
"add" && strCommand !=
"remove"))
497 throw std::runtime_error(
498 "setban \"subnet\" \"add|remove\" (bantime) (absolute)\n" 499 "\nAttempts to add or remove an IP/Subnet from the banned list.\n" 501 "1. \"subnet\" (string, required) The IP/Subnet (see getpeerinfo for nodes IP) with an optional netmask (default is /32 = single IP)\n" 502 "2. \"command\" (string, required) 'add' to add an IP/Subnet to the list, 'remove' to remove an IP/Subnet from the list\n" 503 "3. \"bantime\" (numeric, optional) time in seconds how long (or until when if [absolute] is set) the IP is banned (0 or empty means using the default time of 24h which can also be overwritten by the -bantime startup argument)\n" 504 "4. \"absolute\" (boolean, optional) If set, the bantime must be an absolute timestamp in seconds since epoch (Jan 1 1970 GMT)\n" 515 bool isSubnet =
false;
517 if (request.
params[0].
get_str().find(
"/") != std::string::npos)
531 if (strCommand ==
"add")
540 bool absolute =
false;
546 else if(strCommand ==
"remove")
557 throw std::runtime_error(
559 "\nList all banned IPs/Subnets.\n" 572 for (banmap_t::iterator it = banMap.begin(); it != banMap.end(); it++)
584 return bannedAddresses;
590 throw std::runtime_error(
592 "\nClear all banned IPs.\n" 608 throw std::runtime_error(
609 "setnetworkactive true|false\n" 610 "\nDisable/enable all p2p network activity.\n" 612 "1. \"state\" (boolean, required) true to enable networking, false to disable\n" 629 {
"network",
"ping", &
ping,
true, {} },
630 {
"network",
"getpeerinfo", &
getpeerinfo,
true, {} },
631 {
"network",
"addnode", &
addnode,
true, {
"node",
"command"} },
632 {
"network",
"disconnectnode", &
disconnectnode,
true, {
"address",
"nodeid"} },
636 {
"network",
"setban", &
setban,
true, {
"subnet",
"command",
"bantime",
"absolute"} },
637 {
"network",
"listbanned", &
listbanned,
true, {} },
638 {
"network",
"clearbanned", &
clearbanned,
true, {} },
644 for (
unsigned int vcidx = 0; vcidx <
ARRAYLEN(commands); vcidx++)
const std::string CURRENCY_UNIT
CAmount GetFeePerK() const
Return the fee in liu for a size of 1000 bytes.
UniValue setban(const JSONRPCRequest &request)
const std::string & get_str() const
Node has not been added before.
UniValue getnettotals(const JSONRPCRequest &request)
Fabcoin RPC command dispatcher.
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats)
Get statistics from node state.
void RegisterNetRPCCommands(CRPCTable &t)
Register P2P networking RPC commands.
std::string ToStringIPPort() const
UniValue ValueFromAmount(const CAmount &amount)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
int64_t GetTimeOffset()
"Never go to sea with two chronometers; take one or three." Our three time sources are: ...
UniValue clearbanned(const JSONRPCRequest &request)
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
UniValue getpeerinfo(const JSONRPCRequest &request)
std::map< CSubNet, CBanEntry > banmap_t
int64_t get_int64() const
bool push_back(const UniValue &val)
bool randomize_credentials
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
CCriticalSection cs_mapLocalHost
std::string banReasonToString()
std::map< CNetAddr, LocalServiceInfo > mapLocalHost
A CService with information about it as peer.
UniValue listbanned(const JSONRPCRequest &request)
UniValue setnetworkactive(const JSONRPCRequest &request)
std::string GetWarnings(const std::string &strFor)
Format a string that describes several potential problems detected by the core.
UniValue ping(const JSONRPCRequest &request)
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
UniValue getaddednodeinfo(const JSONRPCRequest &request)
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
bool LookupSubNet(const char *pszName, CSubNet &ret)
UniValue getconnectioncount(const JSONRPCRequest &request)
UniValue disconnectnode(const JSONRPCRequest &request)
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
std::atomic< bool > fPingQueued
bool IsReachable(enum Network net)
check whether a given network is one we can probably connect to
UniValue addnode(const JSONRPCRequest &request)
Node to disconnect not found in connected nodes.
std::unique_ptr< CConnman > g_connman
const UniValue NullUniValue
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
UniValue JSONRPCError(int code, const std::string &message)
No valid connection manager instance found.
struct evm_uint160be address(struct evm_env *env)
std::string GetNetworkName(enum Network net)
Information about a peer.
bool LookupHost(const char *pszName, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
std::vector< int > vHeightInFlight
CFeeRate incrementalRelayFee
bool IsLimited(enum Network net)
UniValue getnetworkinfo(const JSONRPCRequest &request)