don't connect to peers for complete torrent

This commit is contained in:
orignal
2026-10-02 11:26:25 -04:00
parent caceb9d275
commit 2d57d3f678
3 changed files with 14 additions and 10 deletions
+1
View File
@@ -2311,6 +2311,7 @@ namespace torrents
void PeerConnection::HandleI2PPEXExtension (const uint8_t * buf, size_t len)
{
if (m_Torrent->IsComplete ()) return;
std::unordered_set<i2p::data::IdentHash> newPeers;
ParseDictionary (std::string_view ((const char *)buf, len),
[&newPeers](std::string_view key, std::string_view buf)->size_t
+10 -7
View File
@@ -857,14 +857,17 @@ namespace torrents
auto torrent = info ? info->torrent.lock () : nullptr;
if (torrent)
{
std::unordered_set<i2p::data::IdentHash> newPeers;
for (auto it: peers)
if (it.size () == i2p::data::IdentHash::len)
newPeers.emplace ((const uint8_t *)it.data ());
if (!newPeers.empty ())
if (!torrent->IsComplete ())
{
LogPrint (eLogDebug, "TorrentsDHT: ", newPeers.size (), " new peers received");
m_Tunnel.ConnectToNewPeers (torrent, newPeers, ePeerConnectionOriginDHT);
std::unordered_set<i2p::data::IdentHash> newPeers;
for (auto it: peers)
if (it.size () == i2p::data::IdentHash::len)
newPeers.emplace ((const uint8_t *)it.data ());
if (!newPeers.empty ())
{
LogPrint (eLogDebug, "TorrentsDHT: ", newPeers.size (), " new peers received");
m_Tunnel.ConnectToNewPeers (torrent, newPeers, ePeerConnectionOriginDHT);
}
}
LogPrint (eLogDebug, "TorrentsDHT: Send announce to ", toIdent.ToBase64 ());
SendAnnouncePeerQuery (torrent->GetInfoHash (), token, toIdent, toPort);
+3 -3
View File
@@ -706,7 +706,7 @@ namespace torrents
size_t TorrentsTunnel::ConnectToPeers (std::shared_ptr<Torrent> torrent)
{
if (!torrent) return 0;
if (!torrent || torrent->IsComplete ()) return 0;
auto peersToConnect = torrent->GetNonConnectedPeers (); // from trackers
if (!peersToConnect.empty ())
{
@@ -718,7 +718,7 @@ namespace torrents
size_t TorrentsTunnel::ConnectToPeers (std::shared_ptr<Torrent> torrent, size_t trackerID)
{
if (!torrent) return 0;
if (!torrent || torrent->IsComplete ()) return 0;
auto peersToConnect = torrent->GetNonConnectedPeers (trackerID);
if (!peersToConnect.empty ())
{
@@ -731,7 +731,7 @@ namespace torrents
void TorrentsTunnel::ConnectToNewPeers (std::shared_ptr<Torrent> torrent,
std::unordered_set<i2p::data::IdentHash>& newPeers, PeerConnectionOrigin origin)
{
if (!torrent) return;
if (!torrent || torrent->IsComplete ()) return;
if (!newPeers.empty ())
{
for (const auto& it: newPeers)