Electroneum
mock_daemon Class Reference

#include <daemon.h>

Collaboration diagram for mock_daemon:

Public Types

typedef cryptonote::t_cryptonote_protocol_handler< cryptonote::coret_protocol_raw
 
typedef nodetool::node_server< t_protocol_rawt_node_server
 

Public Member Functions

 mock_daemon (cryptonote::core *core, boost::program_options::variables_map const &vm)
 
virtual ~mock_daemon ()
 
mock_daemonset_start_p2p (bool fl)
 
mock_daemonset_start_zmq (bool fl)
 
void init ()
 
void deinit ()
 
void run ()
 
bool run_main ()
 
void stop ()
 
void stop_p2p ()
 
void stop_rpc ()
 
void init_and_run ()
 
void stop_and_deinit ()
 
void try_init_and_run (boost::optional< unsigned > initial_port=boost::none)
 
void mine_blocks (size_t num_blocks, const std::string &miner_address)
 
void start_mining (const std::string &miner_address, uint64_t threads_count=1, bool do_background_mining=false, bool ignore_battery=true)
 
void stop_mining ()
 
uint64_t get_height ()
 
void load_params (boost::program_options::variables_map const &vm)
 
std::string zmq_addr () const
 
std::string rpc_addr () const
 
std::string p2p_addr () const
 
cryptonote::network_type nettype () const
 
cryptonote::corecore () const
 

Static Public Member Functions

static void init_options (boost::program_options::options_description &option_spec)
 
static void default_options (boost::program_options::variables_map &vm)
 
static void set_ports (boost::program_options::variables_map &vm, unsigned initial_port)
 

Public Attributes

cryptonote::corem_core
 
t_protocol_raw m_protocol
 
mock_rpc_daemon m_rpc_server
 
t_node_server m_server
 
cryptonote::network_type m_network_type
 
epee::net_utils::http::http_simple_client m_http_client
 
bool m_start_p2p
 
bool m_start_zmq
 
boost::program_options::variables_map m_vm
 
std::string m_p2p_bind_port
 
std::string m_rpc_bind_port
 
std::string m_zmq_bind_port
 
std::atomic< boolm_stopped
 
std::atomic< boolm_terminated
 
std::atomic< boolm_deinitalized
 
boost::thread m_run_thread
 

Static Public Attributes

static constexpr const std::chrono::seconds rpc_timeout = std::chrono::seconds(60)
 

Detailed Description

Definition at line 74 of file daemon.h.

Member Typedef Documentation

◆ t_node_server

◆ t_protocol_raw

Constructor & Destructor Documentation

◆ mock_daemon()

mock_daemon::mock_daemon ( cryptonote::core core,
boost::program_options::variables_map const &  vm 
)
inline

Definition at line 101 of file daemon.h.

105  : m_core(core)
106  , m_vm(vm)
107  , m_start_p2p(false)
108  , m_start_zmq(false)
109  , m_terminated(false)
110  , m_deinitalized(false)
111  , m_stopped(false)
115  {
116  // Handle circular dependencies
119  load_params(vm);
120  }
std::atomic< bool > m_stopped
Definition: daemon.h:96
bool m_start_p2p
Definition: daemon.h:88
bool m_start_zmq
Definition: daemon.h:89
void set_p2p_endpoint(nodetool::i_p2p_endpoint< connection_context > *p2p)
std::atomic< bool > m_terminated
Definition: daemon.h:97
std::atomic< bool > m_deinitalized
Definition: daemon.h:98
cryptonote::core * m_core
Definition: daemon.h:81
void load_params(boost::program_options::variables_map const &vm)
Definition: daemon.cpp:94
void set_cryptonote_protocol(i_cryptonote_protocol *pprotocol)
set the pointer to the cryptonote protocol object to use
const command_line::arg_descriptor< bool > arg_offline
t_node_server m_server
Definition: daemon.h:84
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Definition: command_line.h:271
t_protocol_raw m_protocol
Definition: daemon.h:82
cryptonote::core * core() const
Definition: daemon.h:153
mock_rpc_daemon m_rpc_server
Definition: daemon.h:83
boost::program_options::variables_map m_vm
Definition: daemon.h:90
Here is the call graph for this function:

◆ ~mock_daemon()

mock_daemon::~mock_daemon ( )
virtual

Definition at line 102 of file daemon.cpp.

103 {
106 
107  if (!m_terminated)
108  {
109  try
110  {
111  stop();
112  }
113  catch (...)
114  {
115  MERROR("Failed to stop");
116  }
117  }
118 
119  if (!m_deinitalized)
120  {
121  deinit();
122  }
123 }
#define MERROR(x)
Definition: misc_log_ex.h:73
std::atomic< bool > m_terminated
Definition: daemon.h:97
std::atomic< bool > m_deinitalized
Definition: daemon.h:98
epee::net_utils::http::http_simple_client m_http_client
Definition: daemon.h:86
void stop()
Definition: daemon.cpp:292
void deinit()
Definition: daemon.cpp:143
Here is the call graph for this function:

Member Function Documentation

◆ core()

cryptonote::core* mock_daemon::core ( ) const
inline

Definition at line 153 of file daemon.h.

153 { return m_core; }
cryptonote::core * m_core
Definition: daemon.h:81

◆ default_options()

void mock_daemon::default_options ( boost::program_options::variables_map &  vm)
static

Definition at line 53 of file daemon.cpp.

54 {
55  std::vector<std::string> exclusive_nodes{"127.0.0.1:65525"};
56  tools::options::set_option(vm, nodetool::arg_p2p_add_exclusive_node, po::variable_value(exclusive_nodes, false));
57 
58  tools::options::set_option(vm, nodetool::arg_p2p_bind_ip, po::variable_value(std::string("127.0.0.1"), false));
59  tools::options::set_option(vm, nodetool::arg_no_igd, po::variable_value(true, false));
60  tools::options::set_option(vm, cryptonote::arg_offline, po::variable_value(true, false));
61  tools::options::set_option(vm, "disable-dns-checkpoints", po::variable_value(true, false));
62 
63  const char *test_mainnet = getenv("TEST_MAINNET");
64  if (!test_mainnet || atoi(test_mainnet) == 0)
65  {
66  tools::options::set_option(vm, cryptonote::arg_testnet_on, po::variable_value(true, false));
67  }
68 
69  // By default pick non-standard ports to avoid confusion with possibly locally running daemons (mainnet/testnet)
70  const char *test_p2p_port = getenv("TEST_P2P_PORT");
71  auto p2p_port = std::string(test_p2p_port && strlen(test_p2p_port) > 0 ? test_p2p_port : "61340");
72  tools::options::set_option(vm, nodetool::arg_p2p_bind_port, po::variable_value(p2p_port, false));
73 
74  const char *test_rpc_port = getenv("TEST_RPC_PORT");
75  auto rpc_port = std::string(test_rpc_port && strlen(test_rpc_port) > 0 ? test_rpc_port : "61341");
76  tools::options::set_option(vm, cryptonote::core_rpc_server::arg_rpc_bind_port, po::variable_value(rpc_port, false));
77 
78  const char *test_zmq_port = getenv("TEST_ZMQ_PORT");
79  auto zmq_port = std::string(test_zmq_port && strlen(test_zmq_port) > 0 ? test_zmq_port : "61342");
80  tools::options::set_option(vm, daemon_args::arg_zmq_rpc_bind_port, po::variable_value(zmq_port, false));
81 
82  po::notify(vm);
83 }
::std::string string
Definition: gtest-port.h:1097
const command_line::arg_descriptor< std::string, false, true, 2 > arg_p2p_bind_port
Definition: net_node.cpp:112
const command_line::arg_descriptor< std::string > arg_p2p_bind_ip
Definition: net_node.cpp:111
const command_line::arg_descriptor< std::string, false, true, 2 > arg_zmq_rpc_bind_port
const command_line::arg_descriptor< bool, false > arg_testnet_on
const command_line::arg_descriptor< std::vector< std::string > > arg_p2p_add_exclusive_node
Definition: net_node.cpp:129
const command_line::arg_descriptor< bool > arg_offline
static void set_option(boost::program_options::variables_map &vm, const std::string &key, const boost::program_options::variable_value &pv)
const command_line::arg_descriptor< bool > arg_no_igd
Definition: net_node.cpp:137
static const command_line::arg_descriptor< std::string, false, true, 2 > arg_rpc_bind_port
Here is the call graph for this function:

◆ deinit()

void mock_daemon::deinit ( )

Definition at line 143 of file daemon.cpp.

144 {
147 
148  try
149  {
151  }
152  catch (...)
153  {
154  MERROR("Failed to deinitialize RPC server...");
155  }
156 
157  if (m_start_p2p)
158  {
159  try
160  {
161  m_server.deinit();
162  }
163  catch (...)
164  {
165  MERROR("Failed to deinitialize p2p...");
166  }
167  }
168 
169  try
170  {
171  m_protocol.deinit();
172  m_protocol.set_p2p_endpoint(nullptr);
173  }
174  catch (...)
175  {
176  MERROR("Failed to stop cryptonote protocol!");
177  }
178 
179  m_deinitalized = true;
180 }
#define MERROR(x)
Definition: misc_log_ex.h:73
bool m_start_p2p
Definition: daemon.h:88
void set_p2p_endpoint(nodetool::i_p2p_endpoint< connection_context > *p2p)
std::atomic< bool > m_deinitalized
Definition: daemon.h:98
epee::net_utils::http::http_simple_client m_http_client
Definition: daemon.h:86
t_node_server m_server
Definition: daemon.h:84
t_protocol_raw m_protocol
Definition: daemon.h:82
mock_rpc_daemon m_rpc_server
Definition: daemon.h:83

◆ get_height()

uint64_t mock_daemon::get_height ( )

Definition at line 371 of file daemon.cpp.

372 {
374 }
uint64_t get_current_blockchain_height() const
get the current height of the blockchain
Definition: blockchain.cpp:322
cryptonote::core * m_core
Definition: daemon.h:81
Blockchain & get_blockchain_storage()
gets the Blockchain instance

◆ init()

void mock_daemon::init ( )

Definition at line 125 of file daemon.cpp.

126 {
127  m_deinitalized = false;
130 
131  CHECK_AND_ASSERT_THROW_MES(m_protocol.init(m_vm), "Failed to initialize cryptonote protocol.");
132  CHECK_AND_ASSERT_THROW_MES(m_rpc_server.init(m_vm, false, main_rpc_port), "Failed to initialize RPC server.");
133 
134  if (m_start_p2p)
135  CHECK_AND_ASSERT_THROW_MES(m_server.init(m_vm), "Failed to initialize p2p server.");
136 
139 
141 }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
bool set_server(const std::string &address, boost::optional< login > user, ssl_options_t ssl_options=ssl_support_t::e_ssl_support_autodetect)
Definition: http_client.h:302
bool m_start_p2p
Definition: daemon.h:88
bool init(const boost::program_options::variables_map &vm, const bool restricted, const std::string &port)
cryptonote::network_type m_network_type
Definition: daemon.h:85
std::atomic< bool > m_deinitalized
Definition: daemon.h:98
bool init(const boost::program_options::variables_map &vm)
bool init(const boost::program_options::variables_map &vm)
epee::net_utils::http::http_simple_client m_http_client
Definition: daemon.h:86
t_node_server m_server
Definition: daemon.h:84
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Definition: command_line.h:271
t_protocol_raw m_protocol
Definition: daemon.h:82
cryptonote::network_type nettype() const
Definition: daemon.h:56
static const command_line::arg_descriptor< std::string, false, true, 2 > arg_rpc_bind_port
std::string rpc_addr() const
Definition: daemon.h:150
mock_rpc_daemon m_rpc_server
Definition: daemon.h:83
boost::program_options::variables_map m_vm
Definition: daemon.h:90
Here is the call graph for this function:

◆ init_and_run()

void mock_daemon::init_and_run ( )

Definition at line 182 of file daemon.cpp.

183 {
184  init();
185  run();
186 }
void init()
Definition: daemon.cpp:125
void run()
Definition: daemon.cpp:222
Here is the call graph for this function:

◆ init_options()

void mock_daemon::init_options ( boost::program_options::options_description &  option_spec)
static

Definition at line 43 of file daemon.cpp.

44 {
45  cryptonote::core::init_options(option_spec);
46  t_node_server::init_options(option_spec);
48 
51 }
const command_line::arg_descriptor< std::string > arg_zmq_rpc_bind_ip
const command_line::arg_descriptor< std::string, false, true, 2 > arg_zmq_rpc_bind_port
static void init_options(boost::program_options::options_description &desc)
adds command line options to the given options set
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
Definition: command_line.h:188
static void init_options(boost::program_options::options_description &desc)
static void init_options(boost::program_options::options_description &desc)
Here is the call graph for this function:

◆ load_params()

void mock_daemon::load_params ( boost::program_options::variables_map const &  vm)

Definition at line 94 of file daemon.cpp.

95 {
100 }
cryptonote::network_type m_network_type
Definition: daemon.h:85
std::string m_zmq_bind_port
Definition: daemon.h:94
const command_line::arg_descriptor< std::string, false, true, 2 > arg_p2p_bind_port
Definition: net_node.cpp:112
const command_line::arg_descriptor< std::string, false, true, 2 > arg_zmq_rpc_bind_port
const command_line::arg_descriptor< bool, false > arg_testnet_on
std::string m_rpc_bind_port
Definition: daemon.h:93
std::string m_p2p_bind_port
Definition: daemon.h:92
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Definition: command_line.h:271
static const command_line::arg_descriptor< std::string, false, true, 2 > arg_rpc_bind_port
Here is the call graph for this function:

◆ mine_blocks()

void mock_daemon::mine_blocks ( size_t  num_blocks,
const std::string &  miner_address 
)

Definition at line 312 of file daemon.cpp.

313 {
314  bool blocks_mined = false;
315  const uint64_t start_height = get_height();
316  const auto mining_timeout = std::chrono::seconds(30);
317  MDEBUG("Current height before mining: " << start_height);
318 
319  start_mining(miner_address);
320  auto mining_started = std::chrono::system_clock::now();
321 
322  while(true) {
324  const uint64_t cur_height = get_height();
325 
326  if (cur_height - start_height >= num_blocks)
327  {
328  MDEBUG("Cur blocks: " << cur_height << " start: " << start_height);
329  blocks_mined = true;
330  break;
331  }
332 
333  auto current_time = std::chrono::system_clock::now();
334  if (mining_timeout < current_time - mining_started)
335  {
336  break;
337  }
338  }
339 
340  stop_mining();
341  CHECK_AND_ASSERT_THROW_MES(blocks_mined, "Mining failed in the time limit");
342 }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
void stop_mining()
Definition: daemon.cpp:361
uint64_t num_blocks(const std::vector< test_event_entry > &events)
Definition: chaingen.cpp:1044
#define MDEBUG(x)
Definition: misc_log_ex.h:76
unsigned __int64 uint64_t
Definition: stdint.h:136
uint64_t get_height()
Definition: daemon.cpp:371
bool sleep_no_w(long ms)
void start_mining(const std::string &miner_address, uint64_t threads_count=1, bool do_background_mining=false, bool ignore_battery=true)
Definition: daemon.cpp:346
Here is the call graph for this function:

◆ nettype()

cryptonote::network_type mock_daemon::nettype ( ) const
inline

Definition at line 152 of file daemon.h.

152 { return m_network_type; }
cryptonote::network_type m_network_type
Definition: daemon.h:85

◆ p2p_addr()

std::string mock_daemon::p2p_addr ( ) const
inline

Definition at line 151 of file daemon.h.

151 { return std::string("127.0.0.1:") + m_p2p_bind_port; }
::std::string string
Definition: gtest-port.h:1097
std::string m_p2p_bind_port
Definition: daemon.h:92

◆ rpc_addr()

std::string mock_daemon::rpc_addr ( ) const
inline

Definition at line 150 of file daemon.h.

150 { return std::string("127.0.0.1:") + m_rpc_bind_port; }
::std::string string
Definition: gtest-port.h:1097
std::string m_rpc_bind_port
Definition: daemon.h:93

◆ run()

void mock_daemon::run ( )

Definition at line 222 of file daemon.cpp.

223 {
224  m_run_thread = boost::thread(boost::bind(&mock_daemon::run_main, this));
225 }
boost::thread m_run_thread
Definition: daemon.h:99
bool run_main()
Definition: daemon.cpp:227
Here is the call graph for this function:

◆ run_main()

bool mock_daemon::run_main ( )

Definition at line 227 of file daemon.cpp.

228 {
229  CHECK_AND_ASSERT_THROW_MES(!m_terminated, "Can't run stopped daemon");
230  CHECK_AND_ASSERT_THROW_MES(!m_start_zmq || m_start_p2p, "ZMQ requires P2P");
231  boost::thread stop_thread = boost::thread([this] {
232  while (!this->m_stopped)
234  this->stop_p2p();
235  });
236 
238  m_stopped = true;
239  stop_thread.join();
240  });
241 
242  try
243  {
244  CHECK_AND_ASSERT_THROW_MES(m_rpc_server.run(2, false), "Failed to start RPC");
245  cryptonote::rpc::DaemonHandler rpc_daemon_handler(*m_core, m_server);
246  cryptonote::rpc::ZmqServer zmq_server(rpc_daemon_handler);
247 
248  if (m_start_zmq)
249  {
250  if (!zmq_server.addTCPSocket("127.0.0.1", m_zmq_bind_port))
251  {
252  MERROR("Failed to add TCP Socket (127.0.0.1:" << m_zmq_bind_port << ") to ZMQ RPC Server");
253 
254  stop_rpc();
255  return false;
256  }
257 
258  MINFO("Starting ZMQ server...");
259  zmq_server.run();
260 
261  MINFO("ZMQ server started at 127.0.0.1: " << m_zmq_bind_port);
262  }
263 
264  if (m_start_p2p)
265  {
266  m_server.run(); // blocks until p2p goes down
267  }
268  else
269  {
270  while (!this->m_stopped)
272  }
273 
274  if (m_start_zmq)
275  zmq_server.stop();
276 
277  stop_rpc();
278  return true;
279  }
280  catch (std::exception const & ex)
281  {
282  MFATAL("Uncaught exception! " << ex.what());
283  return false;
284  }
285  catch (...)
286  {
287  MFATAL("Uncaught exception!");
288  return false;
289  }
290 }
#define MERROR(x)
Definition: misc_log_ex.h:73
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
std::atomic< bool > m_stopped
Definition: daemon.h:96
#define MINFO(x)
Definition: misc_log_ex.h:75
bool m_start_p2p
Definition: daemon.h:88
bool m_start_zmq
Definition: daemon.h:89
#define MFATAL(x)
Definition: misc_log_ex.h:72
auto_scope_leave_caller create_scope_leave_handler(t_scope_leave_handler f)
std::atomic< bool > m_terminated
Definition: daemon.h:97
std::string m_zmq_bind_port
Definition: daemon.h:94
cryptonote::core * m_core
Definition: daemon.h:81
boost::shared_ptr< call_befor_die_base > auto_scope_leave_caller
bool sleep_no_w(long ms)
void stop_p2p()
Definition: daemon.cpp:306
bool run(size_t threads_count, bool wait=true)
t_node_server m_server
Definition: daemon.h:84
void stop_rpc()
Definition: daemon.cpp:300
mock_rpc_daemon m_rpc_server
Definition: daemon.h:83
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_ports()

void mock_daemon::set_ports ( boost::program_options::variables_map &  vm,
unsigned  initial_port 
)
static

Definition at line 85 of file daemon.cpp.

86 {
87  CHECK_AND_ASSERT_THROW_MES(initial_port < 65535-2, "Invalid port number");
88  tools::options::set_option(vm, nodetool::arg_p2p_bind_port, po::variable_value(std::to_string(initial_port), false));
89  tools::options::set_option(vm, cryptonote::core_rpc_server::arg_rpc_bind_port, po::variable_value(std::to_string(initial_port + 1), false));
90  tools::options::set_option(vm, daemon_args::arg_zmq_rpc_bind_port, po::variable_value(std::to_string(initial_port + 2), false));
91  po::notify(vm);
92 }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
const command_line::arg_descriptor< std::string, false, true, 2 > arg_p2p_bind_port
Definition: net_node.cpp:112
const command_line::arg_descriptor< std::string, false, true, 2 > arg_zmq_rpc_bind_port
static void set_option(boost::program_options::variables_map &vm, const std::string &key, const boost::program_options::variable_value &pv)
static const command_line::arg_descriptor< std::string, false, true, 2 > arg_rpc_bind_port
std::string to_string(t_connection_type type)
Here is the call graph for this function:

◆ set_start_p2p()

mock_daemon* mock_daemon::set_start_p2p ( bool  fl)
inline

Definition at line 128 of file daemon.h.

128 { m_start_p2p = fl; return this; }
bool m_start_p2p
Definition: daemon.h:88

◆ set_start_zmq()

mock_daemon* mock_daemon::set_start_zmq ( bool  fl)
inline

Definition at line 129 of file daemon.h.

129 { m_start_zmq = fl; return this; }
bool m_start_zmq
Definition: daemon.h:89

◆ start_mining()

void mock_daemon::start_mining ( const std::string &  miner_address,
uint64_t  threads_count = 1,
bool  do_background_mining = false,
bool  ignore_battery = true 
)

Definition at line 346 of file daemon.cpp.

347 {
349  req.miner_address = miner_address;
350  req.threads_count = threads_count;
351  req.do_background_mining = do_background_mining;
352  req.ignore_battery = ignore_battery;
353 
355  bool r = epee::net_utils::invoke_http_json("/start_mining", req, resp, m_http_client, rpc_timeout);
356  CHECK_AND_ASSERT_THROW_MES(r, "RPC error - start mining");
357  CHECK_AND_ASSERT_THROW_MES(resp.status != CORE_RPC_STATUS_BUSY, "Daemon busy");
358  CHECK_AND_ASSERT_THROW_MES(resp.status == CORE_RPC_STATUS_OK, "Daemon response invalid: " << resp.status);
359 }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
static constexpr const std::chrono::seconds rpc_timeout
Definition: daemon.h:79
bool invoke_http_json(const boost::string_ref uri, const t_request &out_struct, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
#define CORE_RPC_STATUS_BUSY
#define CORE_RPC_STATUS_OK
epee::net_utils::http::http_simple_client m_http_client
Definition: daemon.h:86
Here is the call graph for this function:

◆ stop()

void mock_daemon::stop ( )

Definition at line 292 of file daemon.cpp.

293 {
294  CHECK_AND_ASSERT_THROW_MES(!m_terminated, "Can't stop stopped daemon");
295  m_stopped = true;
296  m_terminated = true;
297  m_run_thread.join();
298 }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
std::atomic< bool > m_stopped
Definition: daemon.h:96
boost::thread m_run_thread
Definition: daemon.h:99
std::atomic< bool > m_terminated
Definition: daemon.h:97

◆ stop_and_deinit()

void mock_daemon::stop_and_deinit ( )

Definition at line 188 of file daemon.cpp.

189 {
190  stop();
191  deinit();
192 }
void stop()
Definition: daemon.cpp:292
void deinit()
Definition: daemon.cpp:143
Here is the call graph for this function:

◆ stop_mining()

void mock_daemon::stop_mining ( )

Definition at line 361 of file daemon.cpp.

362 {
365  bool r = epee::net_utils::invoke_http_json("/stop_mining", req, resp, m_http_client, rpc_timeout);
366  CHECK_AND_ASSERT_THROW_MES(r, "RPC error - stop mining");
367  CHECK_AND_ASSERT_THROW_MES(resp.status != CORE_RPC_STATUS_BUSY, "Daemon busy");
368  CHECK_AND_ASSERT_THROW_MES(resp.status == CORE_RPC_STATUS_OK, "Daemon response invalid: " << resp.status);
369 }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
static constexpr const std::chrono::seconds rpc_timeout
Definition: daemon.h:79
bool invoke_http_json(const boost::string_ref uri, const t_request &out_struct, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
#define CORE_RPC_STATUS_BUSY
#define CORE_RPC_STATUS_OK
epee::net_utils::http::http_simple_client m_http_client
Definition: daemon.h:86
Here is the call graph for this function:

◆ stop_p2p()

void mock_daemon::stop_p2p ( )

Definition at line 306 of file daemon.cpp.

307 {
308  if (m_start_p2p)
310 }
bool m_start_p2p
Definition: daemon.h:88
t_node_server m_server
Definition: daemon.h:84

◆ stop_rpc()

void mock_daemon::stop_rpc ( )

Definition at line 300 of file daemon.cpp.

301 {
304 }
bool timed_wait_server_stop(uint64_t ms)
mock_rpc_daemon m_rpc_server
Definition: daemon.h:83

◆ try_init_and_run()

void mock_daemon::try_init_and_run ( boost::optional< unsigned >  initial_port = boost::none)

Definition at line 194 of file daemon.cpp.

195 {
196  const unsigned max_attempts = 3;
197  for(unsigned attempts=0; attempts < max_attempts; ++attempts)
198  {
199  if (initial_port)
200  {
201  set_ports(m_vm, initial_port.get());
202  load_params(m_vm);
203  MDEBUG("Ports changed, RPC: " << rpc_addr());
204  }
205 
206  try
207  {
208  init_and_run();
209  return;
210  }
211  catch(const std::exception &e)
212  {
213  MWARNING("Could not init and start, attempt: " << attempts << ", reason: " << e.what());
214  if (attempts + 1 >= max_attempts)
215  {
216  throw;
217  }
218  }
219  }
220 }
#define MDEBUG(x)
Definition: misc_log_ex.h:76
void load_params(boost::program_options::variables_map const &vm)
Definition: daemon.cpp:94
static void set_ports(boost::program_options::variables_map &vm, unsigned initial_port)
Definition: daemon.cpp:85
#define MWARNING(x)
Definition: misc_log_ex.h:74
void init_and_run()
Definition: daemon.cpp:182
std::string rpc_addr() const
Definition: daemon.h:150
boost::program_options::variables_map m_vm
Definition: daemon.h:90

◆ zmq_addr()

std::string mock_daemon::zmq_addr ( ) const
inline

Definition at line 149 of file daemon.h.

149 { return std::string("127.0.0.1:") + m_zmq_bind_port; }
::std::string string
Definition: gtest-port.h:1097
std::string m_zmq_bind_port
Definition: daemon.h:94

Member Data Documentation

◆ m_core

cryptonote::core* mock_daemon::m_core

Definition at line 81 of file daemon.h.

◆ m_deinitalized

std::atomic<bool> mock_daemon::m_deinitalized

Definition at line 98 of file daemon.h.

◆ m_http_client

epee::net_utils::http::http_simple_client mock_daemon::m_http_client

Definition at line 86 of file daemon.h.

◆ m_network_type

cryptonote::network_type mock_daemon::m_network_type

Definition at line 85 of file daemon.h.

◆ m_p2p_bind_port

std::string mock_daemon::m_p2p_bind_port

Definition at line 92 of file daemon.h.

◆ m_protocol

t_protocol_raw mock_daemon::m_protocol

Definition at line 82 of file daemon.h.

◆ m_rpc_bind_port

std::string mock_daemon::m_rpc_bind_port

Definition at line 93 of file daemon.h.

◆ m_rpc_server

mock_rpc_daemon mock_daemon::m_rpc_server

Definition at line 83 of file daemon.h.

◆ m_run_thread

boost::thread mock_daemon::m_run_thread

Definition at line 99 of file daemon.h.

◆ m_server

t_node_server mock_daemon::m_server

Definition at line 84 of file daemon.h.

◆ m_start_p2p

bool mock_daemon::m_start_p2p

Definition at line 88 of file daemon.h.

◆ m_start_zmq

bool mock_daemon::m_start_zmq

Definition at line 89 of file daemon.h.

◆ m_stopped

std::atomic<bool> mock_daemon::m_stopped

Definition at line 96 of file daemon.h.

◆ m_terminated

std::atomic<bool> mock_daemon::m_terminated

Definition at line 97 of file daemon.h.

◆ m_vm

boost::program_options::variables_map mock_daemon::m_vm

Definition at line 90 of file daemon.h.

◆ m_zmq_bind_port

std::string mock_daemon::m_zmq_bind_port

Definition at line 94 of file daemon.h.

◆ rpc_timeout

constexpr const std::chrono::seconds mock_daemon::rpc_timeout = std::chrono::seconds(60)
static

Definition at line 79 of file daemon.h.


The documentation for this class was generated from the following files: