Electroneum
Loading...
Searching...
No Matches
net_node_common.h
Go to the documentation of this file.
1// Copyrights(c) 2017-2021, The Electroneum Project
2// Copyrights(c) 2014-2019, 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 <utility>
36#include <vector>
37#include "net/net_utils_base.h"
38#include "p2p_protocol_defs.h"
39
40namespace nodetool
41{
42
43 typedef boost::uuids::uuid uuid;
44 typedef boost::uuids::uuid net_connection_id;
45
46 template<class t_connection_context>
48 {
49 virtual bool relay_notify_to_list(int command, const epee::span<const uint8_t> data_buff, std::vector<std::pair<epee::net_utils::zone, boost::uuids::uuid>> connections)=0;
50 virtual bool invoke_command_to_peer(int command, const epee::span<const uint8_t> req_buff, std::string& resp_buff, const epee::net_utils::connection_context_base& context)=0;
51 virtual bool invoke_notify_to_peer(int command, const epee::span<const uint8_t> req_buff, const epee::net_utils::connection_context_base& context)=0;
55 virtual size_t get_zone_count() const=0;
56 virtual void for_each_connection(std::function<bool(t_connection_context&, peerid_type, uint32_t)> f)=0;
57 virtual bool for_connection(const boost::uuids::uuid&, std::function<bool(t_connection_context&, peerid_type, uint32_t)> f)=0;
58 virtual bool block_host(const epee::net_utils::network_address &address, time_t seconds = 0)=0;
60 virtual std::map<std::string, time_t> get_blocked_hosts()=0;
62 virtual void add_used_stripe_peer(const t_connection_context &context)=0;
63 virtual void remove_used_stripe_peer(const t_connection_context &context)=0;
64 virtual void clear_used_stripe_peers()=0;
65 };
66
67 template<class t_connection_context>
68 struct p2p_endpoint_stub: public i_p2p_endpoint<t_connection_context>
69 {
70 virtual bool relay_notify_to_list(int command, const epee::span<const uint8_t> data_buff, std::vector<std::pair<epee::net_utils::zone, boost::uuids::uuid>> connections)
71 {
72 return false;
73 }
74 virtual bool invoke_command_to_peer(int command, const epee::span<const uint8_t> req_buff, std::string& resp_buff, const epee::net_utils::connection_context_base& context)
75 {
76 return false;
77 }
78 virtual bool invoke_notify_to_peer(int command, const epee::span<const uint8_t> req_buff, const epee::net_utils::connection_context_base& context)
79 {
80 return true;
81 }
83 {
84 return false;
85 }
87 {
88
89 }
90 virtual void for_each_connection(std::function<bool(t_connection_context&,peerid_type,uint32_t)> f)
91 {
92
93 }
94 virtual bool for_connection(const boost::uuids::uuid&, std::function<bool(t_connection_context&,peerid_type,uint32_t)> f)
95 {
96 return false;
97 }
98
99 virtual size_t get_zone_count() const
100 {
101 return 0;
102 }
103
105 {
106 return false;
107 }
108 virtual bool block_host(const epee::net_utils::network_address &address, time_t seconds)
109 {
110 return true;
111 }
113 {
114 return true;
115 }
116 virtual std::map<std::string, time_t> get_blocked_hosts()
117 {
118 return std::map<std::string, time_t>();
119 }
121 {
122 return true;
123 }
124 virtual void add_used_stripe_peer(const t_connection_context &context)
125 {
126 }
127 virtual void remove_used_stripe_peer(const t_connection_context &context)
128 {
129 }
131 {
132 }
133 };
134}
Non-owning sequence of data. Does not deep copy.
Definition span.h:57
boost::uuids::uuid uuid
uint64_t peerid_type
boost::uuids::uuid net_connection_id
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
virtual void request_callback(const epee::net_utils::connection_context_base &context)=0
virtual bool drop_connection(const epee::net_utils::connection_context_base &context)=0
virtual uint64_t get_public_connections_count()=0
virtual bool invoke_notify_to_peer(int command, const epee::span< const uint8_t > req_buff, const epee::net_utils::connection_context_base &context)=0
virtual void for_each_connection(std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)=0
virtual bool for_connection(const boost::uuids::uuid &, std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)=0
virtual bool add_host_fail(const epee::net_utils::network_address &address)=0
virtual bool invoke_command_to_peer(int command, const epee::span< const uint8_t > req_buff, std::string &resp_buff, const epee::net_utils::connection_context_base &context)=0
virtual void add_used_stripe_peer(const t_connection_context &context)=0
virtual void clear_used_stripe_peers()=0
virtual void remove_used_stripe_peer(const t_connection_context &context)=0
virtual bool relay_notify_to_list(int command, const epee::span< const uint8_t > data_buff, std::vector< std::pair< epee::net_utils::zone, boost::uuids::uuid > > connections)=0
virtual size_t get_zone_count() const =0
virtual bool block_host(const epee::net_utils::network_address &address, time_t seconds=0)=0
virtual std::map< std::string, time_t > get_blocked_hosts()=0
virtual bool unblock_host(const epee::net_utils::network_address &address)=0
virtual std::map< std::string, time_t > get_blocked_hosts()
virtual bool invoke_command_to_peer(int command, const epee::span< const uint8_t > req_buff, std::string &resp_buff, const epee::net_utils::connection_context_base &context)
virtual bool invoke_notify_to_peer(int command, const epee::span< const uint8_t > req_buff, const epee::net_utils::connection_context_base &context)
virtual void for_each_connection(std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)
virtual bool unblock_host(const epee::net_utils::network_address &address)
virtual bool block_host(const epee::net_utils::network_address &address, time_t seconds)
virtual uint64_t get_public_connections_count()
virtual void remove_used_stripe_peer(const t_connection_context &context)
virtual void add_used_stripe_peer(const t_connection_context &context)
virtual void clear_used_stripe_peers()
virtual bool add_host_fail(const epee::net_utils::network_address &address)
virtual bool for_connection(const boost::uuids::uuid &, std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)
virtual size_t get_zone_count() const
virtual bool relay_notify_to_list(int command, const epee::span< const uint8_t > data_buff, std::vector< std::pair< epee::net_utils::zone, boost::uuids::uuid > > connections)
virtual void request_callback(const epee::net_utils::connection_context_base &context)
virtual bool drop_connection(const epee::net_utils::connection_context_base &context)
const char * address
Definition multisig.cpp:37