Monero
net_node_common.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 
33 #include <boost/uuid/uuid.hpp>
34 #include "net/net_utils_base.h"
35 #include "p2p_protocol_defs.h"
36 
37 namespace nodetool
38 {
39 
42 
43  template<class t_connection_context>
45  {
46  virtual bool relay_notify_to_list(int command, const std::string& data_buff, const std::list<boost::uuids::uuid>& connections)=0;
47  virtual bool relay_notify_to_all(int command, const std::string& data_buff, const epee::net_utils::connection_context_base& context)=0;
48  virtual bool invoke_command_to_peer(int command, const std::string& req_buff, std::string& resp_buff, const epee::net_utils::connection_context_base& context)=0;
49  virtual bool invoke_notify_to_peer(int command, const std::string& req_buff, const epee::net_utils::connection_context_base& context)=0;
50  virtual bool drop_connection(const epee::net_utils::connection_context_base& context)=0;
51  virtual void request_callback(const epee::net_utils::connection_context_base& context)=0;
52  virtual uint64_t get_connections_count()=0;
53  virtual void for_each_connection(std::function<bool(t_connection_context&, peerid_type, uint32_t)> f)=0;
54  virtual bool for_connection(const boost::uuids::uuid&, std::function<bool(t_connection_context&, peerid_type, uint32_t)> f)=0;
55  virtual bool block_host(const epee::net_utils::network_address &address, time_t seconds = 0)=0;
56  virtual bool unblock_host(const epee::net_utils::network_address &address)=0;
57  virtual std::map<std::string, time_t> get_blocked_hosts()=0;
58  virtual bool add_host_fail(const epee::net_utils::network_address &address)=0;
59  };
60 
61  template<class t_connection_context>
62  struct p2p_endpoint_stub: public i_p2p_endpoint<t_connection_context>
63  {
64  virtual bool relay_notify_to_list(int command, const std::string& data_buff, const std::list<boost::uuids::uuid>& connections)
65  {
66  return false;
67  }
68  virtual bool relay_notify_to_all(int command, const std::string& data_buff, const epee::net_utils::connection_context_base& context)
69  {
70  return false;
71  }
72  virtual bool invoke_command_to_peer(int command, const std::string& req_buff, std::string& resp_buff, const epee::net_utils::connection_context_base& context)
73  {
74  return false;
75  }
76  virtual bool invoke_notify_to_peer(int command, const std::string& req_buff, const epee::net_utils::connection_context_base& context)
77  {
78  return true;
79  }
80  virtual bool drop_connection(const epee::net_utils::connection_context_base& context)
81  {
82  return false;
83  }
84  virtual void request_callback(const epee::net_utils::connection_context_base& context)
85  {
86 
87  }
88  virtual void for_each_connection(std::function<bool(t_connection_context&,peerid_type,uint32_t)> f)
89  {
90 
91  }
92  virtual bool for_connection(const boost::uuids::uuid&, std::function<bool(t_connection_context&,peerid_type,uint32_t)> f)
93  {
94  return false;
95  }
96 
97  virtual uint64_t get_connections_count()
98  {
99  return false;
100  }
101  virtual bool block_host(const epee::net_utils::network_address &address, time_t seconds)
102  {
103  return true;
104  }
105  virtual bool unblock_host(const epee::net_utils::network_address &address)
106  {
107  return true;
108  }
109  virtual std::map<std::string, time_t> get_blocked_hosts()
110  {
111  return std::map<std::string, time_t>();
112  }
113  virtual bool add_host_fail(const epee::net_utils::network_address &address)
114  {
115  return true;
116  }
117  };
118 }
virtual bool block_host(const epee::net_utils::network_address &address, time_t seconds)
Definition: net_node_common.h:101
virtual bool drop_connection(const epee::net_utils::connection_context_base &context)=0
virtual void request_callback(const epee::net_utils::connection_context_base &context)
Definition: net_node_common.h:84
Definition: net_node_common.h:62
virtual bool invoke_command_to_peer(int command, const std::string &req_buff, std::string &resp_buff, const epee::net_utils::connection_context_base &context)=0
boost::uuids::uuid uuid
Definition: net_node_common.h:40
virtual uint64_t get_connections_count()
Definition: net_node_common.h:97
virtual uint64_t get_connections_count()=0
virtual bool relay_notify_to_list(int command, const std::string &data_buff, const std::list< boost::uuids::uuid > &connections)
Definition: net_node_common.h:64
virtual std::map< std::string, time_t > get_blocked_hosts()=0
virtual bool relay_notify_to_list(int command, const std::string &data_buff, const std::list< boost::uuids::uuid > &connections)=0
virtual bool invoke_notify_to_peer(int command, const std::string &req_buff, const epee::net_utils::connection_context_base &context)
Definition: net_node_common.h:76
virtual bool block_host(const epee::net_utils::network_address &address, time_t seconds=0)=0
virtual bool invoke_notify_to_peer(int command, const std::string &req_buff, const epee::net_utils::connection_context_base &context)=0
virtual bool unblock_host(const epee::net_utils::network_address &address)=0
virtual void request_callback(const epee::net_utils::connection_context_base &context)=0
virtual bool for_connection(const boost::uuids::uuid &, std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)
Definition: net_node_common.h:92
virtual bool relay_notify_to_all(int command, const std::string &data_buff, const epee::net_utils::connection_context_base &context)=0
virtual bool add_host_fail(const epee::net_utils::network_address &address)=0
virtual void for_each_connection(std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)=0
virtual bool drop_connection(const epee::net_utils::connection_context_base &context)
Definition: net_node_common.h:80
uint64_t peerid_type
Definition: p2p_protocol_defs.h:47
boost::uuids::uuid net_connection_id
Definition: net_node_common.h:41
virtual bool unblock_host(const epee::net_utils::network_address &address)
Definition: net_node_common.h:105
virtual bool add_host_fail(const epee::net_utils::network_address &address)
Definition: net_node_common.h:113
Definition: net_node.cpp:34
virtual bool relay_notify_to_all(int command, const std::string &data_buff, const epee::net_utils::connection_context_base &context)
Definition: net_node_common.h:68
virtual bool invoke_command_to_peer(int command, const std::string &req_buff, std::string &resp_buff, const epee::net_utils::connection_context_base &context)
Definition: net_node_common.h:72
virtual std::map< std::string, time_t > get_blocked_hosts()
Definition: net_node_common.h:109
virtual void for_each_connection(std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)
Definition: net_node_common.h:88
Definition: net_node_common.h:44
virtual bool for_connection(const boost::uuids::uuid &, std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)=0