Electroneum
net_node_common.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2019, The Electroneum Project
2 // Copyrights(c) 2014-2017, The Monero Project
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without modification, are
7 // permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this list of
10 // conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 // of conditions and the following disclaimer in the documentation and/or other
14 // materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its contributors may be
17 // used to endorse or promote products derived from this software without specific
18 // prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31 
32 #pragma once
33 
34 #include <boost/uuid/uuid.hpp>
35 #include "net/net_utils_base.h"
36 #include "p2p_protocol_defs.h"
37 
38 namespace nodetool
39 {
40 
43 
44  template<class t_connection_context>
46  {
47  virtual bool relay_notify_to_list(int command, const std::string& data_buff, const std::list<boost::uuids::uuid>& connections)=0;
48  virtual bool relay_notify_to_all(int command, const std::string& data_buff, const epee::net_utils::connection_context_base& context)=0;
49  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;
50  virtual bool invoke_notify_to_peer(int command, const std::string& req_buff, const epee::net_utils::connection_context_base& context)=0;
51  virtual bool drop_connection(const epee::net_utils::connection_context_base& context)=0;
52  virtual void request_callback(const epee::net_utils::connection_context_base& context)=0;
53  virtual uint64_t get_connections_count()=0;
54  virtual void for_each_connection(std::function<bool(t_connection_context&, peerid_type, uint32_t)> f)=0;
55  virtual bool for_connection(const boost::uuids::uuid&, std::function<bool(t_connection_context&, peerid_type, uint32_t)> f)=0;
56  virtual bool block_host(const epee::net_utils::network_address &address, time_t seconds = 0)=0;
57  virtual bool unblock_host(const epee::net_utils::network_address &address)=0;
58  virtual std::map<std::string, time_t> get_blocked_hosts()=0;
59  virtual bool add_host_fail(const epee::net_utils::network_address &address)=0;
60  };
61 
62  template<class t_connection_context>
63  struct p2p_endpoint_stub: public i_p2p_endpoint<t_connection_context>
64  {
65  virtual bool relay_notify_to_list(int command, const std::string& data_buff, const std::list<boost::uuids::uuid>& connections)
66  {
67  return false;
68  }
69  virtual bool relay_notify_to_all(int command, const std::string& data_buff, const epee::net_utils::connection_context_base& context)
70  {
71  return false;
72  }
73  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)
74  {
75  return false;
76  }
77  virtual bool invoke_notify_to_peer(int command, const std::string& req_buff, const epee::net_utils::connection_context_base& context)
78  {
79  return true;
80  }
81  virtual bool drop_connection(const epee::net_utils::connection_context_base& context)
82  {
83  return false;
84  }
85  virtual void request_callback(const epee::net_utils::connection_context_base& context)
86  {
87 
88  }
89  virtual void for_each_connection(std::function<bool(t_connection_context&,peerid_type,uint32_t)> f)
90  {
91 
92  }
93  virtual bool for_connection(const boost::uuids::uuid&, std::function<bool(t_connection_context&,peerid_type,uint32_t)> f)
94  {
95  return false;
96  }
97 
98  virtual uint64_t get_connections_count()
99  {
100  return false;
101  }
102  virtual bool block_host(const epee::net_utils::network_address &address, time_t seconds)
103  {
104  return true;
105  }
106  virtual bool unblock_host(const epee::net_utils::network_address &address)
107  {
108  return true;
109  }
110  virtual std::map<std::string, time_t> get_blocked_hosts()
111  {
112  return std::map<std::string, time_t>();
113  }
114  virtual bool add_host_fail(const epee::net_utils::network_address &address)
115  {
116  return true;
117  }
118  };
119 }
virtual bool block_host(const epee::net_utils::network_address &address, time_t seconds)
Definition: net_node_common.h:102
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:85
Definition: net_node_common.h:63
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:41
virtual uint64_t get_connections_count()
Definition: net_node_common.h:98
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:65
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:77
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:93
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:81
uint64_t peerid_type
Definition: p2p_protocol_defs.h:46
boost::uuids::uuid net_connection_id
Definition: net_node_common.h:42
virtual bool unblock_host(const epee::net_utils::network_address &address)
Definition: net_node_common.h:106
virtual bool add_host_fail(const epee::net_utils::network_address &address)
Definition: net_node_common.h:114
Definition: net_node.h:60
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:69
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:73
virtual std::map< std::string, time_t > get_blocked_hosts()
Definition: net_node_common.h:110
virtual void for_each_connection(std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)
Definition: net_node_common.h:89
Definition: net_node_common.h:45
virtual bool for_connection(const boost::uuids::uuid &, std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)=0
json::wvalue context
Definition: mustache.h:12