Monero
p2p.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2018, 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 
34 #include "p2p/net_node.h"
35 #include "daemon/protocol.h"
36 
37 #undef MONERO_DEFAULT_LOG_CATEGORY
38 #define MONERO_DEFAULT_LOG_CATEGORY "daemon"
39 
40 namespace daemonize
41 {
42 
43 class t_p2p final
44 {
45 private:
48 public:
49  static void init_options(boost::program_options::options_description & option_spec)
50  {
51  t_node_server::init_options(option_spec);
52  }
53 private:
55 public:
57  boost::program_options::variables_map const & vm
58  , t_protocol & protocol
59  )
60  : m_server{protocol.get()}
61  {
62  //initialize objects
63  MGINFO("Initializing p2p server...");
64  if (!m_server.init(vm))
65  {
66  throw std::runtime_error("Failed to initialize p2p server.");
67  }
68  MGINFO("p2p server initialized OK");
69  }
70 
71  t_node_server & get()
72  {
73  return m_server;
74  }
75 
76  void run()
77  {
78  MGINFO("Starting p2p net loop...");
79  m_server.run();
80  MGINFO("p2p net loop stopped");
81  }
82 
83  void stop()
84  {
86  }
87 
89  {
90  MGINFO("Deinitializing p2p...");
91  try {
92  m_server.deinit();
93  } catch (...) {
94  MERROR("Failed to deinitialize p2p...");
95  }
96  }
97 };
98 
99 }
static void init_options(boost::program_options::options_description &option_spec)
Definition: p2p.h:49
~t_p2p()
Definition: p2p.h:88
Definition: protocol.h:39
Definition: command_parser_executor.cpp:37
bool send_stop_signal()
Definition: net_node.inl:694
Definition: p2p.h:43
nodetool::node_server< t_protocol_raw > t_node_server
Definition: p2p.h:47
bool init(const boost::program_options::variables_map &vm)
Definition: net_node.inl:424
void stop()
Definition: p2p.h:83
t_p2p(boost::program_options::variables_map const &vm, t_protocol &protocol)
Definition: p2p.h:56
cryptonote::t_cryptonote_protocol_handler< cryptonote::core > t_protocol_raw
Definition: p2p.h:46
void run()
Definition: p2p.h:76
t_node_server m_server
Definition: p2p.h:54
This is the original cryptonote protocol network-events handler, modified by us.
bool run()
Definition: net_node.inl:594
t_protocol_raw & get()
Definition: protocol.h:61
static void init_options(boost::program_options::options_description &desc)
Definition: net_node.inl:68
bool deinit()
Definition: net_node.inl:654