diff --git a/nano/core_test/toml.cpp b/nano/core_test/toml.cpp index 0871684685..5b9c7f5896 100644 --- a/nano/core_test/toml.cpp +++ b/nano/core_test/toml.cpp @@ -408,7 +408,7 @@ TEST (toml, daemon_config_deserialize_no_defaults) peering_port = 999 pow_sleep_interval= 999 preconfigured_peers = ["dev.org"] - blocked_peers = ["192.168.0.1"] + blocked_peers = ["192.168.0.1", "2001:0db8:85a3:0000:0000:8a2e:0370:7334"] preconfigured_representatives = ["nano_3arg3asgtigae3xckabaaewkx3bzsh7nwz7jkmjos79ihyaxwphhm6qgjps4"] receive_minimum = "999" signature_checker_threads = 999 diff --git a/nano/node/network.cpp b/nano/node/network.cpp index 7e52649389..9f33370cc1 100644 --- a/nano/node/network.cpp +++ b/nano/node/network.cpp @@ -67,8 +67,6 @@ nano::network::~network () void nano::network::start () { - Configure_blocked_peers (); - if (!node.flags.disable_connection_cleanup) { ongoing_cleanup (); @@ -349,39 +347,6 @@ void nano::network::broadcast_confirm_req_many (std::deque const & channel) { - if (is_ip_blocked (channel->get_tcp_endpoint ().address ())) - { - node.logger.debug (nano::log::type::network, "Ignoring message from IP {}", channel->get_tcp_endpoint ().address ().to_string ()); - return; - } - node.stats.inc (nano::stat::type::message, to_stat_detail (message.header.type), nano::stat::dir::in); network_message_visitor visitor{ node, channel }; diff --git a/nano/node/network.hpp b/nano/node/network.hpp index 0069c3b9b9..f0785d9441 100644 --- a/nano/node/network.hpp +++ b/nano/node/network.hpp @@ -100,8 +100,6 @@ class network final void broadcast_confirm_req_base (std::shared_ptr const &, std::shared_ptr>> const &, unsigned, bool = false); void broadcast_confirm_req_batched_many (std::unordered_map, std::deque>>, std::function = nullptr, unsigned = broadcast_interval_ms, bool = false); void broadcast_confirm_req_many (std::deque, std::shared_ptr>>>>, std::function = nullptr, unsigned = broadcast_interval_ms); - void Configure_blocked_peers (); - bool is_ip_blocked (const boost::asio::ip::address & ip_address) const; std::shared_ptr find_node_id (nano::account const &); std::shared_ptr find_channel (nano::endpoint const &); bool not_a_peer (nano::endpoint const &, bool); @@ -135,7 +133,6 @@ class network final bool verify_handshake_response (nano::node_id_handshake::response_payload const & response, nano::endpoint const & remote_endpoint); std::optional prepare_handshake_query (nano::endpoint const & remote_endpoint); nano::node_id_handshake::response_payload prepare_handshake_response (nano::node_id_handshake::query_payload const & query, bool v2) const; - std::unordered_set blocked_ips; private: void process_message (nano::message const &, std::shared_ptr const &); diff --git a/nano/node/transport/tcp_server.cpp b/nano/node/transport/tcp_server.cpp index af163701a5..f2b9f1733a 100644 --- a/nano/node/transport/tcp_server.cpp +++ b/nano/node/transport/tcp_server.cpp @@ -44,6 +44,7 @@ nano::transport::tcp_listener::tcp_listener (uint16_t port_a, nano::node & node_ void nano::transport::tcp_listener::start (std::function const &, boost::system::error_code const &)> callback_a) { + configure_blocked_peers (); nano::lock_guard lock{ mutex }; on = true; acceptor.open (local.protocol ()); @@ -136,6 +137,13 @@ void nano::transport::tcp_listener::on_connection (std::functionevict_dead_connections (); + if (this_l->is_ip_blocked (new_connection->remote.address ())) + { + this_l->node.logger.info (nano::log::type::tcp_listener, "Connection refused from blocked IP: {}", new_connection->remote_endpoint ().address ().to_string ()); + this_l->on_connection (std::move (cbk)); + return; + } + if (this_l->connections_per_address.size () >= this_l->max_inbound_connections) { this_l->node.stats.inc (nano::stat::type::tcp, nano::stat::detail::tcp_accept_failure, nano::stat::dir::in); @@ -217,6 +225,44 @@ void nano::transport::tcp_listener::on_connection (std::function #include +#include namespace nano { @@ -35,6 +36,7 @@ class tcp_listener final : public std::enable_shared_from_this bootstrap_count{ 0 }; std::atomic realtime_count{ 0 }; + std::unordered_set blocked_ips; private: boost::asio::strand strand; @@ -48,6 +50,8 @@ class tcp_listener final : public std::enable_shared_from_this const & new_connection); bool limit_reached_for_incoming_subnetwork_connections (std::shared_ptr const & new_connection); + void configure_blocked_peers (); + bool is_ip_blocked (const boost::asio::ip::address & ip_address) const; }; std::unique_ptr collect_container_info (tcp_listener & bootstrap_listener, std::string const & name);