diff --git a/src/xrpld/app/misc/HashRouter.h b/src/xrpld/app/misc/HashRouter.h index 580f9bddc44..a73720c05b0 100644 --- a/src/xrpld/app/misc/HashRouter.h +++ b/src/xrpld/app/misc/HashRouter.h @@ -186,7 +186,7 @@ class HashRouter /** Add a suppression peer and get message's relay status. * Return pair: - * element 1: true if the peer is added. + * element 1: true if the key is added. * element 2: optional is seated to the relay time point or * is unseated if has not relayed yet. */ std::pair> diff --git a/src/xrpld/overlay/detail/PeerImp.cpp b/src/xrpld/overlay/detail/PeerImp.cpp index 0f853aac036..d771c77e702 100644 --- a/src/xrpld/overlay/detail/PeerImp.cpp +++ b/src/xrpld/overlay/detail/PeerImp.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -40,7 +41,6 @@ #include #include #include -// #include #include #include @@ -1620,6 +1620,12 @@ PeerImp::onMessage(std::shared_ptr const& m) "Invalid Ledger/TXset nodes " + std::to_string(m->nodes_size())); } + auto const messageHash = sha512Half(*m); + if (!app_.getHashRouter().addSuppressionPeer(messageHash, id_)) + { + return badData("Duplicate message: " + to_string(messageHash)); + } + // If there is a request cookie, attempt to relay the message if (m->has_requestcookie()) { @@ -1636,7 +1642,6 @@ PeerImp::onMessage(std::shared_ptr const& m) } uint256 const ledgerHash{m->ledgerhash()}; - // Otherwise check if received data for a candidate transaction set if (m->type() == protocol::liTS_CANDIDATE) { @@ -3057,7 +3062,8 @@ PeerImp::sendToMultiple( foundSelf = true; JLOG(p_journal_.debug()) << "sendToMultiple: Sending " << cookies.size() - << " TMLedgerData messages to peer[" << peer->id() << "]"; + << " TMLedgerData messages to peer[" << peer->id() + << "]: " << sha512Half(ledgerData); for (auto const& cookie : cookies) { // Unfortunately, need a separate Message object for every diff --git a/src/xrpld/overlay/detail/ProtocolMessage.h b/src/xrpld/overlay/detail/ProtocolMessage.h index 16672b190bc..2e9837ebacf 100644 --- a/src/xrpld/overlay/detail/ProtocolMessage.h +++ b/src/xrpld/overlay/detail/ProtocolMessage.h @@ -43,6 +43,12 @@ protocolMessageType(protocol::TMGetLedger const&) return protocol::mtGET_LEDGER; } +inline protocol::MessageType +protocolMessageType(protocol::TMLedgerData const&) +{ + return protocol::mtLEDGER_DATA; +} + inline protocol::MessageType protocolMessageType(protocol::TMReplayDeltaRequest const&) { @@ -519,6 +525,29 @@ hash_append(Hasher& h, TMGetLedger const& msg) hash_append(h, msg.querydepth()); } +template +void +hash_append(Hasher& h, TMLedgerData const& msg) +{ + using beast::hash_append; + using namespace ripple; + hash_append(h, safe_cast(protocolMessageType(msg))); + hash_append(h, msg.ledgerhash()); + hash_append(h, msg.ledgerseq()); + hash_append(h, safe_cast(msg.type())); + for (auto const& node : msg.nodes()) + { + hash_append(h, node.nodedata()); + if (node.has_nodeid()) + hash_append(h, node.nodeid()); + } + hash_append(h, msg.nodes_size()); + if (msg.has_requestcookie()) + hash_append(h, msg.requestcookie()); + if (msg.has_error()) + hash_append(h, safe_cast(msg.error())); +} + } // namespace protocol #endif