From 4cea2b13b221bed66023254dd3356f2548a08df4 Mon Sep 17 00:00:00 2001 From: Javier Smooth Date: Mon, 23 Nov 2015 17:34:55 +0000 Subject: Add IP blocking for misbehaving nodes (adapted from Boolberry) With minor cleanup and fixes (spelling, indent) by moneromooo --- src/p2p/net_node.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/p2p/net_node.h') diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index 3eb125208..4aaac813e 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -42,6 +42,7 @@ #include #include #include +#include #include "cryptonote_config.h" #include "warnings.h" @@ -66,7 +67,8 @@ namespace nodetool template class node_server: public epee::levin::levin_commands_handler >, - public i_p2p_endpoint + public i_p2p_endpoint, + public epee::net_utils::i_connection_filter { struct by_conn_id{}; struct by_peer_id{}; @@ -169,6 +171,10 @@ namespace nodetool virtual bool drop_connection(const epee::net_utils::connection_context_base& context); virtual void request_callback(const epee::net_utils::connection_context_base& context); virtual void for_each_connection(std::function f); + virtual bool block_ip(uint32_t adress); + virtual bool add_ip_fail(uint32_t address); + //----------------- i_connection_filter -------------------------------------------------------- + virtual bool is_remote_ip_allowed(uint32_t adress); //----------------------------------------------------------------------------------------------- bool parse_peer_from_string(nodetool::net_address& pe, const std::string& node_addr); bool handle_command_line( @@ -196,6 +202,8 @@ namespace nodetool template bool try_ping(basic_node_data& node_data, p2p_connection_context& context, t_callback cb); bool make_expected_connections_count(bool white_list, size_t expected_connections); + void cache_connect_fail_info(const net_address& addr); + bool is_addr_recently_failed(const net_address& addr); bool is_priority_node(const net_address& na); template @@ -282,6 +290,15 @@ namespace nodetool //keep connections to initiate some interactions net_server m_net_server; boost::uuids::uuid m_network_id; + + std::map m_conn_fails_cache; + epee::critical_section m_conn_fails_cache_lock; + + epee::critical_section m_blocked_ips_lock; + std::map m_blocked_ips; + + epee::critical_section m_ip_fails_score_lock; + std::map m_ip_fails_score; }; } -- cgit v1.2.3