apply some c++11 modernization
This commit is contained in:
parent
263e01f5da
commit
65fef972a2
|
@ -50,10 +50,10 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth = 0, void*
|
|||
#define TORRENT_WHILE_0 \
|
||||
__pragma( warning(push) ) \
|
||||
__pragma( warning(disable:4127) ) \
|
||||
while (0) \
|
||||
while (false) \
|
||||
__pragma( warning(pop) )
|
||||
#else
|
||||
#define TORRENT_WHILE_0 while (0)
|
||||
#define TORRENT_WHILE_0 while (false)
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -77,8 +77,8 @@ struct alloca_destructor
|
|||
|
||||
#include <malloc.h>
|
||||
#define TORRENT_ALLOCA(v, t, n) ::libtorrent::aux::typed_span<t> v; { \
|
||||
std::size_t TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast<std::size_t>(n); \
|
||||
t* TORRENT_ALLOCA_tmp = static_cast<t*>(_alloca(sizeof(t) * TORRENT_ALLOCA_size)); \
|
||||
auto TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast<std::size_t>(n); \
|
||||
auto* TORRENT_ALLOCA_tmp = static_cast<t*>(_alloca(sizeof(t) * TORRENT_ALLOCA_size)); \
|
||||
v = ::libtorrent::aux::typed_span<t>(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \
|
||||
::libtorrent::aux::uninitialized_default_construct(v.begin(), v.end()); \
|
||||
} \
|
||||
|
@ -88,8 +88,8 @@ struct alloca_destructor
|
|||
|
||||
#include <stdlib.h>
|
||||
#define TORRENT_ALLOCA(v, t, n) ::libtorrent::aux::typed_span<t> v; { \
|
||||
std::size_t TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast<std::size_t>(n); \
|
||||
t* TORRENT_ALLOCA_tmp = static_cast<t*>(alloca(sizeof(t) * TORRENT_ALLOCA_size)); \
|
||||
auto TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast<std::size_t>(n); \
|
||||
auto* TORRENT_ALLOCA_tmp = static_cast<t*>(alloca(sizeof(t) * TORRENT_ALLOCA_size)); \
|
||||
v = ::libtorrent::aux::typed_span<t>(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \
|
||||
::libtorrent::aux::uninitialized_default_construct(v.begin(), v.end()); \
|
||||
} \
|
||||
|
@ -99,8 +99,8 @@ struct alloca_destructor
|
|||
|
||||
#include <alloca.h>
|
||||
#define TORRENT_ALLOCA(v, t, n) ::libtorrent::aux::typed_span<t> v; { \
|
||||
std::size_t TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast<std::size_t>(n); \
|
||||
t* TORRENT_ALLOCA_tmp = static_cast<t*>(alloca(sizeof(t) * TORRENT_ALLOCA_size)); \
|
||||
auto TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast<std::size_t>(n); \
|
||||
auto* TORRENT_ALLOCA_tmp = static_cast<t*>(alloca(sizeof(t) * TORRENT_ALLOCA_size)); \
|
||||
v = ::libtorrent::aux::typed_span<t>(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \
|
||||
::libtorrent::aux::uninitialized_default_construct(v.begin(), v.end()); \
|
||||
} \
|
||||
|
|
|
@ -55,12 +55,15 @@ namespace aux {
|
|||
// accrued while the fence was up
|
||||
struct TORRENT_EXPORT disk_job_fence
|
||||
{
|
||||
disk_job_fence();
|
||||
disk_job_fence() = default;
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
~disk_job_fence()
|
||||
{
|
||||
TORRENT_ASSERT(int(m_outstanding_jobs) == 0);
|
||||
TORRENT_ASSERT(m_blocked_jobs.size() == 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
// returns one of the fence_* enums.
|
||||
// if there are no outstanding jobs on the
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace aux {
|
|||
|
||||
struct TORRENT_EXTRA_EXPORT file_progress
|
||||
{
|
||||
file_progress();
|
||||
file_progress() = default;
|
||||
|
||||
void init(piece_picker const& picker
|
||||
, file_storage const& fs);
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace libtorrent {
|
|||
address ensure_v6(address const& a);
|
||||
|
||||
typedef std::function<void(udp::endpoint const& from
|
||||
, char* buffer, int size)> receive_handler_t;
|
||||
, char const* buffer, int size)> receive_handler_t;
|
||||
|
||||
class TORRENT_EXTRA_EXPORT broadcast_socket
|
||||
{
|
||||
|
@ -65,7 +65,7 @@ namespace libtorrent {
|
|||
explicit broadcast_socket(udp::endpoint const& multicast_endpoint);
|
||||
~broadcast_socket() { close(); }
|
||||
|
||||
void open(receive_handler_t const& handler, io_service& ios
|
||||
void open(receive_handler_t handler, io_service& ios
|
||||
, error_code& ec, bool loopback = true);
|
||||
|
||||
enum flags_t { flag_broadcast = 1 };
|
||||
|
|
|
@ -84,7 +84,9 @@ class i2p_stream : public proxy_base
|
|||
public:
|
||||
|
||||
explicit i2p_stream(io_service& io_service);
|
||||
#if TORRENT_USE_ASSERTS
|
||||
~i2p_stream();
|
||||
#endif
|
||||
|
||||
enum command_t
|
||||
{
|
||||
|
|
|
@ -54,10 +54,10 @@ namespace libtorrent { namespace dht {
|
|||
// This structure hold the relevant counters for the storage
|
||||
struct TORRENT_EXPORT dht_storage_counters
|
||||
{
|
||||
std::int32_t torrents;
|
||||
std::int32_t peers;
|
||||
std::int32_t immutable_data;
|
||||
std::int32_t mutable_data;
|
||||
std::int32_t torrents = 0;
|
||||
std::int32_t peers = 0;
|
||||
std::int32_t immutable_data = 0;
|
||||
std::int32_t mutable_data = 0;
|
||||
|
||||
// This member function set the counters to zero.
|
||||
void reset();
|
||||
|
|
|
@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#define TIMESTAMP_HISTORY_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/assert.hpp"
|
||||
|
@ -46,7 +47,7 @@ struct TORRENT_EXTRA_EXPORT timestamp_history
|
|||
{
|
||||
static constexpr int history_size = 20;
|
||||
|
||||
timestamp_history() : m_base(0), m_index(0), m_num_samples(not_initialized) {}
|
||||
timestamp_history() = default;
|
||||
bool initialized() const { return m_num_samples != not_initialized; }
|
||||
|
||||
// add a sample to the timestamp history. If step is true, it's been
|
||||
|
@ -58,15 +59,15 @@ struct TORRENT_EXTRA_EXPORT timestamp_history
|
|||
private:
|
||||
|
||||
// this is a circular buffer
|
||||
std::uint32_t m_history[history_size];
|
||||
std::array<std::uint32_t, history_size> m_history;
|
||||
|
||||
// this is the lowest sample seen in the
|
||||
// last 'history_size' minutes
|
||||
std::uint32_t m_base;
|
||||
std::uint32_t m_base = 0;
|
||||
|
||||
// and this is the index we're currently at
|
||||
// in the circular buffer
|
||||
std::uint16_t m_index;
|
||||
std::uint16_t m_index = 0;
|
||||
|
||||
static constexpr std::uint16_t not_initialized = 0xffff;
|
||||
|
||||
|
@ -76,7 +77,7 @@ private:
|
|||
// if this is set to 'not_initialized' we
|
||||
// have bit seen any samples at all yet
|
||||
// and m_base is not initialized yet
|
||||
std::uint16_t m_num_samples;
|
||||
std::uint16_t m_num_samples = not_initialized;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -203,7 +203,7 @@ private:
|
|||
void discover_device_impl();
|
||||
|
||||
void resend_request(error_code const& e);
|
||||
void on_reply(udp::endpoint const& from, char* buffer
|
||||
void on_reply(udp::endpoint const& from, char const* buffer
|
||||
, std::size_t bytes_transferred);
|
||||
|
||||
struct rootdevice;
|
||||
|
|
|
@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
namespace libtorrent {
|
||||
|
||||
add_torrent_params::add_torrent_params(storage_constructor_type sc)
|
||||
: storage(storage_constructor_type(sc)) {}
|
||||
: storage(std::move(sc)) {}
|
||||
add_torrent_params::add_torrent_params(add_torrent_params&&) noexcept = default;
|
||||
add_torrent_params& add_torrent_params::operator=(add_torrent_params&&) = default;
|
||||
add_torrent_params::add_torrent_params(add_torrent_params const&) = default;
|
||||
|
|
|
@ -2336,7 +2336,7 @@ namespace {
|
|||
#endif
|
||||
}
|
||||
|
||||
return nodes_slot(v4_num_nodes, v4_nodes_idx, v6_num_nodes, v6_nodes_idx);
|
||||
return nodes_slot{v4_num_nodes, v4_nodes_idx, v6_num_nodes, v6_nodes_idx};
|
||||
}
|
||||
|
||||
std::vector<std::pair<sha1_hash, udp::endpoint>> read_nodes(
|
||||
|
|
|
@ -162,7 +162,7 @@ namespace {
|
|||
std::string message(int ev) const override;
|
||||
boost::system::error_condition default_error_condition(
|
||||
int ev) const BOOST_SYSTEM_NOEXCEPT override
|
||||
{ return boost::system::error_condition(ev, *this); }
|
||||
{ return {ev, *this}; }
|
||||
};
|
||||
|
||||
const char* bdecode_error_category::name() const BOOST_SYSTEM_NOEXCEPT
|
||||
|
@ -198,7 +198,7 @@ namespace {
|
|||
{
|
||||
boost::system::error_code make_error_code(error_code_enum e)
|
||||
{
|
||||
return boost::system::error_code(e, bdecode_category());
|
||||
return {e, bdecode_category()};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1165,7 +1165,7 @@ void block_cache::clear(tailqueue<disk_io_job>& jobs)
|
|||
|
||||
for (auto const& p : m_pieces)
|
||||
{
|
||||
cached_piece_entry& pe = const_cast<cached_piece_entry&>(p);
|
||||
auto& pe = const_cast<cached_piece_entry&>(p);
|
||||
#if TORRENT_USE_ASSERTS
|
||||
for (tailqueue_iterator<disk_io_job> i = pe.jobs.iterate(); i.get(); i.next())
|
||||
TORRENT_PIECE_ASSERT((static_cast<disk_io_job const*>(i.get()))->piece == pe.piece, &pe);
|
||||
|
@ -1182,13 +1182,12 @@ void block_cache::clear(tailqueue<disk_io_job>& jobs)
|
|||
if (!bufs.empty()) free_multiple_buffers(bufs);
|
||||
|
||||
// clear lru lists
|
||||
for (int i = 0; i < cached_piece_entry::num_lrus; ++i)
|
||||
m_lru[i].get_all();
|
||||
for (auto& l : m_lru) l.get_all();
|
||||
|
||||
// it's not ok to erase pieces with a refcount > 0
|
||||
// since we're cancelling all jobs though, it shouldn't be too bad
|
||||
// to let the jobs already running complete.
|
||||
for (cache_t::iterator i = m_pieces.begin(); i != m_pieces.end();)
|
||||
for (auto i = m_pieces.begin(); i != m_pieces.end();)
|
||||
{
|
||||
if (i->refcount == 0 && i->piece_refcount == 0)
|
||||
{
|
||||
|
|
|
@ -181,10 +181,10 @@ namespace libtorrent {
|
|||
TORRENT_ASSERT(m_multicast_endpoint.address().is_multicast());
|
||||
}
|
||||
|
||||
void broadcast_socket::open(receive_handler_t const& handler
|
||||
void broadcast_socket::open(receive_handler_t handler
|
||||
, io_service& ios, error_code& ec, bool loopback)
|
||||
{
|
||||
m_on_receive = handler;
|
||||
m_on_receive = std::move(handler);
|
||||
|
||||
std::vector<ip_interface> interfaces = enum_net_interfaces(ios, ec);
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ namespace libtorrent {
|
|||
#endif
|
||||
|
||||
boost::crc_optimal<32, 0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, true, true> crc;
|
||||
crc.process_bytes(buf, std::size_t(num_words * 8));
|
||||
crc.process_bytes(buf, std::size_t(num_words) * 8);
|
||||
return crc.checksum();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -285,7 +285,8 @@ namespace {
|
|||
info_hash
|
||||
};
|
||||
|
||||
storage_holder storage = disk_thread.new_torrent(default_storage_constructor, std::move(params), std::shared_ptr<void>());
|
||||
storage_holder storage = disk_thread.new_torrent(default_storage_constructor
|
||||
, params, std::shared_ptr<void>());
|
||||
|
||||
settings_pack sett;
|
||||
sett.set_int(settings_pack::cache_size, 0);
|
||||
|
@ -582,7 +583,7 @@ namespace {
|
|||
|
||||
for (file_index_t i(0); i != m_files.end_file(); ++i)
|
||||
{
|
||||
files.list().push_back(entry());
|
||||
files.list().emplace_back();
|
||||
entry& file_e = files.list().back();
|
||||
if (m_include_mtime && m_files.mtime(i)) file_e["mtime"] = m_files.mtime(i);
|
||||
file_e["length"] = m_files.file_size(i);
|
||||
|
@ -633,7 +634,7 @@ namespace {
|
|||
int const num_nodes = merkle_num_nodes(num_leafs);
|
||||
int const first_leaf = num_nodes - num_leafs;
|
||||
m_merkle_tree.resize(num_nodes);
|
||||
int const num_pieces = int(m_piece_hash.size());
|
||||
auto const num_pieces = int(m_piece_hash.size());
|
||||
for (int i = 0; i < num_pieces; ++i)
|
||||
m_merkle_tree[first_leaf + i] = m_piece_hash[piece_index_t(i)];
|
||||
for (int i = num_pieces; i < num_leafs; ++i)
|
||||
|
|
|
@ -132,7 +132,7 @@ namespace libtorrent {
|
|||
std::thread::id disk_io_thread_pool::first_thread_id()
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
if (m_threads.empty()) return std::thread::id();
|
||||
if (m_threads.empty()) return {};
|
||||
return m_threads.front().get_id();
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ namespace libtorrent {
|
|||
if (ec) return;
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
if (m_abort) return;
|
||||
if (m_threads.size() == 0) return;
|
||||
if (m_threads.empty()) return;
|
||||
m_idle_timer.expires_from_now(reap_idle_threads_interval);
|
||||
m_idle_timer.async_wait([this](error_code const& e) { reap_idle_threads(e); });
|
||||
int const min_idle = m_min_idle_threads.exchange(m_num_idle_threads);
|
||||
|
|
|
@ -45,8 +45,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
namespace libtorrent { namespace aux {
|
||||
|
||||
disk_job_fence::disk_job_fence() {}
|
||||
|
||||
int disk_job_fence::job_complete(disk_io_job* j, tailqueue<disk_io_job>& jobs)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
|
@ -69,7 +67,7 @@ namespace libtorrent { namespace aux {
|
|||
// while this fence was up. However, if there's another fence
|
||||
// in the queue, stop there and raise the fence again
|
||||
int ret = 0;
|
||||
while (m_blocked_jobs.size())
|
||||
while (!m_blocked_jobs.empty())
|
||||
{
|
||||
disk_io_job *bj = m_blocked_jobs.pop_front();
|
||||
if (bj->flags & disk_io_job::fence)
|
||||
|
|
|
@ -385,7 +385,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
|
|||
bool parse_route(int, rt_msghdr* rtm, ip_route* rt_info)
|
||||
{
|
||||
sockaddr* rti_info[RTAX_MAX];
|
||||
sockaddr* sa = reinterpret_cast<sockaddr*>(rtm + 1);
|
||||
auto* sa = reinterpret_cast<sockaddr*>(rtm + 1);
|
||||
for (int i = 0; i < RTAX_MAX; ++i)
|
||||
{
|
||||
if ((rtm->rtm_addrs & (1 << i)) == 0)
|
||||
|
@ -957,7 +957,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
|
|||
}
|
||||
|
||||
std::unique_ptr<char[]> buf(new (std::nothrow) char[needed]);
|
||||
if (buf.get() == nullptr)
|
||||
if (buf == nullptr)
|
||||
{
|
||||
ec = boost::asio::error::no_memory;
|
||||
return std::vector<ip_route>();
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace libtorrent { namespace aux {
|
|||
|
||||
int count_leading_zeros_sw(span<std::uint32_t const> buf)
|
||||
{
|
||||
int const num = int(buf.size());
|
||||
auto const num = int(buf.size());
|
||||
std::uint32_t const* ptr = buf.data();
|
||||
|
||||
TORRENT_ASSERT(num >= 0);
|
||||
|
@ -79,7 +79,7 @@ namespace libtorrent { namespace aux {
|
|||
|
||||
int count_leading_zeros_hw(span<std::uint32_t const> buf)
|
||||
{
|
||||
int const num = int(buf.size());
|
||||
auto const num = int(buf.size());
|
||||
std::uint32_t const* ptr = buf.data();
|
||||
|
||||
TORRENT_ASSERT(num >= 0);
|
||||
|
@ -116,7 +116,7 @@ namespace libtorrent { namespace aux {
|
|||
|
||||
int count_trailing_ones_sw(span<std::uint32_t const> buf)
|
||||
{
|
||||
int const num = int(buf.size());
|
||||
auto const num = int(buf.size());
|
||||
std::uint32_t const* ptr = buf.data();
|
||||
|
||||
TORRENT_ASSERT(num >= 0);
|
||||
|
@ -139,7 +139,7 @@ namespace libtorrent { namespace aux {
|
|||
|
||||
int count_trailing_ones_hw(span<std::uint32_t const> buf)
|
||||
{
|
||||
int const num = int(buf.size());
|
||||
auto const num = int(buf.size());
|
||||
std::uint32_t const* ptr = buf.data();
|
||||
|
||||
TORRENT_ASSERT(num >= 0);
|
||||
|
|
12
src/file.cpp
12
src/file.cpp
|
@ -784,8 +784,8 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
|||
bool coalesce_read_buffers(span<iovec_t const>& bufs
|
||||
, iovec_t& tmp)
|
||||
{
|
||||
std::size_t const buf_size = aux::numeric_cast<std::size_t>(bufs_size(bufs));
|
||||
char* buf = new char[buf_size];
|
||||
auto const buf_size = aux::numeric_cast<std::size_t>(bufs_size(bufs));
|
||||
auto buf = new char[buf_size];
|
||||
tmp = { buf, buf_size };
|
||||
bufs = span<iovec_t const>(tmp);
|
||||
return true;
|
||||
|
@ -801,8 +801,8 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
|||
bool coalesce_write_buffers(span<iovec_t const>& bufs
|
||||
, iovec_t& tmp)
|
||||
{
|
||||
std::size_t const buf_size = aux::numeric_cast<std::size_t>(bufs_size(bufs));
|
||||
char* buf = new char[buf_size];
|
||||
auto const buf_size = aux::numeric_cast<std::size_t>(bufs_size(bufs));
|
||||
auto buf = new char[buf_size];
|
||||
gather_copy(bufs, buf);
|
||||
tmp = { buf, buf_size };
|
||||
bufs = span<iovec_t const>(tmp);
|
||||
|
@ -1162,7 +1162,7 @@ namespace {
|
|||
}
|
||||
}
|
||||
#else // NON-WINDOWS
|
||||
struct stat st;
|
||||
struct stat st{};
|
||||
if (::fstat(native_handle(), &st) != 0)
|
||||
{
|
||||
ec.assign(errno, system_category());
|
||||
|
@ -1257,7 +1257,7 @@ namespace {
|
|||
}
|
||||
return file_size.QuadPart;
|
||||
#else
|
||||
struct stat fs;
|
||||
struct stat fs = {};
|
||||
if (::fstat(native_handle(), &fs) != 0)
|
||||
{
|
||||
ec.assign(errno, system_category());
|
||||
|
|
|
@ -39,10 +39,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
namespace libtorrent { namespace aux {
|
||||
|
||||
file_progress::file_progress()
|
||||
{
|
||||
}
|
||||
|
||||
void file_progress::init(piece_picker const& picker, file_storage const& fs)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
|
|
@ -483,7 +483,7 @@ namespace {
|
|||
TORRENT_ASSERT(file_iter != m_files.end());
|
||||
if (file_offset < std::int64_t(file_iter->size))
|
||||
{
|
||||
file_slice f;
|
||||
file_slice f{};
|
||||
f.file_index = file_index_t(int(file_iter - m_files.begin()));
|
||||
f.offset = file_offset;
|
||||
f.size = std::min(std::int64_t(file_iter->size) - file_offset, std::int64_t(size));
|
||||
|
@ -530,7 +530,7 @@ namespace {
|
|||
TORRENT_ASSERT_PRECOND(file_index < end_file());
|
||||
TORRENT_ASSERT(m_num_pieces >= 0);
|
||||
|
||||
peer_request ret;
|
||||
peer_request ret{};
|
||||
if (file_index >= end_file())
|
||||
{
|
||||
ret.piece = piece_index_t{m_num_pieces};
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace libtorrent {
|
|||
const char* name() const BOOST_SYSTEM_NOEXCEPT override;
|
||||
std::string message(int ev) const override;
|
||||
boost::system::error_condition default_error_condition(int ev) const BOOST_SYSTEM_NOEXCEPT override
|
||||
{ return boost::system::error_condition(ev, *this); }
|
||||
{ return {ev, *this}; }
|
||||
};
|
||||
|
||||
const char* gzip_error_category::name() const BOOST_SYSTEM_NOEXCEPT
|
||||
|
@ -104,7 +104,7 @@ namespace libtorrent {
|
|||
{
|
||||
boost::system::error_code make_error_code(error_code_enum e)
|
||||
{
|
||||
return boost::system::error_code(e, gzip_category());
|
||||
return {e, gzip_category()};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ namespace {
|
|||
{
|
||||
if (buffer.size() < 2) return -1;
|
||||
|
||||
std::size_t const extra_len = static_cast<std::size_t>((buffer[1] << 8) | buffer[0]);
|
||||
auto const extra_len = static_cast<std::size_t>((buffer[1] << 8) | buffer[0]);
|
||||
if (buffer.size() < extra_len + 2) return -1;
|
||||
buffer = buffer.subspan(extra_len + 2);
|
||||
}
|
||||
|
|
|
@ -130,12 +130,14 @@ namespace libtorrent {
|
|||
#endif
|
||||
}
|
||||
|
||||
#if defined TORRENT_USE_LIBGCRYPT
|
||||
hasher512::~hasher512()
|
||||
{
|
||||
#if defined TORRENT_USE_LIBGCRYPT
|
||||
gcry_md_close(m_context);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
hasher512::~hasher512() = default;
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_MACOS_DEPRECATED_LIBCRYPTO
|
||||
#pragma clang diagnostic pop
|
||||
|
|
|
@ -98,8 +98,7 @@ namespace libtorrent {
|
|||
|
||||
piece_block_progress http_seed_connection::downloading_piece_progress() const
|
||||
{
|
||||
if (m_requests.empty())
|
||||
return piece_block_progress();
|
||||
if (m_requests.empty()) return {};
|
||||
|
||||
std::shared_ptr<torrent> t = associated_torrent().lock();
|
||||
TORRENT_ASSERT(t);
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace libtorrent {
|
|||
, tracker_manager& man
|
||||
, tracker_request const& req
|
||||
, std::weak_ptr<request_callback> c)
|
||||
: tracker_connection(man, req, ios, c)
|
||||
: tracker_connection(man, req, ios, std::move(c))
|
||||
{}
|
||||
|
||||
void http_tracker_connection::start()
|
||||
|
|
|
@ -75,7 +75,7 @@ namespace libtorrent {
|
|||
}
|
||||
boost::system::error_condition default_error_condition(
|
||||
int ev) const BOOST_SYSTEM_NOEXCEPT override
|
||||
{ return boost::system::error_condition(ev, *this); }
|
||||
{ return {ev, *this}; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -89,7 +89,7 @@ namespace libtorrent {
|
|||
{
|
||||
boost::system::error_code make_error_code(i2p_error_code e)
|
||||
{
|
||||
return error_code(e, i2p_category());
|
||||
return {e, i2p_category()};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,8 +180,8 @@ namespace libtorrent {
|
|||
if (m_state == sam_idle && m_name_lookup.empty() && is_open())
|
||||
do_name_lookup(name, std::move(handler));
|
||||
else
|
||||
m_name_lookup.push_back(std::make_pair(std::string(name)
|
||||
, std::move(handler)));
|
||||
m_name_lookup.emplace_back(std::string(name)
|
||||
, std::move(handler));
|
||||
}
|
||||
|
||||
void i2p_connection::do_name_lookup(std::string const& name
|
||||
|
@ -203,7 +203,7 @@ namespace libtorrent {
|
|||
if (!m_name_lookup.empty())
|
||||
{
|
||||
std::pair<std::string, name_lookup_handler>& nl = m_name_lookup.front();
|
||||
do_name_lookup(std::move(nl.first), std::move(nl.second));
|
||||
do_name_lookup(nl.first, std::move(nl.second));
|
||||
m_name_lookup.pop_front();
|
||||
}
|
||||
|
||||
|
@ -227,13 +227,13 @@ namespace libtorrent {
|
|||
#endif
|
||||
}
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
i2p_stream::~i2p_stream()
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
m_magic = 0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void i2p_stream::do_connect(error_code const& e, tcp::resolver::iterator i
|
||||
, handler_type h)
|
||||
|
@ -285,7 +285,7 @@ namespace libtorrent {
|
|||
COMPLETE_ASYNC("i2p_stream::read_line");
|
||||
if (handle_error(e, h)) return;
|
||||
|
||||
int const read_pos = int(m_buffer.size());
|
||||
auto const read_pos = int(m_buffer.size());
|
||||
|
||||
// look for \n which means end of the response
|
||||
if (m_buffer[read_pos - 1] != '\n')
|
||||
|
|
|
@ -383,11 +383,8 @@ namespace aux {
|
|||
// non standard encodings
|
||||
// ----------------------
|
||||
|
||||
const int num_generic_mappings = sizeof(generic_mappings) / sizeof(generic_mappings[0]);
|
||||
|
||||
for (int i = 0; i < num_generic_mappings; ++i)
|
||||
for (auto const& e : generic_mappings)
|
||||
{
|
||||
generic_map_entry const& e = generic_mappings[i];
|
||||
if (find_string(PID + e.offset, e.id)) return e.name;
|
||||
}
|
||||
|
||||
|
@ -396,8 +393,8 @@ namespace aux {
|
|||
|
||||
if (find_string(PID, "eX"))
|
||||
{
|
||||
std::string user(PID + 2, PID + 14);
|
||||
return std::string("eXeem ('") + user.c_str() + "')";
|
||||
std::string user(PID + 2, 12);
|
||||
return std::string("eXeem ('") + user + "')";
|
||||
}
|
||||
bool const is_equ_zero = std::equal(PID, PID + 12, "\0\0\0\0\0\0\0\0\0\0\0\0");
|
||||
|
||||
|
@ -424,10 +421,8 @@ namespace aux {
|
|||
return "Generic";
|
||||
|
||||
std::string unknown("Unknown [");
|
||||
for (peer_id::const_iterator i = p.begin(); i != p.end(); ++i)
|
||||
{
|
||||
unknown += is_print(char(*i)) ? char(*i) : '.';
|
||||
}
|
||||
for (unsigned char const c : p)
|
||||
unknown += is_print(char(c)) ? char(c) : '.';
|
||||
unknown += "]";
|
||||
return unknown;
|
||||
}
|
||||
|
|
|
@ -123,10 +123,20 @@ template <typename T
|
|||
, void (*Retain)(T) = CFRefRetain<T>, void (*Release)(T) = CFRefRelease<T>>
|
||||
struct CFRef
|
||||
{
|
||||
CFRef() {}
|
||||
CFRef() = default;
|
||||
explicit CFRef(T h) : m_h(h) {} // take ownership
|
||||
~CFRef() { release(); }
|
||||
|
||||
CFRef(CFRef&& rhs) : m_h(rhs.m_h) { rhs.m_h = nullptr; }
|
||||
CFRef& operator=(CFRef&& rhs)
|
||||
{
|
||||
if (m_h == rhs.m_h) return *this;
|
||||
release();
|
||||
m_h = rhs.m_h;
|
||||
rhs.m_h = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CFRef(CFRef const& rhs) : m_h(rhs.m_h) { retain(); }
|
||||
CFRef& operator=(CFRef const& rhs)
|
||||
{
|
||||
|
|
|
@ -114,7 +114,7 @@ namespace libtorrent {
|
|||
sha1_hash const k = hash_address(source);
|
||||
|
||||
// do we already have an entry for this external IP?
|
||||
std::vector<external_ip_t>::iterator i = std::find_if(m_external_addresses.begin()
|
||||
auto i = std::find_if(m_external_addresses.begin()
|
||||
, m_external_addresses.end(), [&ip] (external_ip_t const& e) { return e.addr == ip; });
|
||||
|
||||
if (i == m_external_addresses.end())
|
||||
|
@ -137,7 +137,7 @@ namespace libtorrent {
|
|||
// ones with the fewest votes
|
||||
m_external_addresses.erase(m_external_addresses.end() - 1);
|
||||
}
|
||||
m_external_addresses.push_back(external_ip_t());
|
||||
m_external_addresses.emplace_back();
|
||||
i = m_external_addresses.end() - 1;
|
||||
i->addr = ip;
|
||||
}
|
||||
|
|
|
@ -42,13 +42,13 @@ namespace libtorrent { namespace dht {
|
|||
if (e.type() != bdecode_node::dict_t) return node_ids_t();
|
||||
node_ids_t ret;
|
||||
// first look for an old-style nid
|
||||
auto old_nid = e.dict_find_string_value(key);
|
||||
auto const old_nid = e.dict_find_string_value(key);
|
||||
if (old_nid.size() == 20)
|
||||
{
|
||||
ret.emplace_back(address(), node_id(old_nid));
|
||||
return ret;
|
||||
}
|
||||
auto nids = e.dict_find_list(key);
|
||||
auto const nids = e.dict_find_list(key);
|
||||
if (!nids) return ret;
|
||||
for (int i = 0; i < nids.list_size(); i++)
|
||||
{
|
||||
|
@ -83,7 +83,7 @@ namespace {
|
|||
std::string node;
|
||||
std::back_insert_iterator<std::string> out(node);
|
||||
detail::write_endpoint(ep, out);
|
||||
list.push_back(entry(node));
|
||||
list.emplace_back(node);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace {
|
|||
{
|
||||
time_point added;
|
||||
tcp::endpoint addr;
|
||||
bool seed;
|
||||
bool seed = 0;
|
||||
};
|
||||
|
||||
// internal
|
||||
|
@ -100,9 +100,9 @@ namespace {
|
|||
|
||||
struct dht_mutable_item : dht_immutable_item
|
||||
{
|
||||
signature sig;
|
||||
sequence_number seq;
|
||||
public_key key;
|
||||
signature sig{};
|
||||
sequence_number seq{};
|
||||
public_key key{};
|
||||
std::string salt;
|
||||
};
|
||||
|
||||
|
@ -156,7 +156,7 @@ namespace {
|
|||
private:
|
||||
|
||||
// explicitly disallow assignment, to silence msvc warning
|
||||
immutable_item_comparator& operator=(immutable_item_comparator const&);
|
||||
immutable_item_comparator& operator=(immutable_item_comparator const&) = delete;
|
||||
|
||||
std::vector<node_id> const& m_node_ids;
|
||||
};
|
||||
|
@ -270,7 +270,7 @@ namespace {
|
|||
if (random(std::uint32_t(candidates--)) > std::uint32_t(to_pick))
|
||||
continue;
|
||||
|
||||
pe.push_back(entry());
|
||||
pe.emplace_back();
|
||||
std::string& str = pe.back().string();
|
||||
|
||||
str.resize(18);
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace libtorrent { namespace dht {
|
|||
namespace {
|
||||
|
||||
// generate a new write token key every 5 minutes
|
||||
time_duration const key_refresh
|
||||
auto const key_refresh
|
||||
= duration_cast<time_duration>(minutes(5));
|
||||
|
||||
void add_dht_counters(node const& dht, counters& c)
|
||||
|
@ -360,7 +360,8 @@ namespace libtorrent { namespace dht {
|
|||
|
||||
// these functions provide a slightly higher level
|
||||
// interface to the get/put functionality in the DHT
|
||||
void get_immutable_item_callback(item const& it, std::shared_ptr<get_immutable_item_ctx> ctx
|
||||
void get_immutable_item_callback(item const& it
|
||||
, std::shared_ptr<get_immutable_item_ctx> ctx
|
||||
, std::function<void(item const&)> f)
|
||||
{
|
||||
// the reason to wrap here is to control the return value
|
||||
|
|
|
@ -43,10 +43,10 @@ namespace libtorrent { namespace dht {
|
|||
: m_message_rate_limit(5)
|
||||
, m_block_timeout(5 * 60)
|
||||
{
|
||||
for (int i = 0; i < num_ban_nodes; ++i)
|
||||
for (auto& e : m_ban_nodes)
|
||||
{
|
||||
m_ban_nodes[i].count = 0;
|
||||
m_ban_nodes[i].limit = min_time();
|
||||
e.count = 0;
|
||||
e.limit = min_time();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -171,8 +171,8 @@ void get_item::done()
|
|||
|
||||
void get_item_observer::reply(msg const& m)
|
||||
{
|
||||
public_key pk;
|
||||
signature sig;
|
||||
public_key pk{};
|
||||
signature sig{};
|
||||
sequence_number seq{0};
|
||||
|
||||
bdecode_node const r = m.message.dict_find_dict("r");
|
||||
|
|
|
@ -115,7 +115,7 @@ node::node(aux::listen_socket_handle const& sock, socket_manager* sock_man
|
|||
, m_rpc(m_id, m_settings, m_table, sock, sock_man, observer)
|
||||
, m_sock(sock)
|
||||
, m_sock_man(sock_man)
|
||||
, m_get_foreign_node(get_foreign_node)
|
||||
, m_get_foreign_node(std::move(get_foreign_node))
|
||||
, m_observer(observer)
|
||||
, m_protocol(map_protocol_to_descriptor(sock.get_local_endpoint().protocol() == tcp::v4() ? udp::v4() : udp::v6()))
|
||||
, m_last_tracker_tick(aux::time_now())
|
||||
|
@ -286,7 +286,7 @@ void node::incoming(aux::listen_socket_handle const& s, msg const& m)
|
|||
if (ext_ip && ext_ip.string_length() >= 16)
|
||||
{
|
||||
// this node claims we use the wrong node-ID!
|
||||
address_v6::bytes_type b;
|
||||
address_v6::bytes_type b{};
|
||||
std::memcpy(&b[0], ext_ip.string_ptr(), 16);
|
||||
if (m_observer != nullptr)
|
||||
m_observer->set_external_address(m_sock, address_v6(b)
|
||||
|
@ -295,7 +295,7 @@ void node::incoming(aux::listen_socket_handle const& s, msg const& m)
|
|||
#endif
|
||||
if (ext_ip && ext_ip.string_length() >= 4)
|
||||
{
|
||||
address_v4::bytes_type b;
|
||||
address_v4::bytes_type b{};
|
||||
std::memcpy(&b[0], ext_ip.string_ptr(), 4);
|
||||
if (m_observer != nullptr)
|
||||
m_observer->set_external_address(m_sock, address_v4(b)
|
||||
|
@ -507,15 +507,15 @@ void node::get_item(public_key const& pk, std::string const& salt
|
|||
namespace {
|
||||
|
||||
void put(std::vector<std::pair<node_entry, std::string>> const& nodes
|
||||
, std::shared_ptr<put_data> ta)
|
||||
, std::shared_ptr<put_data> const& ta)
|
||||
{
|
||||
ta->set_targets(nodes);
|
||||
ta->start();
|
||||
}
|
||||
|
||||
void put_data_cb(item i, bool auth
|
||||
, std::shared_ptr<put_data> ta
|
||||
, std::function<void(item&)> f)
|
||||
, std::shared_ptr<put_data> const& ta
|
||||
, std::function<void(item&)> const& f)
|
||||
{
|
||||
// call data_callback only when we got authoritative data.
|
||||
if (auth)
|
||||
|
@ -724,7 +724,7 @@ void node::status(std::vector<dht_routing_bucket>& table
|
|||
|
||||
for (auto const& r : m_running_requests)
|
||||
{
|
||||
requests.push_back(dht_lookup());
|
||||
requests.emplace_back();
|
||||
dht_lookup& lookup = requests.back();
|
||||
r->status(lookup);
|
||||
}
|
||||
|
@ -745,12 +745,11 @@ void node::status(session_status& s)
|
|||
|
||||
m_table.status(s);
|
||||
s.dht_total_allocations += m_rpc.num_allocated_observers();
|
||||
for (std::set<traversal_algorithm*>::iterator i = m_running_requests.begin()
|
||||
, end(m_running_requests.end()); i != end; ++i)
|
||||
for (auto& r : m_running_requests)
|
||||
{
|
||||
s.active_requests.push_back(dht_lookup());
|
||||
s.active_requests.emplace_back();
|
||||
dht_lookup& lookup = s.active_requests.back();
|
||||
(*i)->status(lookup);
|
||||
r->status(lookup);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -912,7 +911,7 @@ void node::incoming_request(msg const& m, entry& e)
|
|||
return;
|
||||
}
|
||||
|
||||
int port = int(msg_keys[1].int_value());
|
||||
auto port = int(msg_keys[1].int_value());
|
||||
|
||||
// is the announcer asking to ignore the explicit
|
||||
// listen port and instead use the source port of the packet?
|
||||
|
|
|
@ -91,9 +91,9 @@ node_id generate_id_impl(address const& ip_, std::uint32_t r)
|
|||
std::uint8_t const* mask = nullptr;
|
||||
int num_octets = 0;
|
||||
|
||||
address_v4::bytes_type b4;
|
||||
address_v4::bytes_type b4{};
|
||||
#if TORRENT_USE_IPV6
|
||||
address_v6::bytes_type b6;
|
||||
address_v6::bytes_type b6{};
|
||||
if (ip_.is_v6())
|
||||
{
|
||||
b6 = ip_.to_v6().to_bytes();
|
||||
|
|
|
@ -87,7 +87,7 @@ bool put_data::invoke(observer_ptr o)
|
|||
|
||||
// TODO: what if o is not an instance of put_data_observer? This need to be
|
||||
// redesigned for better type safety.
|
||||
put_data_observer* po = static_cast<put_data_observer*>(o.get());
|
||||
auto* po = static_cast<put_data_observer*>(o.get());
|
||||
|
||||
entry e;
|
||||
e["y"] = "q";
|
||||
|
|
|
@ -246,21 +246,21 @@ node_entry const* routing_table::next_refresh()
|
|||
// this will have a bias towards pinging nodes close to us first.
|
||||
for (auto i = m_buckets.rbegin(), end(m_buckets.rend()); i != end; ++i)
|
||||
{
|
||||
for (auto j = i->live_nodes.begin(), end2(i->live_nodes.end()); j != end2; ++j)
|
||||
for (auto& n : i->live_nodes)
|
||||
{
|
||||
// this shouldn't happen
|
||||
TORRENT_ASSERT(m_id != j->id);
|
||||
if (j->id == m_id) continue;
|
||||
TORRENT_ASSERT(m_id != n.id);
|
||||
if (n.id == m_id) continue;
|
||||
|
||||
if (j->last_queried == min_time())
|
||||
if (n.last_queried == min_time())
|
||||
{
|
||||
candidate = &*j;
|
||||
candidate = &n;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (candidate == nullptr || j->last_queried < candidate->last_queried)
|
||||
if (candidate == nullptr || n.last_queried < candidate->last_queried)
|
||||
{
|
||||
candidate = &*j;
|
||||
candidate = &n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -329,19 +329,16 @@ bool compare_ip_cidr(address const& lhs, address const& rhs)
|
|||
node_entry* routing_table::find_node(udp::endpoint const& ep
|
||||
, routing_table::table_t::iterator* bucket)
|
||||
{
|
||||
for (table_t::iterator i = m_buckets.begin()
|
||||
, end(m_buckets.end()); i != end; ++i)
|
||||
for (auto i = m_buckets.begin() , end(m_buckets.end()); i != end; ++i)
|
||||
{
|
||||
for (bucket_t::iterator j = i->replacements.begin();
|
||||
j != i->replacements.end(); ++j)
|
||||
for (auto j = i->replacements.begin(); j != i->replacements.end(); ++j)
|
||||
{
|
||||
if (j->addr() != ep.address()) continue;
|
||||
if (j->port() != ep.port()) continue;
|
||||
*bucket = i;
|
||||
return &*j;
|
||||
}
|
||||
for (bucket_t::iterator j = i->live_nodes.begin();
|
||||
j != i->live_nodes.end(); ++j)
|
||||
for (auto j = i->live_nodes.begin(); j != i->live_nodes.end(); ++j)
|
||||
{
|
||||
if (j->addr() != ep.address()) continue;
|
||||
if (j->port() != ep.port()) continue;
|
||||
|
|
|
@ -264,7 +264,7 @@ namespace {
|
|||
else if (int(m_size) == this->capacity())
|
||||
{
|
||||
int const capacity = this->capacity() * lazy_entry_grow_factor / 100;
|
||||
lazy_dict_entry* tmp = new (std::nothrow) lazy_dict_entry[capacity + 1];
|
||||
auto* tmp = new (std::nothrow) lazy_dict_entry[capacity + 1];
|
||||
if (tmp == nullptr) return nullptr;
|
||||
std::memcpy(tmp, m_data.dict, sizeof(lazy_dict_entry) * (m_size + 1));
|
||||
for (int i = 0; i < int(m_size); ++i) m_data.dict[i + 1].val.release();
|
||||
|
@ -349,7 +349,7 @@ namespace {
|
|||
pascal_string lazy_entry::dict_find_pstr(char const* name) const
|
||||
{
|
||||
lazy_entry const* e = dict_find(name);
|
||||
if (e == nullptr || e->type() != lazy_entry::string_t) return pascal_string(nullptr, 0);
|
||||
if (e == nullptr || e->type() != lazy_entry::string_t) return {nullptr, 0};
|
||||
return e->string_pstr();
|
||||
}
|
||||
|
||||
|
@ -459,7 +459,7 @@ namespace {
|
|||
pascal_string lazy_entry::list_pstr_at(int i) const
|
||||
{
|
||||
lazy_entry const* e = list_at(i);
|
||||
if (e == nullptr || e->type() != lazy_entry::string_t) return pascal_string(nullptr, 0);
|
||||
if (e == nullptr || e->type() != lazy_entry::string_t) return {nullptr, 0};
|
||||
return e->string_pstr();
|
||||
}
|
||||
|
||||
|
@ -489,8 +489,7 @@ namespace {
|
|||
|
||||
std::pair<char const*, int> lazy_entry::data_section() const
|
||||
{
|
||||
typedef std::pair<char const*, int> return_t;
|
||||
return return_t(m_begin, m_len);
|
||||
return {m_begin, m_len};
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -131,7 +131,7 @@ namespace libtorrent {
|
|||
, storage_constructor_type sc
|
||||
, void* userdata)
|
||||
{
|
||||
add_torrent_params params(sc);
|
||||
add_torrent_params params(std::move(sc));
|
||||
params.storage_mode = storage_mode;
|
||||
params.userdata = userdata;
|
||||
params.save_path = save_path;
|
||||
|
|
|
@ -316,7 +316,7 @@ namespace libtorrent {
|
|||
auto bytes_read = std::size_t(m_file.readv(slot_offset + piece_offset, v, ec));
|
||||
v = v.first(bytes_read);
|
||||
TORRENT_ASSERT(!ec);
|
||||
if (ec || v.size() == 0) return;
|
||||
if (ec || v.empty()) return;
|
||||
|
||||
f(file_offset, {buf.get(), std::size_t(block_to_copy)});
|
||||
|
||||
|
|
|
@ -347,7 +347,7 @@ namespace libtorrent {
|
|||
// most errors are passed through, except for the ones that indicate that
|
||||
// hard links are not supported and require a copy.
|
||||
// TODO: 2 test this on a FAT volume to see what error we get!
|
||||
if (errno != EMLINK || errno != EXDEV)
|
||||
if (errno != EMLINK && errno != EXDEV)
|
||||
{
|
||||
// some error happened, report up to the caller
|
||||
ec.assign(errno, system_category());
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace libtorrent {
|
|||
std::array<char, 96> export_key(key_t const& k)
|
||||
{
|
||||
std::array<char, 96> ret;
|
||||
std::uint8_t* begin = reinterpret_cast<std::uint8_t*>(ret.data());
|
||||
auto* begin = reinterpret_cast<std::uint8_t*>(ret.data());
|
||||
std::uint8_t* end = mp::export_bits(k, begin, 8);
|
||||
|
||||
// TODO: it would be nice to be able to export to a fixed width field, so
|
||||
|
@ -161,7 +161,7 @@ namespace libtorrent {
|
|||
|
||||
int next_barrier = 0;
|
||||
span<span<char const>> out_iovec;
|
||||
if (bufs.size() != 0)
|
||||
if (!bufs.empty())
|
||||
{
|
||||
std::tie(next_barrier, out_iovec)
|
||||
= m_send_barriers.front().enc_handler->encrypt(bufs);
|
||||
|
@ -238,9 +238,8 @@ namespace libtorrent {
|
|||
bool place_barrier = false;
|
||||
if (!m_send_barriers.empty())
|
||||
{
|
||||
std::list<barrier>::iterator end = m_send_barriers.end(); --end;
|
||||
for (std::list<barrier>::iterator b = m_send_barriers.begin();
|
||||
b != end; ++b)
|
||||
auto const end = std::prev(m_send_barriers.end());
|
||||
for (auto b = m_send_barriers.begin(); b != end; ++b)
|
||||
pending_encryption -= b->next;
|
||||
TORRENT_ASSERT(pending_encryption >= 0);
|
||||
m_send_barriers.back().next = pending_encryption;
|
||||
|
@ -314,7 +313,7 @@ namespace libtorrent {
|
|||
int bytes_processed = 0;
|
||||
for (auto& buf : bufs)
|
||||
{
|
||||
unsigned char* const pos = reinterpret_cast<unsigned char*>(buf.data());
|
||||
auto* const pos = reinterpret_cast<unsigned char*>(buf.data());
|
||||
int const len = int(buf.size());
|
||||
|
||||
TORRENT_ASSERT(len >= 0);
|
||||
|
@ -333,7 +332,7 @@ namespace libtorrent {
|
|||
int bytes_processed = 0;
|
||||
for (auto& buf : bufs)
|
||||
{
|
||||
unsigned char* const pos = reinterpret_cast<unsigned char*>(buf.data());
|
||||
auto* const pos = reinterpret_cast<unsigned char*>(buf.data());
|
||||
int const len = int(buf.size());
|
||||
|
||||
TORRENT_ASSERT(len >= 0);
|
||||
|
|
|
@ -1277,7 +1277,7 @@ namespace libtorrent {
|
|||
}
|
||||
|
||||
#if TORRENT_USE_I2P
|
||||
i2p_stream* i2ps = m_socket->get<i2p_stream>();
|
||||
auto* i2ps = m_socket->get<i2p_stream>();
|
||||
if (!i2ps && t->torrent_file().is_i2p()
|
||||
&& !m_settings.get_bool(settings_pack::allow_i2p_mixed))
|
||||
{
|
||||
|
@ -4275,7 +4275,7 @@ namespace libtorrent {
|
|||
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
|
||||
if (type() == connection_type::bittorrent && op != operation_t::connect)
|
||||
{
|
||||
bt_peer_connection* bt = static_cast<bt_peer_connection*>(this);
|
||||
auto* bt = static_cast<bt_peer_connection*>(this);
|
||||
if (bt->supports_encryption()) m_counters.inc_stats_counter(
|
||||
counters::error_encrypted_peers);
|
||||
if (bt->rc4_encrypted() && bt->supports_encryption())
|
||||
|
@ -5540,7 +5540,7 @@ namespace libtorrent {
|
|||
{
|
||||
// this const_cast is a here because chained_buffer need to be
|
||||
// fixed.
|
||||
char* ptr = const_cast<char*>(i->data());
|
||||
auto* ptr = const_cast<char*>(i->data());
|
||||
m_send_buffer.prepend_buffer(span<char>(ptr, i->size())
|
||||
, static_cast<int>(i->size()));
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ void peer_connection_handle::add_extension(std::shared_ptr<peer_plugin> ext)
|
|||
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||
std::shared_ptr<peer_connection> pc = native_handle();
|
||||
TORRENT_ASSERT(pc);
|
||||
pc->add_extension(ext);
|
||||
pc->add_extension(std::move(ext));
|
||||
#else
|
||||
TORRENT_UNUSED(ext);
|
||||
#endif
|
||||
|
@ -329,7 +329,7 @@ void bt_peer_connection_handle::switch_send_crypto(std::shared_ptr<crypto_plugin
|
|||
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
|
||||
std::shared_ptr<bt_peer_connection> pc = native_handle();
|
||||
TORRENT_ASSERT(pc);
|
||||
pc->switch_send_crypto(crypto);
|
||||
pc->switch_send_crypto(std::move(crypto));
|
||||
#else
|
||||
TORRENT_UNUSED(crypto);
|
||||
#endif
|
||||
|
@ -340,7 +340,7 @@ void bt_peer_connection_handle::switch_recv_crypto(std::shared_ptr<crypto_plugin
|
|||
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
|
||||
std::shared_ptr<bt_peer_connection> pc = native_handle();
|
||||
TORRENT_ASSERT(pc);
|
||||
pc->switch_recv_crypto(crypto);
|
||||
pc->switch_recv_crypto(std::move(crypto));
|
||||
#else
|
||||
TORRENT_UNUSED(crypto);
|
||||
#endif
|
||||
|
|
|
@ -98,8 +98,7 @@ namespace libtorrent {
|
|||
m_reverse_cursor = m_piece_map.end_index();
|
||||
m_cursor = piece_index_t(0);
|
||||
|
||||
for (int i = 0; i < piece_pos::num_download_categories; ++i)
|
||||
m_downloads[i].clear();
|
||||
for (auto& c : m_downloads) c.clear();
|
||||
m_block_info.clear();
|
||||
m_free_block_infos.clear();
|
||||
|
||||
|
@ -108,14 +107,13 @@ namespace libtorrent {
|
|||
m_num_have = 0;
|
||||
m_num_passed = 0;
|
||||
m_dirty = true;
|
||||
for (std::vector<piece_pos>::iterator i = m_piece_map.begin()
|
||||
, end(m_piece_map.end()); i != end; ++i)
|
||||
for (auto& m : m_piece_map)
|
||||
{
|
||||
i->peer_count = 0;
|
||||
i->download_state = piece_pos::piece_open;
|
||||
i->index = prio_index_t(0);
|
||||
m.peer_count = 0;
|
||||
m.download_state = piece_pos::piece_open;
|
||||
m.index = prio_index_t(0);
|
||||
#ifdef TORRENT_DEBUG_REFCOUNTS
|
||||
i->have_peers.clear();
|
||||
m.have_peers.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -143,7 +141,7 @@ namespace libtorrent {
|
|||
int state = m_piece_map[index].download_queue();
|
||||
if (state != piece_pos::piece_open)
|
||||
{
|
||||
std::vector<downloading_piece>::const_iterator piece = find_dl_piece(state, index);
|
||||
auto piece = find_dl_piece(state, index);
|
||||
TORRENT_ASSERT(piece != m_downloads[state].end());
|
||||
st = *piece;
|
||||
return;
|
||||
|
@ -200,9 +198,8 @@ namespace libtorrent {
|
|||
// always insert into bucket 0 (piece_downloading)
|
||||
downloading_piece ret;
|
||||
ret.index = piece;
|
||||
int download_state = piece_pos::piece_downloading;
|
||||
std::vector<downloading_piece>::iterator downloading_iter
|
||||
= std::lower_bound(m_downloads[download_state].begin()
|
||||
int const download_state = piece_pos::piece_downloading;
|
||||
auto downloading_iter = std::lower_bound(m_downloads[download_state].begin()
|
||||
, m_downloads[download_state].end(), ret);
|
||||
TORRENT_ASSERT(downloading_iter == m_downloads[download_state].end()
|
||||
|| downloading_iter->index != piece);
|
||||
|
@ -236,7 +233,7 @@ namespace libtorrent {
|
|||
check_piece_state();
|
||||
#endif
|
||||
|
||||
int download_state = m_piece_map[i->index].download_queue();
|
||||
int const download_state = m_piece_map[i->index].download_queue();
|
||||
TORRENT_ASSERT(download_state != piece_pos::piece_open);
|
||||
TORRENT_ASSERT(find_dl_piece(download_state, i->index) == i);
|
||||
#if TORRENT_USE_ASSERTS
|
||||
|
@ -265,16 +262,16 @@ namespace libtorrent {
|
|||
#endif
|
||||
|
||||
std::vector<downloading_piece> ret;
|
||||
for (int k = 0; k < piece_pos::num_download_categories; ++k)
|
||||
ret.insert(ret.end(), m_downloads[k].begin(), m_downloads[k].end());
|
||||
for (auto const& c : m_downloads)
|
||||
ret.insert(ret.end(), c.begin(), c.end());
|
||||
return ret;
|
||||
}
|
||||
|
||||
int piece_picker::get_download_queue_size() const
|
||||
{
|
||||
int ret = 0;
|
||||
for (int k = 0; k < piece_pos::num_download_categories; ++k)
|
||||
ret += int(m_downloads[k].size());
|
||||
for (auto const& c : m_downloads)
|
||||
ret += int(c.size());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -845,7 +842,7 @@ namespace libtorrent {
|
|||
print_pieces();
|
||||
#endif
|
||||
TORRENT_ASSERT(elem_index < m_pieces.end_index());
|
||||
prio_index_t temp;
|
||||
prio_index_t temp{};
|
||||
do
|
||||
{
|
||||
temp = --m_priority_boundaries[priority];
|
||||
|
@ -909,7 +906,7 @@ namespace libtorrent {
|
|||
#endif
|
||||
if (priority > new_priority)
|
||||
{
|
||||
prio_index_t new_index;
|
||||
prio_index_t new_index{};
|
||||
piece_index_t temp = index;
|
||||
for (;;)
|
||||
{
|
||||
|
@ -946,7 +943,7 @@ namespace libtorrent {
|
|||
}
|
||||
else
|
||||
{
|
||||
prio_index_t new_index;
|
||||
prio_index_t new_index{};
|
||||
piece_index_t temp = index;
|
||||
for (;;)
|
||||
{
|
||||
|
@ -1168,11 +1165,8 @@ namespace libtorrent {
|
|||
TORRENT_ASSERT(m_seeds > 0);
|
||||
--m_seeds;
|
||||
|
||||
for (std::vector<piece_pos>::iterator i = m_piece_map.begin()
|
||||
, end(m_piece_map.end()); i != end; ++i)
|
||||
{
|
||||
++i->peer_count;
|
||||
}
|
||||
for (auto& m : m_piece_map)
|
||||
++m.peer_count;
|
||||
|
||||
m_dirty = true;
|
||||
}
|
||||
|
@ -1200,7 +1194,7 @@ namespace libtorrent {
|
|||
break_one_seed();
|
||||
}
|
||||
|
||||
int prev_priority = p.priority(this);
|
||||
int const prev_priority = p.priority(this);
|
||||
|
||||
#ifdef TORRENT_DEBUG_REFCOUNTS
|
||||
TORRENT_ASSERT(p.have_peers.count(peer) == 1);
|
||||
|
@ -1753,8 +1747,7 @@ namespace libtorrent {
|
|||
|
||||
if (p.downloading())
|
||||
{
|
||||
std::vector<downloading_piece>::iterator i = find_dl_piece(
|
||||
p.download_queue(), index);
|
||||
auto i = find_dl_piece(p.download_queue(), index);
|
||||
if (i != m_downloads[p.download_queue()].end())
|
||||
update_piece_state(i);
|
||||
}
|
||||
|
@ -1916,23 +1909,21 @@ namespace {
|
|||
// now, copy over the pointers. We also apply a filter here to not
|
||||
// include ineligible pieces in certain modes. For instance, a piece
|
||||
// that the current peer doesn't have is not included.
|
||||
for (std::vector<downloading_piece>::const_iterator i
|
||||
= m_downloads[piece_pos::piece_downloading].begin()
|
||||
, end(m_downloads[piece_pos::piece_downloading].end()); i != end; ++i)
|
||||
for (auto& dp : m_downloads[piece_pos::piece_downloading])
|
||||
{
|
||||
pc.inc_stats_counter(counters::piece_picker_partial_loops);
|
||||
|
||||
// in time critical mode, only pick high priority pieces
|
||||
if ((options & time_critical_mode)
|
||||
&& piece_priority(i->index) != top_priority)
|
||||
&& piece_priority(dp.index) != top_priority)
|
||||
continue;
|
||||
|
||||
if (!is_piece_free(i->index, pieces)) continue;
|
||||
if (!is_piece_free(dp.index, pieces)) continue;
|
||||
|
||||
TORRENT_ASSERT(m_piece_map[i->index].download_queue()
|
||||
TORRENT_ASSERT(m_piece_map[dp.index].download_queue()
|
||||
== piece_pos::piece_downloading);
|
||||
|
||||
ordered_partials[num_ordered_partials++] = &*i;
|
||||
ordered_partials[num_ordered_partials++] = &dp;
|
||||
}
|
||||
|
||||
// now, sort the list.
|
||||
|
@ -2179,7 +2170,7 @@ namespace {
|
|||
{
|
||||
pc.inc_stats_counter(counters::piece_picker_rand_loops);
|
||||
TORRENT_ASSERT(is_piece_free(k, pieces));
|
||||
interesting_blocks.push_back(piece_block(k, j));
|
||||
interesting_blocks.emplace_back(k, j);
|
||||
--num_blocks;
|
||||
--prefer_contiguous_blocks;
|
||||
if (prefer_contiguous_blocks <= 0
|
||||
|
@ -2328,7 +2319,7 @@ get_out:
|
|||
TORRENT_ASSERT(info.piece_index == dp->index);
|
||||
if (info.state != block_info::state_requested || info.peer == peer)
|
||||
continue;
|
||||
temp.push_back(piece_block(dp->index, idx));
|
||||
temp.emplace_back(dp->index, idx);
|
||||
}
|
||||
// are we done?
|
||||
if (!temp.empty())
|
||||
|
@ -2453,20 +2444,18 @@ get_out:
|
|||
#if TORRENT_USE_INVARIANT_CHECKS
|
||||
void piece_picker::check_peers()
|
||||
{
|
||||
for (std::vector<block_info>::iterator i = m_block_info.begin()
|
||||
, end(m_block_info.end()); i != end; ++i)
|
||||
for (auto const& b : m_block_info)
|
||||
{
|
||||
TORRENT_ASSERT(i->peer == nullptr || static_cast<torrent_peer*>(i->peer)->in_use);
|
||||
TORRENT_ASSERT(b.peer == nullptr || static_cast<torrent_peer*>(b.peer)->in_use);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void piece_picker::clear_peer(torrent_peer* peer)
|
||||
{
|
||||
for (std::vector<block_info>::iterator i = m_block_info.begin()
|
||||
, end(m_block_info.end()); i != end; ++i)
|
||||
for (auto& b : m_block_info)
|
||||
{
|
||||
if (i->peer == peer) i->peer = nullptr;
|
||||
if (b.peer == peer) b.peer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2547,8 +2536,7 @@ get_out:
|
|||
// looked through the downloading pieces
|
||||
if (options & prioritize_partials) return num_blocks;
|
||||
|
||||
std::vector<downloading_piece>::const_iterator i = find_dl_piece(
|
||||
piece_pos::piece_downloading, piece);
|
||||
auto i = find_dl_piece(piece_pos::piece_downloading, piece);
|
||||
TORRENT_ASSERT(i != m_downloads[state].end());
|
||||
|
||||
return add_blocks_downloading(*i, pieces
|
||||
|
@ -2565,7 +2553,7 @@ get_out:
|
|||
num_blocks_in_piece = num_blocks;
|
||||
TORRENT_ASSERT(is_piece_free(piece, pieces));
|
||||
for (int j = 0; j < num_blocks_in_piece; ++j)
|
||||
interesting_blocks.push_back(piece_block(piece, j));
|
||||
interesting_blocks.emplace_back(piece, j);
|
||||
num_blocks -= num_blocks_in_piece;
|
||||
}
|
||||
else
|
||||
|
@ -2580,7 +2568,7 @@ get_out:
|
|||
TORRENT_ASSERT(is_piece_free(k, pieces));
|
||||
for (int j = 0; j < num_blocks_in_piece; ++j)
|
||||
{
|
||||
interesting_blocks.push_back(piece_block(k, j));
|
||||
interesting_blocks.emplace_back(k, j);
|
||||
--num_blocks;
|
||||
--prefer_contiguous_blocks;
|
||||
if (prefer_contiguous_blocks == 0
|
||||
|
@ -2652,7 +2640,7 @@ get_out:
|
|||
block_info const& info = binfo[block_idx];
|
||||
TORRENT_ASSERT(info.piece_index == dp.index);
|
||||
if (info.state != block_info::state_none) continue;
|
||||
backup_blocks2.push_back(piece_block(dp.index, block_idx));
|
||||
backup_blocks2.emplace_back(dp.index, block_idx);
|
||||
}
|
||||
return num_blocks;
|
||||
}
|
||||
|
@ -2666,7 +2654,7 @@ get_out:
|
|||
if (info.state != block_info::state_none) continue;
|
||||
|
||||
// this block is interesting (we don't have it yet).
|
||||
interesting_blocks.push_back(piece_block(dp.index, block_idx));
|
||||
interesting_blocks.emplace_back(dp.index, block_idx);
|
||||
// we have found a block that's free to download
|
||||
--num_blocks;
|
||||
// if we prefer contiguous blocks, continue picking from this
|
||||
|
@ -2875,8 +2863,7 @@ get_out:
|
|||
// the new state
|
||||
downloading_piece cmp;
|
||||
cmp.index = dp_info.index;
|
||||
std::vector<downloading_piece>::iterator i = std::lower_bound(
|
||||
m_downloads[p.download_queue()].begin()
|
||||
auto i = std::lower_bound(m_downloads[p.download_queue()].begin()
|
||||
, m_downloads[p.download_queue()].end(), cmp);
|
||||
TORRENT_ASSERT(i == m_downloads[p.download_queue()].end()
|
||||
|| i->index != dp_info.index);
|
||||
|
@ -3548,9 +3535,9 @@ get_out:
|
|||
int piece_picker::unverified_blocks() const
|
||||
{
|
||||
int counter = 0;
|
||||
for (int k = 0; k < piece_pos::num_download_categories; ++k)
|
||||
for (auto const& c : m_downloads)
|
||||
{
|
||||
for (auto const& dp : m_downloads[k])
|
||||
for (auto const& dp : c)
|
||||
{
|
||||
counter += int(dp.finished);
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace libtorrent {
|
|||
return 256;
|
||||
#elif TORRENT_USE_RLIMIT
|
||||
|
||||
struct rlimit rl;
|
||||
struct rlimit rl{};
|
||||
if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
|
||||
{
|
||||
if (rl.rlim_cur == rlim_infinity)
|
||||
|
@ -125,7 +125,7 @@ namespace libtorrent {
|
|||
#if TORRENT_USE_RLIMIT
|
||||
if (ret > 0)
|
||||
{
|
||||
struct rlimit r;
|
||||
struct rlimit r{};
|
||||
if (getrlimit(rlimit_as, &r) == 0 && r.rlim_cur != rlim_infinity)
|
||||
{
|
||||
if (ret > std::int64_t(r.rlim_cur))
|
||||
|
|
18
src/puff.cpp
18
src/puff.cpp
|
@ -82,8 +82,8 @@
|
|||
// this whole file is just preserved and warnings are suppressed
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
#include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */
|
||||
#include <string.h> /* for NULL */
|
||||
#include <csetjmp> /* for setjmp(), longjmp(), and jmp_buf */
|
||||
#include <cstring> /* for nullptr */
|
||||
#include "libtorrent/puff.hpp" /* prototype for puff() */
|
||||
|
||||
#define local static /* for local function definitions */
|
||||
|
@ -113,7 +113,7 @@ struct state {
|
|||
int bitcnt; /* number of bits in bit buffer */
|
||||
|
||||
/* input limit error return state for bits() and decode() */
|
||||
jmp_buf env;
|
||||
std::jmp_buf env;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -135,7 +135,7 @@ local int bits(struct state *s, int need)
|
|||
val = s->bitbuf;
|
||||
while (s->bitcnt < need) {
|
||||
if (s->incnt == s->inlen)
|
||||
longjmp(s->env, 1); /* out of input */
|
||||
std::longjmp(s->env, 1); /* out of input */
|
||||
val |= long(s->in[s->incnt++]) << s->bitcnt; /* load eight bits */
|
||||
s->bitcnt += 8;
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ local int stored(struct state *s)
|
|||
/* copy len bytes from in to out */
|
||||
if (s->incnt + len > s->inlen)
|
||||
return 2; /* not enough input */
|
||||
if (s->out != NULL) {
|
||||
if (s->out != nullptr) {
|
||||
if (s->outcnt + len > s->outlen)
|
||||
return 1; /* not enough output space */
|
||||
while (len--)
|
||||
|
@ -280,7 +280,7 @@ local int decode(struct state *s, const struct huffman *h)
|
|||
code = first = index = 0;
|
||||
len = 1;
|
||||
next = h->count + 1;
|
||||
while (1) {
|
||||
for (;;) {
|
||||
while (left--) {
|
||||
code |= bitbuf & 1;
|
||||
bitbuf >>= 1;
|
||||
|
@ -300,7 +300,7 @@ local int decode(struct state *s, const struct huffman *h)
|
|||
if (left == 0)
|
||||
break;
|
||||
if (s->incnt == s->inlen)
|
||||
longjmp(s->env, 1); /* out of input */
|
||||
std::longjmp(s->env, 1); /* out of input */
|
||||
bitbuf = s->in[s->incnt++];
|
||||
if (left > 8)
|
||||
left = 8;
|
||||
|
@ -466,7 +466,7 @@ local int codes(struct state *s,
|
|||
return symbol; /* invalid symbol */
|
||||
if (symbol < 256) { /* literal: symbol is the byte */
|
||||
/* write out the literal */
|
||||
if (s->out != NULL) {
|
||||
if (s->out != nullptr) {
|
||||
if (s->outcnt == s->outlen)
|
||||
return 1;
|
||||
s->out[s->outcnt] = symbol;
|
||||
|
@ -491,7 +491,7 @@ local int codes(struct state *s,
|
|||
#endif
|
||||
|
||||
/* copy length bytes from distance bytes back */
|
||||
if (s->out != NULL) {
|
||||
if (s->out != nullptr) {
|
||||
if (s->outcnt + len > s->outlen)
|
||||
return 1;
|
||||
while (len--) {
|
||||
|
|
|
@ -204,17 +204,18 @@ namespace libtorrent {
|
|||
|
||||
for (std::vector<piece_block>::iterator i = interesting_pieces.begin();
|
||||
i != interesting_pieces.end(); ++i)
|
||||
for (piece_block const& pb : interesting_pieces)
|
||||
{
|
||||
if (prefer_contiguous_blocks == 0 && num_requests <= 0) break;
|
||||
|
||||
if (time_critical_mode && p.piece_priority(i->piece_index) != top_priority)
|
||||
if (time_critical_mode && p.piece_priority(pb.piece_index) != top_priority)
|
||||
{
|
||||
// assume the subsequent pieces are not prio 7 and
|
||||
// be done
|
||||
break;
|
||||
}
|
||||
|
||||
int num_block_requests = p.num_peers(*i);
|
||||
int num_block_requests = p.num_peers(pb);
|
||||
if (num_block_requests > 0)
|
||||
{
|
||||
// have we picked enough pieces?
|
||||
|
@ -225,30 +226,30 @@ namespace libtorrent {
|
|||
// as well just exit the loop
|
||||
if (dont_pick_busy_blocks) break;
|
||||
|
||||
TORRENT_ASSERT(p.num_peers(*i) > 0);
|
||||
busy_block = *i;
|
||||
TORRENT_ASSERT(p.num_peers(pb) > 0);
|
||||
busy_block = pb;
|
||||
continue;
|
||||
}
|
||||
|
||||
TORRENT_ASSERT(p.num_peers(*i) == 0);
|
||||
TORRENT_ASSERT(p.num_peers(pb) == 0);
|
||||
|
||||
// don't request pieces we already have in our request queue
|
||||
// This happens when pieces time out or the peer sends us
|
||||
// pieces we didn't request. Those aren't marked in the
|
||||
// piece picker, but we still keep track of them in the
|
||||
// download queue
|
||||
if (std::find_if(dq.begin(), dq.end(), aux::has_block(*i)) != dq.end()
|
||||
|| std::find_if(rq.begin(), rq.end(), aux::has_block(*i)) != rq.end())
|
||||
if (std::find_if(dq.begin(), dq.end(), aux::has_block(pb)) != dq.end()
|
||||
|| std::find_if(rq.begin(), rq.end(), aux::has_block(pb)) != rq.end())
|
||||
{
|
||||
#if TORRENT_USE_ASSERTS
|
||||
std::vector<pending_block>::const_iterator j
|
||||
= std::find_if(dq.begin(), dq.end(), aux::has_block(*i));
|
||||
= std::find_if(dq.begin(), dq.end(), aux::has_block(pb));
|
||||
if (j != dq.end()) TORRENT_ASSERT(j->timed_out || j->not_wanted);
|
||||
#endif
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
c.peer_log(peer_log_alert::info, "PIECE_PICKER"
|
||||
, "not_picking: %d,%d already in queue"
|
||||
, static_cast<int>(i->piece_index), i->block_index);
|
||||
, static_cast<int>(pb.piece_index), pb.block_index);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
@ -256,9 +257,9 @@ namespace libtorrent {
|
|||
// ok, we found a piece that's not being downloaded
|
||||
// by somebody else. request it from this peer
|
||||
// and return
|
||||
if (!c.add_request(*i, {})) continue;
|
||||
TORRENT_ASSERT(p.num_peers(*i) == 1);
|
||||
TORRENT_ASSERT(p.is_requested(*i));
|
||||
if (!c.add_request(pb, {})) continue;
|
||||
TORRENT_ASSERT(p.num_peers(pb) == 1);
|
||||
TORRENT_ASSERT(p.is_requested(pb));
|
||||
num_requests--;
|
||||
}
|
||||
|
||||
|
|
|
@ -432,7 +432,7 @@ namespace {
|
|||
, std::shared_ptr<aux::session_impl> impl)
|
||||
: m_io_service(std::move(ios))
|
||||
, m_thread(std::move(t))
|
||||
, m_impl(impl)
|
||||
, m_impl(std::move(impl))
|
||||
{}
|
||||
session_proxy::session_proxy(session_proxy const&) = default;
|
||||
session_proxy& session_proxy::operator=(session_proxy const&) = default;
|
||||
|
@ -450,7 +450,7 @@ namespace {
|
|||
}
|
||||
|
||||
session_params::session_params(settings_pack sp)
|
||||
: session_params(sp, default_plugins())
|
||||
: session_params(std::move(sp), default_plugins())
|
||||
{}
|
||||
|
||||
session_params::session_params(settings_pack sp
|
||||
|
|
|
@ -398,7 +398,7 @@ namespace {
|
|||
// we cannot capture a unique_ptr into a lambda in c++11, so we use a raw
|
||||
// pointer for now. async_call uses a lambda expression to post the call
|
||||
// to the main thread
|
||||
add_torrent_params* p = new add_torrent_params(std::move(params));
|
||||
auto* p = new add_torrent_params(std::move(params));
|
||||
p->save_path = complete(p->save_path);
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
|
@ -419,7 +419,7 @@ namespace {
|
|||
, bool paused
|
||||
, storage_constructor_type sc)
|
||||
{
|
||||
add_torrent_params p(sc);
|
||||
add_torrent_params p(std::move(sc));
|
||||
p.ti = std::make_shared<torrent_info>(ti);
|
||||
p.save_path = save_path;
|
||||
if (resume_data.type() != entry::undefined_t)
|
||||
|
@ -445,7 +445,7 @@ namespace {
|
|||
{
|
||||
TORRENT_ASSERT_PRECOND(!save_path.empty());
|
||||
|
||||
add_torrent_params p(sc);
|
||||
add_torrent_params p(std::move(sc));
|
||||
p.trackers.push_back(tracker_url);
|
||||
p.info_hash = info_hash;
|
||||
p.save_path = save_path;
|
||||
|
|
|
@ -352,7 +352,7 @@ namespace aux {
|
|||
{
|
||||
TORRENT_UNUSED(ad);
|
||||
|
||||
session_impl* ses = reinterpret_cast<session_impl*>(arg);
|
||||
auto* ses = reinterpret_cast<session_impl*>(arg);
|
||||
const char* servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
|
||||
|
||||
if (!servername || strlen(servername) < 40)
|
||||
|
@ -1356,7 +1356,7 @@ namespace {
|
|||
|
||||
std::uint32_t session_impl::get_tracker_key(address const& iface) const
|
||||
{
|
||||
uintptr_t const ses = reinterpret_cast<uintptr_t>(this);
|
||||
auto const ses = reinterpret_cast<uintptr_t>(this);
|
||||
hasher h(reinterpret_cast<char const*>(&ses), sizeof(ses));
|
||||
if (iface.is_v4())
|
||||
{
|
||||
|
@ -3294,7 +3294,7 @@ namespace {
|
|||
|
||||
if (p.download_queue().size() + p.request_queue().size() > 0)
|
||||
++num_peers[protocol][peer_connection::download_channel];
|
||||
if (p.upload_queue().size() > 0)
|
||||
if (!p.upload_queue().empty())
|
||||
++num_peers[protocol][peer_connection::upload_channel];
|
||||
}
|
||||
|
||||
|
@ -3339,8 +3339,7 @@ namespace {
|
|||
// check for incoming connections that might have timed out
|
||||
// --------------------------------------------------------------
|
||||
|
||||
for (connection_map::iterator i = m_connections.begin();
|
||||
i != m_connections.end();)
|
||||
for (auto i = m_connections.begin(); i != m_connections.end();)
|
||||
{
|
||||
peer_connection* p = (*i).get();
|
||||
++i;
|
||||
|
@ -4052,7 +4051,7 @@ namespace {
|
|||
for (torrent_peer* pi : prev_opt_unchoke)
|
||||
{
|
||||
TORRENT_ASSERT(pi->optimistically_unchoked);
|
||||
peer_connection* p = static_cast<peer_connection*>(pi->connection);
|
||||
auto* p = static_cast<peer_connection*>(pi->connection);
|
||||
std::shared_ptr<torrent> t = p->associated_torrent().lock();
|
||||
pi->optimistically_unchoked = false;
|
||||
m_stats_counters.inc_stats_counter(counters::num_peers_up_unchoked_optimistic, -1);
|
||||
|
@ -4152,7 +4151,7 @@ namespace {
|
|||
{
|
||||
if ((m_download_connect_attempts >= m_settings.get_int(
|
||||
settings_pack::connect_seed_every_n_download)
|
||||
&& want_peers_finished.size())
|
||||
&& !want_peers_finished.empty())
|
||||
|| want_peers_download.empty())
|
||||
{
|
||||
// pick a finished torrent to give a peer to
|
||||
|
@ -4208,8 +4207,7 @@ namespace {
|
|||
// TODO: 3 there should be a pre-calculated list of all peers eligible for
|
||||
// unchoking
|
||||
std::vector<peer_connection*> peers;
|
||||
for (connection_map::iterator i = m_connections.begin();
|
||||
i != m_connections.end();)
|
||||
for (auto i = m_connections.begin(); i != m_connections.end();)
|
||||
{
|
||||
std::shared_ptr<peer_connection> p = *i;
|
||||
TORRENT_ASSERT(p);
|
||||
|
@ -4596,7 +4594,7 @@ namespace {
|
|||
for (auto& t : state_updates)
|
||||
{
|
||||
TORRENT_ASSERT(t->m_links[aux::session_impl::torrent_state_updates].in_list());
|
||||
status.push_back(torrent_status());
|
||||
status.emplace_back();
|
||||
// querying accurate download counters may require
|
||||
// the torrent to be loaded. Loading a torrent, and evicting another
|
||||
// one will lead to calling state_updated(), which screws with
|
||||
|
@ -5774,7 +5772,7 @@ namespace {
|
|||
|
||||
void session_impl::set_dht_storage(dht::dht_storage_constructor_type sc)
|
||||
{
|
||||
m_dht_storage_constructor = sc;
|
||||
m_dht_storage_constructor = std::move(sc);
|
||||
}
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
|
@ -5896,7 +5894,7 @@ namespace {
|
|||
{
|
||||
if (!m_dht) return;
|
||||
m_dht->get_item(dht::public_key(key.data()), std::bind(&session_impl::get_mutable_callback
|
||||
, this, _1, _2), salt);
|
||||
, this, _1, _2), std::move(salt));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -5914,9 +5912,9 @@ namespace {
|
|||
dht::signature const sig = i.sig();
|
||||
dht::public_key const pk = i.pk();
|
||||
dht::sequence_number const seq = i.seq();
|
||||
std::string const salt = i.salt();
|
||||
alerts.emplace_alert<dht_put_alert>(pk.bytes, sig.bytes, salt
|
||||
, seq.value, num);
|
||||
std::string salt = i.salt();
|
||||
alerts.emplace_alert<dht_put_alert>(pk.bytes, sig.bytes
|
||||
, std::move(salt), seq.value, num);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5964,7 +5962,7 @@ namespace {
|
|||
if (!m_dht) return;
|
||||
m_dht->put_item(dht::public_key(key.data())
|
||||
, std::bind(&on_dht_put_mutable_item, std::ref(m_alerts), _1, _2)
|
||||
, std::bind(&put_mutable_callback, _1, cb), salt);
|
||||
, std::bind(&put_mutable_callback, _1, std::move(cb)), salt);
|
||||
}
|
||||
|
||||
void session_impl::dht_get_peers(sha1_hash const& info_hash)
|
||||
|
@ -6771,7 +6769,7 @@ namespace {
|
|||
ips[is_local(local_addr)][local_addr.is_v6()] = local_addr;
|
||||
}
|
||||
|
||||
return external_ip(ips[1][0], ips[0][0], ips[1][1], ips[0][1]);
|
||||
return {ips[1][0], ips[0][0], ips[1][1], ips[0][1]};
|
||||
}
|
||||
|
||||
// this is the DHT observer version. DHT is the implied source
|
||||
|
|
|
@ -83,7 +83,7 @@ namespace {
|
|||
// has this piece failed earlier? If it has, go through the
|
||||
// CRCs from the time it failed and ban the peers that
|
||||
// sent bad blocks
|
||||
std::map<piece_block, block_entry>::iterator i = m_block_hashes.lower_bound(piece_block(p, 0));
|
||||
auto i = m_block_hashes.lower_bound(piece_block(p, 0));
|
||||
if (i == m_block_hashes.end() || i->first.piece_index != p) return;
|
||||
|
||||
int size = m_torrent.torrent_file().piece_size(p);
|
||||
|
@ -172,7 +172,7 @@ namespace {
|
|||
sha1_hash digest;
|
||||
};
|
||||
|
||||
void on_read_failed_block(piece_block b, address a
|
||||
void on_read_failed_block(piece_block const b, address const a
|
||||
, disk_buffer_holder buffer, int const block_size, disk_job_flags_t
|
||||
, storage_error const& error)
|
||||
{
|
||||
|
@ -185,8 +185,7 @@ namespace {
|
|||
h.update({buffer.get(), std::size_t(block_size)});
|
||||
h.update(reinterpret_cast<char const*>(&m_salt), sizeof(m_salt));
|
||||
|
||||
std::pair<peer_list::iterator, peer_list::iterator> const range
|
||||
= m_torrent.find_peers(a);
|
||||
auto const range = m_torrent.find_peers(a);
|
||||
|
||||
// there is no peer with this address anymore
|
||||
if (range.first == range.second) return;
|
||||
|
@ -194,7 +193,7 @@ namespace {
|
|||
torrent_peer* p = (*range.first);
|
||||
block_entry e = {p, h.final()};
|
||||
|
||||
std::map<piece_block, block_entry>::iterator i = m_block_hashes.lower_bound(b);
|
||||
auto i = m_block_hashes.lower_bound(b);
|
||||
|
||||
if (i != m_block_hashes.end() && i->first == b && i->second.peer == p)
|
||||
{
|
||||
|
@ -254,9 +253,9 @@ namespace {
|
|||
#endif
|
||||
}
|
||||
|
||||
void on_read_ok_block(std::pair<piece_block, block_entry> b, address a
|
||||
, disk_buffer_holder buffer, int const block_size, disk_job_flags_t
|
||||
, storage_error const& error)
|
||||
void on_read_ok_block(std::pair<piece_block, block_entry> const b
|
||||
, address const a, disk_buffer_holder buffer, int const block_size
|
||||
, disk_job_flags_t, storage_error const& error)
|
||||
{
|
||||
TORRENT_ASSERT(m_torrent.session().is_single_thread());
|
||||
|
||||
|
@ -271,8 +270,7 @@ namespace {
|
|||
if (b.second.digest == ok_digest) return;
|
||||
|
||||
// find the peer
|
||||
std::pair<peer_list::iterator, peer_list::iterator> range
|
||||
= m_torrent.find_peers(a);
|
||||
auto range = m_torrent.find_peers(a);
|
||||
if (range.first == range.second) return;
|
||||
torrent_peer* p = nullptr;
|
||||
for (; range.first != range.second; ++range.first)
|
||||
|
@ -319,7 +317,7 @@ namespace {
|
|||
std::uint32_t const m_salt;
|
||||
|
||||
// explicitly disallow assignment, to silence msvc warning
|
||||
smart_ban_plugin& operator=(smart_ban_plugin const&);
|
||||
smart_ban_plugin& operator=(smart_ban_plugin const&) = delete;
|
||||
};
|
||||
|
||||
} }
|
||||
|
|
|
@ -40,9 +40,7 @@ namespace libtorrent {
|
|||
namespace socks_error
|
||||
{
|
||||
boost::system::error_code make_error_code(socks_error_code e)
|
||||
{
|
||||
return error_code(e, socks_category());
|
||||
}
|
||||
{ return {e, socks_category()}; }
|
||||
}
|
||||
|
||||
struct socks_error_category : boost::system::error_category
|
||||
|
@ -70,7 +68,7 @@ namespace libtorrent {
|
|||
}
|
||||
boost::system::error_condition default_error_condition(
|
||||
int ev) const BOOST_SYSTEM_NOEXCEPT override
|
||||
{ return boost::system::error_condition(ev, *this); }
|
||||
{ return {ev, *this}; }
|
||||
};
|
||||
|
||||
boost::system::error_category& socks_category()
|
||||
|
|
|
@ -83,7 +83,7 @@ namespace aux {
|
|||
{
|
||||
int const ret = int(m_storage.size());
|
||||
int const size = int(buf.size());
|
||||
if (size < 1) return allocation_slot();
|
||||
if (size < 1) return {};
|
||||
m_storage.resize(ret + size);
|
||||
std::memcpy(&m_storage[ret], buf.data(), numeric_cast<std::size_t>(size));
|
||||
return allocation_slot(ret);
|
||||
|
@ -91,7 +91,7 @@ namespace aux {
|
|||
|
||||
allocation_slot stack_allocator::allocate(int const bytes)
|
||||
{
|
||||
if (bytes < 1) return allocation_slot();
|
||||
if (bytes < 1) return {};
|
||||
int const ret = m_storage.end_index();
|
||||
m_storage.resize(ret + bytes);
|
||||
return allocation_slot(ret);
|
||||
|
|
|
@ -164,7 +164,7 @@ namespace libtorrent {
|
|||
{
|
||||
if (str == nullptr) return nullptr;
|
||||
std::size_t const len = std::strlen(str);
|
||||
char* tmp = new char[len + 1];
|
||||
auto* tmp = new char[len + 1];
|
||||
std::copy(str, str + len, tmp);
|
||||
tmp[len] = '\0';
|
||||
return tmp;
|
||||
|
|
|
@ -46,8 +46,7 @@ std::uint32_t timestamp_history::add_sample(std::uint32_t sample, bool step)
|
|||
{
|
||||
if (!initialized())
|
||||
{
|
||||
for (int i = 0; i < history_size; ++i)
|
||||
m_history[i] = sample;
|
||||
m_history.fill(sample);
|
||||
m_base = sample;
|
||||
m_num_samples = 0;
|
||||
}
|
||||
|
@ -82,10 +81,10 @@ std::uint32_t timestamp_history::add_sample(std::uint32_t sample, bool step)
|
|||
m_history[m_index] = sample;
|
||||
// update m_base
|
||||
m_base = sample;
|
||||
for (int i = 0; i < history_size; ++i)
|
||||
for (auto& h : m_history)
|
||||
{
|
||||
if (compare_less_wrap(m_history[i], m_base, TIME_MASK))
|
||||
m_base = m_history[i];
|
||||
if (compare_less_wrap(h, m_base, TIME_MASK))
|
||||
m_base = h;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -96,10 +95,10 @@ void timestamp_history::adjust_base(int change)
|
|||
TORRENT_ASSERT(initialized());
|
||||
m_base += aux::numeric_cast<std::uint32_t>(change);
|
||||
// make sure this adjustment sticks by updating all history slots
|
||||
for (int i = 0; i < history_size; ++i)
|
||||
for (auto& h : m_history)
|
||||
{
|
||||
if (compare_less_wrap(m_history[i], m_base, TIME_MASK))
|
||||
m_history[i] = m_base;
|
||||
if (compare_less_wrap(h, m_base, TIME_MASK))
|
||||
h = m_base;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -844,7 +844,7 @@ namespace libtorrent {
|
|||
{
|
||||
TORRENT_INCREMENT(m_iterating_connections);
|
||||
if (pc->type() != connection_type::bittorrent) continue;
|
||||
bt_peer_connection* p = static_cast<bt_peer_connection*>(pc);
|
||||
auto* p = static_cast<bt_peer_connection*>(pc);
|
||||
p->write_share_mode();
|
||||
}
|
||||
#endif
|
||||
|
@ -1431,7 +1431,7 @@ namespace libtorrent {
|
|||
X509* cert = X509_STORE_CTX_get_current_cert(ctx.native_handle());
|
||||
|
||||
// Go through the alternate names in the certificate looking for matching DNS entries
|
||||
GENERAL_NAMES* gens = static_cast<GENERAL_NAMES*>(
|
||||
auto* gens = static_cast<GENERAL_NAMES*>(
|
||||
X509_get_ext_d2i(cert, NID_subject_alt_name, nullptr, nullptr));
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
|
@ -1444,7 +1444,7 @@ namespace libtorrent {
|
|||
if (gen->type != GEN_DNS) continue;
|
||||
ASN1_IA5STRING* domain = gen->d.dNSName;
|
||||
if (domain->type != V_ASN1_IA5STRING || !domain->data || !domain->length) continue;
|
||||
const char* torrent_name = reinterpret_cast<const char*>(domain->data);
|
||||
auto const* torrent_name = reinterpret_cast<char const*>(domain->data);
|
||||
std::size_t const name_length = aux::numeric_cast<std::size_t>(domain->length);
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
|
@ -1477,7 +1477,7 @@ namespace libtorrent {
|
|||
}
|
||||
if (common_name && common_name->data && common_name->length)
|
||||
{
|
||||
const char* torrent_name = reinterpret_cast<const char*>(common_name->data);
|
||||
auto const* torrent_name = reinterpret_cast<char const*>(common_name->data);
|
||||
std::size_t const name_length = aux::numeric_cast<std::size_t>(common_name->length);
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
|
@ -1905,7 +1905,7 @@ namespace libtorrent {
|
|||
{
|
||||
TORRENT_INCREMENT(m_iterating_connections);
|
||||
if (pe->type() != connection_type::bittorrent) continue;
|
||||
bt_peer_connection* p = static_cast<bt_peer_connection*>(pe);
|
||||
auto* p = static_cast<bt_peer_connection*>(pe);
|
||||
if (!p->supports_holepunch()) continue;
|
||||
if (p->was_introduced_by(ep)) return p;
|
||||
}
|
||||
|
@ -2032,7 +2032,7 @@ namespace libtorrent {
|
|||
// checking this torrent. pick it up where we left off
|
||||
if (!should_start_full_check
|
||||
&& m_add_torrent_params
|
||||
&& m_add_torrent_params->have_pieces.size() > 0
|
||||
&& !m_add_torrent_params->have_pieces.empty()
|
||||
&& m_add_torrent_params->have_pieces.size() < m_torrent_file->num_pieces())
|
||||
{
|
||||
m_checking_piece = m_num_checked_pieces
|
||||
|
@ -2437,7 +2437,7 @@ namespace libtorrent {
|
|||
void torrent::use_interface(std::string net_interfaces)
|
||||
{
|
||||
std::shared_ptr<settings_pack> p = std::make_shared<settings_pack>();
|
||||
p->set_str(settings_pack::outgoing_interfaces, net_interfaces);
|
||||
p->set_str(settings_pack::outgoing_interfaces, std::move(net_interfaces));
|
||||
m_ses.apply_settings_pack(p);
|
||||
}
|
||||
#endif
|
||||
|
@ -3968,7 +3968,7 @@ namespace libtorrent {
|
|||
p->trust_points = trust_points;
|
||||
if (p->connection)
|
||||
{
|
||||
peer_connection* peer = static_cast<peer_connection*>(p->connection);
|
||||
auto* peer = static_cast<peer_connection*>(p->connection);
|
||||
TORRENT_ASSERT(peer->m_in_use == 1337);
|
||||
peer->received_valid_data(index);
|
||||
}
|
||||
|
@ -4073,7 +4073,7 @@ namespace libtorrent {
|
|||
{
|
||||
if (p && p->connection)
|
||||
{
|
||||
peer_connection* peer = static_cast<peer_connection*>(p->connection);
|
||||
auto* peer = static_cast<peer_connection*>(p->connection);
|
||||
peer->piece_failed = true;
|
||||
}
|
||||
}
|
||||
|
@ -4089,7 +4089,7 @@ namespace libtorrent {
|
|||
bool allow_disconnect = true;
|
||||
if (p->connection)
|
||||
{
|
||||
peer_connection* peer = static_cast<peer_connection*>(p->connection);
|
||||
auto* peer = static_cast<peer_connection*>(p->connection);
|
||||
TORRENT_ASSERT(peer->m_in_use == 1337);
|
||||
|
||||
// the peer implementation can ask not to be disconnected.
|
||||
|
@ -4137,7 +4137,7 @@ namespace libtorrent {
|
|||
|
||||
if (p->connection)
|
||||
{
|
||||
peer_connection* peer = static_cast<peer_connection*>(p->connection);
|
||||
auto* peer = static_cast<peer_connection*>(p->connection);
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
if (should_log())
|
||||
{
|
||||
|
@ -4186,7 +4186,7 @@ namespace libtorrent {
|
|||
{
|
||||
if (p && p->connection)
|
||||
{
|
||||
peer_connection* peer = static_cast<peer_connection*>(p->connection);
|
||||
auto* peer = static_cast<peer_connection*>(p->connection);
|
||||
peer->piece_failed = false;
|
||||
}
|
||||
}
|
||||
|
@ -4690,7 +4690,7 @@ namespace libtorrent {
|
|||
{
|
||||
torrent_peer* tp = *i;
|
||||
if (tp == nullptr || tp->connection == nullptr) continue;
|
||||
peer_connection* peer = static_cast<peer_connection*>(tp->connection);
|
||||
auto* peer = static_cast<peer_connection*>(tp->connection);
|
||||
peer->make_time_critical(piece_block(piece, block));
|
||||
}
|
||||
}
|
||||
|
@ -5540,7 +5540,7 @@ namespace libtorrent {
|
|||
debug_log("removing web seed: \"%s\"", web->url.c_str());
|
||||
#endif
|
||||
|
||||
peer_connection* peer = static_cast<peer_connection*>(web->peer_info.connection);
|
||||
auto* peer = static_cast<peer_connection*>(web->peer_info.connection);
|
||||
if (peer != nullptr)
|
||||
{
|
||||
// if we have a connection for this web seed, we also need to
|
||||
|
@ -6399,7 +6399,7 @@ namespace libtorrent {
|
|||
TORRENT_ASSERT(tp->in_use);
|
||||
if (tp->connection)
|
||||
{
|
||||
peer_connection* peer = static_cast<peer_connection*>(tp->connection);
|
||||
auto* peer = static_cast<peer_connection*>(tp->connection);
|
||||
TORRENT_ASSERT(peer->m_in_use);
|
||||
bi.set_peer(peer->remote());
|
||||
if (bi.state == block_info::requested)
|
||||
|
@ -9940,7 +9940,7 @@ namespace libtorrent {
|
|||
TORRENT_ASSERT(i != m_web_seeds.end());
|
||||
if (i == m_web_seeds.end()) return;
|
||||
|
||||
peer_connection* peer = static_cast<peer_connection*>(i->peer_info.connection);
|
||||
auto* peer = static_cast<peer_connection*>(i->peer_info.connection);
|
||||
if (peer != nullptr)
|
||||
{
|
||||
// if we have a connection for this web seed, we also need to
|
||||
|
@ -10356,7 +10356,7 @@ namespace libtorrent {
|
|||
torrent_peer* p = info.peer;
|
||||
if (p != nullptr && p->connection)
|
||||
{
|
||||
peer_connection* peer = static_cast<peer_connection*>(p->connection);
|
||||
auto* peer = static_cast<peer_connection*>(p->connection);
|
||||
auto pbp = peer->downloading_piece_progress();
|
||||
if (pbp.piece_index == dp.index && pbp.block_index == idx)
|
||||
block = pbp.bytes_downloaded;
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace libtorrent {
|
|||
{
|
||||
std::shared_ptr<torrent> t = m_torrent.lock();
|
||||
if (!t) aux::throw_ex<system_error>(errors::invalid_torrent_handle);
|
||||
session_impl& ses = static_cast<session_impl&>(t->session());
|
||||
auto& ses = static_cast<session_impl&>(t->session());
|
||||
ses.get_io_service().dispatch([=,&ses] ()
|
||||
{
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
|
@ -114,7 +114,7 @@ namespace libtorrent {
|
|||
{
|
||||
std::shared_ptr<torrent> t = m_torrent.lock();
|
||||
if (!t) aux::throw_ex<system_error>(errors::invalid_torrent_handle);
|
||||
session_impl& ses = static_cast<session_impl&>(t->session());
|
||||
auto& ses = static_cast<session_impl&>(t->session());
|
||||
|
||||
// this is the flag to indicate the call has completed
|
||||
bool done = false;
|
||||
|
@ -150,7 +150,7 @@ namespace libtorrent {
|
|||
#else
|
||||
if (!t) return r;
|
||||
#endif
|
||||
session_impl& ses = static_cast<session_impl&>(t->session());
|
||||
auto& ses = static_cast<session_impl&>(t->session());
|
||||
|
||||
// this is the flag to indicate the call has completed
|
||||
bool done = false;
|
||||
|
@ -772,7 +772,7 @@ namespace libtorrent {
|
|||
|
||||
std::shared_ptr<torrent> t = m_torrent.lock();
|
||||
if (!t || !t->has_storage()) return;
|
||||
session_impl& ses = static_cast<session_impl&>(t->session());
|
||||
auto& ses = static_cast<session_impl&>(t->session());
|
||||
status = ses.disk_thread().get_status(t->storage());
|
||||
}
|
||||
#endif
|
||||
|
@ -793,7 +793,7 @@ namespace libtorrent {
|
|||
{
|
||||
std::shared_ptr<torrent> t = m_torrent.lock();
|
||||
if (!t || !t->has_storage()) return {};
|
||||
session_impl& ses = static_cast<session_impl&>(t->session());
|
||||
auto& ses = static_cast<session_impl&>(t->session());
|
||||
return ses.disk_thread().get_status(t->storage());
|
||||
}
|
||||
|
||||
|
|
|
@ -82,8 +82,8 @@ private:
|
|||
std::shared_ptr<socks5> self() { return shared_from_this(); }
|
||||
|
||||
void on_name_lookup(error_code const& e, tcp::resolver::iterator i);
|
||||
void on_connect_timeout(error_code const& ec);
|
||||
void on_connected(error_code const& ec);
|
||||
void on_connect_timeout(error_code const& e);
|
||||
void on_connected(error_code const& e);
|
||||
void handshake1(error_code const& e);
|
||||
void handshake2(error_code const& e);
|
||||
void handshake3(error_code const& e);
|
||||
|
@ -160,7 +160,7 @@ udp_socket::udp_socket(io_service& ios)
|
|||
|
||||
int udp_socket::read(span<packet> pkts, error_code& ec)
|
||||
{
|
||||
int const num = int(pkts.size());
|
||||
auto const num = int(pkts.size());
|
||||
int ret = 0;
|
||||
packet p;
|
||||
|
||||
|
@ -350,7 +350,7 @@ bool udp_socket::unwrap(udp::endpoint& from, span<char>& buf)
|
|||
using namespace libtorrent::detail;
|
||||
|
||||
// the minimum socks5 header size
|
||||
int const size = aux::numeric_cast<int>(buf.size());
|
||||
auto const size = aux::numeric_cast<int>(buf.size());
|
||||
if (size <= 10) return false;
|
||||
|
||||
char* p = buf.data();
|
||||
|
@ -521,11 +521,11 @@ void socks5::on_name_lookup(error_code const& e, tcp::resolver::iterator i)
|
|||
, self(), _1));
|
||||
}
|
||||
|
||||
void socks5::on_connect_timeout(error_code const& ec)
|
||||
void socks5::on_connect_timeout(error_code const& e)
|
||||
{
|
||||
COMPLETE_ASYNC("socks5::on_connect_timeout");
|
||||
|
||||
if (ec == boost::asio::error::operation_aborted) return;
|
||||
if (e == boost::asio::error::operation_aborted) return;
|
||||
|
||||
if (m_abort) return;
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace libtorrent {
|
|||
, tracker_manager& man
|
||||
, tracker_request const& req
|
||||
, std::weak_ptr<request_callback> c)
|
||||
: tracker_connection(man, req, ios, c)
|
||||
: tracker_connection(man, req, ios, std::move(c))
|
||||
, m_transaction_id(0)
|
||||
, m_attempts(0)
|
||||
, m_state(action_t::error)
|
||||
|
@ -146,7 +146,7 @@ namespace libtorrent {
|
|||
std::shared_ptr<request_callback> cb = requester();
|
||||
if (cb && cb->should_log())
|
||||
{
|
||||
cb->debug_log("*** UDP_TRACKER [ host: \"%s\" ip: \"%s\" | error: \"%s\" ]"
|
||||
cb->debug_log(R"(*** UDP_TRACKER [ host: "%s" ip: "%s" | error: "%s" ])"
|
||||
, m_hostname.c_str(), print_endpoint(m_target).c_str(), ec.message().c_str());
|
||||
}
|
||||
#endif
|
||||
|
@ -157,7 +157,7 @@ namespace libtorrent {
|
|||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
if (cb && cb->should_log())
|
||||
{
|
||||
cb->debug_log("*** UDP_TRACKER trying next IP [ host: \"%s\" ip: \"%s\" ]"
|
||||
cb->debug_log(R"(*** UDP_TRACKER trying next IP [ host: "%s" ip: "%s" ])"
|
||||
, m_hostname.c_str(), print_endpoint(m_target).c_str());
|
||||
}
|
||||
#endif
|
||||
|
|
28
src/upnp.cpp
28
src/upnp.cpp
|
@ -71,9 +71,7 @@ constexpr std::size_t max_global_mappings = 50;
|
|||
namespace upnp_errors
|
||||
{
|
||||
boost::system::error_code make_error_code(error_code_enum e)
|
||||
{
|
||||
return error_code(e, upnp_category());
|
||||
}
|
||||
{ return {e, upnp_category()}; }
|
||||
|
||||
} // upnp_errors namespace
|
||||
|
||||
|
@ -372,7 +370,7 @@ void upnp::resend_request(error_code const& ec)
|
|||
}
|
||||
}
|
||||
|
||||
void upnp::on_reply(udp::endpoint const& from, char* buffer
|
||||
void upnp::on_reply(udp::endpoint const& from, char const* buffer
|
||||
, std::size_t const bytes_transferred)
|
||||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
@ -1222,7 +1220,7 @@ struct upnp_error_category : boost::system::error_category
|
|||
boost::system::error_condition default_error_condition(
|
||||
int ev) const BOOST_SYSTEM_NOEXCEPT override
|
||||
{
|
||||
return boost::system::error_condition(ev, *this);
|
||||
return {ev, *this};
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1593,9 +1591,9 @@ void upnp::on_expire(error_code const& ec)
|
|||
time_point const now = aux::time_now();
|
||||
time_point next_expire = max_time();
|
||||
|
||||
for (auto i = m_devices.begin(), end(m_devices.end()); i != end; ++i)
|
||||
for (auto& dev : m_devices)
|
||||
{
|
||||
rootdevice& d = const_cast<rootdevice&>(*i);
|
||||
rootdevice& d = const_cast<rootdevice&>(dev);
|
||||
TORRENT_ASSERT(d.magic == 1337);
|
||||
for (port_mapping_t m{0}; m < m_mappings.end_index(); ++m)
|
||||
{
|
||||
|
@ -1633,21 +1631,21 @@ void upnp::close()
|
|||
m_closing = true;
|
||||
m_socket.close();
|
||||
|
||||
for (auto i = m_devices.begin(), end(m_devices.end()); i != end; ++i)
|
||||
for (auto& dev : m_devices)
|
||||
{
|
||||
rootdevice& d = const_cast<rootdevice&>(*i);
|
||||
rootdevice& d = const_cast<rootdevice&>(dev);
|
||||
TORRENT_ASSERT(d.magic == 1337);
|
||||
if (d.control_url.empty()) continue;
|
||||
for (auto j = d.mapping.begin(), end2(d.mapping.end()); j != end2; ++j)
|
||||
for (auto& m : d.mapping)
|
||||
{
|
||||
if (j->protocol == portmap_protocol::none) continue;
|
||||
if (j->act == portmap_action::add)
|
||||
if (m.protocol == portmap_protocol::none) continue;
|
||||
if (m.act == portmap_action::add)
|
||||
{
|
||||
j->act = portmap_action::none;
|
||||
m.act = portmap_action::none;
|
||||
continue;
|
||||
}
|
||||
j->act = portmap_action::del;
|
||||
m_mappings[port_mapping_t{static_cast<int>(j - d.mapping.begin())}].protocol = portmap_protocol::none;
|
||||
m.act = portmap_action::del;
|
||||
m_mappings[port_mapping_t{static_cast<int>(&m - d.mapping.data())}].protocol = portmap_protocol::none;
|
||||
}
|
||||
if (num_mappings() > 0) update_map(d, port_mapping_t{0});
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ namespace libtorrent {namespace {
|
|||
}
|
||||
|
||||
bool received_metadata(ut_metadata_peer_plugin& source
|
||||
, char const* buf, int const size, int const piece, int const total_size);
|
||||
, char const* buf, int size, int piece, int total_size);
|
||||
|
||||
// returns a piece of the metadata that
|
||||
// we should request.
|
||||
|
@ -333,8 +333,9 @@ namespace libtorrent {namespace {
|
|||
m_pc.disconnect(errors::invalid_metadata_message, operation_t::bittorrent, 2);
|
||||
return true;
|
||||
}
|
||||
int type = int(type_ent->integer());
|
||||
int piece = int(piece_ent->integer());
|
||||
// TODO: make this an enum class
|
||||
auto const type = int(type_ent->integer());
|
||||
auto const piece = int(piece_ent->integer());
|
||||
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA"
|
||||
|
@ -417,7 +418,7 @@ namespace libtorrent {namespace {
|
|||
while (!m_incoming_requests.empty()
|
||||
&& m_pc.send_buffer_size() < send_buffer_limit)
|
||||
{
|
||||
int piece = m_incoming_requests.front();
|
||||
int const piece = m_incoming_requests.front();
|
||||
m_incoming_requests.erase(m_incoming_requests.begin());
|
||||
write_metadata_packet(metadata_piece, piece);
|
||||
}
|
||||
|
@ -436,7 +437,7 @@ namespace libtorrent {namespace {
|
|||
&& m_sent_requests.size() < 2
|
||||
&& has_metadata())
|
||||
{
|
||||
int piece = m_tp.metadata_request(m_pc.has_metadata());
|
||||
int const piece = m_tp.metadata_request(m_pc.has_metadata());
|
||||
if (piece == -1) return;
|
||||
|
||||
m_sent_requests.push_back(piece);
|
||||
|
@ -493,7 +494,7 @@ namespace libtorrent {namespace {
|
|||
// from requesting this block by setting a timeout on it.
|
||||
int ut_metadata_plugin::metadata_request(bool const has_metadata)
|
||||
{
|
||||
std::vector<metadata_piece>::iterator i = std::min_element(
|
||||
auto i = std::min_element(
|
||||
m_requested_metadata.begin(), m_requested_metadata.end());
|
||||
|
||||
if (m_requested_metadata.empty())
|
||||
|
|
|
@ -201,9 +201,7 @@ namespace {
|
|||
|
||||
boost::system::error_condition default_error_condition(
|
||||
int ev) const BOOST_SYSTEM_NOEXCEPT override
|
||||
{
|
||||
return boost::system::error_condition(ev, *this);
|
||||
}
|
||||
{ return {ev, *this}; }
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
|
@ -211,7 +209,7 @@ namespace {
|
|||
{
|
||||
boost::system::error_code make_error_code(utf8_errors::error_code_enum e)
|
||||
{
|
||||
return error_code(e, utf8_category());
|
||||
return {e, utf8_category()};
|
||||
}
|
||||
} // utf_errors namespace
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ namespace libtorrent {
|
|||
|
||||
if (p.size() < sizeof(utp_header)) return false;
|
||||
|
||||
utp_header const* ph = reinterpret_cast<utp_header const*>(p.data());
|
||||
auto const* ph = reinterpret_cast<utp_header const*>(p.data());
|
||||
|
||||
// UTP_LOGV("incoming packet version:%d\n", int(ph->get_version()));
|
||||
|
||||
|
@ -231,7 +231,7 @@ namespace libtorrent {
|
|||
int link_mtu, utp_mtu;
|
||||
mtu_for_dest(ep.address(), link_mtu, utp_mtu);
|
||||
utp_init_mtu(str->get_impl(), link_mtu, utp_mtu);
|
||||
utp_init_socket(str->get_impl(), socket);
|
||||
utp_init_socket(str->get_impl(), std::move(socket));
|
||||
bool ret = utp_incoming_packet(str->get_impl(), p, ep, receive_time);
|
||||
if (!ret) return false;
|
||||
m_cb(c);
|
||||
|
|
|
@ -872,7 +872,7 @@ int utp_stream::read_buffer_size() const
|
|||
|
||||
void utp_stream::on_close_reason(void* self, close_reason_t reason)
|
||||
{
|
||||
utp_stream* s = static_cast<utp_stream*>(self);
|
||||
auto* s = static_cast<utp_stream*>(self);
|
||||
|
||||
// it's possible the socket has been unlinked already, in which case m_impl
|
||||
// will be nullptr
|
||||
|
@ -883,7 +883,7 @@ void utp_stream::on_close_reason(void* self, close_reason_t reason)
|
|||
void utp_stream::on_read(void* self, std::size_t const bytes_transferred
|
||||
, error_code const& ec, bool const shutdown)
|
||||
{
|
||||
utp_stream* s = static_cast<utp_stream*>(self);
|
||||
auto* s = static_cast<utp_stream*>(self);
|
||||
|
||||
UTP_LOGV("%8p: calling read handler read:%d ec:%s shutdown:%d\n", static_cast<void*>(s->m_impl)
|
||||
, int(bytes_transferred), ec.message().c_str(), shutdown);
|
||||
|
@ -903,7 +903,7 @@ void utp_stream::on_read(void* self, std::size_t const bytes_transferred
|
|||
void utp_stream::on_write(void* self, std::size_t const bytes_transferred
|
||||
, error_code const& ec, bool const shutdown)
|
||||
{
|
||||
utp_stream* s = static_cast<utp_stream*>(self);
|
||||
auto* s = static_cast<utp_stream*>(self);
|
||||
|
||||
UTP_LOGV("%8p: calling write handler written:%d ec:%s shutdown:%d\n"
|
||||
, static_cast<void*>(s->m_impl)
|
||||
|
@ -923,7 +923,7 @@ void utp_stream::on_write(void* self, std::size_t const bytes_transferred
|
|||
|
||||
void utp_stream::on_connect(void* self, error_code const& ec, bool shutdown)
|
||||
{
|
||||
utp_stream* s = static_cast<utp_stream*>(self);
|
||||
auto* s = static_cast<utp_stream*>(self);
|
||||
TORRENT_ASSERT(s);
|
||||
|
||||
UTP_LOGV("%8p: calling connect handler ec:%s shutdown:%d\n"
|
||||
|
@ -1310,7 +1310,7 @@ void utp_socket_impl::send_syn()
|
|||
p->num_fast_resend = 0;
|
||||
#endif
|
||||
p->need_resend = false;
|
||||
utp_header* h = reinterpret_cast<utp_header*>(p->buf);
|
||||
auto* h = reinterpret_cast<utp_header*>(p->buf);
|
||||
h->type_ver = (ST_SYN << 4) | 1;
|
||||
h->extension = utp_no_extension;
|
||||
// using recv_id here is intentional! This is an odd
|
||||
|
@ -1645,7 +1645,7 @@ void utp_socket_impl::remove_sack_header(packet* p)
|
|||
|
||||
// remove the sack header
|
||||
std::uint8_t* ptr = p->buf + sizeof(utp_header);
|
||||
utp_header* h = reinterpret_cast<utp_header*>(p->buf);
|
||||
auto* h = reinterpret_cast<utp_header*>(p->buf);
|
||||
|
||||
TORRENT_ASSERT(h->extension == utp_sack);
|
||||
|
||||
|
@ -2135,7 +2135,7 @@ bool utp_socket_impl::resend_packet(packet* p, bool fast_resend)
|
|||
if (fast_resend) ++p->num_fast_resend;
|
||||
#endif
|
||||
p->need_resend = false;
|
||||
utp_header* h = reinterpret_cast<utp_header*>(p->buf);
|
||||
auto* h = reinterpret_cast<utp_header*>(p->buf);
|
||||
// update packet header
|
||||
h->timestamp_difference_microseconds = m_reply_micro;
|
||||
p->send_time = clock_type::now();
|
||||
|
@ -2604,7 +2604,7 @@ bool utp_socket_impl::incoming_packet(span<std::uint8_t const> buf
|
|||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
utp_header const* ph = reinterpret_cast<utp_header const*>(buf.data());
|
||||
auto const* ph = reinterpret_cast<utp_header const*>(buf.data());
|
||||
|
||||
m_sm.inc_stats_counter(counters::utp_packets_in);
|
||||
|
||||
|
|
|
@ -254,8 +254,7 @@ void web_peer_connection::disconnect(error_code const& ec
|
|||
|
||||
piece_block_progress web_peer_connection::downloading_piece_progress() const
|
||||
{
|
||||
if (m_requests.empty())
|
||||
return piece_block_progress();
|
||||
if (m_requests.empty()) return {};
|
||||
|
||||
std::shared_ptr<torrent> t = associated_torrent().lock();
|
||||
TORRENT_ASSERT(t);
|
||||
|
@ -267,7 +266,7 @@ piece_block_progress web_peer_connection::downloading_piece_progress() const
|
|||
// this is used to make sure that the block_index stays within
|
||||
// bounds. If the entire piece is downloaded, the block_index
|
||||
// would otherwise point to one past the end
|
||||
int correction = m_piece.size() ? -1 : 0;
|
||||
int correction = m_piece.empty() ? 0 : -1;
|
||||
ret.block_index = (m_requests.front().start + int(m_piece.size()) + correction) / t->block_size();
|
||||
TORRENT_ASSERT(ret.block_index < int(piece_block::invalid.block_index));
|
||||
TORRENT_ASSERT(ret.piece_index < piece_block::invalid.piece_index);
|
||||
|
@ -514,7 +513,7 @@ namespace {
|
|||
ec = errors::no_content_length;
|
||||
}
|
||||
}
|
||||
return std::tuple<std::int64_t, std::int64_t>(range_start, range_end);
|
||||
return std::make_tuple(range_start, range_end);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -662,7 +661,7 @@ void web_peer_connection::handle_redirect(int const bytes_left)
|
|||
|
||||
if (web->peer_info.connection != nullptr)
|
||||
{
|
||||
peer_connection* pc = static_cast<peer_connection*>(web->peer_info.connection);
|
||||
auto* pc = static_cast<peer_connection*>(web->peer_info.connection);
|
||||
|
||||
// we just learned that this host has this file, and we're currently
|
||||
// connected to it. Make it advertise that it has this file to the
|
||||
|
@ -874,7 +873,7 @@ void web_peer_connection::on_receive(error_code const& error
|
|||
// === CHUNKED ENCODING ===
|
||||
// =========================
|
||||
|
||||
while (m_chunk_pos >= 0 && recv_buffer.size() > 0)
|
||||
while (m_chunk_pos >= 0 && !recv_buffer.empty())
|
||||
{
|
||||
// first deliver any payload we have in the buffer so far, ahead of
|
||||
// the next chunk header.
|
||||
|
|
|
@ -69,7 +69,7 @@ char const* soap_delete_response[] = {
|
|||
"<s:Body><u:DeletePortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:2\">"
|
||||
"</u:DeletePortMapping></s:Body></s:Envelope>"};
|
||||
|
||||
void incoming_msearch(udp::endpoint const& from, char* buffer
|
||||
void incoming_msearch(udp::endpoint const& from, char const* buffer
|
||||
, int size)
|
||||
{
|
||||
http_parser p;
|
||||
|
|
Loading…
Reference in New Issue