check incoming requests queue size and reject or choke if exceeds

This commit is contained in:
orignal committed 2026-09-07 18:41:59 -04:00
1 parent c89880c517
commit 123f5c75ce
2 files changed
+8 -6

No files matched your search

+7 -5
View File
@@ -1579,13 +1579,16 @@ namespace torrents
{
if (m_NumPieces >= MAX_NUM_PIECES)
{
m_IncomingRequestsQueue.emplace_back (index, offset, length);
if (!m_IsRemoteChoked && m_IncomingRequestsQueue.size () > 5*MAX_NUM_PIECES)
{
if (m_IncomingRequestsQueue.size () < MAX_INCOMING_REQUESTS_QUEUE_SIZE)
m_IncomingRequestsQueue.emplace_back (index, offset, length);
else if (m_IsFast)
SendRejectRequestMsg (index, offset, length);
else if (!m_IsRemoteChoked)
{
LogPrint (eLogDebug, "Torrents: Choke");
m_IsRemoteChoked = true;
SendChokeMsg ();
}
}
}
else if (!SendRequestedBlock ({index, offset, length})) // block was not sent
{
@@ -1760,7 +1763,6 @@ namespace torrents
{
auto [q, l] = ExtractInteger (buf);
if (l) m_MaxNumRequests = std::clamp ((size_t)q, MIN_NUM_REQUESTS, MAX_NUM_REQUESTS);
LogPrint (eLogDebug, "Torrents: max num requests ", m_MaxNumRequests);
return l;
}
else if (key == "v")
+1 -1
View File
@@ -44,7 +44,7 @@ namespace torrents
constexpr size_t MAX_NUM_REQUESTS = 24;
constexpr size_t MAX_NUM_PIECES = 6;
constexpr size_t MAX_INCOMING_REQUESTS_QUEUE_SIZE = 32;
constexpr int PIECE_INACTIVITY_TIMEOUT = 60; // in seconds
constexpr int PIECE_INACTIVITY_TIMEOUT = 35; // in seconds
constexpr int HANDSHAKE_RECEIVE_TIMEOUT = 20; // in seconds
constexpr int BANDWIDTH_RATE_SAMPLING_INTERVAL = 20; // in milliseconds