From 22e2f8a1647ef03f90d7b85d7d53098358ddfe73 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 10 May 2004 06:12:29 +0000 Subject: [PATCH] *** empty log message *** --- examples/client_test.cpp | 6 +++--- include/libtorrent/policy.hpp | 2 +- src/identify_client.cpp | 13 +++++++++++++ src/policy.cpp | 13 +++++++------ src/session.cpp | 4 ++-- src/storage.cpp | 7 +++---- src/torrent.cpp | 19 ------------------- 7 files changed, 29 insertions(+), 35 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 6f9596e2f..5166b359b 100755 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -243,8 +243,8 @@ int main(int argc, char* argv[]) std::vector handles; session ses(fingerprint("LT", 0, 1, 0, 0)); - ses.listen_on(std::make_pair(6881, 6889)); -// ses.set_upload_rate_limit(100000); + ses.listen_on(std::make_pair(100, 110)); + ses.set_upload_rate_limit(50000); // ses.set_download_rate_limit(50000); ses.set_http_settings(settings); ses.set_severity_level(alert::debug); @@ -277,7 +277,7 @@ int main(int argc, char* argv[]) handles.push_back(ses.add_torrent(t, save_path, resume_data)); handles.back().set_max_connections(60); - handles.back().set_max_uploads(-1); + handles.back().set_max_uploads(7); handles.back().set_ratio(1.02f); } catch (std::exception& e) diff --git a/include/libtorrent/policy.hpp b/include/libtorrent/policy.hpp index a956db4b4..983c31ec7 100755 --- a/include/libtorrent/policy.hpp +++ b/include/libtorrent/policy.hpp @@ -121,7 +121,7 @@ namespace libtorrent #ifndef NDEBUG bool has_connection(const peer_connection* p); - void check_invariant(); + void check_invariant() const; #endif struct peer diff --git a/src/identify_client.cpp b/src/identify_client.cpp index 69a9b8580..383fe4ed8 100755 --- a/src/identify_client.cpp +++ b/src/identify_client.cpp @@ -177,9 +177,18 @@ namespace libtorrent else if (std::equal(f->id, f->id+2, "MT")) identity << "Moonlight Torrent "; + // Torrent Storm else if (std::equal(f->id, f->id+2, "TS")) identity << "TorrentStorm "; + // SwarmScope + else if (std::equal(f->id, f->id+2, "SS")) + identity << "SwarmScope "; + + // XanTorrent + else if (std::equal(f->id, f->id+2, "XT")) + identity << "XanTorrent "; + // unknown client else identity << std::string(f->id, f->id+2) << " "; @@ -207,6 +216,10 @@ namespace libtorrent else if (std::equal(f->id, f->id+1, "U")) identity << "UPnP "; + // BitTornado + else if (std::equal(f->id, f->id+1, "T")) + identity << "BitTornado "; + // unknown client else identity << std::string(f->id, f->id+1) << " "; diff --git a/src/policy.cpp b/src/policy.cpp index 42bb68929..341405c27 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -653,8 +653,7 @@ namespace libtorrent while (m_num_unchoked > m_max_uploads) { peer* p = find_seed_choke_candidate(); - - if (p == 0) break; + assert(p != 0); p->connection->send_choke(); --m_num_unchoked; @@ -666,6 +665,9 @@ namespace libtorrent { if (!seed_unchoke_one_peer()) break; } +#ifndef NDEBUG + check_invariant(); +#endif } // ---------------------------- @@ -720,7 +722,6 @@ namespace libtorrent // unchoked peers while (m_num_unchoked < m_max_uploads && unchoke_one_peer()); } - #ifndef NDEBUG check_invariant(); #endif @@ -815,7 +816,7 @@ namespace libtorrent using namespace boost::posix_time; using namespace boost::gregorian; - // we don't have ny info about this peer. + // we don't have any info about this peer. // add a new entry peer p(remote, peer::connectable); m_peers.push_back(p); @@ -1087,11 +1088,11 @@ namespace libtorrent , match_peer_ip(c->get_socket()->sender())) != m_peers.end(); } - void policy::check_invariant() + void policy::check_invariant() const { assert(m_max_uploads >= 2); int actual_unchoked = 0; - for (std::vector::iterator i = m_peers.begin(); + for (std::vector::const_iterator i = m_peers.begin(); i != m_peers.end(); ++i) { diff --git a/src/session.cpp b/src/session.cpp index efe5b9437..81bb62062 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -974,7 +974,7 @@ namespace libtorrent assert(bytes_per_second > 0 || bytes_per_second == -1); boost::mutex::scoped_lock l(m_impl.m_mutex); m_impl.m_upload_rate = bytes_per_second; - if (m_impl.m_upload_rate != -1 || !m_impl.m_connections.empty()) + if (m_impl.m_upload_rate != -1/* || !m_impl.m_connections.empty()*/) return; for (detail::session_impl::connection_map::iterator i @@ -990,7 +990,7 @@ namespace libtorrent assert(bytes_per_second > 0 || bytes_per_second == -1); boost::mutex::scoped_lock l(m_impl.m_mutex); m_impl.m_download_rate = bytes_per_second; - if (m_impl.m_download_rate != -1 || !m_impl.m_connections.empty()) + if (m_impl.m_download_rate != -1/* || !m_impl.m_connections.empty()*/) return; for (detail::session_impl::connection_map::iterator i diff --git a/src/storage.cpp b/src/storage.cpp index e25585b25..ddf05a0fe 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1415,12 +1415,11 @@ namespace libtorrent m_slot_to_piece[pos] = pos; m_piece_to_slot[pos] = pos; } + m_unallocated_slots.erase(m_unallocated_slots.begin()); + m_slot_to_piece[new_free_slot] = unassigned; + m_free_slots.push_back(new_free_slot); m_storage.write(&zeros[0], pos, 0, static_cast(m_info.piece_size(pos))); - - m_free_slots.push_back(new_free_slot); - m_slot_to_piece[new_free_slot] = unassigned; - m_unallocated_slots.erase(m_unallocated_slots.begin()); } assert(m_free_slots.size() > 0); diff --git a/src/torrent.cpp b/src/torrent.cpp index 422a2e7c3..62e97cf2d 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -243,25 +243,6 @@ namespace libtorrent m_got_tracker_response = true; } -/* - bool torrent::has_peer(const peer_id& id) const - { - assert(std::count_if(m_connections.begin() - , m_connections.end() - , peer_by_id(id)) <= 1); - - // pretend that we are connected to - // ourself to avoid real connections - // to ourself - if (id == m_ses.m_peer_id) return true; - - return std::find_if( - m_connections.begin() - , m_connections.end() - , peer_by_id(id)) - != m_connections.end(); - } -*/ size_type torrent::bytes_left() const {