From 0bbfc816a8ec4988bdd7734a59a9219fde1d4e52 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 5 Sep 2026 21:18:56 -0400 Subject: [PATCH] handle allowed fast msg --- libi2pd_client/Torrents.cpp | 19 ++++++++++++++++++- libi2pd_client/Torrents.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libi2pd_client/Torrents.cpp b/libi2pd_client/Torrents.cpp index d9cffa06..07776fc6 100644 --- a/libi2pd_client/Torrents.cpp +++ b/libi2pd_client/Torrents.cpp @@ -1192,7 +1192,7 @@ namespace torrents HandleRejectRequestMsg (m_ReceiveBuffer + offset + 1, msgLen - 1); break; case eMessageTypeAllowedFast: - LogPrint (eLogDebug, "Torrents: allowed fast msg received"); + HandleAllowedFastMsg (m_ReceiveBuffer + offset + 1, msgLen - 1); break; default: LogPrint (eLogWarning, "Torrents: Unexpected message type ", (int)m_ReceiveBuffer[offset], ". Ignored"); @@ -1705,6 +1705,23 @@ namespace torrents m_SuggestedPieceIndex = index; } + void PeerConnection::HandleAllowedFastMsg (const uint8_t * buf, size_t len) + { + if (len < 4 || !m_Torrent) return; + uint32_t index = bufbe32toh (buf); + LogPrint (eLogDebug, "Torrents: allowed fast msg received"); + if (m_IsChoked && index < m_Torrent->GetNumPieces ()) + { + Piece& piece = m_Torrent->GetPiece (index); + if (!piece.IsComplete () && !piece.IsRequested ()) + { + uint32_t offset = 0, len = 0; + while (std::tie (offset, len) = piece.GetNextBlockToRequest (), len > 0) + SendRequestedBlock ({index, offset, len}); + } + } + } + void PeerConnection::HandleExtendedMsg (const uint8_t * buf, size_t len) { if (len < 1) return; diff --git a/libi2pd_client/Torrents.h b/libi2pd_client/Torrents.h index 602c73e3..49d5559d 100644 --- a/libi2pd_client/Torrents.h +++ b/libi2pd_client/Torrents.h @@ -341,6 +341,7 @@ namespace torrents void SendChokeMsg (); void HandleChokeMsg (); void HandleSuggestPieceMsg (const uint8_t * buf, size_t len); + void HandleAllowedFastMsg (const uint8_t * buf, size_t len); void HandleExtendedMsg (const uint8_t * buf, size_t len); void SendExtendedMsg (uint8_t extendedMsgID = 0, std::string_view payload = "", std::string_view data = ""); void AddExtendedMsgHandler (std::string_view extensionName, int64_t msgID);