From 952f5aad9efe09cf1ad6b69749ef2c2a0c462c7f Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 14 Sep 2026 10:11:42 -0400 Subject: [PATCH] open seeded file in read-only mode --- libi2pd_client/Torrents.cpp | 9 +++++++-- libi2pd_client/TorrentsTunnel.cpp | 14 ++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/libi2pd_client/Torrents.cpp b/libi2pd_client/Torrents.cpp index ca7146c5..642a8e25 100644 --- a/libi2pd_client/Torrents.cpp +++ b/libi2pd_client/Torrents.cpp @@ -207,9 +207,14 @@ namespace torrents { if (!f.is_open ()) { + auto mode = std::ios::binary | std::ios::in; auto filePath = fullFilePath; - if (isPart) filePath += ".part"; - f.open (filePath, std::ios::binary | std::ios::in | std::ios::out); + if (isPart) + { + filePath += ".part"; + mode |= std::ios::out; + } + f.open (filePath, mode); } auto ts = i2p::util::GetMonotonicSeconds (); if (ts > lastFlushTime + TORRENT_FILE_FLUSH_INTERVAL) diff --git a/libi2pd_client/TorrentsTunnel.cpp b/libi2pd_client/TorrentsTunnel.cpp index 89e6ac71..0695f442 100644 --- a/libi2pd_client/TorrentsTunnel.cpp +++ b/libi2pd_client/TorrentsTunnel.cpp @@ -806,7 +806,6 @@ namespace torrents { auto ts = i2p::util::GetMonotonicSeconds (); for (auto it: m_Torrents) - { if (ts > it.second->GetNextUpdateStatusTime ()) { if (!it.second->IsStopped () && (it.second->IsActive () || !it.second->IsComplete ())) @@ -819,15 +818,14 @@ namespace torrents else UpdatePeersPerPiece (it.second); } + boost::asio::post (GetDiskIOService (), [torrent = it.second, ts]() + { + for (auto it: torrent->GetFiles ()) + if (ts > it->lastAccessTime + TORRENT_FILE_INACTIVITY_TIMEOUT) + it->Close (); + }); it.second->SetNextUpdateStatusTime (ts + TORRENTS_STATUS_UPDATE_INTERVAL + GetLocalDestination ()->GetRng ()() % TORRENTS_STATUS_UPDATE_INTERVAL_VARIANCE); } - boost::asio::post (GetDiskIOService (), [torrent = it.second, ts]() - { - for (auto it: torrent->GetFiles ()) - if (ts > it->lastAccessTime + TORRENT_FILE_INACTIVITY_TIMEOUT) - it->Close (); - }); - } ScheduleStatusUpdate (); } }