Monero
Toggle main menu visibility
Loading...
Searching...
No Matches
src
daemon
rpc.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
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30
31
#pragma once
32
33
#include "
rpc/core_rpc_server.h
"
34
35
#undef MONERO_DEFAULT_LOG_CATEGORY
36
#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
37
38
namespace
daemonize
39
{
40
41
class
t_rpc
final
42
{
43
public
:
44
static
void
init_options
(boost::program_options::options_description & option_spec)
45
{
46
cryptonote::core_rpc_server::init_options
(option_spec);
47
}
48
private
:
49
cryptonote::core_rpc_server
m_server
;
50
const
std::string
m_description
;
51
public
:
52
t_rpc
(
53
boost::program_options::variables_map
const
&
vm
54
,
t_core
& core
55
,
t_p2p
&
p2p
56
,
const
bool
restricted
57
,
const
std::string & port
58
,
const
std::string & description
59
,
bool
allow_rpc_payment
60
)
61
:
m_server
{core.
get
(),
p2p
.
get
()},
m_description
{description}
62
{
63
MGINFO(
"Initializing "
<<
m_description
<<
" RPC server..."
);
64
65
if
(!
m_server
.init(
vm
, restricted, port, allow_rpc_payment,
command_line::get_arg
(
vm
,
daemon_args::arg_proxy
)))
66
{
67
throw
std::runtime_error(
"Failed to initialize "
+
m_description
+
" RPC server."
);
68
}
69
MGINFO(
m_description
<<
" RPC server initialized OK on port: "
<<
m_server
.get_binded_port());
70
}
71
72
void
run
()
73
{
74
MGINFO(
"Starting "
<<
m_description
<<
" RPC server..."
);
75
if
(!
m_server
.run(2,
false
))
76
{
77
throw
std::runtime_error(
"Failed to start "
+
m_description
+
" RPC server."
);
78
}
79
MGINFO(
m_description
<<
" RPC server started ok"
);
80
}
81
82
void
stop
()
83
{
84
MGINFO(
"Stopping "
<<
m_description
<<
" RPC server..."
);
85
m_server
.send_stop_signal();
86
m_server
.timed_wait_server_stop(5000);
87
}
88
89
cryptonote::core_rpc_server
*
get_server
()
90
{
91
return
&
m_server
;
92
}
93
94
~t_rpc
()
95
{
96
MGINFO(
"Deinitializing "
<<
m_description
<<
" RPC server..."
);
97
try
{
98
m_server
.deinit();
99
}
catch
(...) {
100
MERROR(
"Failed to deinitialize "
<<
m_description
<<
" RPC server..."
);
101
}
102
}
103
};
104
105
}
cryptonote::core_rpc_server
Definition
core_rpc_server.h:56
cryptonote::core_rpc_server::init_options
static void init_options(boost::program_options::options_description &desc)
Definition
core_rpc_server.cpp:153
daemonize::t_core
Definition
core.h:44
daemonize::t_p2p
Definition
p2p.h:45
daemonize::t_rpc::init_options
static void init_options(boost::program_options::options_description &option_spec)
Definition
rpc.h:44
daemonize::t_rpc::run
void run()
Definition
rpc.h:72
daemonize::t_rpc::get_server
cryptonote::core_rpc_server * get_server()
Definition
rpc.h:89
daemonize::t_rpc::t_rpc
t_rpc(boost::program_options::variables_map const &vm, t_core &core, t_p2p &p2p, const bool restricted, const std::string &port, const std::string &description, bool allow_rpc_payment)
Definition
rpc.h:52
daemonize::t_rpc::~t_rpc
~t_rpc()
Definition
rpc.h:94
daemonize::t_rpc::stop
void stop()
Definition
rpc.h:82
daemonize::t_rpc::m_description
const std::string m_description
Definition
rpc.h:50
daemonize::t_rpc::m_server
cryptonote::core_rpc_server m_server
Definition
rpc.h:49
core_rpc_server.h
get
void get(std::istream &input, bool &res)
Definition
io.h:61
command_line::get_arg
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Definition
command_line.h:269
daemon_args::arg_proxy
const command_line::arg_descriptor< std::string > arg_proxy
Definition
command_line_args.h:99
daemonize
Definition
command_parser_executor.cpp:39
p2p
Definition
p2p.py:1
vm
randomx_vm * vm
Definition
tests.cpp:20
Generated on
for Monero by
1.17.0