From 143c1661fe92f5f34e7db4c1a4a0039556986db8 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sun, 17 Aug 2008 00:10:56 +0000 Subject: [PATCH] lt sync 2607 - fixes upnp --- libtorrent/include/libtorrent/bandwidth_manager.hpp | 2 ++ libtorrent/include/libtorrent/create_torrent.hpp | 12 ++++++++++++ libtorrent/include/libtorrent/disk_io_thread.hpp | 3 ++- libtorrent/include/libtorrent/error_code.hpp | 4 ++++ libtorrent/src/bt_peer_connection.cpp | 4 ++++ libtorrent/src/create_torrent.cpp | 12 ++++++++++++ libtorrent/src/enum_net.cpp | 8 ++++---- libtorrent/src/file_storage.cpp | 4 ++++ libtorrent/src/lazy_bdecode.cpp | 6 ++++-- libtorrent/src/peer_connection.cpp | 4 ++++ libtorrent/src/storage.cpp | 4 ++++ libtorrent/src/torrent_info.cpp | 4 ++++ libtorrent/src/upnp.cpp | 2 +- 13 files changed, 61 insertions(+), 8 deletions(-) diff --git a/libtorrent/include/libtorrent/bandwidth_manager.hpp b/libtorrent/include/libtorrent/bandwidth_manager.hpp index ef58337c5..b548603be 100644 --- a/libtorrent/include/libtorrent/bandwidth_manager.hpp +++ b/libtorrent/include/libtorrent/bandwidth_manager.hpp @@ -268,6 +268,7 @@ private: if (m_abort) return; error_code ec; + TORRENT_ASSERT(e.expires_at > time_now()); m_history_timer.expires_at(e.expires_at, ec); m_history_timer.async_wait(bind(&bandwidth_manager::on_history_expire, this, _1)); } @@ -311,6 +312,7 @@ private: if (!m_history.empty() && !m_abort) { error_code ec; + TORRENT_ASSERT(m_history.back().expires_at > now); m_history_timer.expires_at(m_history.back().expires_at, ec); m_history_timer.async_wait(bind(&bandwidth_manager::on_history_expire, this, _1)); } diff --git a/libtorrent/include/libtorrent/create_torrent.hpp b/libtorrent/include/libtorrent/create_torrent.hpp index e631a145a..108de8fda 100644 --- a/libtorrent/include/libtorrent/create_torrent.hpp +++ b/libtorrent/include/libtorrent/create_torrent.hpp @@ -143,14 +143,22 @@ namespace libtorrent { using boost::filesystem::path; using boost::filesystem::directory_iterator; +#if BOOST_VERSION < 103600 std::string const& leaf = l.leaf(); +#else + std::string const& leaf = l.filename(); +#endif if (leaf == ".." || leaf == ".") return; if (!pred(l)) return; path f(p / l); if (is_directory(f)) { for (directory_iterator i(f), end; i != end; ++i) +#if BOOST_VERSION < 103600 add_files_impl(fs, p, l / i->leaf(), pred); +#else + add_files_impl(fs, p, l / i->filename(), pred); +#endif } else { @@ -162,7 +170,11 @@ namespace libtorrent template void add_files(file_storage& fs, boost::filesystem::path const& file, Pred p) { +#if BOOST_VERSION < 103600 detail::add_files_impl(fs, complete(file).branch_path(), file.leaf(), p); +#else + detail::add_files_impl(fs, complete(file).parent_path(), file.filename(), p); +#endif } inline void add_files(file_storage& fs, boost::filesystem::path const& file) diff --git a/libtorrent/include/libtorrent/disk_io_thread.hpp b/libtorrent/include/libtorrent/disk_io_thread.hpp index 922896741..23e8dd349 100644 --- a/libtorrent/include/libtorrent/disk_io_thread.hpp +++ b/libtorrent/include/libtorrent/disk_io_thread.hpp @@ -39,8 +39,9 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/storage.hpp" #include -#include #include +#include +#include #include #include #include diff --git a/libtorrent/include/libtorrent/error_code.hpp b/libtorrent/include/libtorrent/error_code.hpp index ffc7d662e..36c8da342 100644 --- a/libtorrent/include/libtorrent/error_code.hpp +++ b/libtorrent/include/libtorrent/error_code.hpp @@ -73,7 +73,11 @@ namespace libtorrent inline boost::system::error_category const& get_system_category() { return boost::system::get_system_category(); } inline boost::system::error_category const& get_posix_category() +#if BOOST_VERSION < 103600 { return boost::system::get_posix_category(); } +#else + { return boost::system::get_generic_category(); } +#endif #endif } diff --git a/libtorrent/src/bt_peer_connection.cpp b/libtorrent/src/bt_peer_connection.cpp index 1d7b5830f..c68640d79 100755 --- a/libtorrent/src/bt_peer_connection.cpp +++ b/libtorrent/src/bt_peer_connection.cpp @@ -252,6 +252,7 @@ namespace libtorrent if (m_supports_dht_port && m_ses.m_dht) write_dht_port(m_ses.get_dht_settings().service_port); #endif + if (is_interesting()) write_interested(); } void bt_peer_connection::write_dht_port(int listen_port) @@ -1435,6 +1436,9 @@ namespace libtorrent else if (t->num_have() == 0) { // don't send a bitfield if we don't have any pieces +#ifdef TORRENT_VERBOSE_LOGGING + (*m_logger) << time_now_string() << " *** NOT SENDING BITFIELD"; +#endif #ifndef NDEBUG m_sent_bitfield = true; #endif diff --git a/libtorrent/src/create_torrent.cpp b/libtorrent/src/create_torrent.cpp index 98f590d20..67448bb7b 100644 --- a/libtorrent/src/create_torrent.cpp +++ b/libtorrent/src/create_torrent.cpp @@ -49,7 +49,11 @@ namespace libtorrent , m_private(false) { TORRENT_ASSERT(fs.num_files() > 0); +#if BOOST_VERSION < 103600 if (!m_multifile && m_files.at(0).path.has_branch_path()) m_multifile = true; +#else + if (!m_multifile && m_files.at(0).path.has_parent_path()) m_multifile = true; +#endif // make sure the size is an even power of 2 #ifndef NDEBUG @@ -75,7 +79,11 @@ namespace libtorrent , m_private(false) { TORRENT_ASSERT(fs.num_files() > 0); +#if BOOST_VERSION < 103600 if (!m_multifile && m_files.at(0).path.has_branch_path()) m_multifile = true; +#else + if (!m_multifile && m_files.at(0).path.has_parent_path()) m_multifile = true; +#endif const int target_size = 40 * 1024; int size = fs.total_size() / (target_size / 20); @@ -190,7 +198,11 @@ namespace libtorrent file_e["length"] = i->size; entry& path_e = file_e["path"]; +#if BOOST_VERSION < 103600 TORRENT_ASSERT(i->path.has_branch_path()); +#else + TORRENT_ASSERT(i->path.has_parent_path()); +#endif TORRENT_ASSERT(*i->path.begin() == m_files.name()); for (fs::path::iterator j = boost::next(i->path.begin()); diff --git a/libtorrent/src/enum_net.cpp b/libtorrent/src/enum_net.cpp index eb5a9eeef..7f2a1fef7 100644 --- a/libtorrent/src/enum_net.cpp +++ b/libtorrent/src/enum_net.cpp @@ -150,10 +150,10 @@ namespace libtorrent { namespace if_indextoname(*(int*)RTA_DATA(rt_attr), rt_info->name); break; case RTA_GATEWAY: - rt_info->gateway = address_v4(*(u_int*)RTA_DATA(rt_attr)); + rt_info->gateway = address_v4(ntohl(*(u_int*)RTA_DATA(rt_attr))); break; case RTA_DST: - rt_info->destination = address_v4(*(u_int*)RTA_DATA(rt_attr)); + rt_info->destination = address_v4(ntohl(*(u_int*)RTA_DATA(rt_attr))); break; } } @@ -230,9 +230,9 @@ namespace libtorrent bool in_local_network(io_service& ios, address const& addr, error_code& ec) { - std::vector const& net = enum_net_interfaces(ios, ec); + std::vector net = enum_net_interfaces(ios, ec); if (ec) return false; - for (std::vector::const_iterator i = net.begin() + for (std::vector::iterator i = net.begin() , end(net.end()); i != end; ++i) { if (in_subnet(addr, *i)) return true; diff --git a/libtorrent/src/file_storage.cpp b/libtorrent/src/file_storage.cpp index a0c4145f3..dd732bef1 100644 --- a/libtorrent/src/file_storage.cpp +++ b/libtorrent/src/file_storage.cpp @@ -131,7 +131,11 @@ namespace libtorrent void file_storage::add_file(fs::path const& file, size_type size) { TORRENT_ASSERT(size >= 0); +#if BOOST_VERSION < 103600 if (!file.has_branch_path()) +#else + if (!file.has_parent_path()) +#endif { // you have already added at least one file with a // path to the file (branch_path), which means that diff --git a/libtorrent/src/lazy_bdecode.cpp b/libtorrent/src/lazy_bdecode.cpp index a6a6ad6d0..d53cbbb59 100644 --- a/libtorrent/src/lazy_bdecode.cpp +++ b/libtorrent/src/lazy_bdecode.cpp @@ -88,10 +88,10 @@ namespace libtorrent lazy_entry* top = stack.back(); if (int(stack.size()) > depth_limit) return fail_bdecode(); - if (start == end) return fail_bdecode(); + if (start >= end) return fail_bdecode(); char t = *start; ++start; - if (start == end && t != 'e') return fail_bdecode(); + if (start >= end && t != 'e') return fail_bdecode(); switch (top->type()) { @@ -107,8 +107,10 @@ namespace libtorrent start = parse_int(start, end, ':', len); if (start == 0 || start + len + 3 > end || *start != ':') return fail_bdecode(); ++start; + if (start == end) fail_bdecode(); lazy_entry* ent = top->dict_append(start); start += len; + if (start >= end) fail_bdecode(); stack.push_back(ent); t = *start; ++start; diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index 95dda99f9..e8451d036 100755 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -2133,6 +2133,8 @@ namespace libtorrent { if (m_interesting) return; m_interesting = true; + boost::shared_ptr t = m_torrent.lock(); + if (!t->valid_metadata()) return; write_interested(); #ifdef TORRENT_VERBOSE_LOGGING @@ -2144,6 +2146,8 @@ namespace libtorrent { if (!m_interesting) return; m_interesting = false; + boost::shared_ptr t = m_torrent.lock(); + if (!t->valid_metadata()) return; write_not_interested(); m_became_uninteresting = time_now(); diff --git a/libtorrent/src/storage.cpp b/libtorrent/src/storage.cpp index dffea8267..ed6546e23 100755 --- a/libtorrent/src/storage.cpp +++ b/libtorrent/src/storage.cpp @@ -265,7 +265,11 @@ namespace libtorrent create_directory(new_path); for (basic_directory_iterator i(old_path), end; i != end; ++i) { +#if BOOST_VERSION < 103600 recursive_copy(i->path(), new_path / i->leaf(), ec); +#else + recursive_copy(i->path(), new_path / i->filename(), ec); +#endif if (ec) return; } } diff --git a/libtorrent/src/torrent_info.cpp b/libtorrent/src/torrent_info.cpp index 0c3e0fe5d..6fb5fa992 100755 --- a/libtorrent/src/torrent_info.cpp +++ b/libtorrent/src/torrent_info.cpp @@ -385,7 +385,11 @@ namespace libtorrent { name = tmp.leaf(); } +#if BOOST_VERSION < 103600 else if (tmp.has_branch_path()) +#else + else if (tmp.has_parent_path()) +#endif { fs::path p; for (fs::path::iterator i = tmp.begin() diff --git a/libtorrent/src/upnp.cpp b/libtorrent/src/upnp.cpp index d4cc8a4ca..d98e95284 100644 --- a/libtorrent/src/upnp.cpp +++ b/libtorrent/src/upnp.cpp @@ -339,7 +339,7 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer { m_log << time_now_string() << " <== (" << from << ") UPnP device " "ignored because it's not on our local network "; - std::vector const& net = enum_net_interfaces(m_io_service, ec); + std::vector net = enum_net_interfaces(m_io_service, ec); for (std::vector::const_iterator i = net.begin() , end(net.end()); i != end; ++i) {