handle allowed fast msg

This commit is contained in:
orignal
2026-09-05 21:18:56 -04:00
parent a63b7b1030
commit 0bbfc816a8
2 changed files with 19 additions and 1 deletions
+18 -1
View File
@@ -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;
+1
View File
@@ -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);