mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Added duplicate check for self npl messages.
This commit is contained in:
@@ -12,6 +12,9 @@ namespace conf
|
||||
{
|
||||
constexpr size_t CONCURRENT_READ_REQUEST_MAX_LIMIT = 32;
|
||||
|
||||
// Max size of messages which are subjected to duplicate message check.
|
||||
constexpr size_t MAX_SIZE_FOR_DUP_CHECK = 1 * 1024 * 1024; // 1 MB
|
||||
|
||||
#define CURRENT_TIME_CONFIG ((conf::cfg.contract.consensus.roundtime * 100) + conf::cfg.contract.consensus.stage_slice)
|
||||
|
||||
// Struct to represent ip and port of the peer.
|
||||
|
||||
@@ -13,9 +13,6 @@ namespace p2pmsg = msg::fbuf::p2pmsg;
|
||||
|
||||
namespace p2p
|
||||
{
|
||||
// Max size of messages which are subjected to duplicate message check.
|
||||
constexpr size_t MAX_SIZE_FOR_DUP_CHECK = 1 * 1024 * 1024; // 1 MB
|
||||
|
||||
// The set of recent peer message hashes used for duplicate detection.
|
||||
util::rollover_hashset recent_peermsg_hashes(200);
|
||||
|
||||
@@ -80,7 +77,7 @@ namespace p2p
|
||||
|
||||
// Messages larger than the duplicate message threshold is ignored from the duplicate message check
|
||||
// due to the overhead in hash generation for larger messages.
|
||||
if (message_size <= MAX_SIZE_FOR_DUP_CHECK && !recent_peermsg_hashes.try_emplace(crypto::get_hash(msg)))
|
||||
if (message_size <= conf::MAX_SIZE_FOR_DUP_CHECK && !recent_peermsg_hashes.try_emplace(crypto::get_hash(msg)))
|
||||
{
|
||||
increment_metric(comm::SESSION_THRESHOLDS::MAX_DUPMSGS_PER_MINUTE, 1);
|
||||
LOG_DEBUG << "Duplicate peer message. type:" << mi.type << " from:" << display_name();
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "../msg/fbuf/p2pmsg_generated.h"
|
||||
#include "../msg/fbuf/p2pmsg_conversion.hpp"
|
||||
#include "../msg/fbuf/common_helpers.hpp"
|
||||
#include "../util/rollover_hashset.hpp"
|
||||
#include "../crypto.hpp"
|
||||
|
||||
namespace p2pmsg = msg::fbuf::p2pmsg;
|
||||
|
||||
@@ -14,6 +16,9 @@ namespace p2p::self
|
||||
|
||||
std::optional<conf::peer_ip_port> ip_port;
|
||||
|
||||
// The set of recent self message hashes used for duplicate detection.
|
||||
util::rollover_hashset recent_selfmsg_hashes(200);
|
||||
|
||||
/**
|
||||
* Processes the next queued message (if any).
|
||||
* @return 0 if no messages in queue. 1 if message was processed successfully. -1 on error.
|
||||
@@ -27,11 +32,27 @@ namespace p2p::self
|
||||
const peer_message_info mi = p2pmsg::get_peer_message_info(msg);
|
||||
|
||||
if (mi.type == p2pmsg::P2PMsgContent_ProposalMsg)
|
||||
{
|
||||
handle_proposal_message(p2pmsg::create_proposal_from_msg(mi, hash_proposal_msg(*mi.p2p_msg->content_as_ProposalMsg())));
|
||||
}
|
||||
else if (mi.type == p2pmsg::P2PMsgContent_NonUnlProposalMsg)
|
||||
{
|
||||
handle_nonunl_proposal_message(p2pmsg::create_nonunl_proposal_from_msg(mi));
|
||||
}
|
||||
else if (mi.type == p2pmsg::P2PMsgContent_NplMsg)
|
||||
{
|
||||
// For self messages, we perform duplicate checks for NPL messages.
|
||||
|
||||
// Messages larger than the duplicate message threshold is ignored from the duplicate message check
|
||||
// due to the overhead in hash generation for larger messages.
|
||||
if (msg.size() <= conf::MAX_SIZE_FOR_DUP_CHECK && !recent_selfmsg_hashes.try_emplace(crypto::get_hash(msg)))
|
||||
{
|
||||
LOG_DEBUG << "Duplicate self npl message.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
handle_npl_message(p2pmsg::create_npl_from_msg(mi));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user