From 029e185a1e481ddbe47b33aafa6c4401f6c7e20a Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 17 Dec 2003 03:40:13 +0000 Subject: [PATCH] *** empty log message *** --- examples/client_test.cpp | 2 +- examples/simple_client.cpp | 2 +- include/libtorrent/fingerprint.hpp | 8 ++++---- include/libtorrent/torrent.hpp | 3 +++ src/peer_connection.cpp | 2 +- src/policy.cpp | 33 +++++++++++++++++++++++++++++- src/session.cpp | 2 +- 7 files changed, 43 insertions(+), 9 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index ae98e8e71..06cad4544 100755 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -282,7 +282,7 @@ int main(int argc, char* argv[]) << "u: " << add_suffix(i->up_speed) << "/s " << "(" << add_suffix(i->total_upload) << ") " // << "df: " << add_suffix((int)i->total_download - (int)i->total_upload) << " " - << "b: " << add_suffix(i->load_balancing) << "/s " + << "b: " << add_suffix(i->load_balancing) << " " << "f: " << static_cast((i->flags & peer_info::interesting)?"I":"_") << static_cast((i->flags & peer_info::choked)?"C":"_") diff --git a/examples/simple_client.cpp b/examples/simple_client.cpp index e85bf4867..b600ecf8a 100755 --- a/examples/simple_client.cpp +++ b/examples/simple_client.cpp @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) try { - session s(6881, "E\x1"); + session s(6881); std::ifstream in(argv[1], std::ios_base::binary); in.unsetf(std::ios_base::skipws); diff --git a/include/libtorrent/fingerprint.hpp b/include/libtorrent/fingerprint.hpp index 0a51f95e3..481005a6d 100755 --- a/include/libtorrent/fingerprint.hpp +++ b/include/libtorrent/fingerprint.hpp @@ -61,10 +61,10 @@ namespace libtorrent { std::stringstream s; s << "-" << id[0] << id[1] - << major_version - << minor_version - << revision_version - << tag_version << "-"; + << (int)major_version + << (int)minor_version + << (int)revision_version + << (int)tag_version << "-"; return s.str(); } diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 125894525..7f32fd93e 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -192,6 +192,9 @@ namespace libtorrent bool have_piece(unsigned int index) const { return m_have_pieces[index]; } + const std::vector& pieces() const + { return m_have_pieces; } + // when we get a have- or bitfield- messages, this is called for every // piece a peer has gained. // returns true if this piece is interesting (i.e. if we would like to download it) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 477cef8d4..da496e5c1 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -377,7 +377,7 @@ bool libtorrent::peer_connection::dispatch_message(int received) else { m_have_piece[index] = true; - if (m_torrent->peer_has(index)) + if (!m_torrent->peer_has(index) && !is_interesting()) m_torrent->get_policy().peer_is_interesting(*this); } break; diff --git a/src/policy.cpp b/src/policy.cpp index 146199840..ab2d0f16b 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -507,14 +507,45 @@ namespace libtorrent void policy::piece_finished(int index, bool successfully_verified) { + if (successfully_verified) + { + // have all peers update their interested-flag + for (std::vector::iterator i = m_peers.begin(); + i != m_peers.end(); + ++i) + { + if (i->connection == 0) continue; + // if we're not interested, we will not become interested + if (!i->connection->is_interesting()) continue; + + bool interested = false; + const std::vector& peer_has = i->connection->get_bitfield(); + const std::vector& we_have = m_torrent->pieces(); + assert(we_have.size() == peer_has.size()); + for (int j = 0; j != we_have.size(); ++j) + { + if (!we_have[j] && peer_has[j]) + { + interested = true; + break; + } + } + if (!interested) + i->connection->not_interested(); + } + } // TODO: if verification failed, mark the peers that were involved // in some way } + // TODO: we must be able to get interested + // in a peer again, if a piece fails that + // this peer has. void policy::block_finished(peer_connection& c, piece_block b) { // if the peer hasn't choked us, ask for another piece - if (!c.has_peer_choked()) request_a_block(*m_torrent, c); + if (!c.has_peer_choked()) + request_a_block(*m_torrent, c); } // this is called when we are unchoked by a peer diff --git a/src/session.cpp b/src/session.cpp index 2d979d4b6..947d82345 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -76,7 +76,7 @@ namespace int quota_limit; // bandwidth limit int estimated_upload_capacity; // estimated channel bandwidth - bool operator < (connection_info &other) const + bool operator < (const connection_info &other) const { return estimated_upload_capacity < other.estimated_upload_capacity; }