From 78aefcc80648e81ff68a0cab258e7d2739c3ae79 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 20 Nov 2019 12:32:23 +0100 Subject: [PATCH] fix deprecation warnings for deprecated classes --- CMakeLists.txt | 1 + examples/client_test.cpp | 5 +- fuzzers/src/lazy_bdecode.cpp | 9 ++- include/libtorrent/Makefile.am | 1 + include/libtorrent/alert_types.hpp | 39 ++++++++++ include/libtorrent/aux_/deprecated.hpp | 88 ++++++++++++++++++++++ include/libtorrent/aux_/export.hpp | 6 +- include/libtorrent/aux_/proxy_settings.hpp | 5 +- include/libtorrent/config.hpp | 45 +---------- include/libtorrent/file_storage.hpp | 68 +++++++++++------ include/libtorrent/fingerprint.hpp | 2 +- include/libtorrent/hex.hpp | 19 +++++ include/libtorrent/identify_client.hpp | 2 +- include/libtorrent/lazy_entry.hpp | 17 +++++ include/libtorrent/session_handle.hpp | 24 ++++-- include/libtorrent/torrent_info.hpp | 18 +++++ tools/dht_put.cpp | 53 ++++++++++--- 17 files changed, 303 insertions(+), 99 deletions(-) create mode 100644 include/libtorrent/aux_/deprecated.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c5d08d6fe..ffe2f71ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,6 +219,7 @@ set(libtorrent_aux_include_files cppint_import_export cpuid deferred_handler + deprecated deque dev_random disable_warnings_pop diff --git a/examples/client_test.cpp b/examples/client_test.cpp index f5fbae675..7250a9182 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1082,10 +1082,9 @@ example alert_masks: std::vector 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 diff --git a/fuzzers/src/lazy_bdecode.cpp b/fuzzers/src/lazy_bdecode.cpp index 9e56efdb7..98aaad5a3 100644 --- a/fuzzers/src/lazy_bdecode.cpp +++ b/fuzzers/src/lazy_bdecode.cpp @@ -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(data), reinterpret_cast(data) + size, ret, ec, &pos); +#if defined __GNUC__ +#pragma GCC diagnostic pop +#endif return 0; } diff --git a/include/libtorrent/Makefile.am b/include/libtorrent/Makefile.am index a28d8c7e3..de7f00178 100644 --- a/include/libtorrent/Makefile.am +++ b/include/libtorrent/Makefile.am @@ -171,6 +171,7 @@ nobase_include_HEADERS = \ aux_/disable_warnings_pop.hpp \ aux_/disk_job_fence.hpp \ aux_/deferred_handler.hpp \ + aux_/deprecated.hpp \ aux_/dev_random.hpp \ aux_/deque.hpp \ aux_/escape_string.hpp \ diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index d3c598aba..753eb48ea 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -54,6 +54,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/stack_allocator.hpp" #include "libtorrent/aux_/noexcept_movable.hpp" #include "libtorrent/portmap.hpp" // for portmap_transport +#include "libtorrent/aux_/deprecated.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp" #include @@ -209,6 +210,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. @@ -224,6 +236,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 @@ -1819,6 +1839,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 @@ -1846,6 +1877,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 diff --git a/include/libtorrent/aux_/deprecated.hpp b/include/libtorrent/aux_/deprecated.hpp new file mode 100644 index 000000000..22097efb3 --- /dev/null +++ b/include/libtorrent/aux_/deprecated.hpp @@ -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 diff --git a/include/libtorrent/aux_/export.hpp b/include/libtorrent/aux_/export.hpp index 096acce9c..b86ea340e 100644 --- a/include/libtorrent/aux_/export.hpp +++ b/include/libtorrent/aux_/export.hpp @@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE. #include +#include "libtorrent/aux_/deprecated.hpp" + #if !defined TORRENT_ABI_VERSION # ifdef TORRENT_NO_DEPRECATE # define TORRENT_ABI_VERSION 2 @@ -91,9 +93,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 diff --git a/include/libtorrent/aux_/proxy_settings.hpp b/include/libtorrent/aux_/proxy_settings.hpp index dde015af5..e3b0e7114 100644 --- a/include/libtorrent/aux_/proxy_settings.hpp +++ b/include/libtorrent/aux_/proxy_settings.hpp @@ -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 diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 652d2914d..fb8532426 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -56,36 +56,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 @@ -99,13 +75,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 - // auto and decltype(auto) return types supports since MSVS2015 // https://msdn.microsoft.com/en-us/library/hh567368.aspx // we need to force C++14 feature due VS2017 inability to parse C++11 syntax @@ -402,18 +371,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 diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index e418e9436..c2b0cb202 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -55,6 +55,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 @@ -64,6 +68,10 @@ namespace libtorrent { file_entry(file_entry&&) noexcept = default; file_entry& operator=(file_entry&&) & noexcept = 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; @@ -282,6 +290,14 @@ namespace libtorrent { 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 @@ -303,30 +319,6 @@ namespace libtorrent { 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 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 internal_file_entry // were deprecated in 1.0. Use the variants that take an // index instead @@ -359,8 +351,36 @@ namespace libtorrent { 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 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; diff --git a/include/libtorrent/fingerprint.hpp b/include/libtorrent/fingerprint.hpp index cf33f8645..91f4ae05e 100644 --- a/include/libtorrent/fingerprint.hpp +++ b/include/libtorrent/fingerprint.hpp @@ -78,7 +78,7 @@ namespace libtorrent { // The fingerprint class represents information about a client and its version. It is used // to encode this information into the client's peer id. - struct TORRENT_DEPRECATED TORRENT_DEPRECATED_EXPORT fingerprint + struct TORRENT_DEPRECATED_EXPORT fingerprint { fingerprint(const char* id_string, int major, int minor, int revision, int tag); diff --git a/include/libtorrent/hex.hpp b/include/libtorrent/hex.hpp index 6c95376c8..de6510dcc 100644 --- a/include/libtorrent/hex.hpp +++ b/include/libtorrent/hex.hpp @@ -66,6 +66,17 @@ namespace libtorrent { } #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 +87,14 @@ namespace libtorrent { 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 } diff --git a/include/libtorrent/identify_client.hpp b/include/libtorrent/identify_client.hpp index fec750ddd..f9b023c55 100644 --- a/include/libtorrent/identify_client.hpp +++ b/include/libtorrent/identify_client.hpp @@ -82,7 +82,7 @@ namespace aux { // id. This can be used to automate the identification of clients. It will // not be able to identify peers with non- standard encodings. Only Azureus // style, Shadow's style and Mainline style. - TORRENT_DEPRECATED_EXPORT TORRENT_DEPRECATED + TORRENT_DEPRECATED_EXPORT boost::optional client_fingerprint(peer_id const& p); diff --git a/include/libtorrent/lazy_entry.hpp b/include/libtorrent/lazy_entry.hpp index 9d4ad3490..bc91d3dd9 100644 --- a/include/libtorrent/lazy_entry.hpp +++ b/include/libtorrent/lazy_entry.hpp @@ -91,6 +91,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 @@ -400,6 +410,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 diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index 7dff1bbd2..22e3ae817 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -809,14 +809,6 @@ namespace libtorrent { // shifting. void remove_torrent(const torrent_handle& h, remove_flags_t options = {}); -#if TORRENT_ABI_VERSION == 1 - // deprecated in libtorrent 1.1. use settings_pack instead - TORRENT_DEPRECATED - void set_pe_settings(pe_settings const& settings); - 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. @@ -825,6 +817,22 @@ namespace libtorrent { settings_pack get_settings() const; #if TORRENT_ABI_VERSION == 1 + +#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& settings); + TORRENT_DEPRECATED + pe_settings get_pe_settings() const; + +#if defined __GNUC__ +#pragma GCC diagnostic 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``. diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index ddf03154c..70f856ab9 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -394,8 +394,26 @@ namespace libtorrent { 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 diff --git a/tools/dht_put.cpp b/tools/dht_put.cpp index e09dd1393..c3c4fc42a 100644 --- a/tools/dht_put.cpp +++ b/tools/dht_put.cpp @@ -32,7 +32,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 @@ -49,10 +48,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[]) @@ -63,6 +58,43 @@ int main(int argc, char* argv[]) #else +std::string to_hex(lt::span key) +{ + std::string out; + for (auto const b : key) + { + char buf[20]; + std::snprintf(buf, sizeof(3), "%02x", static_cast(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 in, span 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 = (t1 << 4) | (t2 & 0xf); + } + return true; +} + namespace { void usage() { @@ -198,12 +230,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"); @@ -273,8 +306,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; @@ -352,8 +384,7 @@ int main(int argc, char* argv[]) return 1; } std::array 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;