diff -U2 -r /var/lib/copr-rpmbuild/results/i2pd-git/upstream-unpacked/Source0/i2pd-openssl/libi2pd_client/Torrents.cpp /var/lib/copr-rpmbuild/results/i2pd-git/srpm-unpacked/i2pd-openssl.tar.gz-extract/i2pd-openssl/libi2pd_client/Torrents.cpp --- /var/lib/copr-rpmbuild/results/i2pd-git/upstream-unpacked/Source0/i2pd-openssl/libi2pd_client/Torrents.cpp 2026-08-11 00:28:57.000000000 +0000 +++ /var/lib/copr-rpmbuild/results/i2pd-git/srpm-unpacked/i2pd-openssl.tar.gz-extract/i2pd-openssl/libi2pd_client/Torrents.cpp 2026-08-11 00:26:12.000000000 +0000 @@ -206,15 +206,15 @@ } - void Piece::Dump (PieceFileFragment&& fragment) + void Piece::Dump (const std::string& fullPath, size_t offset) { m_IsSending = true; - if (m_Data && fragment.fragmentOffset + fragment.fragmentSize <= m_Size) + if (m_Data) { - std::fstream f(fragment.fullFilePath, std::ios::binary | std::ios::in | std::ios::out ); + std::fstream f(fullPath, std::ios::binary | std::ios::in | std::ios::out ); if (f) { - f.seekp (fragment.fileOffset, std::ios::beg); - f.write ((const char *)m_Data + fragment.fragmentOffset, fragment.fragmentSize); - LogPrint (eLogDebug, "Torrents: Saved bytes ", fragment.fileOffset, " - ", fragment.fileOffset + fragment.fragmentSize - 1, " to ", fragment.fullFilePath); + f.seekp (offset, std::ios::beg); + f.write ((const char *)m_Data, m_Size); + LogPrint (eLogDebug, "Torrents: Saved bytes ", offset, " - ", offset + m_Size - 1, " to ", fullPath); } } @@ -222,14 +222,14 @@ } - bool Piece::Load (PieceFileFragment&& fragment) + bool Piece::Load (const std::string& fullPath, size_t offset) { - if (fragment.fragmentOffset + fragment.fragmentSize > m_Size) return false; - std::ifstream f(fragment.fullFilePath, std::ifstream::binary); + if (m_Data) return true; + std::ifstream f(fullPath, std::ifstream::binary); if (f) { - if (!m_Data) m_Data = new uint8_t[m_Size]; - f.seekg (fragment.fileOffset, std::ios::beg); - f.read ((char *)m_Data + fragment.fragmentOffset, fragment.fragmentSize); - LogPrint (eLogDebug, "Torrents: Loaded bytes ", fragment.fileOffset, " - ", fragment.fileOffset + fragment.fragmentSize - 1, " from ", fragment.fullFilePath); + m_Data = new uint8_t[m_Size]; + f.seekg (offset, std::ios::beg); + f.read ((char *)m_Data, m_Size); + LogPrint (eLogDebug, "Torrents: Loaded bytes ", offset, " - ", offset + m_Size - 1, " from ", fullPath); } else @@ -988,11 +988,11 @@ if (piece.VerifyHash ()) { - PieceFileFragment fragment{ GetTorrentsTunnel ()->GetTorrentFilePath (m_Torrent->GetName () + ".part"), - index*m_Torrent->GetPieceLength (), 0, piece.GetSize () }; + auto path = GetTorrentsTunnel ()->GetTorrentFilePath (m_Torrent->GetName () + ".part"); auto resumePath = GetTorrentsTunnel ()->GetTorrentFilePath (m_Torrent->GetName () + ".resume"); + auto offset = index*m_Torrent->GetPieceLength (); boost::asio::post (GetTorrentsTunnel ()->GetDiskIOService (), - [&piece, fragment = std::move (fragment), resumePath, torrent = m_Torrent]() mutable // piece belongs to torrent + [&piece, path, resumePath, offset, torrent = m_Torrent]() // piece belongs to torrent { - piece.Dump (std::move (fragment)); + piece.Dump (path, offset); torrent->SaveTorrentResumeFile (resumePath); }); @@ -1068,26 +1068,19 @@ { // try to load from file - PieceFileFragment fragment{ GetTorrentsTunnel ()->GetTorrentFilePath ( - m_Torrent->GetName () + (m_Torrent->IsComplete () ? "" : ".part")), - index*m_Torrent->GetPieceLength (), 0, piece.GetSize () }; - RequestedBlock requestBlock{index, offset, length}; + auto path = GetTorrentsTunnel ()->GetTorrentFilePath (m_Torrent->GetName () + (m_Torrent->IsComplete () ? "" : ".part")); boost::asio::post (GetTorrentsTunnel ()->GetDiskIOService (), - [&piece, fragment = std::move (fragment), requestBlock = std::move(requestBlock), - torrent = m_Torrent, s = shared_from_this ()]() mutable// piece belongs to torrent + [&piece, path, index, offset, length, torrent = m_Torrent, s = shared_from_this ()]() // piece belongs to torrent { piece.SetIsSending (true); - if (piece.Load (std::move (fragment))) + if (piece.Load (path, index*torrent->GetPieceLength ())) { - if (piece.VerifyHash ()) - boost::asio::post (s->GetTorrentsTunnel ()->GetService (), - [requestedBlock = std::move (requestBlock), s]() - { - if (s->m_NumPieces < MAX_NUM_PIECES) - s->SendRequestedBlock (requestedBlock); - else - s->m_IncomingRequestsQueue.emplace_back (std::move (requestedBlock)); - }); - else - LogPrint (eLogError, "Torrent: Corrupted piece ", requestBlock.index, " from ", fragment.fullFilePath); + boost::asio::post (s->GetTorrentsTunnel ()->GetService (), + [requestedBlock = RequestedBlock{index, offset, length}, s]() + { + if (s->m_NumPieces < MAX_NUM_PIECES) + s->SendRequestedBlock (requestedBlock); + else + s->m_IncomingRequestsQueue.emplace_back (std::move (requestedBlock)); + }); } piece.SetIsSending (false); diff -U2 -r /var/lib/copr-rpmbuild/results/i2pd-git/upstream-unpacked/Source0/i2pd-openssl/libi2pd_client/Torrents.h /var/lib/copr-rpmbuild/results/i2pd-git/srpm-unpacked/i2pd-openssl.tar.gz-extract/i2pd-openssl/libi2pd_client/Torrents.h --- /var/lib/copr-rpmbuild/results/i2pd-git/upstream-unpacked/Source0/i2pd-openssl/libi2pd_client/Torrents.h 2026-08-11 00:28:57.000000000 +0000 +++ /var/lib/copr-rpmbuild/results/i2pd-git/srpm-unpacked/i2pd-openssl.tar.gz-extract/i2pd-openssl/libi2pd_client/Torrents.h 2026-08-11 00:26:12.000000000 +0000 @@ -74,12 +74,4 @@ }; - struct PieceFileFragment // fragment to save to/load from file - { - std::string fullFilePath; - size_t fileOffset = 0; - size_t fragmentOffset = 0; // from start of piece - size_t fragmentSize = 0; - }; - class PeerConnection; class Piece final @@ -108,6 +100,6 @@ void BlockReceived (const uint8_t * block, size_t len, size_t offset); - void Dump (PieceFileFragment&& fragment); - bool Load (PieceFileFragment&& fragment); + void Dump (const std::string& fullPath, size_t offset); + bool Load (const std::string& fullPath, size_t offset); const uint8_t * GetData () const { return m_Data; } size_t GetSize () const { return m_Size; }