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