Monero
bootstrap_daemon.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 #include <map>
5 
6 #include <boost/optional/optional.hpp>
7 #include <boost/thread/mutex.hpp>
8 #include <boost/utility/string_ref.hpp>
9 
10 #include "net/http_client.h"
11 #include "storages/http_abstract_invoke.h"
12 
14 
15 namespace cryptonote
16 {
17 
19  {
20  public:
22  std::function<std::map<std::string, bool>()> get_public_nodes,
23  bool rpc_payment_enabled);
25  const std::string &address,
26  boost::optional<epee::net_utils::http::login> credentials,
27  bool rpc_payment_enabled);
28 
29  std::string address() const noexcept;
30  boost::optional<uint64_t> get_height();
31  bool handle_result(bool success, const std::string &status);
32 
33  template <class t_request, class t_response>
34  bool invoke_http_json(const boost::string_ref uri, const t_request &out_struct, t_response &result_struct)
35  {
37  {
38  return false;
39  }
40 
41  const bool result = epee::net_utils::invoke_http_json(uri, out_struct, result_struct, m_http_client);
42  return handle_result(result, result_struct.status);
43  }
44 
45  template <class t_request, class t_response>
46  bool invoke_http_bin(const boost::string_ref uri, const t_request &out_struct, t_response &result_struct)
47  {
49  {
50  return false;
51  }
52 
53  const bool result = epee::net_utils::invoke_http_bin(uri, out_struct, result_struct, m_http_client);
54  return handle_result(result, result_struct.status);
55  }
56 
57  template <class t_request, class t_response>
58  bool invoke_http_json_rpc(const boost::string_ref command_name, const t_request &out_struct, t_response &result_struct)
59  {
61  {
62  return false;
63  }
64 
65  const bool result = epee::net_utils::invoke_http_json_rpc(
66  "/json_rpc",
67  std::string(command_name.begin(), command_name.end()),
68  out_struct,
69  result_struct,
71  return handle_result(result, result_struct.status);
72  }
73 
74  private:
75  bool set_server(const std::string &address, const boost::optional<epee::net_utils::http::login> &credentials = boost::none);
77 
78  private:
79  epee::net_utils::http::http_simple_client m_http_client;
81  const std::unique_ptr<bootstrap_node::selector> m_selector;
82  boost::mutex m_selector_mutex;
83  };
84 
85 }
cryptonote::bootstrap_daemon::bootstrap_daemon
bootstrap_daemon(std::function< std::map< std::string, bool >()> get_public_nodes, bool rpc_payment_enabled)
Definition: bootstrap_daemon.cpp:17
cryptonote::bootstrap_daemon::m_selector_mutex
boost::mutex m_selector_mutex
Definition: bootstrap_daemon.h:82
cryptonote::bootstrap_daemon::invoke_http_bin
bool invoke_http_bin(const boost::string_ref uri, const t_request &out_struct, t_response &result_struct)
Definition: bootstrap_daemon.h:46
cryptonote::bootstrap_daemon::m_rpc_payment_enabled
const bool m_rpc_payment_enabled
Definition: bootstrap_daemon.h:80
cryptonote::bootstrap_daemon::get_height
boost::optional< uint64_t > get_height()
Definition: bootstrap_daemon.cpp:48
cryptonote::bootstrap_daemon::switch_server_if_needed
bool switch_server_if_needed()
Definition: bootstrap_daemon.cpp:94
cryptonote::bootstrap_daemon
Definition: bootstrap_daemon.h:19
cryptonote::bootstrap_daemon::invoke_http_json_rpc
bool invoke_http_json_rpc(const boost::string_ref command_name, const t_request &out_struct, t_response &result_struct)
Definition: bootstrap_daemon.h:58
success
expect< void > success() noexcept
Definition: expect.h:397
cryptonote::bootstrap_daemon::address
std::string address() const noexcept
Definition: bootstrap_daemon.cpp:38
bootstrap_node_selector.h
cryptonote
Holds cryptonote related classes and helpers.
Definition: blockchain_db.cpp:45
cryptonote::bootstrap_daemon::invoke_http_json
bool invoke_http_json(const boost::string_ref uri, const t_request &out_struct, t_response &result_struct)
Definition: bootstrap_daemon.h:34
cryptonote::bootstrap_daemon::set_server
bool set_server(const std::string &address, const boost::optional< epee::net_utils::http::login > &credentials=boost::none)
Definition: bootstrap_daemon.cpp:81
cryptonote::bootstrap_daemon::handle_result
bool handle_result(bool success, const std::string &status)
Definition: bootstrap_daemon.cpp:66
cryptonote::bootstrap_daemon::m_http_client
epee::net_utils::http::http_simple_client m_http_client
Definition: bootstrap_daemon.h:79
cryptonote::bootstrap_daemon::m_selector
const std::unique_ptr< bootstrap_node::selector > m_selector
Definition: bootstrap_daemon.h:81