| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include <boost/uuid/uuid.hpp> |
| 34 |
#include <utility> |
| 35 |
#include <vector> |
| 36 |
#include "cryptonote_basic/blobdatatype.h" |
| 37 |
#include "cryptonote_protocol/enums.h" |
| 38 |
#include "cryptonote_protocol/fwd.h" |
| 39 |
#include "net/enums.h" |
| 40 |
#include "net/net_utils_base.h" |
| 41 |
#include "p2p_protocol_defs.h" |
| 42 |
|
| 43 |
namespace epee { namespace levin { class message_writer; } } |
| 44 |
|
| 45 |
namespace nodetool |
| 46 |
{ |
| 47 |
|
| 48 |
typedef boost::uuids::uuid uuid; |
| 49 |
typedef boost::uuids::uuid net_connection_id; |
| 50 |
|
| 51 |
template<class t_connection_context> |
| 52 |
struct i_p2p_endpoint |
| 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; |
| 56 |
virtual bool invoke_notify_to_peer(int command, epee::levin::message_writer message, const epee::net_utils::connection_context_base& context)=0; |
| 57 |
virtual bool drop_connection(const epee::net_utils::connection_context_base& context)=0; |
| 58 |
virtual void request_callback(const epee::net_utils::connection_context_base& context)=0; |
| 59 |
virtual uint64_t get_public_connections_count()=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; |
| 63 |
virtual bool unblock_host(const epee::net_utils::network_address &address)=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 |
{ |
| 81 |
return epee::net_utils::zone::invalid; |
| 82 |
} |
| 83 |
virtual bool invoke_notify_to_peer(int command, epee::levin::message_writer message, const epee::net_utils::connection_context_base& context) |
| 84 |
{ |
| 85 |
return true; |
| 86 |
} |
| 87 |
virtual bool drop_connection(const epee::net_utils::connection_context_base& context) |
| 88 |
{ |
| 89 |
return false; |
| 90 |
} |
| 91 |
virtual void request_callback(const epee::net_utils::connection_context_base& context) |
| 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 |
|
| 104 |
virtual uint64_t get_public_connections_count() |
| 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 |
} |
| 112 |
virtual bool unblock_host(const epee::net_utils::network_address &address) |
| 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 |
} |
| 134 |
virtual void clear_used_stripe_peers() |
| 135 |
{ |
| 136 |
} |
| 137 |
}; |
| 138 |
} |