mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-07 02:36:47 +00:00
Limit number of requested nodes to handle
This commit is contained in:
@@ -1494,7 +1494,8 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMGetLedger> const& m)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify ledger node IDs. Full parsing is deferred to the job.
|
||||
// Verify ledger node counts. Full parsing of the node IDs is deferred to the job, so the I/O
|
||||
// thread is not burdened with SHAMapNodeID deserialization for every TMGetLedger message.
|
||||
if (itype != protocol::liBASE && m->nodeids_size() <= 0)
|
||||
{
|
||||
badData("Invalid ledger node IDs");
|
||||
@@ -1518,9 +1519,7 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMGetLedger> const& m)
|
||||
}
|
||||
}
|
||||
|
||||
// Queue a job to process the request. Full parsing of the node IDs is
|
||||
// performed inside the job so the I/O thread is not burdened with
|
||||
// SHAMapNodeID deserialization for every TMGetLedger message.
|
||||
// Queue a job to process the request.
|
||||
std::weak_ptr<PeerImp> const weak = shared_from_this();
|
||||
app_.getJobQueue().addJob(JtLedgerReq, "RcvGetLedger", [weak, m, itype]() {
|
||||
auto peer = weak.lock();
|
||||
@@ -1530,16 +1529,22 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMGetLedger> const& m)
|
||||
std::vector<SHAMapNodeID> nodeIDs;
|
||||
if (itype != protocol::liBASE)
|
||||
{
|
||||
nodeIDs.reserve(m->nodeids_size());
|
||||
nodeIDs.reserve(std::min(m->nodeids_size(), Tuning::kSoftMaxReplyNodes));
|
||||
for (auto const& nodeId : m->nodeids())
|
||||
{
|
||||
if (nodeIDs.size() >= Tuning::kSoftMaxReplyNodes)
|
||||
{
|
||||
// Charge the peer for sending too many node IDs, but continue processing the
|
||||
// received node IDs. If the request is legitimate then at least they will get
|
||||
// a response and won't have to resend the request.
|
||||
peer->charge(
|
||||
Resource::kFeeModerateBurdenPeer, "TMGetLedger: too many node IDs");
|
||||
break;
|
||||
}
|
||||
auto parsed = deserializeSHAMapNodeID(nodeId);
|
||||
if (!parsed)
|
||||
{
|
||||
JLOG(peer->pJournal_.warn()) << "TMGetLedger: Invalid node ID";
|
||||
post(peer->strand_, [peer]() {
|
||||
peer->charge(Resource::kFeeInvalidData, "TMGetLedger: Invalid node ID");
|
||||
});
|
||||
peer->charge(Resource::kFeeInvalidData, "TMGetLedger: Invalid node ID");
|
||||
return;
|
||||
}
|
||||
nodeIDs.push_back(std::move(*parsed));
|
||||
|
||||
Reference in New Issue
Block a user