From 431664fec42035ca2b4a27f3f8d9b4686a66cf85 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Mon, 24 Dec 2007 22:27:26 +0000 Subject: [PATCH] lt sync --- .../include/libtorrent/disk_io_thread.hpp | 4 +- libtorrent/include/libtorrent/ip_filter.hpp | 37 ++++++++++--------- libtorrent/include/libtorrent/upnp.hpp | 2 +- libtorrent/src/disk_io_thread.cpp | 17 ++++++--- libtorrent/src/ip_filter.cpp | 12 +++--- libtorrent/src/peer_connection.cpp | 6 ++- libtorrent/src/policy.cpp | 6 +++ libtorrent/src/session_impl.cpp | 6 +++ libtorrent/src/upnp.cpp | 1 - 9 files changed, 56 insertions(+), 35 deletions(-) diff --git a/libtorrent/include/libtorrent/disk_io_thread.hpp b/libtorrent/include/libtorrent/disk_io_thread.hpp index 3aef6f7b7..1d9d88534 100644 --- a/libtorrent/include/libtorrent/disk_io_thread.hpp +++ b/libtorrent/include/libtorrent/disk_io_thread.hpp @@ -102,7 +102,9 @@ namespace libtorrent int disk_allocations() const { return m_allocations; } #endif - + + void join(); + // aborts read operations void stop(boost::intrusive_ptr s); void add_job(disk_io_job const& j diff --git a/libtorrent/include/libtorrent/ip_filter.hpp b/libtorrent/include/libtorrent/ip_filter.hpp index eee76cdc4..1adb14551 100644 --- a/libtorrent/include/libtorrent/ip_filter.hpp +++ b/libtorrent/include/libtorrent/ip_filter.hpp @@ -76,9 +76,9 @@ namespace detail template Addr zero() { - typename Addr::bytes_type zero; + Addr zero; std::fill(zero.begin(), zero.end(), 0); - return Addr(zero); + return zero; } template<> @@ -87,8 +87,8 @@ namespace detail template Addr plus_one(Addr const& a) { - typename Addr::bytes_type tmp(a.to_bytes()); - typedef typename Addr::bytes_type::reverse_iterator iter; + Addr tmp(a); + typedef typename Addr::reverse_iterator iter; for (iter i = tmp.rbegin() , end(tmp.rend()); i != end; ++i) { @@ -99,7 +99,7 @@ namespace detail } *i = 0; } - return Addr(tmp); + return tmp; } inline boost::uint16_t plus_one(boost::uint16_t val) { return val + 1; } @@ -107,8 +107,8 @@ namespace detail template Addr minus_one(Addr const& a) { - typename Addr::bytes_type tmp(a.to_bytes()); - typedef typename Addr::bytes_type::reverse_iterator iter; + Addr tmp(a); + typedef typename Addr::reverse_iterator iter; for (iter i = tmp.rbegin() , end(tmp.rend()); i != end; ++i) { @@ -119,7 +119,7 @@ namespace detail } *i = (std::numeric_limits::max)(); } - return Addr(tmp); + return tmp; } inline boost::uint16_t minus_one(boost::uint16_t val) { return val - 1; } @@ -127,9 +127,9 @@ namespace detail template Addr max_addr() { - typename Addr::bytes_type tmp; + Addr tmp; std::fill(tmp.begin(), tmp.end() - , (std::numeric_limits::max)()); + , (std::numeric_limits::max)()); return Addr(tmp); } @@ -220,23 +220,24 @@ namespace detail return i->access; } - std::vector > export_filter() const + template + std::vector > export_filter() const { - std::vector > ret; + std::vector > ret; ret.reserve(m_access_list.size()); for (typename range_t::const_iterator i = m_access_list.begin() , end(m_access_list.end()); i != end;) { - ip_range r; - r.first = i->start; + ip_range r; + r.first = ExternalAddressType(i->start); r.flags = i->access; ++i; if (i == end) - r.last = max_addr(); + r.last = ExternalAddressType(max_addr()); else - r.last = minus_one(i->start); + r.last = ExternalAddressType(minus_one(i->start)); ret.push_back(r); } @@ -288,8 +289,8 @@ public: private: - detail::filter_impl m_filter4; - detail::filter_impl m_filter6; + detail::filter_impl m_filter4; + detail::filter_impl m_filter6; }; class TORRENT_EXPORT port_filter diff --git a/libtorrent/include/libtorrent/upnp.hpp b/libtorrent/include/libtorrent/upnp.hpp index 0b799d1e9..9c4b2ce54 100644 --- a/libtorrent/include/libtorrent/upnp.hpp +++ b/libtorrent/include/libtorrent/upnp.hpp @@ -75,6 +75,7 @@ public: // it will not be mapped void set_mappings(int tcp, int udp); + void discover_device(); void close(); private: @@ -89,7 +90,6 @@ private: void resend_request(asio::error_code const& e); void on_reply(udp::endpoint const& from, char* buffer , std::size_t bytes_transferred); - void discover_device(); struct rootdevice; diff --git a/libtorrent/src/disk_io_thread.cpp b/libtorrent/src/disk_io_thread.cpp index e0fa982bc..886d5d891 100644 --- a/libtorrent/src/disk_io_thread.cpp +++ b/libtorrent/src/disk_io_thread.cpp @@ -62,12 +62,7 @@ namespace libtorrent disk_io_thread::~disk_io_thread() { - mutex_t::scoped_lock l(m_mutex); - m_abort = true; - m_signal.notify_all(); - l.unlock(); - - m_disk_io_thread.join(); + TORRENT_ASSERT(m_abort == true); } #ifndef NDEBUG @@ -95,6 +90,16 @@ namespace libtorrent #endif + void disk_io_thread::join() + { + mutex_t::scoped_lock l(m_mutex); + m_abort = true; + m_signal.notify_all(); + l.unlock(); + + m_disk_io_thread.join(); + } + // aborts read operations void disk_io_thread::stop(boost::intrusive_ptr s) { diff --git a/libtorrent/src/ip_filter.cpp b/libtorrent/src/ip_filter.cpp index 05334e578..eb91de0d0 100644 --- a/libtorrent/src/ip_filter.cpp +++ b/libtorrent/src/ip_filter.cpp @@ -44,12 +44,12 @@ namespace libtorrent if (first.is_v4()) { TORRENT_ASSERT(last.is_v4()); - m_filter4.add_rule(first.to_v4(), last.to_v4(), flags); + m_filter4.add_rule(first.to_v4().to_bytes(), last.to_v4().to_bytes(), flags); } else if (first.is_v6()) { TORRENT_ASSERT(last.is_v6()); - m_filter6.add_rule(first.to_v6(), last.to_v6(), flags); + m_filter6.add_rule(first.to_v6().to_bytes(), last.to_v6().to_bytes(), flags); } else TORRENT_ASSERT(false); @@ -58,15 +58,15 @@ namespace libtorrent int ip_filter::access(address const& addr) const { if (addr.is_v4()) - return m_filter4.access(addr.to_v4()); + return m_filter4.access(addr.to_v4().to_bytes()); TORRENT_ASSERT(addr.is_v6()); - return m_filter6.access(addr.to_v6()); + return m_filter6.access(addr.to_v6().to_bytes()); } ip_filter::filter_tuple_t ip_filter::export_filter() const { - return boost::make_tuple(m_filter4.export_filter() - , m_filter6.export_filter()); + return boost::make_tuple(m_filter4.export_filter() + , m_filter6.export_filter()); } void port_filter::add_rule(boost::uint16_t first, boost::uint16_t last, int flags) diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index fd9c32bf4..e63788d0f 100755 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -1399,8 +1399,10 @@ namespace libtorrent if (t->alerts().should_post(alert::fatal)) { - std::string err = "torrent paused: disk write error, " + j.str; - t->alerts().post_alert(file_error_alert(t->get_handle(), err)); + if (j.str != "write failed: No space left on device"){ + std::string err = "torrent paused: disk write error, " + j.str; + t->alerts().post_alert(file_error_alert(t->get_handle(), err)); + } } t->pause(); return; diff --git a/libtorrent/src/policy.cpp b/libtorrent/src/policy.cpp index f203eaa56..2fdc5358a 100755 --- a/libtorrent/src/policy.cpp +++ b/libtorrent/src/policy.cpp @@ -533,6 +533,12 @@ namespace libtorrent if (i->second.type == peer::not_connectable) continue; if (i->second.seed && finished) continue; if (i->second.failcount >= max_failcount) continue; + + // prefer peers with lower failcount + if (candidate != m_peers.end() + && candidate->second.failcount < i->second.failcount) + continue; + if (now - i->second.connected < seconds(i->second.failcount * min_reconnect_time)) continue; if (ses.m_port_filter.access(i->second.ip.port()) & port_filter::blocked) diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index c1969d523..5eaad1c16 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -2198,6 +2198,11 @@ namespace detail #endif m_checker_thread->join(); +#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) + (*m_logger) << time_now_string() << " waiting for disk io thread\n"; +#endif + m_disk_thread.join(); + TORRENT_ASSERT(m_torrents.empty()); TORRENT_ASSERT(m_connections.empty()); #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) @@ -2347,6 +2352,7 @@ namespace detail , bind(&session_impl::on_port_mapping , this, _1, _2, _3)); + m_upnp->discover_device(); m_upnp->set_mappings(m_listen_interface.port(), #ifndef TORRENT_DISABLE_DHT m_dht ? m_dht_settings.service_port : diff --git a/libtorrent/src/upnp.cpp b/libtorrent/src/upnp.cpp index bab8cae8a..70588b5ad 100644 --- a/libtorrent/src/upnp.cpp +++ b/libtorrent/src/upnp.cpp @@ -81,7 +81,6 @@ upnp::upnp(io_service& ios, connection_queue& cc m_log.open("upnp.log", std::ios::in | std::ios::out | std::ios::trunc); #endif m_retry_count = 0; - discover_device(); } upnp::~upnp()