diff --git a/include/libtorrent/bandwidth_manager.hpp b/include/libtorrent/bandwidth_manager.hpp index 4df9d4f2f..75e1f1d4e 100644 --- a/include/libtorrent/bandwidth_manager.hpp +++ b/include/libtorrent/bandwidth_manager.hpp @@ -90,47 +90,47 @@ struct bandwidth_limit { static const int inf = boost::integer_traits::const_max; - bandwidth_limit() + bandwidth_limit() throw() : m_quota_left(0) , m_local_limit(inf) , m_current_rate(0) {} - void throttle(int limit) + void throttle(int limit) throw() { m_local_limit = limit; } - int throttle() const + int throttle() const throw() { return m_local_limit; } - void assign(int amount) + void assign(int amount) throw() { assert(amount > 0); m_current_rate += amount; m_quota_left += amount; } - void use_quota(int amount) + void use_quota(int amount) throw() { assert(amount <= m_quota_left); m_quota_left -= amount; } - int quota_left() const + int quota_left() const throw() { return (std::max)(m_quota_left, 0); } - void expire(int amount) + void expire(int amount) throw() { assert(amount >= 0); m_current_rate -= amount; } - int max_assignable() const + int max_assignable() const throw() { if (m_local_limit == inf) return inf; if (m_local_limit <= m_current_rate) return 0; @@ -160,7 +160,7 @@ private: }; template -T clamp(T val, T ceiling, T floor) +T clamp(T val, T ceiling, T floor) throw() { assert(ceiling >= floor); if (val >= ceiling) return ceiling; @@ -171,7 +171,7 @@ T clamp(T val, T ceiling, T floor) template struct bandwidth_manager { - bandwidth_manager(io_service& ios, int channel) + bandwidth_manager(io_service& ios, int channel) throw() : m_ios(ios) , m_history_timer(m_ios) , m_limit(bandwidth_limit::inf) @@ -179,14 +179,14 @@ struct bandwidth_manager , m_channel(channel) {} - void throttle(int limit) + void throttle(int limit) throw() { mutex_t::scoped_lock l(m_mutex); assert(limit >= 0); m_limit = limit; } - int throttle() const + int throttle() const throw() { mutex_t::scoped_lock l(m_mutex); return m_limit; @@ -197,7 +197,7 @@ struct bandwidth_manager // this is used by web seeds void request_bandwidth(intrusive_ptr peer , int blk - , bool non_prioritized) + , bool non_prioritized) throw() { INVARIANT_CHECK; assert(blk > 0); @@ -257,8 +257,11 @@ struct bandwidth_manager private: - void add_history_entry(history_entry const& e) try + void add_history_entry(history_entry const& e) throw() { +#ifndef NDEBUG + try { +#endif INVARIANT_CHECK; m_history.push_front(e); m_current_quota += e.amount; @@ -268,11 +271,17 @@ private: m_history_timer.expires_at(e.expires_at); m_history_timer.async_wait(bind(&bandwidth_manager::on_history_expire, this, _1)); +#ifndef NDEBUG + } + catch (std::exception&) { assert(false); } +#endif } - catch (std::exception&) { assert(false); } - void on_history_expire(asio::error_code const& e) try + void on_history_expire(asio::error_code const& e) throw() { +#ifndef NDEBUG + try { +#endif INVARIANT_CHECK; if (e) return; @@ -303,14 +312,20 @@ private: // means we can hand out more (in case there // are still consumers in line) if (!m_queue.empty()) hand_out_bandwidth(); +#ifndef NDEBUG + } + catch (std::exception&) + { + assert(false); + } +#endif } - catch (std::exception&) - { - assert(false); - }; - void hand_out_bandwidth() try + void hand_out_bandwidth() throw() { +#ifndef NDEBUG + try { +#endif INVARIANT_CHECK; ptime now(time_now()); @@ -404,9 +419,12 @@ private: add_history_entry(history_entry( qe.peer, t, hand_out_amount, now + bw_window_size)); } +#ifndef NDEBUG + } + catch (std::exception& e) + { assert(false); }; +#endif } - catch (std::exception& e) - { assert(false); }; typedef boost::mutex mutex_t; diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 41df77475..18cbf6c2f 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -197,39 +197,41 @@ namespace libtorrent { namespace } virtual bool on_extended(int length, int msg, buffer::const_interval body) - try { if (msg != extension_index) return false; if (m_message_index == 0) return false; if (length > 500 * 1024) - throw protocol_error("ut peer exchange message larger than 500 kB"); + throw protocol_error("uT peer exchange message larger than 500 kB"); if (body.left() < length) return true; - entry pex_msg = bdecode(body.begin, body.end); - std::string const& peers = pex_msg["added"].string(); - std::string const& peer_flags = pex_msg["added.f"].string(); - - int num_peers = peers.length() / 6; - char const* in = peers.c_str(); - char const* fin = peer_flags.c_str(); - - if (int(peer_flags.size()) != num_peers) - return true; - - peer_id pid(0); - policy& p = m_torrent.get_policy(); - for (int i = 0; i < num_peers; ++i) + try { - tcp::endpoint adr = detail::read_v4_endpoint(in); - char flags = detail::read_uint8(fin); - p.peer_from_tracker(adr, pid, peer_info::pex, flags); - } - return true; - } - catch (std::exception&) - { + entry pex_msg = bdecode(body.begin, body.end); + std::string const& peers = pex_msg["added"].string(); + std::string const& peer_flags = pex_msg["added.f"].string(); + + int num_peers = peers.length() / 6; + char const* in = peers.c_str(); + char const* fin = peer_flags.c_str(); + + if (int(peer_flags.size()) != num_peers) + return true; + + peer_id pid(0); + policy& p = m_torrent.get_policy(); + for (int i = 0; i < num_peers; ++i) + { + tcp::endpoint adr = detail::read_v4_endpoint(in); + char flags = detail::read_uint8(fin); + p.peer_from_tracker(adr, pid, peer_info::pex, flags); + } + } + catch (std::exception&) + { + throw protocol_error("invalid uT peer exchange message"); + } return true; } diff --git a/test/test_metadata_extension.cpp b/test/test_metadata_extension.cpp index ac1cc7289..543684e3f 100644 --- a/test/test_metadata_extension.cpp +++ b/test/test_metadata_extension.cpp @@ -21,11 +21,13 @@ void test_transfer(bool clear_files = true, bool disconnect = false) ses2.add_extension(&create_metadata_plugin); torrent_handle tor1; torrent_handle tor2; +#ifndef TORRENT_DISABLE_ENCRYPTION pe_settings pes; pes.out_enc_policy = pe_settings::disabled; pes.in_enc_policy = pe_settings::disabled; ses1.set_pe_settings(pes); ses2.set_pe_settings(pes); +#endif boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0, clear_files);