merge RC_1_2 into master
This commit is contained in:
@ -207,6 +207,7 @@ set(libtorrent_aux_include_files
|
||||
cppint_import_export
|
||||
cpuid
|
||||
deferred_handler
|
||||
deprecated
|
||||
deque
|
||||
dev_random
|
||||
disable_warnings_pop
|
||||
|
@ -15,6 +15,7 @@
|
||||
* update networking API to networking TS compatible boost.asio
|
||||
* overhauled disk I/O subsystem to use memory mapped files (where available)
|
||||
|
||||
* optimize setting with unlimited unchoke slots
|
||||
* fixed restoring of trackers, comment, creation date and created-by in resume data
|
||||
* fix handling of torrents with too large pieces
|
||||
* fixed division by zero in anti-leech choker
|
||||
|
1
Makefile
1
Makefile
@ -574,6 +574,7 @@ HEADERS = \
|
||||
aux_/cppint_import_export.hpp \
|
||||
aux_/cpuid.hpp \
|
||||
aux_/deferred_handler.hpp \
|
||||
aux_/deprecated.hpp \
|
||||
aux_/deque.hpp \
|
||||
aux_/dev_random.hpp \
|
||||
aux_/disable_warnings_pop.hpp \
|
||||
|
@ -1080,10 +1080,9 @@ example alert_masks:
|
||||
std::vector<char> in;
|
||||
if (load_file(".ses_state", in))
|
||||
{
|
||||
lt::bdecode_node e;
|
||||
lt::error_code ec;
|
||||
if (bdecode(&in[0], &in[0] + in.size(), e, ec) == 0)
|
||||
params = read_session_params(e, session_handle::save_dht_state);
|
||||
lt::bdecode_node e = lt::bdecode(in, ec);
|
||||
if (!ec) params = read_session_params(e, session_handle::save_dht_state);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -38,9 +38,16 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
||||
{
|
||||
lt::error_code ec;
|
||||
lt::lazy_entry ret;
|
||||
int pos;
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
lt::lazy_entry ret;
|
||||
lazy_bdecode(reinterpret_cast<char const*>(data), reinterpret_cast<char const*>(data) + size, ret, ec, &pos);
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/portmap.hpp" // for portmap_transport
|
||||
#include "libtorrent/tracker_manager.hpp" // for event_t
|
||||
#include "libtorrent/socket_type.hpp"
|
||||
#include "libtorrent/aux_/deprecated.hpp"
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
#include <boost/shared_array.hpp>
|
||||
@ -221,6 +222,17 @@ TORRENT_VERSION_NAMESPACE_2
|
||||
TORRENT_DEFINE_ALERT_IMPL(name, seq, prio)
|
||||
|
||||
#if TORRENT_ABI_VERSION == 1
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
// warning C4996: X: was declared deprecated
|
||||
#pragma warning( disable : 4996 )
|
||||
#endif
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
// The ``torrent_added_alert`` is posted once every time a torrent is successfully
|
||||
// added. It doesn't contain any members of its own, but inherits the torrent handle
|
||||
// from its base class.
|
||||
@ -236,6 +248,14 @@ TORRENT_VERSION_NAMESPACE_2
|
||||
static constexpr alert_category_t static_category = alert::status_notification;
|
||||
std::string message() const override;
|
||||
};
|
||||
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// The ``torrent_removed_alert`` is posted whenever a torrent is removed. Since
|
||||
@ -1827,6 +1847,17 @@ TORRENT_VERSION_NAMESPACE_2
|
||||
};
|
||||
|
||||
#if TORRENT_ABI_VERSION == 1
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
// warning C4996: X: was declared deprecated
|
||||
#pragma warning( disable : 4996 )
|
||||
#endif
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
// This alert is posted when a bittorrent feature is blocked because of the
|
||||
// anonymous mode. For instance, if the tracker proxy is not set up, no
|
||||
// trackers will be used, because trackers can only be used through proxies
|
||||
@ -1854,6 +1885,14 @@ TORRENT_VERSION_NAMESPACE_2
|
||||
int kind;
|
||||
std::string str;
|
||||
};
|
||||
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif // TORRENT_ABI_VERSION
|
||||
|
||||
// This alert is generated when we receive a local service discovery message
|
||||
|
88
include/libtorrent/aux_/deprecated.hpp
Normal file
88
include/libtorrent/aux_/deprecated.hpp
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2019, Arvid Norberg
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the author nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef TORRENT_DEPRECATED_HPP_INCLUDED
|
||||
#define TORRENT_DEPRECATED_HPP_INCLUDED
|
||||
|
||||
#if defined __clang__
|
||||
|
||||
// ====== CLANG ========
|
||||
|
||||
# if !defined TORRENT_BUILDING_LIBRARY
|
||||
// TODO: figure out which version of clang this is supported in
|
||||
# define TORRENT_DEPRECATED __attribute__ ((deprecated))
|
||||
# define TORRENT_DEPRECATED_ENUM __attribute__ ((deprecated))
|
||||
# define TORRENT_DEPRECATED_MEMBER __attribute__ ((deprecated))
|
||||
# endif
|
||||
|
||||
#elif defined __GNUC__
|
||||
|
||||
// ======== GCC ========
|
||||
|
||||
// deprecation markup is only enabled when libtorrent
|
||||
// headers are included by clients, not while building
|
||||
// libtorrent itself
|
||||
# if __GNUC__ >= 3 && !defined TORRENT_BUILDING_LIBRARY
|
||||
# define TORRENT_DEPRECATED __attribute__ ((deprecated))
|
||||
# endif
|
||||
|
||||
# if __GNUC__ >= 6 && !defined TORRENT_BUILDING_LIBRARY
|
||||
# define TORRENT_DEPRECATED_ENUM __attribute__ ((deprecated))
|
||||
# define TORRENT_DEPRECATED_MEMBER __attribute__ ((deprecated))
|
||||
# endif
|
||||
|
||||
#elif defined _MSC_VER
|
||||
|
||||
// ======= MSVC =========
|
||||
|
||||
// deprecation markup is only enabled when libtorrent
|
||||
// headers are included by clients, not while building
|
||||
// libtorrent itself
|
||||
#if !defined TORRENT_BUILDING_LIBRARY
|
||||
# define TORRENT_DEPRECATED __declspec(deprecated)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef TORRENT_DEPRECATED
|
||||
#define TORRENT_DEPRECATED
|
||||
#endif
|
||||
|
||||
#ifndef TORRENT_DEPRECATED_ENUM
|
||||
#define TORRENT_DEPRECATED_ENUM
|
||||
#endif
|
||||
|
||||
#ifndef TORRENT_DEPRECATED_MEMBER
|
||||
#define TORRENT_DEPRECATED_MEMBER
|
||||
#endif
|
||||
|
||||
#endif
|
@ -36,6 +36,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <boost/config.hpp>
|
||||
#include "libtorrent/config.hpp"
|
||||
|
||||
#include "libtorrent/aux_/deprecated.hpp"
|
||||
|
||||
#if !defined TORRENT_ABI_VERSION
|
||||
# ifdef TORRENT_NO_DEPRECATE
|
||||
# define TORRENT_ABI_VERSION 3
|
||||
@ -124,9 +126,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// only export this type if deprecated functions are enabled
|
||||
#if TORRENT_ABI_VERSION >= 2
|
||||
# define TORRENT_DEPRECATED_EXPORT TORRENT_EXTRA_EXPORT
|
||||
# define TORRENT_DEPRECATED_EXPORT TORRENT_EXTRA_EXPORT TORRENT_DEPRECATED
|
||||
#else
|
||||
# define TORRENT_DEPRECATED_EXPORT TORRENT_EXPORT
|
||||
# define TORRENT_DEPRECATED_EXPORT TORRENT_EXPORT TORRENT_DEPRECATED
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -45,9 +45,7 @@ namespace aux {
|
||||
|
||||
struct session_settings;
|
||||
|
||||
// The ``proxy_settings`` structs contains the information needed to
|
||||
// direct certain traffic to a proxy.
|
||||
struct TORRENT_DEPRECATED_EXPORT proxy_settings
|
||||
struct TORRENT_EXTRA_EXPORT proxy_settings
|
||||
{
|
||||
// defaults constructs proxy settings, initializing it to the default
|
||||
// settings.
|
||||
@ -89,7 +87,6 @@ namespace aux {
|
||||
bool proxy_tracker_connections = true;
|
||||
};
|
||||
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
@ -425,8 +425,22 @@ namespace aux {
|
||||
void add_dht_node(udp::endpoint const& n) override;
|
||||
void add_dht_router(std::pair<std::string, int> const& node);
|
||||
#if TORRENT_ABI_VERSION <= 2
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning( disable : 4996 ) // warning C4996: X: was declared deprecated
|
||||
#endif
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
void set_dht_settings(dht::dht_settings const& s);
|
||||
dht::dht_settings get_dht_settings() const;
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// you must give up ownership of the dht state
|
||||
|
@ -58,36 +58,12 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#pragma GCC diagnostic ignored "-Wformat-extra-args"
|
||||
#endif
|
||||
|
||||
// ====== CLANG ========
|
||||
|
||||
#if defined __clang__
|
||||
|
||||
# if !defined TORRENT_BUILDING_LIBRARY
|
||||
// TODO: figure out which version of clang this is supported in
|
||||
# define TORRENT_DEPRECATED_ENUM __attribute__ ((deprecated))
|
||||
# define TORRENT_DEPRECATED_MEMBER __attribute__ ((deprecated))
|
||||
# endif
|
||||
|
||||
// ======= GCC =========
|
||||
|
||||
#elif defined __GNUC__
|
||||
#if defined __GNUC__
|
||||
|
||||
#ifdef _GLIBCXX_CONCEPT_CHECKS
|
||||
#define TORRENT_COMPLETE_TYPES_REQUIRED 1
|
||||
#endif
|
||||
|
||||
// deprecation markup is only enabled when libtorrent
|
||||
// headers are included by clients, not while building
|
||||
// libtorrent itself
|
||||
# if __GNUC__ >= 3 && !defined TORRENT_BUILDING_LIBRARY
|
||||
# define TORRENT_DEPRECATED __attribute__ ((deprecated))
|
||||
# endif
|
||||
|
||||
# if __GNUC__ >= 6 && !defined TORRENT_BUILDING_LIBRARY
|
||||
# define TORRENT_DEPRECATED_ENUM __attribute__ ((deprecated))
|
||||
# define TORRENT_DEPRECATED_MEMBER __attribute__ ((deprecated))
|
||||
# endif
|
||||
|
||||
// ======= SUNPRO =========
|
||||
|
||||
#elif defined __SUNPRO_CC
|
||||
@ -101,13 +77,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
// class X needs to have dll-interface to be used by clients of class Y
|
||||
#pragma warning(disable:4251)
|
||||
|
||||
// deprecation markup is only enabled when libtorrent
|
||||
// headers are included by clients, not while building
|
||||
// libtorrent itself
|
||||
#if !defined TORRENT_BUILDING_LIBRARY
|
||||
# define TORRENT_DEPRECATED __declspec(deprecated)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -425,18 +394,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#define TORRENT_HAS_FALLOCATE 1
|
||||
#endif
|
||||
|
||||
#ifndef TORRENT_DEPRECATED
|
||||
#define TORRENT_DEPRECATED
|
||||
#endif
|
||||
|
||||
#ifndef TORRENT_DEPRECATED_ENUM
|
||||
#define TORRENT_DEPRECATED_ENUM
|
||||
#endif
|
||||
|
||||
#ifndef TORRENT_DEPRECATED_MEMBER
|
||||
#define TORRENT_DEPRECATED_MEMBER
|
||||
#endif
|
||||
|
||||
#ifndef TORRENT_USE_COMMONCRYPTO
|
||||
#define TORRENT_USE_COMMONCRYPTO 0
|
||||
#endif
|
||||
|
@ -59,6 +59,10 @@ namespace libtorrent {
|
||||
// information about a file in a file_storage
|
||||
struct TORRENT_DEPRECATED_EXPORT file_entry
|
||||
{
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
// hidden
|
||||
file_entry();
|
||||
// hidden
|
||||
@ -68,6 +72,10 @@ namespace libtorrent {
|
||||
file_entry(file_entry&&) noexcept = default;
|
||||
file_entry& operator=(file_entry&&) & = default;
|
||||
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// the full path of this file. The paths are unicode strings
|
||||
// encoded in UTF-8.
|
||||
std::string path;
|
||||
@ -319,6 +327,14 @@ namespace aux {
|
||||
void rename_file(file_index_t index, std::string const& new_filename);
|
||||
|
||||
#if TORRENT_ABI_VERSION == 1
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning(disable: 4996)
|
||||
#endif
|
||||
TORRENT_DEPRECATED
|
||||
void add_file_borrow(char const* filename, int filename_len
|
||||
, std::string const& path, std::int64_t file_size
|
||||
@ -340,30 +356,7 @@ namespace aux {
|
||||
void set_name(std::wstring const& n);
|
||||
|
||||
void rename_file_deprecated(file_index_t index, std::wstring const& new_filename);
|
||||
#endif // TORRENT_ABI_VERSION
|
||||
|
||||
// returns a list of file_slice objects representing the portions of
|
||||
// files the specified piece index, byte offset and size range overlaps.
|
||||
// this is the inverse mapping of map_file().
|
||||
//
|
||||
// Preconditions of this function is that the input range is within the
|
||||
// torrents address space. ``piece`` may not be negative and
|
||||
//
|
||||
// ``piece`` * piece_size + ``offset`` + ``size``
|
||||
//
|
||||
// may not exceed the total size of the torrent.
|
||||
std::vector<file_slice> map_block(piece_index_t piece, std::int64_t offset
|
||||
, int size) const;
|
||||
|
||||
// returns a peer_request representing the piece index, byte offset
|
||||
// and size the specified file range overlaps. This is the inverse
|
||||
// mapping over map_block(). Note that the ``peer_request`` return type
|
||||
// is meant to hold bittorrent block requests, which may not be larger
|
||||
// than 16 kiB. Mapping a range larger than that may return an overflown
|
||||
// integer.
|
||||
peer_request map_file(file_index_t file, std::int64_t offset, int size) const;
|
||||
|
||||
#if TORRENT_ABI_VERSION == 1
|
||||
// all functions depending on aux::file_entry
|
||||
// were deprecated in 1.0. Use the variants that take an
|
||||
// index instead
|
||||
@ -396,8 +389,36 @@ namespace aux {
|
||||
reverse_iterator rend_deprecated() const { return m_files.rend(); }
|
||||
iterator file_at_offset_deprecated(std::int64_t offset) const;
|
||||
file_entry at_deprecated(int index) const;
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
#endif // TORRENT_ABI_VERSION
|
||||
|
||||
// returns a list of file_slice objects representing the portions of
|
||||
// files the specified piece index, byte offset and size range overlaps.
|
||||
// this is the inverse mapping of map_file().
|
||||
//
|
||||
// Preconditions of this function is that the input range is within the
|
||||
// torrents address space. ``piece`` may not be negative and
|
||||
//
|
||||
// ``piece`` * piece_size + ``offset`` + ``size``
|
||||
//
|
||||
// may not exceed the total size of the torrent.
|
||||
std::vector<file_slice> map_block(piece_index_t piece, std::int64_t offset
|
||||
, int size) const;
|
||||
|
||||
// returns a peer_request representing the piece index, byte offset
|
||||
// and size the specified file range overlaps. This is the inverse
|
||||
// mapping over map_block(). Note that the ``peer_request`` return type
|
||||
// is meant to hold bittorrent block requests, which may not be larger
|
||||
// than 16 kiB. Mapping a range larger than that may return an overflown
|
||||
// integer.
|
||||
peer_request map_file(file_index_t file, std::int64_t offset, int size) const;
|
||||
|
||||
// returns the number of files in the file_storage
|
||||
int num_files() const noexcept;
|
||||
|
||||
|
@ -46,26 +46,46 @@ namespace aux {
|
||||
TORRENT_EXTRA_EXPORT int hex_to_int(char in);
|
||||
TORRENT_EXTRA_EXPORT bool is_hex(span<char const> in);
|
||||
|
||||
#if TORRENT_ABI_VERSION == 1
|
||||
#define TORRENT_CONDITIONAL_EXPORT TORRENT_EXPORT
|
||||
#else
|
||||
#define TORRENT_CONDITIONAL_EXPORT TORRENT_EXTRA_EXPORT
|
||||
#endif
|
||||
|
||||
// The overload taking a ``std::string`` converts (binary) the string ``s``
|
||||
// to hexadecimal representation and returns it.
|
||||
// The overload taking a ``char const*`` and a length converts the binary
|
||||
// buffer [``in``, ``in`` + len) to hexadecimal and prints it to the buffer
|
||||
// ``out``. The caller is responsible for making sure the buffer pointed to
|
||||
// by ``out`` is large enough, i.e. has at least len * 2 bytes of space.
|
||||
TORRENT_DEPRECATED_EXPORT std::string to_hex(span<char const> s);
|
||||
TORRENT_DEPRECATED_EXPORT void to_hex(span<char const> in, char* out);
|
||||
TORRENT_DEPRECATED_EXPORT void to_hex(char const* in, int const len, char* out);
|
||||
TORRENT_CONDITIONAL_EXPORT std::string to_hex(span<char const> s);
|
||||
TORRENT_CONDITIONAL_EXPORT void to_hex(span<char const> in, char* out);
|
||||
TORRENT_CONDITIONAL_EXPORT void to_hex(char const* in, int const len, char* out);
|
||||
|
||||
// converts the buffer [``in``, ``in`` + len) from hexadecimal to
|
||||
// binary. The binary output is written to the buffer pointed to
|
||||
// by ``out``. The caller is responsible for making sure the buffer
|
||||
// at ``out`` has enough space for the result to be written to, i.e.
|
||||
// (len + 1) / 2 bytes.
|
||||
TORRENT_DEPRECATED_EXPORT bool from_hex(span<char const> in, char* out);
|
||||
TORRENT_CONDITIONAL_EXPORT bool from_hex(span<char const> in, char* out);
|
||||
|
||||
#undef TORRENT_CONDITIONAL_EXPORT
|
||||
|
||||
|
||||
} // namespace aux
|
||||
|
||||
#if TORRENT_ABI_VERSION == 1
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
// warning C4996: X: was declared deprecated
|
||||
#pragma warning( disable : 4996 )
|
||||
#endif
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
// deprecated in 1.2
|
||||
TORRENT_DEPRECATED
|
||||
inline void to_hex(char const* in, int len, char* out)
|
||||
@ -76,6 +96,14 @@ namespace aux {
|
||||
TORRENT_DEPRECATED
|
||||
inline bool from_hex(char const *in, int len, char* out)
|
||||
{ return aux::from_hex({in, len}, out); }
|
||||
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
} // namespace libtorrent
|
||||
|
||||
|
@ -158,6 +158,15 @@ namespace dht {
|
||||
int max_infohashes_sample_count = 20;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning( disable : 4996 ) // warning C4996: X: was declared deprecated
|
||||
#endif
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
// internal
|
||||
struct settings : dht_settings
|
||||
{
|
||||
@ -169,6 +178,14 @@ namespace dht {
|
||||
|
||||
TORRENT_EXTRA_EXPORT dht_settings read_dht_settings(bdecode_node const& e);
|
||||
TORRENT_EXTRA_EXPORT entry save_dht_settings(dht_settings const& settings);
|
||||
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
@ -93,6 +93,16 @@ namespace libtorrent {
|
||||
TORRENT_DEPRECATED_EXPORT int lazy_bdecode(char const* start, char const* end
|
||||
, lazy_entry& ret, int depth_limit = 1000, int item_limit = 1000000);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
// warning C4996: X: was declared deprecated
|
||||
#pragma warning( disable : 4996 )
|
||||
#endif
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
// this is a string that is not 0-terminated. Instead it
|
||||
// comes with a length, specified in bytes. This is particularly
|
||||
// useful when parsing bencoded structures, because strings are
|
||||
@ -402,6 +412,13 @@ namespace libtorrent {
|
||||
TORRENT_DEPRECATED_EXPORT std::string print_entry(lazy_entry const& e
|
||||
, bool single_line = false, int indent = 0);
|
||||
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
// defined in bdecode.cpp
|
||||
TORRENT_DEPRECATED
|
||||
TORRENT_EXTRA_EXPORT char const* parse_int(char const* start
|
||||
|
@ -166,8 +166,23 @@ TORRENT_VERSION_NAMESPACE_3
|
||||
std::vector<std::shared_ptr<plugin>> extensions;
|
||||
|
||||
#if TORRENT_ABI_VERSION <= 2
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning( disable : 4996 ) // warning C4996: X: was declared deprecated
|
||||
#endif
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
// this is deprecated. Use the dht_* settings instead.
|
||||
dht::dht_settings dht_settings;
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
dht::dht_state dht_state;
|
||||
|
@ -331,12 +331,27 @@ namespace libtorrent {
|
||||
#endif
|
||||
|
||||
#if TORRENT_ABI_VERSION <= 2
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning( disable : 4996 ) // warning C4996: X: was declared deprecated
|
||||
#endif
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
// ``set_dht_settings`` sets some parameters available to the dht node.
|
||||
// See dht_settings for more information.
|
||||
//
|
||||
// ``get_dht_settings()`` returns the current settings
|
||||
void set_dht_settings(dht::dht_settings const& settings);
|
||||
dht::dht_settings get_dht_settings() const;
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// ``is_dht_running()`` returns true if the DHT support has been started
|
||||
@ -793,14 +808,6 @@ namespace libtorrent {
|
||||
// shifting.
|
||||
void remove_torrent(const torrent_handle&, remove_flags_t = {});
|
||||
|
||||
#if TORRENT_ABI_VERSION == 1
|
||||
// deprecated in libtorrent 1.1. use settings_pack instead
|
||||
TORRENT_DEPRECATED
|
||||
void set_pe_settings(pe_settings const&);
|
||||
TORRENT_DEPRECATED
|
||||
pe_settings get_pe_settings() const;
|
||||
#endif
|
||||
|
||||
// Applies the settings specified by the settings_pack ``s``. This is an
|
||||
// asynchronous operation that will return immediately and actually apply
|
||||
// the settings to the main thread of libtorrent some time later.
|
||||
@ -809,6 +816,29 @@ namespace libtorrent {
|
||||
settings_pack get_settings() const;
|
||||
|
||||
#if TORRENT_ABI_VERSION == 1
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning( disable : 4996 ) // warning C4996: X: was declared deprecated
|
||||
#endif
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
// deprecated in libtorrent 1.1. use settings_pack instead
|
||||
TORRENT_DEPRECATED
|
||||
void set_pe_settings(pe_settings const&);
|
||||
TORRENT_DEPRECATED
|
||||
pe_settings get_pe_settings() const;
|
||||
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
// ``set_i2p_proxy`` sets the i2p_ proxy, and tries to open a persistent
|
||||
// connection to it. The only used fields in the proxy settings structs
|
||||
// are ``hostname`` and ``port``.
|
||||
|
@ -45,7 +45,21 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
namespace libtorrent {
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning( disable : 4996 ) // warning C4996: X: was declared deprecated
|
||||
#endif
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
using dht_settings = dht::dht_settings;
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
using aux::proxy_settings;
|
||||
|
||||
|
@ -1454,7 +1454,8 @@ namespace aux {
|
||||
|
||||
// ``unchoke_slots_limit`` is the max number of unchoked peers in the
|
||||
// session. The number of unchoke slots may be ignored depending on
|
||||
// what ``choking_algorithm`` is set to.
|
||||
// what ``choking_algorithm`` is set to. Setting this limit to -1
|
||||
// means unlimited, i.e. all peers will always be unchoked.
|
||||
unchoke_slots_limit,
|
||||
|
||||
#if TORRENT_ABI_VERSION == 1
|
||||
|
@ -409,8 +409,26 @@ namespace aux {
|
||||
file_iterator file_at_offset(std::int64_t offset) const
|
||||
{ return m_files.file_at_offset_deprecated(offset); }
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
// warning C4996: X: was declared deprecated
|
||||
#pragma warning( disable : 4996 )
|
||||
#endif
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
TORRENT_DEPRECATED
|
||||
file_entry file_at(int index) const { return m_files.at_deprecated(index); }
|
||||
|
||||
#if defined __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif // TORRENT_ABI_VERSION
|
||||
|
||||
// If you need index-access to files you can use the ``num_files()`` along
|
||||
|
@ -201,8 +201,8 @@ namespace {
|
||||
// allow lots of peers to try to connect simultaneously
|
||||
set.set_int(settings_pack::listen_queue_size, 3000);
|
||||
|
||||
// unchoke many peers
|
||||
set.set_int(settings_pack::unchoke_slots_limit, 2000);
|
||||
// unchoke all peers
|
||||
set.set_int(settings_pack::unchoke_slots_limit, -1);
|
||||
|
||||
set.set_int(settings_pack::read_cache_line_size, 32);
|
||||
set.set_int(settings_pack::write_cache_line_size, 256);
|
||||
|
@ -4004,6 +4004,9 @@ void apply_deprecated_dht_settings(settings_pack& sett, bdecode_node const& s)
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
if (m_stats_counters[counters::num_unchoke_slots] == 0) return;
|
||||
|
||||
// if we unchoke everyone, skip this logic
|
||||
if (settings().get_int(settings_pack::unchoke_slots_limit) < 0) return;
|
||||
|
||||
std::vector<opt_unchoke_candidate> opt_unchoke;
|
||||
|
||||
// collect the currently optimistically unchoked peers here, so we can
|
||||
@ -4269,6 +4272,13 @@ void apply_deprecated_dht_settings(settings_pack& sett, bdecode_node const& s)
|
||||
time_duration const unchoke_interval = now - m_last_choke;
|
||||
m_last_choke = now;
|
||||
|
||||
// if we unchoke everyone, skip this logic
|
||||
if (settings().get_int(settings_pack::unchoke_slots_limit) < 0)
|
||||
{
|
||||
m_stats_counters.set_value(counters::num_unchoke_slots, std::numeric_limits<int>::max());
|
||||
return;
|
||||
}
|
||||
|
||||
// build list of all peers that are
|
||||
// unchokable.
|
||||
// TODO: 3 there should be a pre-calculated list of all peers eligible for
|
||||
@ -6250,6 +6260,25 @@ void apply_deprecated_dht_settings(settings_pack& sett, bdecode_node const& s)
|
||||
m_alerts.emplace_alert<performance_alert>(torrent_handle()
|
||||
, performance_alert::too_many_optimistic_unchoke_slots);
|
||||
}
|
||||
|
||||
if (allowed_upload_slots == std::numeric_limits<int>::max())
|
||||
{
|
||||
// this means we're not aplpying upload slot limits, unchoke
|
||||
// everyone
|
||||
for (auto const& p : m_connections)
|
||||
{
|
||||
if (p->is_disconnecting() || p->is_connecting())
|
||||
continue;
|
||||
|
||||
auto const t = p->associated_torrent().lock();
|
||||
t->unchoke_peer(*p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// trigger recalculating unchoke slots
|
||||
m_unchoke_time_scaler = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void session_impl::update_connection_speed()
|
||||
|
@ -36,7 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
#include "libtorrent/session.hpp"
|
||||
#include "libtorrent/hex.hpp" // for from_hex
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/bencode.hpp" // for bencode()
|
||||
#include "libtorrent/kademlia/item.hpp" // for sign_mutable_item
|
||||
@ -53,10 +52,6 @@ using namespace lt;
|
||||
using namespace lt::dht;
|
||||
using namespace std::placeholders;
|
||||
|
||||
// TODO: don't use internal functions to libtorrent
|
||||
using lt::aux::from_hex;
|
||||
using lt::aux::to_hex;
|
||||
|
||||
#ifdef TORRENT_DISABLE_DHT
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
@ -67,6 +62,43 @@ int main(int argc, char* argv[])
|
||||
|
||||
#else
|
||||
|
||||
std::string to_hex(lt::span<char const> key)
|
||||
{
|
||||
std::string out;
|
||||
for (auto const b : key)
|
||||
{
|
||||
char buf[20];
|
||||
std::snprintf(buf, sizeof(3), "%02x", static_cast<unsigned char>(b));
|
||||
out += (char*)buf;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
int hex_to_int(char in)
|
||||
{
|
||||
if (in >= '0' && in <= '9') return int(in) - '0';
|
||||
if (in >= 'A' && in <= 'F') return int(in) - 'A' + 10;
|
||||
if (in >= 'a' && in <= 'f') return int(in) - 'a' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool from_hex(span<char const> in, span<char> out)
|
||||
{
|
||||
if (in.size() != out.size() * 2) return false;
|
||||
auto o = out.begin();
|
||||
for (auto i = in.begin(); i != in.end(); ++i, ++o)
|
||||
{
|
||||
int const t1 = hex_to_int(*i);
|
||||
if (t1 == -1) return false;
|
||||
++i;
|
||||
if (i == in.end()) return false;
|
||||
int const t2 = hex_to_int(*i);
|
||||
if (t2 == -1) return false;
|
||||
*o = static_cast<char>((t1 << 4) | (t2 & 0xf));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
void usage()
|
||||
{
|
||||
@ -202,12 +234,13 @@ void load_dht_state(lt::session& s)
|
||||
return;
|
||||
}
|
||||
|
||||
bdecode_node e;
|
||||
error_code ec;
|
||||
bdecode(state.data(), state.data() + state.size(), e, ec);
|
||||
bdecode_node e = bdecode(state, ec);
|
||||
if (ec)
|
||||
{
|
||||
std::fprintf(stderr, "failed to parse .dht file: (%d) %s\n"
|
||||
, ec.value(), ec.message().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::printf("load dht state from .dht\n");
|
||||
@ -277,8 +310,7 @@ int main(int argc, char* argv[])
|
||||
usage();
|
||||
}
|
||||
sha1_hash target;
|
||||
bool ret = from_hex({argv[0], 40}, target.data());
|
||||
if (!ret)
|
||||
if (!from_hex({argv[0], 40}, target))
|
||||
{
|
||||
std::fprintf(stderr, "invalid hex encoding of target hash\n");
|
||||
return 1;
|
||||
@ -356,8 +388,7 @@ int main(int argc, char* argv[])
|
||||
return 1;
|
||||
}
|
||||
std::array<char, 32> public_key;
|
||||
bool ret = from_hex({argv[0], len}, &public_key[0]);
|
||||
if (!ret)
|
||||
if (!from_hex({argv[0], len}, public_key))
|
||||
{
|
||||
std::fprintf(stderr, "invalid hex encoding of public key\n");
|
||||
return 1;
|
||||
|
Reference in New Issue
Block a user