From a59c4263e754923ae41477799f841888da2f75db Mon Sep 17 00:00:00 2001 From: Josh Davis Date: Thu, 16 Oct 2008 20:56:28 +1100 Subject: [PATCH] AUTO_LT_SYNC --- libtorrent/include/libtorrent/stat.hpp | 14 ++++++++++++++ libtorrent/src/peer_connection.cpp | 17 +++++++++++------ libtorrent/src/piece_picker.cpp | 4 ---- libtorrent/src/policy.cpp | 10 ---------- libtorrent/src/storage.cpp | 7 +++++-- libtorrent/src/torrent.cpp | 1 + tord/tord.py | 11 +++++------ 7 files changed, 36 insertions(+), 28 deletions(-) diff --git a/libtorrent/include/libtorrent/stat.hpp b/libtorrent/include/libtorrent/stat.hpp index ef4fdd0..d99593a 100644 --- a/libtorrent/include/libtorrent/stat.hpp +++ b/libtorrent/include/libtorrent/stat.hpp @@ -87,6 +87,14 @@ namespace libtorrent size_type counter() const { return m_counter; } + void clear() + { + std::memset(m_rate_history, 0, sizeof(m_rate_history)); + m_counter = 0; + m_total_counter = 0; + m_rate_sum = 0; + } + private: #ifndef NDEBUG @@ -306,6 +314,12 @@ namespace libtorrent num_channels }; + void clear() + { + for (int i = 0; i < num_channels; ++i) + m_stat[i].clear(); + } + private: stat_channel m_stat[num_channels]; diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index 564d077..3f0e9ea 100644 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -282,9 +282,12 @@ namespace libtorrent TORRENT_ASSERT(p); peer_connection const& rhs = *p; + size_type c1; + size_type c2; + // first compare how many bytes they've sent us - size_type c1 = m_statistics.total_payload_download() - m_downloaded_at_last_unchoke; - size_type c2 = rhs.m_statistics.total_payload_download() - rhs.m_downloaded_at_last_unchoke; + c1 = m_statistics.total_payload_download() - m_downloaded_at_last_unchoke; + c2 = rhs.m_statistics.total_payload_download() - rhs.m_downloaded_at_last_unchoke; if (c1 > c2) return true; if (c1 < c2) return false; @@ -297,10 +300,12 @@ namespace libtorrent // in order to not switch back and forth too often, // unchoked peers must be at least one piece ahead // of a choked peer to be sorted at a lower unchoke-priority - boost::shared_ptr t = m_torrent.lock(); - TORRENT_ASSERT(t); - if (!is_choked()) c1 -= t->torrent_file().piece_length(); - if (!rhs.is_choked()) c2 -= t->torrent_file().piece_length(); + boost::shared_ptr t1 = m_torrent.lock(); + TORRENT_ASSERT(t1); + boost::shared_ptr t2 = rhs.associated_torrent().lock(); + TORRENT_ASSERT(t2); + if (!is_choked()) c1 -= t1->torrent_file().piece_length(); + if (!rhs.is_choked()) c2 -= t2->torrent_file().piece_length(); return c1 < c2; } diff --git a/libtorrent/src/piece_picker.cpp b/libtorrent/src/piece_picker.cpp index c1941a6..a16be12 100644 --- a/libtorrent/src/piece_picker.cpp +++ b/libtorrent/src/piece_picker.cpp @@ -996,10 +996,6 @@ namespace libtorrent #ifdef TORRENT_PICKER_LOG print_pieces(); #endif - -#ifndef NDEBUG - check_invariant(); -#endif } void piece_picker::we_dont_have(int index) diff --git a/libtorrent/src/policy.cpp b/libtorrent/src/policy.cpp index dd2edcc..0304fc6 100644 --- a/libtorrent/src/policy.cpp +++ b/libtorrent/src/policy.cpp @@ -931,16 +931,6 @@ namespace libtorrent c.add_free_upload(-diff); } } -/* - if (!c.is_choked()) - { - c.send_choke(); - --m_num_unchoked; - - if (m_torrent->is_seed()) seed_unchoke_one_peer(); - else unchoke_one_peer(); - } -*/ } /* bool policy::unchoke_one_peer() diff --git a/libtorrent/src/storage.cpp b/libtorrent/src/storage.cpp index 1588e2a..28464ed 100644 --- a/libtorrent/src/storage.cpp +++ b/libtorrent/src/storage.cpp @@ -396,8 +396,11 @@ namespace libtorrent + " bytes"; return false; } - if ((compact_mode && time != s->second) - || (!compact_mode && time < s->second)) + // allow one second 'slack', because of FAT volumes + // in sparse mode, allow the files to be more recent + // than the resume data, but only by 5 minutes + if ((compact_mode && (time > s->second + 1 || time < s->second - 1)) || + (!compact_mode && (time > s->second + 5 * 60) || time < s->second - 1)) { if (error) *error = "timestamp mismatch for file '" + i->path.native_file_string() diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index caadd15..6012362 100644 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -4112,6 +4112,7 @@ namespace libtorrent { // tell the tracker that we're back m_start_sent = false; + m_stat.clear(); announce_with_tracker(); } diff --git a/tord/tord.py b/tord/tord.py index 456b7f0..91402cf 100644 --- a/tord/tord.py +++ b/tord/tord.py @@ -239,12 +239,11 @@ class Torrent: self.fastresume_write() def generate_files(self): - #for id, f in enumerate(self.info.files()): - 1 - #self.files_id += [(self.hash, id)] - #self.files_path += [f.path] - #self.files_size += [f.size] - #self.files_offset += [f.offset] + for id, f in enumerate(self.info.files()): + self.files_id += [(self.hash, id)] + self.files_path += [f.path] + self.files_size += [f.size] + self.files_offset += [f.offset] def checked_cb(self): if self.handle.status().progress == 1: self.finished_cb() -- 2.11.4.GIT