From 243353a14482b37dc84bd1abfff40049f5d18b18 Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sat, 12 May 2018 19:12:51 -0700 Subject: [PATCH] account for partially downloaded pieces when announcing as a seed --- ChangeLog | 1 + src/torrent.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6a522a5e6..6b5bdd743 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ * fix backwards compatibility to downloads without partfiles * improve part-file related error messages * fix reporting &redundant= in tracker announces + * fix tracker announces reporting more data downloaded than the size of the torrent * fix tie-break in duplicate peer connection disconnect logic * fix issue with SSL tracker connections left in CLOSE_WAIT state * defer truncating existing files until the first time we write to them diff --git a/src/torrent.cpp b/src/torrent.cpp index 075bbeb52..fee1f047b 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3223,10 +3223,34 @@ namespace { req.ssl_ctx = m_ssl_ctx.get(); #endif + req.redundant = m_total_redundant_bytes; // exclude redundant bytes if we should if (!settings().get_bool(settings_pack::report_true_downloaded)) + { req.downloaded -= m_total_redundant_bytes; - req.redundant = m_total_redundant_bytes; + + // if the torrent is complete we know that all incoming pieces will be + // marked redundant so add them to the redundant count + // this is mainly needed to cover the case where a torrent has just completed + // but still has partially downloaded pieces + // if the incoming pieces are not accounted for it could cause the downloaded + // amount to exceed the total size of the torrent which upsets some trackers + if (is_seed()) + { + for (peer_iterator i = m_connections.begin(); + i != m_connections.end(); ++i) + { + TORRENT_INCREMENT(m_iterating_connections); + peer_connection* p = *i; + boost::optional pbp = p->downloading_piece_progress(); + if (pbp && pbp->bytes_downloaded > 0) + { + req.downloaded -= pbp->bytes_downloaded; + req.redundant += pbp->bytes_downloaded; + } + } + } + } if (req.downloaded < 0) req.downloaded = 0; req.event = e;