Monero
Loading...
Searching...
No Matches
net_node_common.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 <boost/uuid/uuid.hpp>
34#include <utility>
35#include <vector>
39#include "net/enums.h"
40#include "net/net_utils_base.h"
41#include "p2p_protocol_defs.h"
42
43namespace epee { namespace levin { class message_writer; } }
44
45namespace nodetool
46{
47
48 typedef boost::uuids::uuid uuid;
49 typedef boost::uuids::uuid net_connection_id;
50
51 template<class t_connection_context>
53 {
54 virtual bool relay_notify_to_list(int command, epee::levin::message_writer message, std::vector<std::pair<epee::net_utils::zone, boost::uuids::uuid>> connections)=0;
55 virtual epee::net_utils::zone send_txs(std::vector<cryptonote::blobdata> txs, const epee::net_utils::zone origin, const boost::uuids::uuid& source, cryptonote::relay_method tx_relay)=0;
60 virtual void for_each_connection(std::function<bool(t_connection_context&, peerid_type, uint32_t)> f)=0;
61 virtual bool for_connection(const boost::uuids::uuid&, std::function<bool(t_connection_context&, peerid_type, uint32_t)> f)=0;
62 virtual bool block_host(epee::net_utils::network_address address, time_t seconds = 0, bool add_only = false)=0;
64 virtual std::map<std::string, time_t> get_blocked_hosts()=0;
65 virtual std::map<epee::net_utils::ipv4_network_subnet, time_t> get_blocked_subnets()=0;
66 virtual bool add_host_fail(const epee::net_utils::network_address &address, unsigned int score = 1)=0;
67 virtual void add_used_stripe_peer(const t_connection_context &context)=0;
68 virtual void remove_used_stripe_peer(const t_connection_context &context)=0;
69 virtual void clear_used_stripe_peers()=0;
70 };
71
72 template<class t_connection_context>
73 struct p2p_endpoint_stub: public i_p2p_endpoint<t_connection_context>
74 {
75 virtual bool relay_notify_to_list(int command, epee::levin::message_writer message, std::vector<std::pair<epee::net_utils::zone, boost::uuids::uuid>> connections)
76 {
77 return false;
78 }
79 virtual epee::net_utils::zone send_txs(std::vector<cryptonote::blobdata> txs, const epee::net_utils::zone origin, const boost::uuids::uuid& source, cryptonote::relay_method tx_relay)
80 {
82 }
84 {
85 return true;
86 }
88 {
89 return false;
90 }
92 {
93
94 }
95 virtual void for_each_connection(std::function<bool(t_connection_context&,peerid_type,uint32_t)> f)
96 {
97
98 }
99 virtual bool for_connection(const boost::uuids::uuid&, std::function<bool(t_connection_context&,peerid_type,uint32_t)> f)
100 {
101 return false;
102 }
103
105 {
106 return false;
107 }
108 virtual bool block_host(epee::net_utils::network_address address, time_t seconds, bool add_only)
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 }
120 virtual std::map<epee::net_utils::ipv4_network_subnet, time_t> get_blocked_subnets()
121 {
122 return std::map<epee::net_utils::ipv4_network_subnet, time_t>();
123 }
124 virtual bool add_host_fail(const epee::net_utils::network_address &address, unsigned int score)
125 {
126 return true;
127 }
128 virtual void add_used_stripe_peer(const t_connection_context &context)
129 {
130 }
131 virtual void remove_used_stripe_peer(const t_connection_context &context)
132 {
133 }
135 {
136 }
137 };
138}
Provides space for levin (p2p) header, so that payload can be sent without copy.
Definition levin_base.h:132
Definition net_utils_base.h:225
uint32_t address
Definition getifaddr.c:269
relay_method
Methods tracking how a tx was received and relayed.
Definition enums.h:37
Definition levin_base.h:44
zone
Definition enums.h:50
@ invalid
Definition enums.h:51
TODO: (mj-xmr) This will be reduced in an another PR.
Definition byte_slice.h:40
Definition levin_notify.h:52
boost::uuids::uuid uuid
Definition net_node_common.h:48
uint64_t peerid_type
Definition p2p_protocol_defs.h:49
boost::uuids::uuid net_connection_id
Definition net_node_common.h:49
const CharType(& source)[N]
Definition pointer.h:1147
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
Definition net_utils_base.h:367
Definition net_node_common.h:53
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 relay_notify_to_list(int command, epee::levin::message_writer message, std::vector< std::pair< epee::net_utils::zone, boost::uuids::uuid > > connections)=0
virtual void for_each_connection(std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)=0
virtual std::map< epee::net_utils::ipv4_network_subnet, time_t > get_blocked_subnets()=0
virtual bool add_host_fail(const epee::net_utils::network_address &address, unsigned int score=1)=0
virtual bool for_connection(const boost::uuids::uuid &, std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)=0
virtual bool block_host(epee::net_utils::network_address address, time_t seconds=0, bool add_only=false)=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 invoke_notify_to_peer(int command, epee::levin::message_writer message, const epee::net_utils::connection_context_base &context)=0
virtual std::map< std::string, time_t > get_blocked_hosts()=0
virtual epee::net_utils::zone send_txs(std::vector< cryptonote::blobdata > txs, const epee::net_utils::zone origin, const boost::uuids::uuid &source, cryptonote::relay_method tx_relay)=0
virtual bool unblock_host(const epee::net_utils::network_address &address)=0
Definition net_node_common.h:74
virtual std::map< std::string, time_t > get_blocked_hosts()
Definition net_node_common.h:116
virtual bool relay_notify_to_list(int command, epee::levin::message_writer message, std::vector< std::pair< epee::net_utils::zone, boost::uuids::uuid > > connections)
Definition net_node_common.h:75
virtual epee::net_utils::zone send_txs(std::vector< cryptonote::blobdata > txs, const epee::net_utils::zone origin, const boost::uuids::uuid &source, cryptonote::relay_method tx_relay)
Definition net_node_common.h:79
virtual void for_each_connection(std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)
Definition net_node_common.h:95
virtual std::map< epee::net_utils::ipv4_network_subnet, time_t > get_blocked_subnets()
Definition net_node_common.h:120
virtual bool unblock_host(const epee::net_utils::network_address &address)
Definition net_node_common.h:112
virtual bool block_host(epee::net_utils::network_address address, time_t seconds, bool add_only)
Definition net_node_common.h:108
virtual uint64_t get_public_connections_count()
Definition net_node_common.h:104
virtual bool invoke_notify_to_peer(int command, epee::levin::message_writer message, const epee::net_utils::connection_context_base &context)
Definition net_node_common.h:83
virtual void remove_used_stripe_peer(const t_connection_context &context)
Definition net_node_common.h:131
virtual void add_used_stripe_peer(const t_connection_context &context)
Definition net_node_common.h:128
virtual void clear_used_stripe_peers()
Definition net_node_common.h:134
virtual bool add_host_fail(const epee::net_utils::network_address &address, unsigned int score)
Definition net_node_common.h:124
virtual bool for_connection(const boost::uuids::uuid &, std::function< bool(t_connection_context &, peerid_type, uint32_t)> f)
Definition net_node_common.h:99
virtual void request_callback(const epee::net_utils::connection_context_base &context)
Definition net_node_common.h:91
virtual bool drop_connection(const epee::net_utils::connection_context_base &context)
Definition net_node_common.h:87