From 9f5fa96cad6ef7bc4891f1164257dc5e13aed354 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 7 Jun 2008 14:03:21 +0000 Subject: [PATCH] fixed bug related to m_have_piece optimization. Renamed num_pieces() to num_have() to avoid confusion --- include/libtorrent/torrent.hpp | 2 +- src/bt_peer_connection.cpp | 8 ++++---- src/policy.cpp | 6 +++--- src/torrent.cpp | 24 ++++++++++++------------ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 20946c884..da33b7ecd 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -381,7 +381,7 @@ namespace libtorrent return has_picker()?m_picker->have_piece(index):true; } - int num_pieces() const + int num_have() const { return has_picker() ?m_picker->num_have() diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index b81daf9f4..307bcd4d2 100755 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -1426,7 +1426,7 @@ namespace libtorrent TORRENT_ASSERT(t->valid_metadata()); // in this case, have_all or have_none should be sent instead - TORRENT_ASSERT(!m_supports_fast || !t->is_seed() || t->num_pieces() != 0); + TORRENT_ASSERT(!m_supports_fast || !t->is_seed() || t->num_have() != 0); if (m_supports_fast && t->is_seed()) { @@ -1434,13 +1434,13 @@ namespace libtorrent send_allowed_set(); return; } - else if (m_supports_fast && t->num_pieces() == 0) + else if (m_supports_fast && t->num_have() == 0) { write_have_none(); send_allowed_set(); return; } - else if (t->num_pieces() == 0) + else if (t->num_have() == 0) { // don't send a bitfield if we don't have any pieces #ifndef NDEBUG @@ -1449,7 +1449,7 @@ namespace libtorrent return; } - int num_pieces = t->picker().num_pieces(); + int num_pieces = t->torrent_file().num_pieces(); int lazy_pieces[50]; int num_lazy_pieces = 0; int lazy_piece = 0; diff --git a/src/policy.cpp b/src/policy.cpp index 8c01d09ec..f38a94bbb 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -200,7 +200,7 @@ namespace libtorrent int prefer_whole_pieces = c.prefer_whole_pieces(); - bool rarest_first = t.num_pieces() >= t.settings().initial_picker_threshold; + bool rarest_first = t.num_have() >= t.settings().initial_picker_threshold; if (prefer_whole_pieces == 0) { @@ -644,7 +644,7 @@ namespace libtorrent error_code ec; TORRENT_ASSERT(c.remote() == c.get_socket()->remote_endpoint(ec) || ec); - if (m_peers.size() >= m_torrent->settings().max_peerlist_size) + if (int(m_peers.size()) >= m_torrent->settings().max_peerlist_size) { c.disconnect("peer list size exceeded, refusing incoming connection"); return false; @@ -773,7 +773,7 @@ namespace libtorrent return 0; } - if (m_peers.size() >= m_torrent->settings().max_peerlist_size) + if (int(m_peers.size()) >= m_torrent->settings().max_peerlist_size) return 0; // we don't have any info about this peer. diff --git a/src/torrent.cpp b/src/torrent.cpp index b41edd2e7..8344a1fec 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -959,7 +959,7 @@ namespace libtorrent const int last_piece = m_torrent_file->num_pieces() - 1; size_type total_done - = size_type(num_pieces()) * m_torrent_file->piece_length(); + = size_type(num_have()) * m_torrent_file->piece_length(); // if we have the last piece, we have to correct // the amount we have, since the first calculation @@ -990,14 +990,14 @@ namespace libtorrent return make_tuple(m_torrent_file->total_size() , m_torrent_file->total_size()); - TORRENT_ASSERT(num_pieces() >= m_picker->num_have_filtered()); - size_type wanted_done = size_type(num_pieces() - m_picker->num_have_filtered()) + TORRENT_ASSERT(num_have() >= m_picker->num_have_filtered()); + size_type wanted_done = size_type(num_have() - m_picker->num_have_filtered()) * piece_size; TORRENT_ASSERT(wanted_done >= 0); size_type total_done - = size_type(num_pieces()) * piece_size; - TORRENT_ASSERT(num_pieces() < m_torrent_file->num_pieces()); + = size_type(num_have()) * piece_size; + TORRENT_ASSERT(num_have() < m_torrent_file->num_pieces()); // if we have the last piece, we have to correct // the amount we have, since the first calculation @@ -1122,7 +1122,7 @@ namespace libtorrent { // Thist happens when a piece has been downloaded completely // but not yet verified against the hash - std::cerr << "num_pieces: " << num_pieces() << std::endl; + std::cerr << "num_have: " << num_have() << std::endl; std::cerr << "unfinished:" << std::endl; @@ -1172,7 +1172,7 @@ namespace libtorrent ?"disk failed":"failed") << " ]\n"; #endif - bool was_finished = m_picker->num_filtered() + num_pieces() + bool was_finished = m_picker->num_filtered() + num_have() == torrent_file().num_pieces(); if (passed_hash_check == 0) @@ -1203,7 +1203,7 @@ namespace libtorrent if (!was_finished && (is_seed() - || m_picker->num_filtered() + num_pieces() + || m_picker->num_filtered() + num_have() == torrent_file().num_pieces())) { TORRENT_ASSERT(passed_hash_check == 0); @@ -1528,7 +1528,7 @@ namespace libtorrent bool was_finished = is_finished(); bool filter_updated = m_picker->set_piece_priority(index, priority); - TORRENT_ASSERT(num_pieces() >= m_picker->num_have_filtered()); + TORRENT_ASSERT(num_have() >= m_picker->num_have_filtered()); if (filter_updated) update_peer_interest(was_finished); } @@ -1566,7 +1566,7 @@ namespace libtorrent TORRENT_ASSERT(*i >= 0); TORRENT_ASSERT(*i <= 7); filter_updated |= m_picker->set_piece_priority(index, *i); - TORRENT_ASSERT(num_pieces() >= m_picker->num_have_filtered()); + TORRENT_ASSERT(num_have() >= m_picker->num_have_filtered()); } if (filter_updated) update_peer_interest(was_finished); } @@ -3268,7 +3268,7 @@ namespace libtorrent if (!m_picker->is_downloaded(i->first)) TORRENT_ASSERT(m_picker->num_peers(i->first) == i->second); } - TORRENT_ASSERT(num_pieces() >= m_picker->num_have_filtered()); + TORRENT_ASSERT(num_have() >= m_picker->num_have_filtered()); } if (valid_metadata()) @@ -4019,7 +4019,7 @@ namespace libtorrent for (int i = 0; i < num_pieces; ++i) if (m_picker->have_piece(i)) st.pieces.set_bit(i); } - st.num_pieces = num_pieces(); + st.num_pieces = num_have(); st.num_seeds = num_seeds(); if (m_picker.get()) st.distributed_copies = m_picker->distributed_copies();