From 9f05f6fc646db754acc1cfadf22e7424b7f03229 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Wed, 23 Apr 2008 01:14:11 +0000 Subject: [PATCH] lt sync 2219 --- libtorrent/bindings/python/src/session.cpp | 15 +++++++++++++++ libtorrent/include/libtorrent/session.hpp | 1 + libtorrent/src/peer_connection.cpp | 9 ++++++++- libtorrent/src/session.cpp | 7 +++++++ libtorrent/src/session_impl.cpp | 12 +++--------- libtorrent/src/torrent.cpp | 20 +++++++++++++++++++- libtorrent/src/udp_socket.cpp | 4 ++++ libtorrent/src/udp_tracker_connection.cpp | 2 +- 8 files changed, 58 insertions(+), 12 deletions(-) diff --git a/libtorrent/bindings/python/src/session.cpp b/libtorrent/bindings/python/src/session.cpp index 0c049a12c..a0c60f818 100755 --- a/libtorrent/bindings/python/src/session.cpp +++ b/libtorrent/bindings/python/src/session.cpp @@ -119,6 +119,19 @@ namespace s.start_upnp(); return; } + + list get_torrents(session& s) + { + list ret; + std::vector torrents = s.get_torrents(); + + for (std::vector::iterator i = torrents.begin(); i != torrents.end(); ++i) + { + ret.append(*i); + } + return ret; + } + #ifndef TORRENT_DISABLE_GEO_IP bool load_asnum_db(session& s, std::string file) { @@ -298,6 +311,8 @@ void bind_session() .def("start_natpmp", &start_natpmp, session_start_natpmp_doc) .def("stop_natpmp", allow_threads(&session::stop_natpmp), session_stop_natpmp_doc) .def("set_ip_filter", allow_threads(&session::set_ip_filter), session_set_ip_filter_doc) + .def("find_torrent", allow_threads(&session::find_torrent)) + .def("get_torrents", &get_torrents) ; register_ptr_to_python >(); diff --git a/libtorrent/include/libtorrent/session.hpp b/libtorrent/include/libtorrent/session.hpp index 63dae16e7..45bb27688 100755 --- a/libtorrent/include/libtorrent/session.hpp +++ b/libtorrent/include/libtorrent/session.hpp @@ -203,6 +203,7 @@ namespace libtorrent #endif #ifndef TORRENT_DISABLE_GEO_IP + int as_for_ip(address const& addr); bool load_asnum_db(char const* file); bool load_country_db(char const* file); #endif diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index 1dae48110..c2f49b3a3 100755 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -526,7 +526,14 @@ namespace libtorrent // optimization, don't send have messages // to peers that already have the piece if (!m_ses.settings().send_redundant_have - && has_piece(index)) return; + && has_piece(index)) + { +#ifdef TORRENT_VERBOSE_LOGGING + (*m_logger) << time_now_string() + << " ==> HAVE [ piece: " << index << " ] SUPRESSED\n"; +#endif + return; + } #ifdef TORRENT_VERBOSE_LOGGING (*m_logger) << time_now_string() diff --git a/libtorrent/src/session.cpp b/libtorrent/src/session.cpp index 538ae47d5..1d54bc40d 100755 --- a/libtorrent/src/session.cpp +++ b/libtorrent/src/session.cpp @@ -185,6 +185,13 @@ namespace libtorrent { return m_impl->load_country_db(file); } + + int session::as_for_ip(address const& addr) + { + aux::session_impl::mutex_t::scoped_lock l(m_impl->m_mutex); + return m_impl->as_for_ip(addr); + } + #endif void session::load_state(entry const& ses_state) diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index 419dccf85..e8b34c9bb 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -159,7 +159,7 @@ namespace aux { , m_num_unchoked(0) , m_unchoke_time_scaler(0) , m_optimistic_unchoke_time_scaler(0) - , m_disconnect_time_scaler(0) + , m_disconnect_time_scaler(90) , m_incoming_connection(false) , m_last_tick(time_now()) #ifndef TORRENT_DISABLE_DHT @@ -1355,7 +1355,7 @@ namespace aux { --m_disconnect_time_scaler; if (m_disconnect_time_scaler <= 0) { - m_disconnect_time_scaler = 60; + m_disconnect_time_scaler = 90; // every 60 seconds, disconnect the worst peer // if we have reached the connection limit @@ -1366,6 +1366,7 @@ namespace aux { < bind(&torrent::num_peers, bind(&torrent_map::value_type::second, _2))); TORRENT_ASSERT(i != m_torrents.end()); + // TODO: make the number of peers a percentage of the number of connected peers i->second->get_policy().disconnect_one_peer(); } } @@ -1565,13 +1566,6 @@ namespace aux { m_queued_for_checking.pop_front(); if (!m_queued_for_checking.empty()) m_queued_for_checking.front()->start_checking(); - - if (m_alerts.should_post(alert::info)) - { - m_alerts.post_alert(torrent_checked_alert( - t->get_handle() - , "torrent finished checking")); - } } torrent_handle session_impl::add_torrent( diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index 73c1284be..48a466a9c 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -206,6 +206,10 @@ namespace libtorrent , m_max_connections((std::numeric_limits::max)()) , m_deficit_counter(0) , m_policy(this) + , m_active_time(seconds(0)) + , m_seeding_time(seconds(0)) + , m_total_uploaded(0) + , m_total_downloaded(0) { #ifndef NDEBUG m_files_checked = false; @@ -271,6 +275,10 @@ namespace libtorrent , m_max_connections((std::numeric_limits::max)()) , m_deficit_counter(0) , m_policy(this) + , m_active_time(seconds(0)) + , m_seeding_time(seconds(0)) + , m_total_uploaded(0) + , m_total_downloaded(0) { #ifndef NDEBUG m_files_checked = false; @@ -1149,7 +1157,9 @@ namespace libtorrent #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) (*m_ses.m_logger) << time_now_string() << " *** PIECE_FINISHED [ p: " - << index << " chk: " << (passed_hash_check?"passed":"failed") << " ]\n"; + << index << " chk: " << ((passed_hash_check == 0) + ?"passed":passed_hash_check == -1 + ?"disk failed":"failed") << " ]\n"; #endif bool was_seed = is_seed(); @@ -2981,6 +2991,14 @@ namespace libtorrent #endif } } + + if (m_ses.m_alerts.should_post(alert::info)) + { + m_ses.m_alerts.post_alert(torrent_checked_alert( + get_handle() + , "torrent finished checking")); + } + #ifndef NDEBUG m_files_checked = true; #endif diff --git a/libtorrent/src/udp_socket.cpp b/libtorrent/src/udp_socket.cpp index 6f64997a9..ccbb3992b 100644 --- a/libtorrent/src/udp_socket.cpp +++ b/libtorrent/src/udp_socket.cpp @@ -24,6 +24,8 @@ udp_socket::udp_socket(asio::io_service& ios, udp_socket::callback_t const& c void udp_socket::send(udp::endpoint const& ep, char const* p, int len, asio::error_code& ec) { + if (ec == asio::error::operation_aborted) return; + if (m_tunnel_packets) { // send udp packets through SOCKS5 server @@ -39,6 +41,8 @@ void udp_socket::send(udp::endpoint const& ep, char const* p, int len, asio::err void udp_socket::on_read(udp::socket* s, asio::error_code const& e, std::size_t bytes_transferred) { + if (e == asio::error::operation_aborted) return; + if (!m_callback) return; if (e) diff --git a/libtorrent/src/udp_tracker_connection.cpp b/libtorrent/src/udp_tracker_connection.cpp index 7347dbe4b..a6320786f 100755 --- a/libtorrent/src/udp_tracker_connection.cpp +++ b/libtorrent/src/udp_tracker_connection.cpp @@ -84,7 +84,7 @@ namespace libtorrent : tracker_connection(man, req, ios, bind_infc, c) , m_man(man) , m_name_lookup(ios) - , m_socket(ios, boost::bind(&udp_tracker_connection::on_receive, this, _1, _2, _3, _4), cc) + , m_socket(ios, boost::bind(&udp_tracker_connection::on_receive, self(), _1, _2, _3, _4), cc) , m_transaction_id(0) , m_connection_id(0) , m_settings(stn)