Branch data Line data Source code
# 1 : : // Copyright (c) 2018-2020 The Bitcoin Core developers
# 2 : : // Distributed under the MIT software license, see the accompanying
# 3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
# 4 : :
# 5 : : #ifndef BITCOIN_INTERFACES_NODE_H
# 6 : : #define BITCOIN_INTERFACES_NODE_H
# 7 : :
# 8 : : #include <amount.h> // For CAmount
# 9 : : #include <net.h> // For NodeId
# 10 : : #include <net_types.h> // For banmap_t
# 11 : : #include <netaddress.h> // For Network
# 12 : : #include <netbase.h> // For ConnectionDirection
# 13 : : #include <support/allocators/secure.h> // For SecureString
# 14 : : #include <util/translation.h>
# 15 : :
# 16 : : #include <functional>
# 17 : : #include <memory>
# 18 : : #include <stddef.h>
# 19 : : #include <stdint.h>
# 20 : : #include <string>
# 21 : : #include <tuple>
# 22 : : #include <vector>
# 23 : :
# 24 : : class BanMan;
# 25 : : class CCoinControl;
# 26 : : class CFeeRate;
# 27 : : class CNodeStats;
# 28 : : class Coin;
# 29 : : class RPCTimerInterface;
# 30 : : class UniValue;
# 31 : : class proxyType;
# 32 : : enum class SynchronizationState;
# 33 : : struct CNodeStateStats;
# 34 : : struct NodeContext;
# 35 : : struct bilingual_str;
# 36 : :
# 37 : : namespace interfaces {
# 38 : : class Handler;
# 39 : : class WalletClient;
# 40 : : struct BlockTip;
# 41 : :
# 42 : : //! Block and header tip information
# 43 : : struct BlockAndHeaderTipInfo
# 44 : : {
# 45 : : int block_height;
# 46 : : int64_t block_time;
# 47 : : int header_height;
# 48 : : int64_t header_time;
# 49 : : double verification_progress;
# 50 : : };
# 51 : :
# 52 : : //! Top-level interface for a bitcoin node (bitcoind process).
# 53 : : class Node
# 54 : : {
# 55 : : public:
# 56 : 0 : virtual ~Node() {}
# 57 : :
# 58 : : //! Init logging.
# 59 : : virtual void initLogging() = 0;
# 60 : :
# 61 : : //! Init parameter interaction.
# 62 : : virtual void initParameterInteraction() = 0;
# 63 : :
# 64 : : //! Get warnings.
# 65 : : virtual bilingual_str getWarnings() = 0;
# 66 : :
# 67 : : // Get log flags.
# 68 : : virtual uint32_t getLogCategories() = 0;
# 69 : :
# 70 : : //! Initialize app dependencies.
# 71 : : virtual bool baseInitialize() = 0;
# 72 : :
# 73 : : //! Start node.
# 74 : : virtual bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info = nullptr) = 0;
# 75 : :
# 76 : : //! Stop node.
# 77 : : virtual void appShutdown() = 0;
# 78 : :
# 79 : : //! Start shutdown.
# 80 : : virtual void startShutdown() = 0;
# 81 : :
# 82 : : //! Return whether shutdown was requested.
# 83 : : virtual bool shutdownRequested() = 0;
# 84 : :
# 85 : : //! Map port.
# 86 : : virtual void mapPort(bool use_upnp, bool use_natpmp) = 0;
# 87 : :
# 88 : : //! Get proxy.
# 89 : : virtual bool getProxy(Network net, proxyType& proxy_info) = 0;
# 90 : :
# 91 : : //! Get number of connections.
# 92 : : virtual size_t getNodeCount(ConnectionDirection flags) = 0;
# 93 : :
# 94 : : //! Get stats for connected nodes.
# 95 : : using NodesStats = std::vector<std::tuple<CNodeStats, bool, CNodeStateStats>>;
# 96 : : virtual bool getNodesStats(NodesStats& stats) = 0;
# 97 : :
# 98 : : //! Get ban map entries.
# 99 : : virtual bool getBanned(banmap_t& banmap) = 0;
# 100 : :
# 101 : : //! Ban node.
# 102 : : virtual bool ban(const CNetAddr& net_addr, int64_t ban_time_offset) = 0;
# 103 : :
# 104 : : //! Unban node.
# 105 : : virtual bool unban(const CSubNet& ip) = 0;
# 106 : :
# 107 : : //! Disconnect node by address.
# 108 : : virtual bool disconnectByAddress(const CNetAddr& net_addr) = 0;
# 109 : :
# 110 : : //! Disconnect node by id.
# 111 : : virtual bool disconnectById(NodeId id) = 0;
# 112 : :
# 113 : : //! Get total bytes recv.
# 114 : : virtual int64_t getTotalBytesRecv() = 0;
# 115 : :
# 116 : : //! Get total bytes sent.
# 117 : : virtual int64_t getTotalBytesSent() = 0;
# 118 : :
# 119 : : //! Get mempool size.
# 120 : : virtual size_t getMempoolSize() = 0;
# 121 : :
# 122 : : //! Get mempool dynamic usage.
# 123 : : virtual size_t getMempoolDynamicUsage() = 0;
# 124 : :
# 125 : : //! Get header tip height and time.
# 126 : : virtual bool getHeaderTip(int& height, int64_t& block_time) = 0;
# 127 : :
# 128 : : //! Get num blocks.
# 129 : : virtual int getNumBlocks() = 0;
# 130 : :
# 131 : : //! Get best block hash.
# 132 : : virtual uint256 getBestBlockHash() = 0;
# 133 : :
# 134 : : //! Get last block time.
# 135 : : virtual int64_t getLastBlockTime() = 0;
# 136 : :
# 137 : : //! Get verification progress.
# 138 : : virtual double getVerificationProgress() = 0;
# 139 : :
# 140 : : //! Is initial block download.
# 141 : : virtual bool isInitialBlockDownload() = 0;
# 142 : :
# 143 : : //! Get reindex.
# 144 : : virtual bool getReindex() = 0;
# 145 : :
# 146 : : //! Get importing.
# 147 : : virtual bool getImporting() = 0;
# 148 : :
# 149 : : //! Set network active.
# 150 : : virtual void setNetworkActive(bool active) = 0;
# 151 : :
# 152 : : //! Get network active.
# 153 : : virtual bool getNetworkActive() = 0;
# 154 : :
# 155 : : //! Get dust relay fee.
# 156 : : virtual CFeeRate getDustRelayFee() = 0;
# 157 : :
# 158 : : //! Execute rpc command.
# 159 : : virtual UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) = 0;
# 160 : :
# 161 : : //! List rpc commands.
# 162 : : virtual std::vector<std::string> listRpcCommands() = 0;
# 163 : :
# 164 : : //! Set RPC timer interface if unset.
# 165 : : virtual void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) = 0;
# 166 : :
# 167 : : //! Unset RPC timer interface.
# 168 : : virtual void rpcUnsetTimerInterface(RPCTimerInterface* iface) = 0;
# 169 : :
# 170 : : //! Get unspent outputs associated with a transaction.
# 171 : : virtual bool getUnspentOutput(const COutPoint& output, Coin& coin) = 0;
# 172 : :
# 173 : : //! Get wallet client.
# 174 : : virtual WalletClient& walletClient() = 0;
# 175 : :
# 176 : : //! Register handler for init messages.
# 177 : : using InitMessageFn = std::function<void(const std::string& message)>;
# 178 : : virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
# 179 : :
# 180 : : //! Register handler for message box messages.
# 181 : : using MessageBoxFn =
# 182 : : std::function<bool(const bilingual_str& message, const std::string& caption, unsigned int style)>;
# 183 : : virtual std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) = 0;
# 184 : :
# 185 : : //! Register handler for question messages.
# 186 : : using QuestionFn = std::function<bool(const bilingual_str& message,
# 187 : : const std::string& non_interactive_message,
# 188 : : const std::string& caption,
# 189 : : unsigned int style)>;
# 190 : : virtual std::unique_ptr<Handler> handleQuestion(QuestionFn fn) = 0;
# 191 : :
# 192 : : //! Register handler for progress messages.
# 193 : : using ShowProgressFn = std::function<void(const std::string& title, int progress, bool resume_possible)>;
# 194 : : virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0;
# 195 : :
# 196 : : //! Register handler for number of connections changed messages.
# 197 : : using NotifyNumConnectionsChangedFn = std::function<void(int new_num_connections)>;
# 198 : : virtual std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) = 0;
# 199 : :
# 200 : : //! Register handler for network active messages.
# 201 : : using NotifyNetworkActiveChangedFn = std::function<void(bool network_active)>;
# 202 : : virtual std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) = 0;
# 203 : :
# 204 : : //! Register handler for notify alert messages.
# 205 : : using NotifyAlertChangedFn = std::function<void()>;
# 206 : : virtual std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) = 0;
# 207 : :
# 208 : : //! Register handler for ban list messages.
# 209 : : using BannedListChangedFn = std::function<void()>;
# 210 : : virtual std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) = 0;
# 211 : :
# 212 : : //! Register handler for block tip messages.
# 213 : : using NotifyBlockTipFn =
# 214 : : std::function<void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)>;
# 215 : : virtual std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) = 0;
# 216 : :
# 217 : : //! Register handler for header tip messages.
# 218 : : using NotifyHeaderTipFn =
# 219 : : std::function<void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)>;
# 220 : : virtual std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) = 0;
# 221 : :
# 222 : : //! Get and set internal node context. Useful for testing, but not
# 223 : : //! accessible across processes.
# 224 : 0 : virtual NodeContext* context() { return nullptr; }
# 225 : 0 : virtual void setContext(NodeContext* context) { }
# 226 : : };
# 227 : :
# 228 : : //! Return implementation of Node interface.
# 229 : : std::unique_ptr<Node> MakeNode(NodeContext* context = nullptr);
# 230 : :
# 231 : : //! Block tip (could be a header or not, depends on the subscribed signal).
# 232 : : struct BlockTip {
# 233 : : int block_height;
# 234 : : int64_t block_time;
# 235 : : uint256 block_hash;
# 236 : : };
# 237 : :
# 238 : : } // namespace interfaces
# 239 : :
# 240 : : #endif // BITCOIN_INTERFACES_NODE_H
|