2013-11-20 14:18:57 +01:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2015-12-13 14:51:43 +01:00
|
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
2014-11-20 03:19:29 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-20 14:18:57 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2018-04-02 00:30:17 +02:00
|
|
|
#ifndef BITCOIN_RPC_PROTOCOL_H
|
|
|
|
#define BITCOIN_RPC_PROTOCOL_H
|
2013-11-20 14:18:57 +01:00
|
|
|
|
2014-11-20 03:19:29 +01:00
|
|
|
//! HTTP status codes
|
2013-11-20 14:18:57 +01:00
|
|
|
enum HTTPStatusCode
|
|
|
|
{
|
|
|
|
HTTP_OK = 200,
|
|
|
|
HTTP_BAD_REQUEST = 400,
|
|
|
|
HTTP_UNAUTHORIZED = 401,
|
|
|
|
HTTP_FORBIDDEN = 403,
|
|
|
|
HTTP_NOT_FOUND = 404,
|
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
|
|
|
HTTP_BAD_METHOD = 405,
|
2013-11-20 14:18:57 +01:00
|
|
|
HTTP_INTERNAL_SERVER_ERROR = 500,
|
2014-11-26 13:51:02 +01:00
|
|
|
HTTP_SERVICE_UNAVAILABLE = 503,
|
2013-11-20 14:18:57 +01:00
|
|
|
};
|
|
|
|
|
2016-07-29 07:30:19 +02:00
|
|
|
//! Dash Core RPC error codes
|
2013-11-20 14:18:57 +01:00
|
|
|
enum RPCErrorCode
|
|
|
|
{
|
2014-11-20 03:19:29 +01:00
|
|
|
//! Standard JSON-RPC 2.0 errors
|
2017-03-09 10:02:13 +01:00
|
|
|
// RPC_INVALID_REQUEST is internally mapped to HTTP_BAD_REQUEST (400).
|
|
|
|
// It should not be used for application-layer errors.
|
2013-11-20 14:18:57 +01:00
|
|
|
RPC_INVALID_REQUEST = -32600,
|
2017-03-09 10:02:13 +01:00
|
|
|
// RPC_METHOD_NOT_FOUND is internally mapped to HTTP_NOT_FOUND (404).
|
|
|
|
// It should not be used for application-layer errors.
|
2013-11-20 14:18:57 +01:00
|
|
|
RPC_METHOD_NOT_FOUND = -32601,
|
|
|
|
RPC_INVALID_PARAMS = -32602,
|
2020-06-11 10:39:04 +02:00
|
|
|
// RPC_INTERNAL_ERROR should only be used for genuine errors in dashd
|
2017-03-09 12:32:34 +01:00
|
|
|
// (for example datadir corruption).
|
2013-11-20 14:18:57 +01:00
|
|
|
RPC_INTERNAL_ERROR = -32603,
|
|
|
|
RPC_PARSE_ERROR = -32700,
|
|
|
|
|
2014-11-20 03:19:29 +01:00
|
|
|
//! General application defined errors
|
2016-08-28 16:05:40 +02:00
|
|
|
RPC_MISC_ERROR = -1, //!< std::exception thrown in command handling
|
|
|
|
RPC_TYPE_ERROR = -3, //!< Unexpected type was passed as parameter
|
|
|
|
RPC_INVALID_ADDRESS_OR_KEY = -5, //!< Invalid address or key
|
|
|
|
RPC_OUT_OF_MEMORY = -7, //!< Ran out of memory during operation
|
|
|
|
RPC_INVALID_PARAMETER = -8, //!< Invalid, missing or duplicate parameter
|
|
|
|
RPC_DATABASE_ERROR = -20, //!< Database error
|
|
|
|
RPC_DESERIALIZATION_ERROR = -22, //!< Error parsing or validating structure in raw format
|
|
|
|
RPC_VERIFY_ERROR = -25, //!< General error during transaction or block submission
|
|
|
|
RPC_VERIFY_REJECTED = -26, //!< Transaction or block was rejected by network rules
|
|
|
|
RPC_VERIFY_ALREADY_IN_CHAIN = -27, //!< Transaction already in chain
|
|
|
|
RPC_IN_WARMUP = -28, //!< Client still warming up
|
2017-09-27 14:38:03 +02:00
|
|
|
RPC_METHOD_DEPRECATED = -32, //!< RPC method is deprecated
|
2020-11-24 02:39:50 +01:00
|
|
|
RPC_PLATFORM_RESTRICTION = -33, //!< This RPC command cannot be run by platform-user
|
2013-11-20 14:18:57 +01:00
|
|
|
|
2014-11-20 03:19:29 +01:00
|
|
|
//! Aliases for backward compatibility
|
2014-06-26 16:39:27 +02:00
|
|
|
RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR,
|
|
|
|
RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED,
|
|
|
|
RPC_TRANSACTION_ALREADY_IN_CHAIN= RPC_VERIFY_ALREADY_IN_CHAIN,
|
2013-11-20 14:18:57 +01:00
|
|
|
|
2014-11-20 03:19:29 +01:00
|
|
|
//! P2P client errors
|
2016-08-28 16:05:40 +02:00
|
|
|
RPC_CLIENT_NOT_CONNECTED = -9, //!< Dash is not connected
|
|
|
|
RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, //!< Still downloading initial blocks
|
|
|
|
RPC_CLIENT_NODE_ALREADY_ADDED = -23, //!< Node is already added
|
|
|
|
RPC_CLIENT_NODE_NOT_ADDED = -24, //!< Node has not been added before
|
|
|
|
RPC_CLIENT_NODE_NOT_CONNECTED = -29, //!< Node to disconnect not found in connected nodes
|
|
|
|
RPC_CLIENT_INVALID_IP_OR_SUBNET = -30, //!< Invalid IP/Subnet
|
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
|
|
|
RPC_CLIENT_P2P_DISABLED = -31, //!< No valid connection manager instance found
|
2013-11-20 14:18:57 +01:00
|
|
|
|
2014-11-20 03:19:29 +01:00
|
|
|
//! Wallet errors
|
2016-08-28 16:05:40 +02:00
|
|
|
RPC_WALLET_ERROR = -4, //!< Unspecified problem with wallet (key not found etc.)
|
|
|
|
RPC_WALLET_INSUFFICIENT_FUNDS = -6, //!< Not enough funds in wallet or account
|
2017-10-20 19:27:55 +02:00
|
|
|
RPC_WALLET_INVALID_LABEL_NAME = -11, //!< Invalid label name
|
2016-08-28 16:05:40 +02:00
|
|
|
RPC_WALLET_KEYPOOL_RAN_OUT = -12, //!< Keypool ran out, call keypoolrefill first
|
|
|
|
RPC_WALLET_UNLOCK_NEEDED = -13, //!< Enter the wallet passphrase with walletpassphrase first
|
|
|
|
RPC_WALLET_PASSPHRASE_INCORRECT = -14, //!< The wallet passphrase entered was incorrect
|
|
|
|
RPC_WALLET_WRONG_ENC_STATE = -15, //!< Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)
|
|
|
|
RPC_WALLET_ENCRYPTION_FAILED = -16, //!< Failed to encrypt the wallet
|
|
|
|
RPC_WALLET_ALREADY_UNLOCKED = -17, //!< Wallet is already unlocked
|
2017-07-27 17:51:14 +02:00
|
|
|
RPC_WALLET_NOT_FOUND = -18, //!< Invalid wallet specified
|
|
|
|
RPC_WALLET_NOT_SPECIFIED = -19, //!< No wallet specified (error when there are multiple wallets loaded)
|
2018-04-27 17:03:33 +02:00
|
|
|
|
|
|
|
|
2017-10-20 19:27:55 +02:00
|
|
|
//! Backwards compatible aliases
|
|
|
|
RPC_WALLET_INVALID_ACCOUNT_NAME = RPC_WALLET_INVALID_LABEL_NAME,
|
2018-04-27 17:03:33 +02:00
|
|
|
//! Unused reserved codes, kept around for backwards compatibility. Do not reuse.
|
|
|
|
RPC_FORBIDDEN_BY_SAFE_MODE = -2, //!< Server is in safe mode, and command is not allowed in safe mode
|
2013-11-20 14:18:57 +01:00
|
|
|
};
|
|
|
|
|
2018-04-02 00:30:17 +02:00
|
|
|
#endif // BITCOIN_RPC_PROTOCOL_H
|