diff --git a/libtorrent/include/libtorrent/alert_types.hpp b/libtorrent/include/libtorrent/alert_types.hpp index bef778b5f..e2154a4c1 100644 --- a/libtorrent/include/libtorrent/alert_types.hpp +++ b/libtorrent/include/libtorrent/alert_types.hpp @@ -158,7 +158,7 @@ namespace libtorrent enum performance_warning_t { outstanding_disk_buffer_limit_reached, - outstanding_request_limit_reached, + outstanding_request_limit_reached }; performance_alert(torrent_handle const& h diff --git a/libtorrent/include/libtorrent/bandwidth_manager.hpp b/libtorrent/include/libtorrent/bandwidth_manager.hpp index b548603be..20344ebc5 100644 --- a/libtorrent/include/libtorrent/bandwidth_manager.hpp +++ b/libtorrent/include/libtorrent/bandwidth_manager.hpp @@ -153,7 +153,8 @@ struct bandwidth_manager m_queue.clear(); m_history.clear(); m_current_quota = 0; - m_history_timer.cancel(); + error_code ec; + m_history_timer.cancel(ec); } #ifndef NDEBUG diff --git a/libtorrent/include/libtorrent/lazy_entry.hpp b/libtorrent/include/libtorrent/lazy_entry.hpp index ffb5b67ee..547900c99 100644 --- a/libtorrent/include/libtorrent/lazy_entry.hpp +++ b/libtorrent/include/libtorrent/lazy_entry.hpp @@ -226,7 +226,7 @@ namespace libtorrent std::ostream& operator<<(std::ostream& os, lazy_entry const& e); -}; +} #endif diff --git a/libtorrent/include/libtorrent/peer_info.hpp b/libtorrent/include/libtorrent/peer_info.hpp index e28216ce0..a2bbc3056 100644 --- a/libtorrent/include/libtorrent/peer_info.hpp +++ b/libtorrent/include/libtorrent/peer_info.hpp @@ -205,7 +205,7 @@ namespace libtorrent { enum flags_t { - banned = 1, + banned = 1 }; tcp::endpoint ip; diff --git a/libtorrent/include/libtorrent/piece_picker.hpp b/libtorrent/include/libtorrent/piece_picker.hpp index f9f4985e4..2e76e8a9f 100644 --- a/libtorrent/include/libtorrent/piece_picker.hpp +++ b/libtorrent/include/libtorrent/piece_picker.hpp @@ -380,7 +380,7 @@ namespace libtorrent // the priority value that means the piece is filtered filter_priority = 0, // the max number the peer count can hold - max_peer_count = 0x3ff, + max_peer_count = 0x3ff }; bool have() const { return index == we_have_index; } diff --git a/libtorrent/include/libtorrent/session_status.hpp b/libtorrent/include/libtorrent/session_status.hpp index 6f74f5ff4..6c3475a09 100644 --- a/libtorrent/include/libtorrent/session_status.hpp +++ b/libtorrent/include/libtorrent/session_status.hpp @@ -33,6 +33,8 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_SESSION_STATUS_HPP_INCLUDED #define TORRENT_SESSION_STATUS_HPP_INCLUDED +#include "libtorrent/config.hpp" +#include "libtorrent/size_type.hpp" namespace libtorrent { diff --git a/libtorrent/include/libtorrent/ssl_stream.hpp b/libtorrent/include/libtorrent/ssl_stream.hpp index 363c819f6..c4deb1352 100644 --- a/libtorrent/include/libtorrent/ssl_stream.hpp +++ b/libtorrent/include/libtorrent/ssl_stream.hpp @@ -54,7 +54,8 @@ public: : m_context(io_service, asio::ssl::context::sslv23_client) , m_sock(io_service, m_context) { - m_context.set_verify_mode(asio::ssl::context::verify_none); + error_code ec; + m_context.set_verify_mode(asio::ssl::context::verify_none, ec); } typedef Stream next_layer_type; diff --git a/libtorrent/src/broadcast_socket.cpp b/libtorrent/src/broadcast_socket.cpp index 43654a11a..5e3372ee5 100644 --- a/libtorrent/src/broadcast_socket.cpp +++ b/libtorrent/src/broadcast_socket.cpp @@ -219,9 +219,6 @@ namespace libtorrent if (ec) return; s->bind(udp::endpoint(addr, 0), ec); if (ec) return; - if (addr.is_v4()) - s->set_option(outbound_interface(addr.to_v4()), ec); - if (ec) return; m_unicast_sockets.push_back(socket_entry(s)); socket_entry& se = m_unicast_sockets.back(); s->async_receive_from(asio::buffer(se.buffer, sizeof(se.buffer)) diff --git a/libtorrent/src/bt_peer_connection.cpp b/libtorrent/src/bt_peer_connection.cpp index dcf0a5bcb..f09628f07 100755 --- a/libtorrent/src/bt_peer_connection.cpp +++ b/libtorrent/src/bt_peer_connection.cpp @@ -1279,6 +1279,7 @@ namespace libtorrent else ++i; } + if (is_disconnecting()) return; #endif // there is supposed to be a remote listen port diff --git a/libtorrent/src/http_connection.cpp b/libtorrent/src/http_connection.cpp index 73904dae6..cd4f8c4c1 100644 --- a/libtorrent/src/http_connection.cpp +++ b/libtorrent/src/http_connection.cpp @@ -205,7 +205,8 @@ void http_connection::on_connect_timeout() if (!m_endpoints.empty()) { - m_sock.close(); + error_code ec; + m_sock.close(ec); } else { @@ -226,8 +227,8 @@ void http_connection::on_timeout(boost::weak_ptr p { if (c->m_connection_ticket > -1 && !c->m_endpoints.empty()) { - c->m_sock.close(); error_code ec; + c->m_sock.close(ec); c->m_timer.expires_at(c->m_last_receive + c->m_timeout, ec); c->m_timer.async_wait(bind(&http_connection::on_timeout, p, _1)); } @@ -321,7 +322,8 @@ void http_connection::on_connect(error_code const& e) else if (!m_endpoints.empty() && !m_abort) { // The connection failed. Try the next endpoint in the list. - m_sock.close(); + error_code ec; + m_sock.close(ec); queue_connect(); } else @@ -353,7 +355,8 @@ void http_connection::callback(error_code const& e, char const* data, int size) } } m_called = true; - m_timer.cancel(); + error_code ec; + m_timer.cancel(ec); if (m_handler) m_handler(e, m_parser, data, size, *this); } } diff --git a/libtorrent/src/http_tracker_connection.cpp b/libtorrent/src/http_tracker_connection.cpp index bfde36e76..6e92a5567 100755 --- a/libtorrent/src/http_tracker_connection.cpp +++ b/libtorrent/src/http_tracker_connection.cpp @@ -157,8 +157,9 @@ namespace libtorrent if (m_settings.announce_ip != address()) { - url += "&ip="; - url += m_settings.announce_ip.to_string(); + error_code ec; + std::string ip = m_settings.announce_ip.to_string(ec); + if (!ec) url += "&ip=" + ip; } #ifndef TORRENT_DISABLE_ENCRYPTION @@ -377,7 +378,9 @@ namespace libtorrent peer_entry p; p.pid.clear(); - p.ip = detail::read_v4_address(i).to_string(); + error_code ec; + p.ip = detail::read_v4_address(i).to_string(ec); + if (ec) continue; p.port = detail::read_uint16(i); peer_list.push_back(p); } @@ -409,7 +412,9 @@ namespace libtorrent peer_entry p; p.pid.clear(); - p.ip = detail::read_v6_address(i).to_string(); + error_code ec; + p.ip = detail::read_v6_address(i).to_string(ec); + if (ec) continue; p.port = detail::read_uint16(i); peer_list.push_back(p); } diff --git a/libtorrent/src/kademlia/dht_tracker.cpp b/libtorrent/src/kademlia/dht_tracker.cpp index dbd917706..74a0fd132 100644 --- a/libtorrent/src/kademlia/dht_tracker.cpp +++ b/libtorrent/src/kademlia/dht_tracker.cpp @@ -87,10 +87,12 @@ namespace void read_endpoint_list(libtorrent::entry const* n, std::vector& epl) { using namespace libtorrent; + if (n->type() != entry::list_t) return; entry::list_type const& contacts = n->list(); for (entry::list_type::const_iterator i = contacts.begin() , end(contacts.end()); i != end; ++i) { + if (i->type() != entry::string_t) return; std::string const& p = i->string(); if (p.size() < 6) continue; std::string::const_iterator in = p.begin(); @@ -189,14 +191,15 @@ namespace libtorrent { namespace dht m_dht.set_node_id(boost::lexical_cast(nid->string())); } - m_timer.expires_from_now(seconds(1)); + error_code ec; + m_timer.expires_from_now(seconds(1), ec); m_timer.async_wait(bind(&dht_tracker::tick, self(), _1)); - m_connection_timer.expires_from_now(seconds(10)); + m_connection_timer.expires_from_now(seconds(10), ec); m_connection_timer.async_wait( bind(&dht_tracker::connection_timeout, self(), _1)); - m_refresh_timer.expires_from_now(seconds(5)); + m_refresh_timer.expires_from_now(seconds(5), ec); m_refresh_timer.async_wait(bind(&dht_tracker::refresh_timeout, self(), _1)); m_dht.bootstrap(initial_nodes, bind(&dht_tracker::on_bootstrap, self())); @@ -206,9 +209,10 @@ namespace libtorrent { namespace dht { mutex_t::scoped_lock l(m_mutex); m_abort = true; - m_timer.cancel(); - m_connection_timer.cancel(); - m_refresh_timer.cancel(); + error_code ec; + m_timer.cancel(ec); + m_connection_timer.cancel(ec); + m_refresh_timer.cancel(ec); m_host_resolver.cancel(); } @@ -780,7 +784,6 @@ namespace libtorrent { namespace dht void write_nodes_entry(entry& r, libtorrent::dht::msg const& m) { bool ipv6_nodes = false; - r["nodes"] = entry(entry::string_t); entry& n = r["nodes"]; std::back_insert_iterator out(n.string()); for (msg::nodes_t::const_iterator i = m.nodes.begin() @@ -797,7 +800,6 @@ namespace libtorrent { namespace dht if (ipv6_nodes) { - r["nodes2"] = entry(entry::list_t); entry& p = r["nodes2"]; std::string endpoint; for (msg::nodes_t::const_iterator i = m.nodes.begin() diff --git a/libtorrent/src/kademlia/node.cpp b/libtorrent/src/kademlia/node.cpp index 67c6174e2..258cb3b87 100644 --- a/libtorrent/src/kademlia/node.cpp +++ b/libtorrent/src/kademlia/node.cpp @@ -122,7 +122,9 @@ bool node_impl::verify_token(msg const& m) } hasher h1; - std::string address = m.addr.address().to_string(); + error_code ec; + std::string address = m.addr.address().to_string(ec); + if (ec) return false; h1.update(&address[0], address.length()); h1.update((char*)&m_secret[0], sizeof(m_secret[0])); h1.update((char*)&m.info_hash[0], sha1_hash::size); @@ -146,7 +148,9 @@ entry node_impl::generate_token(msg const& m) std::string token; token.resize(4); hasher h; - std::string address = m.addr.address().to_string(); + error_code ec; + std::string address = m.addr.address().to_string(ec); + TORRENT_ASSERT(!ec); h.update(&address[0], address.length()); h.update((char*)&m_secret[0], sizeof(m_secret[0])); h.update((char*)&m.info_hash[0], sha1_hash::size); diff --git a/libtorrent/src/logger.cpp b/libtorrent/src/logger.cpp index 1ecba5045..944e559ae 100644 --- a/libtorrent/src/logger.cpp +++ b/libtorrent/src/logger.cpp @@ -211,8 +211,9 @@ namespace virtual boost::shared_ptr new_connection( peer_connection* pc) { + error_code ec; return boost::shared_ptr(new logger_peer_plugin( - pc->remote().address().to_string() + "_" + pc->remote().address().to_string(ec) + "_" + boost::lexical_cast(pc->remote().port()) + ".log")); } }; diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index 6cf29e841..d2790cdf0 100755 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -155,7 +155,8 @@ namespace libtorrent #endif #endif #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING - m_logger = m_ses.create_log(m_remote.address().to_string() + "_" + error_code ec; + m_logger = m_ses.create_log(m_remote.address().to_string(ec) + "_" + boost::lexical_cast(m_remote.port()), m_ses.listen_port()); (*m_logger) << "*** OUTGOING CONNECTION\n"; #endif @@ -2440,7 +2441,8 @@ namespace libtorrent { TORRENT_ASSERT(m_connecting); #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - (*m_ses.m_logger) << time_now_string() << " CONNECTION TIMED OUT: " << m_remote.address().to_string() + error_code ec; + (*m_ses.m_logger) << time_now_string() << " CONNECTION TIMED OUT: " << m_remote.address().to_string(ec) << "\n"; #endif disconnect("timed out: connect", 1); @@ -3714,10 +3716,11 @@ namespace libtorrent m_connecting = false; m_ses.m_half_open.done(m_connection_ticket); + error_code ec; if (e) { #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - (*m_ses.m_logger) << time_now_string() << " CONNECTION FAILED: " << m_remote.address().to_string() + (*m_ses.m_logger) << time_now_string() << " CONNECTION FAILED: " << m_remote.address().to_string(ec) << ": " << e.message() << "\n"; #endif disconnect(e.message().c_str(), 1); @@ -3731,11 +3734,10 @@ namespace libtorrent TORRENT_ASSERT(m_socket); #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING - (*m_ses.m_logger) << time_now_string() << " COMPLETED: " << m_remote.address().to_string() + (*m_ses.m_logger) << time_now_string() << " COMPLETED: " << m_remote.address().to_string(ec) << " rtt = " << m_rtt << "\n"; #endif - error_code ec; if (m_remote == m_socket->local_endpoint(ec)) { // if the remote endpoint is the same as the local endpoint, we're connected diff --git a/libtorrent/src/policy.cpp b/libtorrent/src/policy.cpp index db9861373..2c67d9f8a 100755 --- a/libtorrent/src/policy.cpp +++ b/libtorrent/src/policy.cpp @@ -825,7 +825,8 @@ namespace libtorrent // to this peer. don't connect to // it again. - m_torrent->debug_log("already connected to peer: " + remote.address().to_string() + ":" + error_code ec; + m_torrent->debug_log("already connected to peer: " + remote.address().to_string(ec) + ":" + boost::lexical_cast(remote.port()) + " " + boost::lexical_cast(i->second.connection->pid())); diff --git a/libtorrent/src/session.cpp b/libtorrent/src/session.cpp index 474f88a24..3451ba353 100755 --- a/libtorrent/src/session.cpp +++ b/libtorrent/src/session.cpp @@ -150,7 +150,11 @@ namespace libtorrent if (flags & start_default_features) { start_upnp(); - start_upnp(); + start_natpmp(); +#ifndef TORRENT_DISABLE_DHT + start_dht(); +#endif + start_lsd(); } } @@ -185,6 +189,10 @@ namespace libtorrent { start_upnp(); start_natpmp(); +#ifndef TORRENT_DISABLE_DHT + start_dht(); +#endif + start_lsd(); } } diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index 2bb28478b..d67abdce6 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -1845,8 +1845,11 @@ namespace aux { #ifndef NDEBUG sha1_hash i_hash = t.torrent_file().info_hash(); #endif - i->second->set_queue_position(-1); + t.set_queue_position(-1); m_torrents.erase(i); + std::list >::iterator k + = std::find(m_queued_for_checking.begin(), m_queued_for_checking.end(), tptr); + if (k != m_queued_for_checking.end()) m_queued_for_checking.erase(k); TORRENT_ASSERT(m_torrents.find(i_hash) == m_torrents.end()); return; } @@ -2052,15 +2055,10 @@ namespace aux { || m_dht_same_port) { m_dht_same_port = true; - // if you hit this assert you are trying to start the - // DHT with the same port as the tcp listen port - // (which is default) _before_ you have opened the - // tcp listen port (so there is no configured port to use) - // basically, make sure you call listen_on() before - // start_dht(). See documentation for listen_on() for - // more information. - TORRENT_ASSERT(m_listen_interface.port() > 0); - m_dht_settings.service_port = m_listen_interface.port(); + if (m_listen_interface.port() > 0) + m_dht_settings.service_port = m_listen_interface.port(); + else + m_dht_settings.service_port = 45000 + (rand() % 10000); } m_external_udp_port = m_dht_settings.service_port; if (m_natpmp.get() && m_udp_mapping[0] == -1) diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index fdee753d7..1786b009b 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -761,7 +761,7 @@ namespace libtorrent // we're done, or encounter a failure if (ret == piece_manager::need_full_check) return; - m_ses.done_checking(shared_from_this()); + if (!m_abort) m_ses.done_checking(shared_from_this()); files_checked(); } @@ -886,8 +886,9 @@ namespace libtorrent if (req.left == -1) req.left = 16*1024; req.event = e; tcp::endpoint ep = m_ses.get_ipv6_interface(); + error_code ec; if (ep != tcp::endpoint()) - req.ipv6 = ep.address().to_string(); + req.ipv6 = ep.address().to_string(ec); req.url = m_trackers[m_currently_trying_tracker].url; // if we are aborting. we don't want any new peers @@ -1064,7 +1065,8 @@ namespace libtorrent if (m_ses.m_ip_filter.access(host->endpoint().address()) & ip_filter::blocked) { #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - debug_log("blocked ip from tracker: " + host->endpoint().address().to_string()); + error_code ec; + debug_log("blocked ip from tracker: " + host->endpoint().address().to_string(ec)); #endif if (m_ses.m_alerts.should_post()) { @@ -1599,7 +1601,10 @@ namespace libtorrent if (m_owning_storage.get()) m_storage->async_release_files( bind(&torrent::on_files_released, shared_from_this(), _1, _2)); - + + if (m_state == torrent_status::checking_files) + m_ses.done_checking(shared_from_this()); + m_owning_storage = 0; m_host_resolver.cancel(); } @@ -2379,9 +2384,15 @@ namespace libtorrent || p->in_handshake() || p->remote().address().is_v6()) return; - m_resolving_country = true; asio::ip::address_v4 reversed(swap_bytes(p->remote().address().to_v4().to_ulong())); - tcp::resolver::query q(reversed.to_string() + ".zz.countries.nerd.dk", "0"); + error_code ec; + tcp::resolver::query q(reversed.to_string(ec) + ".zz.countries.nerd.dk", "0"); + if (ec) + { + p->set_country("!!"); + return; + } + m_resolving_country = true; m_host_resolver.async_resolve(q, bind(&torrent::on_country_lookup, shared_from_this(), _1, _2, p)); } diff --git a/libtorrent/src/torrent_handle.cpp b/libtorrent/src/torrent_handle.cpp index 80e266bc3..c484c9254 100755 --- a/libtorrent/src/torrent_handle.cpp +++ b/libtorrent/src/torrent_handle.cpp @@ -509,7 +509,7 @@ namespace libtorrent { INVARIANT_CHECK; #ifdef BOOST_NO_EXCEPTIONS - const static torrent_info empty; + const static torrent_info empty(sha1_hash(0)); #endif boost::shared_ptr t = m_torrent.lock(); if (!t) @@ -540,7 +540,7 @@ namespace libtorrent INVARIANT_CHECK; entry ret(entry::dictionary_t); - TORRENT_FORWARD(write_resume_data(ret)); + TORRENT_FORWARD_RETURN2(write_resume_data(ret), ret); t->filesystem().write_resume_data(ret); return ret;