Monero
Loading...
Searching...
No Matches
daemon.h
Go to the documentation of this file.
1// Copyright (c) 2014-2022, The Monero Project
2//
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without modification, are
6// permitted provided that the following conditions are met:
7//
8// 1. Redistributions of source code must retain the above copyright notice, this list of
9// conditions and the following disclaimer.
10//
11// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12// of conditions and the following disclaimer in the documentation and/or other
13// materials provided with the distribution.
14//
15// 3. Neither the name of the copyright holder nor the names of its contributors may be
16// used to endorse or promote products derived from this software without specific
17// prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29#pragma once
30
31#include "misc_log_ex.h"
32#include "daemon/daemon.h"
33#include "rpc/daemon_handler.h"
34#include "rpc/zmq_server.h"
35#include "common/password.h"
36#include "common/util.h"
37#include "daemon/core.h"
38#include "daemon/p2p.h"
39#include "daemon/protocol.h"
40#include "daemon/rpc.h"
44#include "version.h"
45#include "tools.h"
46
47
49public:
54
55 static void init_options(boost::program_options::options_description& desc){ cryptonote::core_rpc_server::init_options(desc); }
58
61 MAP_URI_AUTO_JON2("/send_raw_transaction", on_send_raw_tx_2, cryptonote::COMMAND_RPC_SEND_RAW_TX)
62 MAP_URI_AUTO_JON2("/sendrawtransaction", on_send_raw_tx_2, cryptonote::COMMAND_RPC_SEND_RAW_TX)
63 else { // Default to parent for non-overriden callbacks
64 return cryptonote::core_rpc_server::handle_http_request_map(query_info, response_info, m_conn_context);
65 }
67
68 bool on_send_raw_tx_2(const cryptonote::COMMAND_RPC_SEND_RAW_TX::request& req, cryptonote::COMMAND_RPC_SEND_RAW_TX::response& res, const cryptonote::core_rpc_server::connection_context *ctx);
69
70protected:
72};
73
75public:
78
79 static constexpr const std::chrono::seconds rpc_timeout = std::chrono::seconds(120);
80
87
90 boost::program_options::variables_map m_vm;
91
92 std::string m_p2p_bind_port;
93 std::string m_rpc_bind_port;
94 std::string m_zmq_bind_port;
95
96 std::atomic<bool> m_stopped;
97 std::atomic<bool> m_terminated;
98 std::atomic<bool> m_deinitalized;
99 boost::thread m_run_thread;
100
103 boost::program_options::variables_map const & vm
104 )
105 : m_core(core)
106 , m_vm(vm)
112 , m_protocol{*core, nullptr, command_line::get_arg(vm, cryptonote::arg_offline)}
115 {
116 // Handle circular dependencies
117 m_protocol.set_p2p_endpoint(&m_server);
118 m_core->set_cryptonote_protocol(&m_protocol);
120 }
121
122 virtual ~mock_daemon();
123
124 static void init_options(boost::program_options::options_description & option_spec);
125 static void default_options(boost::program_options::variables_map & vm);
126 static void set_ports(boost::program_options::variables_map & vm, unsigned initial_port);
127
128 mock_daemon * set_start_p2p(bool fl) { m_start_p2p = fl; return this; }
129 mock_daemon * set_start_zmq(bool fl) { m_start_zmq = fl; return this; }
130
131 void init();
132 void deinit();
133 void run();
134 bool run_main();
135 void stop();
136 void stop_p2p();
137 void stop_rpc();
138 void init_and_run();
139 void stop_and_deinit();
140 void try_init_and_run(boost::optional<unsigned> initial_port=boost::none);
141
142 void mine_blocks(size_t num_blocks, const std::string &miner_address);
143 void start_mining(const std::string &miner_address, uint64_t threads_count=1, bool do_background_mining=false, bool ignore_battery=true);
144 void stop_mining();
145 uint64_t get_height();
146
147 void load_params(boost::program_options::variables_map const & vm);
148
149 std::string zmq_addr() const { return std::string("127.0.0.1:") + m_zmq_bind_port; }
150 std::string rpc_addr() const { return std::string("127.0.0.1:") + m_rpc_bind_port; }
151 std::string p2p_addr() const { return std::string("127.0.0.1:") + m_p2p_bind_port; }
153 cryptonote::core * core() const { return m_core; }
154};
uint64_t num_blocks(const std::vector< test_event_entry > &events)
Definition chaingen.cpp:1220
Definition core_rpc_server.h:56
core_rpc_server(core &cr, nodetool::node_server< cryptonote::t_cryptonote_protocol_handler< cryptonote::core > > &p2p)
Definition core_rpc_server.cpp:172
epee::net_utils::connection_context_base connection_context
Definition core_rpc_server.h:80
static void init_options(boost::program_options::options_description &desc)
Definition core_rpc_server.cpp:153
handles core cryptonote functionality
Definition cryptonote_core.h:87
Definition cryptonote_protocol_handler.h:80
bool run(size_t threads_count, bool wait=true)
Definition http_server_impl_base.h:108
bool deinit()
Definition http_server_impl_base.h:122
Definition daemon.h:74
std::string p2p_addr() const
Definition daemon.h:151
cryptonote::core * core() const
Definition daemon.h:153
mock_daemon * set_start_zmq(bool fl)
Definition daemon.h:129
bool m_start_zmq
Definition daemon.h:89
mock_daemon(cryptonote::core *core, boost::program_options::variables_map const &vm)
Definition daemon.h:101
std::string rpc_addr() const
Definition daemon.h:150
std::atomic< bool > m_deinitalized
Definition daemon.h:98
boost::program_options::variables_map m_vm
Definition daemon.h:90
std::atomic< bool > m_terminated
Definition daemon.h:97
std::string m_zmq_bind_port
Definition daemon.h:94
std::atomic< bool > m_stopped
Definition daemon.h:96
std::string m_rpc_bind_port
Definition daemon.h:93
t_protocol_raw m_protocol
Definition daemon.h:82
t_node_server m_server
Definition daemon.h:84
cryptonote::network_type m_network_type
Definition daemon.h:85
epee::net_utils::http::http_simple_client m_http_client
Definition daemon.h:86
boost::thread m_run_thread
Definition daemon.h:99
std::string zmq_addr() const
Definition daemon.h:149
cryptonote::network_type nettype() const
Definition daemon.h:152
void load_params(boost::program_options::variables_map const &vm)
Definition daemon.cpp:94
std::string m_p2p_bind_port
Definition daemon.h:92
mock_rpc_daemon m_rpc_server
Definition daemon.h:83
mock_daemon * set_start_p2p(bool fl)
Definition daemon.h:128
static constexpr const std::chrono::seconds rpc_timeout
Definition daemon.h:79
bool m_start_p2p
Definition daemon.h:88
cryptonote::t_cryptonote_protocol_handler< cryptonote::core > t_protocol_raw
Definition daemon.h:76
cryptonote::core * m_core
Definition daemon.h:81
nodetool::node_server< t_protocol_raw > t_node_server
Definition daemon.h:77
Definition daemon.h:48
CHAIN_HTTP_TO_MAP2(cryptonote::core_rpc_server::connection_context)
void nettype(cryptonote::network_type nettype)
Definition daemon.h:57
static void init_options(boost::program_options::options_description &desc)
Definition daemon.h:55
cryptonote::network_type nettype() const
Definition daemon.h:56
else
Definition daemon.h:63
bool on_send_raw_tx_2(const cryptonote::COMMAND_RPC_SEND_RAW_TX::request &req, cryptonote::COMMAND_RPC_SEND_RAW_TX::response &res, const cryptonote::core_rpc_server::connection_context *ctx)
Definition daemon.cpp:36
mock_rpc_daemon(cryptonote::core &cr, nodetool::node_server< cryptonote::t_cryptonote_protocol_handler< cryptonote::core > > &p2p)
Definition daemon.h:50
cryptonote::network_type m_network_type
Definition daemon.h:71
Definition net_node.h:132
#define false
const char * res
Definition hmac_keccak.cpp:42
#define BEGIN_URI_MAP2()
Definition http_server_handlers_map2.h:60
#define MAP_URI_AUTO_JON2(s_pattern, callback_f, command_type)
Definition http_server_handlers_map2.h:104
#define END_URI_MAP2()
Definition http_server_handlers_map2.h:144
#define const
Definition ipfrdr.c:80
static void init()
Definition logging.cpp:42
Definition command_line.cpp:37
Holds cryptonote related classes and helpers.
Definition blockchain_db.cpp:45
network_type
Definition cryptonote_config.h:302
http_simple_client_template< blocked_mode_client > http_simple_client
Definition http_client.h:877
Definition p2p.py:1
unsigned __int64 uint64_t
Definition stdint.h:136
randomx_vm * vm
Definition tests.cpp:20