From 446b3c865bbc43169aaa37fad230e4cbb700aaed Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 4 Dec 2020 13:59:51 +0000 Subject: [PATCH] p2p: drop peers that spam peer lists There's always some people who just want to abuse things --- src/cryptonote_config.h | 1 + src/p2p/net_node.inl | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 826cabe17..13f0c471b 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -132,6 +132,7 @@ #define P2P_DEFAULT_HANDSHAKE_INTERVAL 60 //secondes #define P2P_DEFAULT_PACKET_MAX_SIZE 50000000 //50000000 bytes maximum packet size #define P2P_DEFAULT_PEERS_IN_HANDSHAKE 250 +#define P2P_MAX_PEERS_IN_HANDSHAKE 250 #define P2P_DEFAULT_CONNECTION_TIMEOUT 5000 //5 seconds #define P2P_DEFAULT_SOCKS_CONNECT_TIMEOUT 45 // seconds #define P2P_DEFAULT_PING_CONNECTION_TIMEOUT 2000 //2 seconds diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index c71dfc2de..7dcc9d0bd 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -2060,6 +2060,11 @@ namespace nodetool template bool node_server::handle_remote_peerlist(const std::vector& peerlist, const epee::net_utils::connection_context_base& context) { + if (peerlist.size() > P2P_MAX_PEERS_IN_HANDSHAKE) + { + MWARNING(context << "peer sent " << peerlist.size() << " peers, considered spamming"); + return false; + } std::vector peerlist_ = peerlist; if(!sanitize_peerlist(peerlist_)) return false;