diff --git a/.travis.yml b/.travis.yml index f1de95075..e6e48187f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,10 +12,6 @@ env: - libt_branch=RC_1_2 gui=false build_system=qmake - libt_branch=RC_1_2 gui=true build_system=cmake - libt_branch=RC_1_2 gui=false build_system=cmake - - libt_branch=RC_1_1 gui=true build_system=qmake - - libt_branch=RC_1_1 gui=false build_system=qmake - - libt_branch=RC_1_1 gui=true build_system=cmake - - libt_branch=RC_1_1 gui=false build_system=cmake global: - secure: "OI9CUjj4lTb0HwwIZU5PbECU3hLlAL6KC8KsbwohG8/O3j5fLcnmDsK4Ad9us5cC39sS11Jcd1kDP2qRcCuST/glVNhLkcjKkiQerOfd5nQ/qL4JYfz/1mfP5mdpz9jHKzpLUIG+TXkbSTjP6VVmsb5KPT+3pKEdRFZB+Pu9+J8=" - coverity_branch: coverity_scan @@ -24,8 +20,6 @@ matrix: allow_failures: - env: libt_branch=RC_1_2 gui=true build_system=cmake - env: libt_branch=RC_1_2 gui=false build_system=cmake - - env: libt_branch=RC_1_1 gui=true build_system=cmake - - env: libt_branch=RC_1_1 gui=false build_system=cmake branches: except: @@ -129,53 +123,11 @@ install: ccache -M 512M ccache -V && ccache --show-stats && ccache --zero-stats fi - - | - if [ "$libt_branch" = "RC_1_1" ] && [ "$TRAVIS_OS_NAME" = "linux" ]; then - wget https://builds.shiki.hu/travis/deb/version - if ! cmp --quiet "version" "$HOME/travis/deb/version" ; then - echo "Cached files are different from server. Downloading new ones." - # First delete old files - rm -r "$HOME/travis/deb" - mkdir "$HOME/travis/deb" - cp "version" $HOME/travis/deb - cd "$HOME/travis/deb" - wget https://builds.shiki.hu/travis/deb/libtorrent-rasterbar-dev_1.1.x_amd64.deb - wget https://builds.shiki.hu/travis/deb/libtorrent-rasterbar9_1.1.x_amd64.deb - fi - - sudo dpkg -i "$HOME/travis/deb/libtorrent-rasterbar-dev_1.1.x_amd64.deb" "$HOME/travis/deb/libtorrent-rasterbar9_1.1.x_amd64.deb" - fi - | if [ "$libt_branch" = "RC_1_2" ] && [ "$TRAVIS_OS_NAME" = "linux" ]; then # Will install latest 1.2.x daily build from the PPA sudo apt-get -y install libtorrent-rasterbar-dev fi - - | - if [ "$libt_branch" = "RC_1_1" ] && [ "$TRAVIS_OS_NAME" = "osx" ]; then - wget https://builds.shiki.hu/travis/brew/1_1/version - if ! cmp --quiet "version" "$HOME/travis/brew/1_1/version" ; then - echo "Cached files are different from server. Downloading new ones." - # First delete old files - rm -r "$HOME/travis/brew/1_1" - mkdir "$HOME/travis/brew/1_1" - cp "version" $HOME/travis/brew/1_1 - cd "$HOME/travis/brew/1_1" - wget https://builds.shiki.hu/travis/brew/1_1/libtorrent-rasterbar.rb - wget https://builds.shiki.hu/travis/brew/1_1/bd36a4b440aa138a88e375c1a3b672f1a1bc6606e7866fc3415b6b98fa49e771--libtorrent-rasterbar-1.1.13.high_sierra.bottle.tar.gz - fi - # Copy custom libtorrent bottle to homebrew's download cache so it can find and install it - # Also install our custom libtorrent formula by passing the local path to it - # These 2 files are restored from Travis' cache. - cp "$HOME/travis/brew/1_1/bd36a4b440aa138a88e375c1a3b672f1a1bc6606e7866fc3415b6b98fa49e771--libtorrent-rasterbar-1.1.13.high_sierra.bottle.tar.gz" "$(brew --cache)/downloads" - brew uninstall libtorrent-rasterbar - brew install "$HOME/travis/brew/1_1/libtorrent-rasterbar.rb" - - # NOTE about the bottle name - # The part before the "--" characters is a sha256 hash of the string - # of the URL homebrew itself would use to download the bottle. - # In this case the URL is the following: - # http://127.0.0.1/libtorrent-rasterbar-1.1.13.high_sierra.bottle.tar.gz - fi - | if [ "$libt_branch" = "RC_1_2" ] && [ "$TRAVIS_OS_NAME" = "osx" ]; then wget https://builds.shiki.hu/travis/brew/version diff --git a/CMakeLists.txt b/CMakeLists.txt index 19a7612e0..1d32cd9d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ include(FeatureSummary) set(requiredBoostVersion 1.40) set(requiredQtVersion 5.9.0) set(requiredOpensslVersion 1.0) -set(requiredLibtorrentVersion 1.1.10) +set(requiredLibtorrentVersion 1.2) if (WIN32) include(winconf) diff --git a/INSTALL b/INSTALL index 3c18c304b..6da1e98e0 100644 --- a/INSTALL +++ b/INSTALL @@ -5,7 +5,7 @@ qBittorrent - A BitTorrent client in C++ / Qt - Boost >= 1.40 - - libtorrent-rasterbar >= 1.1.10 (by Arvid Norberg) + - libtorrent-rasterbar >= 1.2 (by Arvid Norberg) * https://www.libtorrent.org/ * Be careful: another library (the one used by rTorrent) uses a similar name diff --git a/configure b/configure index 43f34e619..02dfdc151 100755 --- a/configure +++ b/configure @@ -5292,12 +5292,12 @@ if test -n "$libtorrent_CFLAGS"; then pkg_cv_libtorrent_CFLAGS="$libtorrent_CFLAGS" elif test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG" && \ - { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libtorrent-rasterbar >= 1.1.10\""; } >&5 - ($PKG_CONFIG --exists --print-errors "libtorrent-rasterbar >= 1.1.10") 2>&5 + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libtorrent-rasterbar >= 1.2\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libtorrent-rasterbar >= 1.2") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then - pkg_cv_libtorrent_CFLAGS=`$PKG_CONFIG --cflags "libtorrent-rasterbar >= 1.1.10" 2>/dev/null` + pkg_cv_libtorrent_CFLAGS=`$PKG_CONFIG --cflags "libtorrent-rasterbar >= 1.2" 2>/dev/null` test "x$?" != "x0" && pkg_failed=yes else pkg_failed=yes @@ -5309,12 +5309,12 @@ if test -n "$libtorrent_LIBS"; then pkg_cv_libtorrent_LIBS="$libtorrent_LIBS" elif test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG" && \ - { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libtorrent-rasterbar >= 1.1.10\""; } >&5 - ($PKG_CONFIG --exists --print-errors "libtorrent-rasterbar >= 1.1.10") 2>&5 + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libtorrent-rasterbar >= 1.2\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libtorrent-rasterbar >= 1.2") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then - pkg_cv_libtorrent_LIBS=`$PKG_CONFIG --libs "libtorrent-rasterbar >= 1.1.10" 2>/dev/null` + pkg_cv_libtorrent_LIBS=`$PKG_CONFIG --libs "libtorrent-rasterbar >= 1.2" 2>/dev/null` test "x$?" != "x0" && pkg_failed=yes else pkg_failed=yes @@ -5335,14 +5335,14 @@ else _pkg_short_errors_supported=no fi if test $_pkg_short_errors_supported = yes; then - libtorrent_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libtorrent-rasterbar >= 1.1.10" 2>&1` + libtorrent_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libtorrent-rasterbar >= 1.2" 2>&1` else - libtorrent_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libtorrent-rasterbar >= 1.1.10" 2>&1` + libtorrent_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libtorrent-rasterbar >= 1.2" 2>&1` fi # Put the nasty error message in config.log where it belongs echo "$libtorrent_PKG_ERRORS" >&5 - as_fn_error $? "Package requirements (libtorrent-rasterbar >= 1.1.10) were not met: + as_fn_error $? "Package requirements (libtorrent-rasterbar >= 1.2) were not met: $libtorrent_PKG_ERRORS diff --git a/configure.ac b/configure.ac index 55e673b3e..c56126f77 100644 --- a/configure.ac +++ b/configure.ac @@ -178,7 +178,7 @@ AC_MSG_NOTICE([Boost.System LIB: "$BOOST_SYSTEM_LIB"]) LIBS="$BOOST_SYSTEM_LIB $LIBS" PKG_CHECK_MODULES(libtorrent, - [libtorrent-rasterbar >= 1.1.10], + [libtorrent-rasterbar >= 1.2], [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS"]) diff --git a/src/app/qtlocalpeer/qtlockedfile.cpp b/src/app/qtlocalpeer/qtlockedfile.cpp index 9b6b2acb1..f3041c56c 100644 --- a/src/app/qtlocalpeer/qtlockedfile.cpp +++ b/src/app/qtlocalpeer/qtlockedfile.cpp @@ -111,10 +111,6 @@ QtLockedFile::QtLockedFile() : QFile() { -#ifdef Q_OS_WIN - wmutex = 0; - rmutex = 0; -#endif m_lock_mode = NoLock; } @@ -128,10 +124,6 @@ QtLockedFile::QtLockedFile() QtLockedFile::QtLockedFile(const QString &name) : QFile(name) { -#ifdef Q_OS_WIN - wmutex = 0; - rmutex = 0; -#endif m_lock_mode = NoLock; } diff --git a/src/app/qtlocalpeer/qtlockedfile.h b/src/app/qtlocalpeer/qtlockedfile.h index e97b4c761..ee89062d9 100644 --- a/src/app/qtlocalpeer/qtlockedfile.h +++ b/src/app/qtlocalpeer/qtlockedfile.h @@ -103,8 +103,8 @@ namespace QtLP_Private Qt::HANDLE getMutexHandle(int idx, bool doCreate); bool waitMutex(Qt::HANDLE mutex, bool doBlock); - Qt::HANDLE wmutex; - Qt::HANDLE rmutex; + Qt::HANDLE wmutex = nullptr; + Qt::HANDLE rmutex = nullptr; QVector rmutexes; QString mutexname; #endif diff --git a/src/base/bittorrent/customstorage.cpp b/src/base/bittorrent/customstorage.cpp index be25034a4..864707821 100644 --- a/src/base/bittorrent/customstorage.cpp +++ b/src/base/bittorrent/customstorage.cpp @@ -28,7 +28,6 @@ #include "customstorage.h" -#if (LIBTORRENT_VERSION_NUM >= 10200) #include #include @@ -43,8 +42,8 @@ lt::storage_interface *customStorageConstructor(const lt::storage_params ¶ms CustomStorage::CustomStorage(const lt::storage_params ¶ms, lt::file_pool &filePool) : lt::default_storage {params, filePool} + , m_savePath {Utils::Fs::expandPathAbs(QString::fromStdString(params.path))} { - m_savePath = Utils::Fs::expandPathAbs(QString::fromStdString(params.path)); } bool CustomStorage::verify_resume_data(const lt::add_torrent_params &rd, const lt::aux::vector &links, lt::storage_error &ec) @@ -99,4 +98,3 @@ void CustomStorage::handleCompleteFiles(const QString &savePath) } } } -#endif diff --git a/src/base/bittorrent/customstorage.h b/src/base/bittorrent/customstorage.h index e7a200d76..a55640eed 100644 --- a/src/base/bittorrent/customstorage.h +++ b/src/base/bittorrent/customstorage.h @@ -28,9 +28,6 @@ #pragma once -#include - -#if (LIBTORRENT_VERSION_NUM >= 10200) #include #include #include @@ -54,4 +51,3 @@ private: lt::aux::vector m_filePriorities; QString m_savePath; }; -#endif diff --git a/src/base/bittorrent/infohash.cpp b/src/base/bittorrent/infohash.cpp index e050efbb8..d60233998 100644 --- a/src/base/bittorrent/infohash.cpp +++ b/src/base/bittorrent/infohash.cpp @@ -89,9 +89,5 @@ bool BitTorrent::operator!=(const InfoHash &left, const InfoHash &right) uint BitTorrent::qHash(const InfoHash &key, const uint seed) { -#if (LIBTORRENT_VERSION_NUM < 10200) - return ::qHash(static_cast(key), seed); -#else return ::qHash((std::hash {})(key), seed); -#endif } diff --git a/src/base/bittorrent/infohash.h b/src/base/bittorrent/infohash.h index 049746fae..bc1eb21ac 100644 --- a/src/base/bittorrent/infohash.h +++ b/src/base/bittorrent/infohash.h @@ -30,7 +30,6 @@ #define BITTORRENT_INFOHASH_H #include -#include #include @@ -46,11 +45,7 @@ namespace BitTorrent static constexpr int length() { -#if (LIBTORRENT_VERSION_NUM < 10200) - return lt::sha1_hash::size; -#else return lt::sha1_hash::size(); -#endif } bool isValid() const; diff --git a/src/base/bittorrent/nativesessionextension.cpp b/src/base/bittorrent/nativesessionextension.cpp index 6b37a0c4d..dc27e8c1f 100644 --- a/src/base/bittorrent/nativesessionextension.cpp +++ b/src/base/bittorrent/nativesessionextension.cpp @@ -37,17 +37,12 @@ namespace void handleFastresumeRejectedAlert(const lt::fastresume_rejected_alert *alert) { if (alert->error.value() == lt::errors::mismatching_file_size) { -#if (LIBTORRENT_VERSION_NUM < 10200) - alert->handle.auto_managed(false); -#else alert->handle.unset_flags(lt::torrent_flags::auto_managed); -#endif alert->handle.pause(); } } } -#if (LIBTORRENT_VERSION_NUM >= 10200) lt::feature_flags_t NativeSessionExtension::implemented_features() { return alert_feature; @@ -57,12 +52,6 @@ std::shared_ptr NativeSessionExtension::new_torrent(const lt { return std::make_shared(torrentHandle); } -#else -boost::shared_ptr NativeSessionExtension::new_torrent(const lt::torrent_handle &torrentHandle, ClientData) -{ - return boost::make_shared(torrentHandle); -} -#endif void NativeSessionExtension::on_alert(const lt::alert *alert) { diff --git a/src/base/bittorrent/nativesessionextension.h b/src/base/bittorrent/nativesessionextension.h index 0c01cc555..209b7d715 100644 --- a/src/base/bittorrent/nativesessionextension.h +++ b/src/base/bittorrent/nativesessionextension.h @@ -39,11 +39,7 @@ class NativeSessionExtension final : public lt::plugin using ClientData = void *; #endif -#if (LIBTORRENT_VERSION_NUM >= 10200) lt::feature_flags_t implemented_features() override; std::shared_ptr new_torrent(const lt::torrent_handle &torrentHandle, ClientData) override; -#else - boost::shared_ptr new_torrent(const lt::torrent_handle &torrentHandle, ClientData) override; -#endif void on_alert(const lt::alert *alert) override; }; diff --git a/src/base/bittorrent/nativetorrentextension.cpp b/src/base/bittorrent/nativetorrentextension.cpp index 509ad7322..8a9d12245 100644 --- a/src/base/bittorrent/nativetorrentextension.cpp +++ b/src/base/bittorrent/nativetorrentextension.cpp @@ -34,21 +34,13 @@ namespace { bool isPaused(const lt::torrent_status &torrentStatus) { -#if (LIBTORRENT_VERSION_NUM < 10200) - return (torrentStatus.paused && !torrentStatus.auto_managed); -#else return ((torrentStatus.flags & lt::torrent_flags::paused) && !(torrentStatus.flags & lt::torrent_flags::auto_managed)); -#endif } bool isAutoManaged(const lt::torrent_status &torrentStatus) { -#if (LIBTORRENT_VERSION_NUM < 10200) - return torrentStatus.auto_managed; -#else return static_cast(torrentStatus.flags & lt::torrent_flags::auto_managed); -#endif } } @@ -58,35 +50,20 @@ NativeTorrentExtension::NativeTorrentExtension(const lt::torrent_handle &torrent } // This method is called when state of torrent is changed -#if (LIBTORRENT_VERSION_NUM < 10200) -void NativeTorrentExtension::on_state(const int state) -#else void NativeTorrentExtension::on_state(const lt::torrent_status::state_t state) -#endif { // When a torrent enters "checking files" state while paused, we temporarily resume it // (really we just allow libtorrent to resume it by enabling auto management for it). if (state == lt::torrent_status::checking_files) { - if (isPaused(m_torrentHandle.status({}))) { -#if (LIBTORRENT_VERSION_NUM < 10200) - m_torrentHandle.stop_when_ready(true); - m_torrentHandle.auto_managed(true); -#else + if (isPaused(m_torrentHandle.status({}))) m_torrentHandle.set_flags(lt::torrent_flags::stop_when_ready | lt::torrent_flags::auto_managed); -#endif - } } } bool NativeTorrentExtension::on_pause() { - if (!isAutoManaged(m_torrentHandle.status({}))) { -#if (LIBTORRENT_VERSION_NUM < 10200) - m_torrentHandle.stop_when_ready(false); -#else + if (!isAutoManaged(m_torrentHandle.status({}))) m_torrentHandle.unset_flags(lt::torrent_flags::stop_when_ready); -#endif - } // return `false` to allow standard handler // and other extensions to be also invoked. diff --git a/src/base/bittorrent/nativetorrentextension.h b/src/base/bittorrent/nativetorrentextension.h index d197bd736..66986831e 100644 --- a/src/base/bittorrent/nativetorrentextension.h +++ b/src/base/bittorrent/nativetorrentextension.h @@ -30,7 +30,6 @@ #include #include -#include class NativeTorrentExtension final : public lt::torrent_plugin { @@ -38,11 +37,7 @@ public: explicit NativeTorrentExtension(const lt::torrent_handle &torrentHandle); private: -#if (LIBTORRENT_VERSION_NUM < 10200) - void on_state(int state) override; -#else void on_state(lt::torrent_status::state_t state) override; -#endif bool on_pause() override; lt::torrent_handle m_torrentHandle; diff --git a/src/base/bittorrent/peerinfo.cpp b/src/base/bittorrent/peerinfo.cpp index 5e07955e7..d3c263979 100644 --- a/src/base/bittorrent/peerinfo.cpp +++ b/src/base/bittorrent/peerinfo.cpp @@ -28,8 +28,6 @@ #include "peerinfo.h" -#include - #include #include "base/bittorrent/torrenthandle.h" @@ -211,15 +209,9 @@ qlonglong PeerInfo::totalDownload() const QBitArray PeerInfo::pieces() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - using PieceIndex = int; -#else - using PieceIndex = lt::piece_index_t; -#endif - QBitArray result(m_nativeInfo.pieces.size()); for (int i = 0; i < result.size(); ++i) { - if (m_nativeInfo.pieces[PieceIndex {i}]) + if (m_nativeInfo.pieces[lt::piece_index_t {i}]) result.setBit(i, true); } return result; diff --git a/src/base/bittorrent/portforwarderimpl.cpp b/src/base/bittorrent/portforwarderimpl.cpp index 1a7eb02bf..d8da2b1e8 100644 --- a/src/base/bittorrent/portforwarderimpl.cpp +++ b/src/base/bittorrent/portforwarderimpl.cpp @@ -82,7 +82,7 @@ void PortForwarderImpl::deletePort(const quint16 port) { if (m_mappedPorts.contains(port)) { if (isEnabled()) { - for (const LTPortMapping &portMapping : m_mappedPorts[port]) + for (const lt::port_mapping_t &portMapping : m_mappedPorts[port]) m_provider->delete_port_mapping(portMapping); } m_mappedPorts.remove(port); diff --git a/src/base/bittorrent/portforwarderimpl.h b/src/base/bittorrent/portforwarderimpl.h index 2c6f584e5..d1ff91ea0 100644 --- a/src/base/bittorrent/portforwarderimpl.h +++ b/src/base/bittorrent/portforwarderimpl.h @@ -31,19 +31,12 @@ #include #include -#include +#include #include #include "base/net/portforwarder.h" -#if (LIBTORRENT_VERSION_NUM < 10200) -using LTPortMapping = int; -#else -#include -using LTPortMapping = lt::port_mapping_t; -#endif - class PortForwarderImpl final : public Net::PortForwarder { Q_OBJECT @@ -65,5 +58,5 @@ private: bool m_active; lt::session *m_provider; - QHash> m_mappedPorts; + QHash> m_mappedPorts; }; diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 8d5d6c0f7..af6df18ae 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -44,20 +44,16 @@ #include #include #include +#include #include #include -#include #include #include +#include #include #include #include #include -#include - -#if (LIBTORRENT_VERSION_NUM >= 10200) -#include -#endif #include #include @@ -115,24 +111,6 @@ using namespace BitTorrent; namespace { -#if (LIBTORRENT_VERSION_NUM < 10200) - using LTAlertCategory = int; - using LTDownloadPriority = int; - using LTPeerClass = int; - using LTQueuePosition = int; - using LTSessionFlags = int; - using LTStatusFlags = int; - using LTString = std::string; -#else - using LTAlertCategory = lt::alert_category_t; - using LTDownloadPriority = lt::download_priority_t; - using LTPeerClass = lt::peer_class_t; - using LTQueuePosition = lt::queue_position_t; - using LTSessionFlags = lt::session_flags_t; - using LTStatusFlags = lt::status_flags_t; - using LTString = lt::string_view; -#endif - template QString fromLTString(const LTStr &str) { @@ -186,11 +164,7 @@ namespace } lt::error_code ec; -#if (LIBTORRENT_VERSION_NUM < 10200) - lt::bdecode(data.constData(), (data.constData() + data.size()), root, ec); -#else root = lt::bdecode(data, ec); -#endif } #endif @@ -202,10 +176,7 @@ namespace #endif { lt::error_code ec; -#if (LIBTORRENT_VERSION_NUM < 10200) - lt::bdecode_node root; - lt::bdecode(data.constData(), (data.constData() + data.size()), root, ec); -#elif defined(NEED_TO_FIX_BROKEN_PATH) +#if defined(NEED_TO_FIX_BROKEN_PATH) // TODO: Remove together with fixBrokenSavePath() lt::bdecode_node root = lt::bdecode(data, ec); #else @@ -236,7 +207,7 @@ namespace torrentParams.paused = root.dict_find_int_value("qBt-paused", (isPaused && !isAutoManaged)); torrentParams.forced = root.dict_find_int_value("qBt-forced", (!isPaused && !isAutoManaged)); - const LTString ratioLimitString = root.dict_find_string_value("qBt-ratioLimit"); + const lt::string_view ratioLimitString = root.dict_find_string_value("qBt-ratioLimit"); if (ratioLimitString.empty()) torrentParams.ratioLimit = root.dict_find_int_value("qBt-ratioLimit", TorrentHandle::USE_GLOBAL_RATIO * 1000) / 1000.0; else @@ -1135,7 +1106,7 @@ void Session::configureComponents() void Session::initializeNativeSession() { - const LTAlertCategory alertMask = lt::alert::error_notification + const lt::alert_category_t alertMask = lt::alert::error_notification | lt::alert::file_progress_notification | lt::alert::ip_block_notification | lt::alert::peer_notification @@ -1165,19 +1136,8 @@ void Session::initializeNativeSession() pack.set_bool(lt::settings_pack::upnp_ignore_nonrouters, true); #endif -#if (LIBTORRENT_VERSION_NUM < 10200) - // Disable support for SSL torrents for now - pack.set_int(lt::settings_pack::ssl_listen, 0); - // To prevent ISPs from blocking seeding - pack.set_bool(lt::settings_pack::lazy_bitfields, true); - // Disk cache pool is rarely tested in libtorrent and doesn't free buffers - // Soon to be deprecated there - // More info: https://github.com/arvidn/libtorrent/issues/2251 - pack.set_bool(lt::settings_pack::use_disk_cache_pool, false); -#endif - loadLTSettings(pack); - m_nativeSession = new lt::session {pack, LTSessionFlags {0}}; + m_nativeSession = new lt::session {pack, lt::session_flags_t {0}}; LogMsg(tr("Peer ID: ") + QString::fromStdString(peerId)); LogMsg(tr("HTTP User-Agent is '%1'").arg(USER_AGENT)); @@ -1203,11 +1163,7 @@ void Session::initializeNativeSession() if (isPeXEnabled()) m_nativeSession->add_extension(<::create_ut_pex_plugin); -#if (LIBTORRENT_VERSION_NUM < 10200) - m_nativeSession->add_extension(boost::shared_ptr {new NativeSessionExtension}); -#else m_nativeSession->add_extension(std::make_shared()); -#endif } void Session::processBannedIPs(lt::ip_filter &filter) @@ -1593,41 +1549,38 @@ void Session::configurePeerClasses() // Proactively do the same for 0.0.0.0 and address_v4::any() f.add_rule(lt::address_v4::any() , lt::address_v4::broadcast() - , 1 << static_cast>(lt::session::global_peer_class_id)); + , 1 << static_cast>(lt::session::global_peer_class_id)); -#if (LIBTORRENT_VERSION_NUM >= 10200) || TORRENT_USE_IPV6 // IPv6 may not be available on OS and the parsing // would result in an exception -> abnormal program termination // Affects Windows XP try { f.add_rule(lt::address_v6::any() , lt::address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") - , 1 << static_cast>(lt::session::global_peer_class_id)); + , 1 << static_cast>(lt::session::global_peer_class_id)); } catch (const std::exception &) {} -#endif if (ignoreLimitsOnLAN()) { // local networks f.add_rule(lt::address_v4::from_string("10.0.0.0") , lt::address_v4::from_string("10.255.255.255") - , 1 << static_cast>(lt::session::local_peer_class_id)); + , 1 << static_cast>(lt::session::local_peer_class_id)); f.add_rule(lt::address_v4::from_string("172.16.0.0") , lt::address_v4::from_string("172.31.255.255") - , 1 << static_cast>(lt::session::local_peer_class_id)); + , 1 << static_cast>(lt::session::local_peer_class_id)); f.add_rule(lt::address_v4::from_string("192.168.0.0") , lt::address_v4::from_string("192.168.255.255") - , 1 << static_cast>(lt::session::local_peer_class_id)); + , 1 << static_cast>(lt::session::local_peer_class_id)); // link local f.add_rule(lt::address_v4::from_string("169.254.0.0") , lt::address_v4::from_string("169.254.255.255") - , 1 << static_cast>(lt::session::local_peer_class_id)); + , 1 << static_cast>(lt::session::local_peer_class_id)); // loopback f.add_rule(lt::address_v4::from_string("127.0.0.0") , lt::address_v4::from_string("127.255.255.255") - , 1 << static_cast>(lt::session::local_peer_class_id)); + , 1 << static_cast>(lt::session::local_peer_class_id)); -#if (LIBTORRENT_VERSION_NUM >= 10200) || TORRENT_USE_IPV6 // IPv6 may not be available on OS and the parsing // would result in an exception -> abnormal program termination // Affects Windows XP @@ -1635,18 +1588,17 @@ void Session::configurePeerClasses() // link local f.add_rule(lt::address_v6::from_string("fe80::") , lt::address_v6::from_string("febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff") - , 1 << static_cast>(lt::session::local_peer_class_id)); + , 1 << static_cast>(lt::session::local_peer_class_id)); // unique local addresses f.add_rule(lt::address_v6::from_string("fc00::") , lt::address_v6::from_string("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") - , 1 << static_cast>(lt::session::local_peer_class_id)); + , 1 << static_cast>(lt::session::local_peer_class_id)); // loopback f.add_rule(lt::address_v6::loopback() , lt::address_v6::loopback() - , 1 << static_cast>(lt::session::local_peer_class_id)); + , 1 << static_cast>(lt::session::local_peer_class_id)); } catch (const std::exception &) {} -#endif } m_nativeSession->set_peer_class_filter(f); @@ -1861,11 +1813,7 @@ bool Session::deleteTorrent(const InfoHash &hash, const DeleteOption deleteOptio if (iter != m_moveStorageQueue.end()) { // We shouldn't actually remove torrent until existing "move storage jobs" are done torrentQueuePositionBottom(nativeHandle); -#if (LIBTORRENT_VERSION_NUM < 10200) - nativeHandle.auto_managed(false); -#else nativeHandle.unset_flags(lt::torrent_flags::auto_managed); -#endif nativeHandle.pause(); } else { @@ -1917,7 +1865,7 @@ bool Session::cancelLoadMetadata(const InfoHash &hash) const lt::torrent_handle torrent = m_nativeSession->find_torrent(hash); if (!torrent.is_valid()) return false; - if (!torrent.status(LTStatusFlags {0}).has_metadata) { + if (!torrent.status(lt::status_flags_t {0}).has_metadata) { // if hidden torrent is still loading metadata... --m_extraLimit; adjustLimits(); @@ -2081,187 +2029,6 @@ bool Session::addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magnetUri, TorrentInfo torrentInfo, const QByteArray &fastresumeData) { -#if (LIBTORRENT_VERSION_NUM < 10200) - params.savePath = normalizeSavePath(params.savePath, ""); - - if (!params.category.isEmpty()) { - if (!m_categories.contains(params.category) && !addCategory(params.category)) - params.category = ""; - } - - const bool fromMagnetUri = magnetUri.isValid(); - // If empty then Automatic mode, otherwise Manual mode - QString savePath = params.savePath.isEmpty() ? categorySavePath(params.category) : params.savePath; - lt::add_torrent_params p; - InfoHash hash; - - if (fromMagnetUri) { - hash = magnetUri.hash(); - - const auto it = m_loadedMetadata.constFind(hash); - if (it != m_loadedMetadata.constEnd()) { - // Adding preloaded torrent... - const TorrentInfo metadata = it.value(); - if (metadata.isValid()) { - // Metadata is received and torrent_handle is being deleted - // so we can't reuse it. Just add torrent using its metadata. - return addTorrent_impl(params - , MagnetUri {}, metadata, fastresumeData); - } - - // Reuse existing torrent_handle - lt::torrent_handle handle = m_nativeSession->find_torrent(hash); - - // Preloaded torrent is in "Upload mode" so we need to disable it - // otherwise the torrent never be downloaded (until application restart) - handle.set_upload_mode(false); - - if (params.paused) { - // Preloaded torrent isn't auto managed already - handle.pause(); - } - else if (!params.forced) { - handle.auto_managed(true); - handle.pause(); - } - - m_loadedMetadata.remove(hash); - m_addingTorrents.insert(hash, params); - - --m_extraLimit; - adjustLimits(); - - // use common 2nd step of torrent addition - createTorrentHandle(handle); - return true; - } - - p = magnetUri.addTorrentParams(); - if (isTempPathEnabled()) { - p.save_path = Utils::Fs::toNativePath(tempPath()).toStdString(); - } - else { - // If empty then Automatic mode, otherwise Manual mode - const QString savePath = params.savePath.isEmpty() ? categorySavePath(params.category) : params.savePath; - p.save_path = Utils::Fs::toNativePath(savePath).toStdString(); - } - } - else { - if (!torrentInfo.isValid()) { - // We can have an invalid torrentInfo when there isn't a matching - // .torrent file to the .fastresume we loaded. Possibly from a - // failed upgrade. - return false; - } - - hash = torrentInfo.hash(); - } - - // We should not add the torrent if it is already - // processed or is pending to add to session - if (m_addingTorrents.contains(hash) || m_loadedMetadata.contains(hash)) - return false; - - TorrentHandle *const torrent = m_torrents.value(hash); - if (torrent) { // a duplicate torrent is added - if (torrent->isPrivate() || (!fromMagnetUri && torrentInfo.isPrivate())) - return false; - - // merge trackers and web seeds - torrent->addTrackers(fromMagnetUri ? magnetUri.trackers() : torrentInfo.trackers()); - torrent->addUrlSeeds(fromMagnetUri ? magnetUri.urlSeeds() : torrentInfo.urlSeeds()); - return true; - } - - if (!fromMagnetUri) { - if (params.restored) { // load from existing fastresume - // converting relative save_path to absolute - QByteArray patchedFastresumeData = fastresumeData; - int start = patchedFastresumeData.indexOf("9:save_path"); - if (start > -1) { - start += 11; - const int end = patchedFastresumeData.indexOf(':', start); - const int len = Utils::ByteArray::midView(patchedFastresumeData, start, (end - start)).toInt(); - if (len > 0) { - const QByteArray relativePath = Utils::ByteArray::midView(patchedFastresumeData, (end + 1), len); - const QByteArray absolutePath = Profile::instance()->fromPortablePath(QString::fromUtf8(relativePath)).toUtf8(); - if (relativePath != absolutePath) { - const QByteArray replaceBefore = "9:save_path" + QByteArray::number(len) + ':' + relativePath; - const QByteArray replaceAfter = "9:save_path" + QByteArray::number(absolutePath.size()) + ':' + absolutePath; - patchedFastresumeData.replace(replaceBefore, replaceAfter); - } - } - } - - p.resume_data = std::vector {patchedFastresumeData.constData() - , (patchedFastresumeData.constData() + patchedFastresumeData.size())}; - p.flags |= lt::add_torrent_params::flag_use_resume_save_path; - } - else { // new torrent - if (!params.hasRootFolder) - torrentInfo.stripRootFolder(); - - // If empty then Automatic mode, otherwise Manual mode - QString savePath = params.savePath.isEmpty() ? categorySavePath(params.category) : params.savePath; - // Metadata - if (!params.hasSeedStatus) - findIncompleteFiles(torrentInfo, savePath); // if needed points savePath to incomplete folder too - p.save_path = Utils::Fs::toNativePath(savePath).toStdString(); - - // if torrent name wasn't explicitly set we handle the case of - // initial renaming of torrent content and rename torrent accordingly - if (params.name.isEmpty()) { - QString contentName = torrentInfo.rootFolder(); - if (contentName.isEmpty() && (torrentInfo.filesCount() == 1)) - contentName = torrentInfo.fileName(0); - - if (!contentName.isEmpty() && (contentName != torrentInfo.name())) - params.name = contentName; - } - - Q_ASSERT(p.file_priorities.empty()); - std::transform(params.filePriorities.cbegin(), params.filePriorities.cend() - , std::back_inserter(p.file_priorities), [](const DownloadPriority priority) - { - return static_cast(priority); - }); - } - - p.ti = torrentInfo.nativeInfo(); - } - - // Common - p.flags &= ~lt::add_torrent_params::flag_duplicate_is_error; // Already checked - if (params.paused || !params.forced) - p.flags |= lt::add_torrent_params::flag_paused; - else - p.flags &= ~lt::add_torrent_params::flag_paused; - if (params.paused || params.forced) - p.flags &= ~lt::add_torrent_params::flag_auto_managed; - else - p.flags |= lt::add_torrent_params::flag_auto_managed; - // Limits - p.max_connections = maxConnectionsPerTorrent(); - p.max_uploads = maxUploadsPerTorrent(); - p.upload_limit = params.uploadLimit; - p.download_limit = params.downloadLimit; - // Preallocation mode - p.storage_mode = isPreallocationEnabled() - ? lt::storage_mode_allocate : lt::storage_mode_sparse; - - // Seeding mode - // Skip checking and directly start seeding - if (params.skipChecking) - p.flags |= lt::add_torrent_params::flag_seed_mode; - else - p.flags &= ~lt::add_torrent_params::flag_seed_mode; - - m_addingTorrents.insert(hash, params); - // Adding torrent to BitTorrent session - m_nativeSession->async_add_torrent(p); - - return true; -#else params.savePath = normalizeSavePath(params.savePath, ""); if (!params.category.isEmpty()) { @@ -2433,7 +2200,6 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne m_nativeSession->async_add_torrent(p); return true; -#endif } bool Session::findIncompleteFiles(TorrentInfo &torrentInfo, QString &savePath) const @@ -2500,14 +2266,6 @@ bool Session::loadMetadata(const MagnetUri &magnetUri) const QString savePath = Utils::Fs::tempPath() + static_cast(hash); p.save_path = Utils::Fs::toNativePath(savePath).toStdString(); -#if (LIBTORRENT_VERSION_NUM < 10200) - // Forced start - p.flags &= ~lt::add_torrent_params::flag_paused; - p.flags &= ~lt::add_torrent_params::flag_auto_managed; - - // Solution to avoid accidental file writes - p.flags |= lt::add_torrent_params::flag_upload_mode; -#else // Forced start p.flags &= ~lt::torrent_flags::paused; p.flags &= ~lt::torrent_flags::auto_managed; @@ -2516,7 +2274,6 @@ bool Session::loadMetadata(const MagnetUri &magnetUri) p.flags |= lt::torrent_flags::upload_mode; p.storage = customStorageConstructor; -#endif // Adding torrent to BitTorrent session lt::error_code ec; @@ -2606,7 +2363,7 @@ void Session::saveTorrentsQueue() QMap queue; // Use QMap since it should be ordered by key for (const TorrentHandleImpl *torrent : asConst(m_torrents)) { // We require actual (non-cached) queue position here! - const int queuePos = static_cast>(torrent->nativeHandle().queue_position()); + const int queuePos = static_cast>(torrent->nativeHandle().queue_position()); if (queuePos >= 0) queue[queuePos] = torrent->hash(); } @@ -4088,11 +3845,7 @@ void Session::moveTorrentStorage(const MoveStorageJob &job) const job.torrentHandle.move_storage(job.path.toUtf8().constData() , ((job.mode == MoveStorageMode::Overwrite) -#if (LIBTORRENT_VERSION_NUM < 10200) - ? lt::always_replace_files : lt::dont_replace)); -#else - ? lt::move_flags_t::always_replace_files : lt::move_flags_t::dont_replace)); -#endif + ? lt::move_flags_t::always_replace_files : lt::move_flags_t::dont_replace)); } void Session::handleMoveTorrentStorageJobFinished(const QString &errorMessage) @@ -4496,11 +4249,9 @@ void Session::handleAlert(const lt::alert *a) case lt::external_ip_alert::alert_type: handleExternalIPAlert(static_cast(a)); break; -#if (LIBTORRENT_VERSION_NUM >= 10200) case lt::alerts_dropped_alert::alert_type: handleAlertsDroppedAlert(static_cast(a)); break; -#endif case lt::storage_moved_alert::alert_type: handleStorageMovedAlert(static_cast(a)); break; @@ -4593,13 +4344,8 @@ void Session::createTorrentHandle(const lt::torrent_handle &nativeHandle) LogMsg(tr("Torrent errored. Torrent: \"%1\". Error: %2.").arg(torrent->name(), torrent->error()), Log::WARNING); // Check if file(s) exist when using seed mode - if (params.skipChecking && torrent->hasMetadata()) { -#if (LIBTORRENT_VERSION_NUM < 10200) - nativeHandle.read_piece(0); -#else + if (params.skipChecking && torrent->hasMetadata()) nativeHandle.read_piece(lt::piece_index_t(0)); -#endif - } } void Session::handleAddTorrentAlert(const lt::add_torrent_alert *p) @@ -4706,17 +4452,10 @@ void Session::handleFileErrorAlert(const lt::file_error_alert *p) void Session::handleReadPieceAlert(const lt::read_piece_alert *p) const { -#if (LIBTORRENT_VERSION_NUM < 10200) - if (p->ec) { - p->handle.auto_managed(false); - p->handle.force_recheck(); - } -#else if (p->error) { p->handle.unset_flags(lt::torrent_flags::auto_managed); p->handle.force_recheck(); } -#endif } void Session::handlePortmapWarningAlert(const lt::portmap_error_alert *p) @@ -4733,11 +4472,7 @@ void Session::handlePortmapAlert(const lt::portmap_alert *p) void Session::handlePeerBlockedAlert(const lt::peer_blocked_alert *p) { lt::error_code ec; -#if LIBTORRENT_VERSION_NUM < 10200 - const std::string ip = p->ip.to_string(ec); -#else const std::string ip = p->endpoint.address().to_string(ec); -#endif QString reason; switch (p->reason) { case lt::peer_blocked_alert::ip_filter: @@ -4767,11 +4502,7 @@ void Session::handlePeerBlockedAlert(const lt::peer_blocked_alert *p) void Session::handlePeerBanAlert(const lt::peer_ban_alert *p) { lt::error_code ec; -#if (LIBTORRENT_VERSION_NUM < 10200) - const std::string ip = p->ip.address().to_string(ec); -#else const std::string ip = p->endpoint.address().to_string(ec); -#endif if (!ec) Logger::instance()->addPeer(QString::fromLatin1(ip.c_str()), false); @@ -4798,29 +4529,6 @@ void Session::handleUrlSeedAlert(const lt::url_seed_alert *p) void Session::handleListenSucceededAlert(const lt::listen_succeeded_alert *p) { QString proto = "INVALID"; -#if (LIBTORRENT_VERSION_NUM < 10200) - switch (p->sock_type) - { - case lt::listen_succeeded_alert::udp: - proto = "UDP"; - break; - case lt::listen_succeeded_alert::tcp: - proto = "TCP"; - break; - case lt::listen_succeeded_alert::tcp_ssl: - proto = "TCP_SSL"; - break; - case lt::listen_succeeded_alert::i2p: - proto = "I2P"; - break; - case lt::listen_succeeded_alert::socks5: - proto = "SOCKS5"; - break; - case lt::listen_succeeded_alert::utp_ssl: - proto = "UTP_SSL"; - break; - } -#else switch (p->socket_type) { case lt::socket_type_t::udp: @@ -4842,16 +4550,11 @@ void Session::handleListenSucceededAlert(const lt::listen_succeeded_alert *p) proto = "UTP_SSL"; break; } -#endif lt::error_code ec; LogMsg(tr("Successfully listening on IP: %1, port: %2/%3" , "e.g: Successfully listening on IP: 192.168.0.1, port: TCP/6881") -#if (LIBTORRENT_VERSION_NUM < 10200) - .arg(p->endpoint.address().to_string(ec).c_str(), proto, QString::number(p->endpoint.port())), Log::INFO); -#else .arg(p->address.to_string(ec).c_str(), proto, QString::number(p->port)), Log::INFO); -#endif // Force reannounce on all torrents because some trackers blacklist some ports for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents()) @@ -4861,29 +4564,6 @@ void Session::handleListenSucceededAlert(const lt::listen_succeeded_alert *p) void Session::handleListenFailedAlert(const lt::listen_failed_alert *p) { QString proto = "INVALID"; -#if (LIBTORRENT_VERSION_NUM < 10200) - switch (p->sock_type) - { - case lt::listen_failed_alert::udp: - proto = "UDP"; - break; - case lt::listen_failed_alert::tcp: - proto = "TCP"; - break; - case lt::listen_failed_alert::tcp_ssl: - proto = "TCP_SSL"; - break; - case lt::listen_failed_alert::i2p: - proto = "I2P"; - break; - case lt::listen_failed_alert::socks5: - proto = "SOCKS5"; - break; - case lt::listen_failed_alert::utp_ssl: - proto = "UTP_SSL"; - break; - } -#else switch (p->socket_type) { case lt::socket_type_t::udp: @@ -4905,18 +4585,12 @@ void Session::handleListenFailedAlert(const lt::listen_failed_alert *p) proto = "UTP_SSL"; break; } -#endif lt::error_code ec; LogMsg(tr("Failed to listen on IP: %1, port: %2/%3. Reason: %4" , "e.g: Failed to listen on IP: 192.168.0.1, port: TCP/6881. Reason: already in use") -#if (LIBTORRENT_VERSION_NUM < 10200) - .arg(p->endpoint.address().to_string(ec).c_str(), proto, QString::number(p->endpoint.port()) - , QString::fromLocal8Bit(p->error.message().c_str())), Log::CRITICAL); -#else .arg(p->address.to_string(ec).c_str(), proto, QString::number(p->port) , QString::fromLocal8Bit(p->error.message().c_str())), Log::CRITICAL); -#endif } void Session::handleExternalIPAlert(const lt::external_ip_alert *p) @@ -4931,11 +4605,7 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) const qreal interval = lt::total_milliseconds(p->timestamp() - m_statsLastTimestamp) / 1000.; m_statsLastTimestamp = p->timestamp(); -#if (LIBTORRENT_VERSION_NUM < 10200) - const auto &stats = p->values; -#else const auto stats = p->counters(); -#endif m_status.hasIncomingConnections = static_cast(stats[m_metricIndices.net.hasIncomingConnections]); @@ -4998,13 +4668,11 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) emit statsUpdated(); } -#if (LIBTORRENT_VERSION_NUM >= 10200) void Session::handleAlertsDroppedAlert(const lt::alerts_dropped_alert *p) const { LogMsg(tr("Error: Internal alert queue full and alerts were dropped, you might see degraded performance. Dropped alert types: %1. Message: %2") .arg(QString::fromStdString(p->dropped_alerts.to_string()), QString::fromStdString(p->message())), Log::CRITICAL); } -#endif void Session::handleStorageMovedAlert(const lt::storage_moved_alert *p) { diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 139308581..0d18dfe91 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -35,6 +35,7 @@ #include #include +#include #include #include @@ -600,9 +601,7 @@ namespace BitTorrent void handleListenFailedAlert(const lt::listen_failed_alert *p); void handleExternalIPAlert(const lt::external_ip_alert *p); void handleSessionStatsAlert(const lt::session_stats_alert *p); -#if (LIBTORRENT_VERSION_NUM >= 10200) void handleAlertsDroppedAlert(const lt::alerts_dropped_alert *p) const; -#endif void handleStorageMovedAlert(const lt::storage_moved_alert *p); void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p); #if (LIBTORRENT_VERSION_NUM >= 10204) diff --git a/src/base/bittorrent/torrentcreatorthread.cpp b/src/base/bittorrent/torrentcreatorthread.cpp index 2c5c95bd6..12a1d1e7e 100644 --- a/src/base/bittorrent/torrentcreatorthread.cpp +++ b/src/base/bittorrent/torrentcreatorthread.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include @@ -50,14 +49,6 @@ namespace { -#if (LIBTORRENT_VERSION_NUM < 10200) - using LTCreateFlags = int; - using LTPieceIndex = int; -#else - using LTCreateFlags = lt::create_flags_t; - using LTPieceIndex = lt::piece_index_t; -#endif - // do not include files and folders whose // name starts with a . bool fileFilter(const std::string &f) @@ -141,7 +132,7 @@ void TorrentCreatorThread::run() if (isInterruptionRequested()) return; lt::create_torrent newTorrent(fs, m_params.pieceSize, m_params.paddedFileSizeLimit - , (m_params.isAlignmentOptimized ? lt::create_torrent::optimize_alignment : LTCreateFlags {})); + , (m_params.isAlignmentOptimized ? lt::create_torrent::optimize_alignment : lt::create_flags_t {})); // Add url seeds for (QString seed : asConst(m_params.urlSeeds)) { @@ -162,9 +153,9 @@ void TorrentCreatorThread::run() // calculate the hash for all pieces lt::set_piece_hashes(newTorrent, Utils::Fs::toNativePath(parentPath).toStdString() - , [this, &newTorrent](const LTPieceIndex n) + , [this, &newTorrent](const lt::piece_index_t n) { - sendProgressSignal(static_cast>(n), newTorrent.num_pieces()); + sendProgressSignal(static_cast>(n), newTorrent.num_pieces()); }); // Set qBittorrent as creator and add user comment to // torrent_info structure @@ -216,5 +207,5 @@ int TorrentCreatorThread::calculateTotalPieces(const QString &inputPath, const i lt::add_files(fs, Utils::Fs::toNativePath(inputPath).toStdString(), fileFilter); return lt::create_torrent(fs, pieceSize, paddedFileSizeLimit - , (isAlignmentOptimized ? lt::create_torrent::optimize_alignment : LTCreateFlags {})).num_pieces(); + , (isAlignmentOptimized ? lt::create_torrent::optimize_alignment : lt::create_flags_t {})).num_pieces(); } diff --git a/src/base/bittorrent/torrenthandleimpl.cpp b/src/base/bittorrent/torrenthandleimpl.cpp index 77226e2e4..062ec56a7 100644 --- a/src/base/bittorrent/torrenthandleimpl.cpp +++ b/src/base/bittorrent/torrenthandleimpl.cpp @@ -41,15 +41,10 @@ #include #include #include +#include #include #include - -#if (LIBTORRENT_VERSION_NUM >= 10200) -#include #include -#else -#include -#endif #include #include @@ -77,7 +72,6 @@ const QString QB_EXT {QStringLiteral(".!qB")}; using namespace BitTorrent; -#if (LIBTORRENT_VERSION_NUM >= 10200) namespace libtorrent { namespace aux @@ -89,30 +83,19 @@ namespace libtorrent } } } -#endif namespace { -#if (LIBTORRENT_VERSION_NUM < 10200) - using LTDownloadPriority = int; - using LTPieceIndex = int; - using LTQueuePosition = int; -#else - using LTDownloadPriority = lt::download_priority_t; - using LTPieceIndex = lt::piece_index_t; - using LTQueuePosition = lt::queue_position_t; -#endif - - std::vector toLTDownloadPriorities(const QVector &priorities) + std::vector toLTDownloadPriorities(const QVector &priorities) { - std::vector out; + std::vector out; out.reserve(priorities.size()); std::transform(priorities.cbegin(), priorities.cend() , std::back_inserter(out), [](BitTorrent::DownloadPriority priority) { - return static_cast( - static_cast>(priority)); + return static_cast( + static_cast>(priority)); }); return out; } @@ -371,23 +354,15 @@ QString TorrentHandleImpl::actualStorageLocation() const bool TorrentHandleImpl::isAutoManaged() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return m_nativeStatus.auto_managed; -#else return static_cast(m_nativeStatus.flags & lt::torrent_flags::auto_managed); -#endif } void TorrentHandleImpl::setAutoManaged(const bool enable) { -#if (LIBTORRENT_VERSION_NUM < 10200) - m_nativeHandle.auto_managed(enable); -#else if (enable) m_nativeHandle.set_flags(lt::torrent_flags::auto_managed); else m_nativeHandle.unset_flags(lt::torrent_flags::auto_managed); -#endif } QVector TorrentHandleImpl::trackers() const @@ -526,22 +501,14 @@ void TorrentHandleImpl::clearPeers() bool TorrentHandleImpl::connectPeer(const PeerAddress &peerAddress) { lt::error_code ec; -#if (LIBTORRENT_VERSION_NUM < 10200) - const lt::address addr = lt::address::from_string(peerAddress.ip.toString().toStdString(), ec); -#else const lt::address addr = lt::make_address(peerAddress.ip.toString().toStdString(), ec); -#endif if (ec) return false; const lt::tcp::endpoint endpoint(addr, peerAddress.port); try { m_nativeHandle.connect_peer(endpoint); } -#if (LIBTORRENT_VERSION_NUM < 10200) - catch (const boost::system::system_error &err) { -#else catch (const lt::system_error &err) { -#endif LogMsg(tr("Failed to add peer \"%1\" to torrent \"%2\". Reason: %3") .arg(peerAddress.toString(), name(), QString::fromLocal8Bit(err.what())), Log::WARNING); return false; @@ -699,16 +666,12 @@ QStringList TorrentHandleImpl::absoluteFilePaths() const QVector TorrentHandleImpl::filePriorities() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - const std::vector fp = m_nativeHandle.file_priorities(); -#else - const std::vector fp = m_nativeHandle.get_file_priorities(); -#endif + const std::vector fp = m_nativeHandle.get_file_priorities(); QVector ret; - std::transform(fp.cbegin(), fp.cend(), std::back_inserter(ret), [](LTDownloadPriority priority) + std::transform(fp.cbegin(), fp.cend(), std::back_inserter(ret), [](lt::download_priority_t priority) { - return static_cast(static_cast>(priority)); + return static_cast(static_cast>(priority)); }); return ret; } @@ -720,12 +683,8 @@ TorrentInfo TorrentHandleImpl::info() const bool TorrentHandleImpl::isPaused() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return (m_nativeStatus.paused && !isAutoManaged()); -#else return ((m_nativeStatus.flags & lt::torrent_flags::paused) && !isAutoManaged()); -#endif } bool TorrentHandleImpl::isResumed() const @@ -735,12 +694,8 @@ bool TorrentHandleImpl::isResumed() const bool TorrentHandleImpl::isQueued() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return (m_nativeStatus.paused && isAutoManaged()); -#else return ((m_nativeStatus.flags & lt::torrent_flags::paused) && isAutoManaged()); -#endif } bool TorrentHandleImpl::isChecking() const @@ -818,21 +773,13 @@ bool TorrentHandleImpl::isSeed() const bool TorrentHandleImpl::isForced() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return (!m_nativeStatus.paused && !isAutoManaged()); -#else return (!(m_nativeStatus.flags & lt::torrent_flags::paused) && !isAutoManaged()); -#endif } bool TorrentHandleImpl::isSequentialDownload() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return m_nativeStatus.sequential_download; -#else return static_cast(m_nativeStatus.flags & lt::torrent_flags::sequential_download); -#endif } bool TorrentHandleImpl::hasFirstLastPiecePriority() const @@ -840,19 +787,15 @@ bool TorrentHandleImpl::hasFirstLastPiecePriority() const if (!hasMetadata()) return m_needsToSetFirstLastPiecePriority; -#if (LIBTORRENT_VERSION_NUM < 10200) - const std::vector filePriorities = nativeHandle().file_priorities(); -#else - const std::vector filePriorities = nativeHandle().get_file_priorities(); -#endif + const std::vector filePriorities = nativeHandle().get_file_priorities(); for (int i = 0; i < static_cast(filePriorities.size()); ++i) { - if (filePriorities[i] <= LTDownloadPriority {0}) + if (filePriorities[i] <= lt::download_priority_t {0}) continue; const TorrentInfo::PieceRange extremities = info().filePieces(i); - const LTDownloadPriority firstPiecePrio = nativeHandle().piece_priority(LTPieceIndex {extremities.first()}); - const LTDownloadPriority lastPiecePrio = nativeHandle().piece_priority(LTPieceIndex {extremities.last()}); - return ((firstPiecePrio == LTDownloadPriority {7}) && (lastPiecePrio == LTDownloadPriority {7})); + const lt::download_priority_t firstPiecePrio = nativeHandle().piece_priority(lt::piece_index_t {extremities.first()}); + const lt::download_priority_t lastPiecePrio = nativeHandle().piece_priority(lt::piece_index_t {extremities.last()}); + return ((firstPiecePrio == lt::download_priority_t {7}) && (lastPiecePrio == lt::download_priority_t {7})); } return false; @@ -931,20 +874,16 @@ bool TorrentHandleImpl::hasError() const bool TorrentHandleImpl::hasFilteredPieces() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - const std::vector pp = m_nativeHandle.piece_priorities(); -#else - const std::vector pp = m_nativeHandle.get_piece_priorities(); -#endif - return std::any_of(pp.cbegin(), pp.cend(), [](const LTDownloadPriority priority) + const std::vector pp = m_nativeHandle.get_piece_priorities(); + return std::any_of(pp.cbegin(), pp.cend(), [](const lt::download_priority_t priority) { - return (priority == LTDownloadPriority {0}); + return (priority == lt::download_priority_t {0}); }); } int TorrentHandleImpl::queuePosition() const { - if (m_nativeStatus.queue_position < LTQueuePosition {0}) return 0; + if (m_nativeStatus.queue_position < lt::queue_position_t {0}) return 0; return static_cast(m_nativeStatus.queue_position) + 1; } @@ -966,29 +905,17 @@ qlonglong TorrentHandleImpl::totalUpload() const qlonglong TorrentHandleImpl::activeTime() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return m_nativeStatus.active_time; -#else return lt::total_seconds(m_nativeStatus.active_duration); -#endif } qlonglong TorrentHandleImpl::finishedTime() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return m_nativeStatus.finished_time; -#else return lt::total_seconds(m_nativeStatus.finished_duration); -#endif } qlonglong TorrentHandleImpl::seedingTime() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return m_nativeStatus.seeding_time; -#else return lt::total_seconds(m_nativeStatus.seeding_duration); -#endif } qlonglong TorrentHandleImpl::eta() const @@ -1031,11 +958,7 @@ qlonglong TorrentHandleImpl::eta() const QVector TorrentHandleImpl::filesProgress() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - std::vector fp; -#else std::vector fp; -#endif m_nativeHandle.file_progress(fp, lt::torrent_handle::piece_granularity); const int count = static_cast(fp.size()); @@ -1113,24 +1036,16 @@ QDateTime TorrentHandleImpl::completedTime() const qlonglong TorrentHandleImpl::timeSinceUpload() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return m_nativeStatus.time_since_upload; -#else if (m_nativeStatus.last_upload.time_since_epoch().count() == 0) return -1; return lt::total_seconds(lt::clock_type::now() - m_nativeStatus.last_upload); -#endif } qlonglong TorrentHandleImpl::timeSinceDownload() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return m_nativeStatus.time_since_download; -#else if (m_nativeStatus.last_download.time_since_epoch().count() == 0) return -1; return lt::total_seconds(lt::clock_type::now() - m_nativeStatus.last_download); -#endif } qlonglong TorrentHandleImpl::timeSinceActivity() const @@ -1154,11 +1069,7 @@ int TorrentHandleImpl::uploadLimit() const bool TorrentHandleImpl::superSeeding() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return m_nativeStatus.super_seeding; -#else return static_cast(m_nativeStatus.flags & lt::torrent_flags::super_seeding); -#endif } QVector TorrentHandleImpl::peers() const @@ -1177,7 +1088,7 @@ QBitArray TorrentHandleImpl::pieces() const { QBitArray result(m_nativeStatus.pieces.size()); for (int i = 0; i < result.size(); ++i) { - if (m_nativeStatus.pieces[LTPieceIndex {i}]) + if (m_nativeStatus.pieces[lt::piece_index_t {i}]) result.setBit(i, true); } return result; @@ -1191,11 +1102,7 @@ QBitArray TorrentHandleImpl::downloadingPieces() const m_nativeHandle.get_download_queue(queue); for (const lt::partial_piece_info &info : queue) -#if (LIBTORRENT_VERSION_NUM < 10200) - result.setBit(info.piece_index); -#else - result.setBit(static_cast>(info.piece_index)); -#endif + result.setBit(static_cast>(info.piece_index)); return result; } @@ -1231,19 +1138,11 @@ int TorrentHandleImpl::maxSeedingTime() const qreal TorrentHandleImpl::realRatio() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - const boost::int64_t upload = m_nativeStatus.all_time_upload; - // special case for a seeder who lost its stats, also assume nobody will import a 99% done torrent - const boost::int64_t download = (m_nativeStatus.all_time_download < (m_nativeStatus.total_done * 0.01)) - ? m_nativeStatus.total_done - : m_nativeStatus.all_time_download; -#else const int64_t upload = m_nativeStatus.all_time_upload; // special case for a seeder who lost its stats, also assume nobody will import a 99% done torrent const int64_t download = (m_nativeStatus.all_time_download < (m_nativeStatus.total_done * 0.01)) ? m_nativeStatus.total_done : m_nativeStatus.all_time_download; -#endif if (download == 0) return (upload == 0) ? 0 : MAX_RATIO; @@ -1365,10 +1264,6 @@ void TorrentHandleImpl::forceRecheck() void TorrentHandleImpl::setSequentialDownload(const bool enable) { -#if (LIBTORRENT_VERSION_NUM < 10200) - m_nativeHandle.set_sequential_download(enable); - m_nativeStatus.sequential_download = enable; // prevent return cached value -#else if (enable) { m_nativeHandle.set_flags(lt::torrent_flags::sequential_download); m_nativeStatus.flags |= lt::torrent_flags::sequential_download; // prevent return cached value @@ -1377,7 +1272,6 @@ void TorrentHandleImpl::setSequentialDownload(const bool enable) m_nativeHandle.unset_flags(lt::torrent_flags::sequential_download); m_nativeStatus.flags &= ~lt::torrent_flags::sequential_download; // prevent return cached value } -#endif saveResumeData(); } @@ -1396,24 +1290,19 @@ void TorrentHandleImpl::setFirstLastPiecePriorityImpl(const bool enabled, const return; } -#if (LIBTORRENT_VERSION_NUM < 10200) - const std::vector filePriorities = !updatedFilePrio.isEmpty() ? toLTDownloadPriorities(updatedFilePrio) - : nativeHandle().file_priorities(); - std::vector piecePriorities = nativeHandle().piece_priorities(); -#else - const std::vector filePriorities = !updatedFilePrio.isEmpty() ? toLTDownloadPriorities(updatedFilePrio) + const std::vector filePriorities = !updatedFilePrio.isEmpty() ? toLTDownloadPriorities(updatedFilePrio) : nativeHandle().get_file_priorities(); - std::vector piecePriorities = nativeHandle().get_piece_priorities(); -#endif + std::vector piecePriorities = nativeHandle().get_piece_priorities(); + // Updating file priorities is an async operation in libtorrent, when we just updated it and immediately query it // we might get the old/wrong values, so we rely on `updatedFilePrio` in this case. for (int index = 0; index < static_cast(filePriorities.size()); ++index) { - const LTDownloadPriority filePrio = filePriorities[index]; - if (filePrio <= LTDownloadPriority {0}) + const lt::download_priority_t filePrio = filePriorities[index]; + if (filePrio <= lt::download_priority_t {0}) continue; // Determine the priority to set - const LTDownloadPriority newPrio = enabled ? LTDownloadPriority {7} : filePrio; + const lt::download_priority_t newPrio = enabled ? lt::download_priority_t {7} : filePrio; const TorrentInfo::PieceRange extremities = info().filePieces(index); // worst case: AVI index = 1% of total file size (at the end of the file) @@ -1474,9 +1363,9 @@ void TorrentHandleImpl::moveStorage(const QString &newPath, const MoveStorageMod void TorrentHandleImpl::renameFile(const int index, const QString &name) { - m_oldPath[LTFileIndex {index}].push_back(filePath(index)); + m_oldPath[lt::file_index_t {index}].push_back(filePath(index)); ++m_renameCount; - m_nativeHandle.rename_file(LTFileIndex {index}, Utils::Fs::toNativePath(name).toStdString()); + m_nativeHandle.rename_file(lt::file_index_t {index}, Utils::Fs::toNativePath(name).toStdString()); } void TorrentHandleImpl::handleStateUpdate(const lt::torrent_status &nativeStatus) @@ -1611,17 +1500,10 @@ void TorrentHandleImpl::handleTorrentResumedAlert(const lt::torrent_resumed_aler void TorrentHandleImpl::handleSaveResumeDataAlert(const lt::save_resume_data_alert *p) { -#if (LIBTORRENT_VERSION_NUM < 10200) - const bool useDummyResumeData = !(p && p->resume_data); - auto resumeDataPtr = std::make_shared(useDummyResumeData - ? lt::entry {} - : *(p->resume_data)); -#else const bool useDummyResumeData = !p; auto resumeDataPtr = std::make_shared(useDummyResumeData ? lt::entry {} : lt::write_resume_data(p->params)); -#endif lt::entry &resumeData = *resumeDataPtr; updateStatus(); @@ -1653,11 +1535,7 @@ void TorrentHandleImpl::handleSaveResumeDataAlert(const lt::save_resume_data_ale resumeData["qBt-queuePosition"] = (static_cast(nativeHandle().queue_position()) + 1); // qBt starts queue at 1 resumeData["qBt-hasRootFolder"] = m_hasRootFolder; -#if (LIBTORRENT_VERSION_NUM < 10200) - if (m_nativeStatus.stop_when_ready) { -#else if (m_nativeStatus.flags & lt::torrent_flags::stop_when_ready) { -#endif // We need to redefine these values when torrent starting/rechecking // in "paused" state since native values can be logically wrong // (torrent can be not paused and auto_managed when it is checking). @@ -1746,7 +1624,7 @@ void TorrentHandleImpl::handleFileRenamedAlert(const lt::file_renamed_alert *p) void TorrentHandleImpl::handleFileRenameFailedAlert(const lt::file_rename_failed_alert *p) { LogMsg(tr("File rename failed. Torrent: \"%1\", file: \"%2\", reason: \"%3\"") - .arg(name(), filePath(static_cast>(p->index)) + .arg(name(), filePath(static_cast>(p->index)) , QString::fromLocal8Bit(p->error.message().c_str())), Log::WARNING); m_oldPath[p->index].removeFirst(); @@ -1769,12 +1647,12 @@ void TorrentHandleImpl::handleFileCompletedAlert(const lt::file_completed_alert qDebug("A file completed download in torrent \"%s\"", qUtf8Printable(name())); if (m_session->isAppendExtensionEnabled()) { - QString name = filePath(static_cast>(p->index)); + QString name = filePath(static_cast>(p->index)); if (name.endsWith(QB_EXT)) { const QString oldName = name; name.chop(QB_EXT.size()); qDebug("Renaming %s to %s", qUtf8Printable(oldName), qUtf8Printable(name)); - renameFile(static_cast>(p->index), name); + renameFile(static_cast>(p->index), name); } } } @@ -2027,14 +1905,10 @@ void TorrentHandleImpl::setDownloadLimit(const int limit) void TorrentHandleImpl::setSuperSeeding(const bool enable) { -#if (LIBTORRENT_VERSION_NUM < 10200) - m_nativeHandle.super_seeding(enable); -#else if (enable) m_nativeHandle.set_flags(lt::torrent_flags::super_seeding); else m_nativeHandle.unset_flags(lt::torrent_flags::super_seeding); -#endif } void TorrentHandleImpl::flushCache() const diff --git a/src/base/bittorrent/torrenthandleimpl.h b/src/base/bittorrent/torrenthandleimpl.h index 36aeeb504..0ba12d3c3 100644 --- a/src/base/bittorrent/torrenthandleimpl.h +++ b/src/base/bittorrent/torrenthandleimpl.h @@ -259,12 +259,6 @@ namespace BitTorrent private: typedef std::function EventTrigger; -#if (LIBTORRENT_VERSION_NUM < 10200) - using LTFileIndex = int; -#else - using LTFileIndex = lt::file_index_t; -#endif - void updateStatus(); void updateStatus(const lt::torrent_status &nativeStatus); void updateState(); @@ -315,7 +309,7 @@ namespace BitTorrent // Until libtorrent provide an "old_name" field in `file_renamed_alert` // we will rely on this workaround to remove empty leftover folders - QHash> m_oldPath; + QHash> m_oldPath; QHash m_trackerInfos; diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index 299dad867..90a50b2c7 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -28,10 +28,6 @@ #include "torrentinfo.h" -#if (LIBTORRENT_VERSION_NUM < 10200) -#include -#endif - #include #include #include @@ -52,26 +48,11 @@ #include "infohash.h" #include "trackerentry.h" -namespace -{ -#if (LIBTORRENT_VERSION_NUM < 10200) - using LTPieceIndex = int; - using LTFileIndex = int; -#else - using LTPieceIndex = lt::piece_index_t; - using LTFileIndex = lt::file_index_t; -#endif -} - using namespace BitTorrent; -TorrentInfo::TorrentInfo(NativeConstPtr nativeInfo) +TorrentInfo::TorrentInfo(std::shared_ptr nativeInfo) { -#if (LIBTORRENT_VERSION_NUM < 10200) - m_nativeInfo = boost::const_pointer_cast(nativeInfo); -#else m_nativeInfo = std::const_pointer_cast(nativeInfo); -#endif } TorrentInfo::TorrentInfo(const TorrentInfo &other) @@ -93,21 +74,15 @@ TorrentInfo TorrentInfo::load(const QByteArray &data, QString *error) noexcept const int tokenLimit = 10000000; lt::error_code ec; -#if (LIBTORRENT_VERSION_NUM < 10200) - lt::bdecode_node node; - bdecode(data.constData(), (data.constData() + data.size()), node, ec - , nullptr, depthLimit, tokenLimit); -#else const lt::bdecode_node node = lt::bdecode(data, ec , nullptr, depthLimit, tokenLimit); -#endif if (ec) { if (error) *error = QString::fromStdString(ec.message()); return TorrentInfo(); } - TorrentInfo info {NativePtr(new lt::torrent_info(node, ec))}; + TorrentInfo info {std::shared_ptr(new lt::torrent_info(node, ec))}; if (ec) { if (error) *error = QString::fromStdString(ec.message()); @@ -160,11 +135,7 @@ void TorrentInfo::saveToFile(const QString &path) const if (!isValid()) throw RuntimeError {tr("Invalid metadata.")}; -#if (LIBTORRENT_VERSION_NUM < 10200) - const lt::create_torrent torrentCreator = lt::create_torrent(*(nativeInfo()), true); -#else const lt::create_torrent torrentCreator = lt::create_torrent(*(nativeInfo())); -#endif const lt::entry torrentEntry = torrentCreator.generate(); QFile torrentFile {path}; @@ -197,13 +168,8 @@ QDateTime TorrentInfo::creationDate() const { if (!isValid()) return {}; -#if (LIBTORRENT_VERSION_NUM < 10200) - const boost::optional date = m_nativeInfo->creation_date(); - return (date ? QDateTime::fromSecsSinceEpoch(*date) : QDateTime()); -#else const std::time_t date = m_nativeInfo->creation_date(); return ((date != 0) ? QDateTime::fromSecsSinceEpoch(date) : QDateTime()); -#endif } QString TorrentInfo::creator() const @@ -245,7 +211,7 @@ int TorrentInfo::pieceLength() const int TorrentInfo::pieceLength(const int index) const { if (!isValid()) return -1; - return m_nativeInfo->piece_size(LTPieceIndex {index}); + return m_nativeInfo->piece_size(lt::piece_index_t {index}); } int TorrentInfo::piecesCount() const @@ -258,7 +224,7 @@ QString TorrentInfo::filePath(const int index) const { if (!isValid()) return {}; return Utils::Fs::toUniformPath( - QString::fromStdString(m_nativeInfo->files().file_path(LTFileIndex {index}))); + QString::fromStdString(m_nativeInfo->files().file_path(lt::file_index_t {index}))); } QStringList TorrentInfo::filePaths() const @@ -279,19 +245,19 @@ QString TorrentInfo::origFilePath(const int index) const { if (!isValid()) return {}; return Utils::Fs::toUniformPath( - QString::fromStdString(m_nativeInfo->orig_files().file_path(LTFileIndex {index}))); + QString::fromStdString(m_nativeInfo->orig_files().file_path(lt::file_index_t {index}))); } qlonglong TorrentInfo::fileSize(const int index) const { if (!isValid()) return -1; - return m_nativeInfo->files().file_size(LTFileIndex {index}); + return m_nativeInfo->files().file_size(lt::file_index_t {index}); } qlonglong TorrentInfo::fileOffset(const int index) const { if (!isValid()) return -1; - return m_nativeInfo->files().file_offset(LTFileIndex {index}); + return m_nativeInfo->files().file_offset(lt::file_index_t {index}); } QVector TorrentInfo::trackers() const @@ -350,8 +316,8 @@ QVector TorrentInfo::fileIndicesForPiece(const int pieceIndex) const return {}; const std::vector files( - nativeInfo()->map_block(LTPieceIndex {pieceIndex}, 0 - , nativeInfo()->piece_size(LTPieceIndex {pieceIndex}))); + nativeInfo()->map_block(lt::piece_index_t {pieceIndex}, 0 + , nativeInfo()->piece_size(lt::piece_index_t {pieceIndex}))); QVector res; res.reserve(int(files.size())); std::transform(files.begin(), files.end(), std::back_inserter(res), @@ -370,7 +336,7 @@ QVector TorrentInfo::pieceHashes() const hashes.reserve(count); for (int i = 0; i < count; ++i) - hashes += {m_nativeInfo->hash_for_piece_ptr(LTPieceIndex {i}), InfoHash::length()}; + hashes += {m_nativeInfo->hash_for_piece_ptr(lt::piece_index_t {i}), InfoHash::length()}; return hashes; } @@ -399,8 +365,8 @@ TorrentInfo::PieceRange TorrentInfo::filePieces(const int fileIndex) const } const lt::file_storage &files = nativeInfo()->files(); - const auto fileSize = files.file_size(LTFileIndex {fileIndex}); - const auto fileOffset = files.file_offset(LTFileIndex {fileIndex}); + const auto fileSize = files.file_size(lt::file_index_t {fileIndex}); + const auto fileOffset = files.file_offset(lt::file_index_t {fileIndex}); const int beginIdx = (fileOffset / pieceLength()); const int endIdx = ((fileOffset + fileSize - 1) / pieceLength()); @@ -413,7 +379,7 @@ TorrentInfo::PieceRange TorrentInfo::filePieces(const int fileIndex) const void TorrentInfo::renameFile(const int index, const QString &newPath) { if (!isValid()) return; - nativeInfo()->rename_file(LTFileIndex {index}, Utils::Fs::toNativePath(newPath).toStdString()); + nativeInfo()->rename_file(lt::file_index_t {index}, Utils::Fs::toNativePath(newPath).toStdString()); } int BitTorrent::TorrentInfo::fileIndex(const QString &fileName) const @@ -464,14 +430,14 @@ void TorrentInfo::stripRootFolder() if (files.name() != newName) { files.set_name(newName); for (int i = 0; i < files.num_files(); ++i) - files.rename_file(LTFileIndex {i}, files.file_path(LTFileIndex {i})); + files.rename_file(lt::file_index_t {i}, files.file_path(lt::file_index_t {i})); } files.set_name(""); m_nativeInfo->remap_files(files); } -TorrentInfo::NativePtr TorrentInfo::nativeInfo() const +std::shared_ptr TorrentInfo::nativeInfo() const { return m_nativeInfo; } diff --git a/src/base/bittorrent/torrentinfo.h b/src/base/bittorrent/torrentinfo.h index 6d140007b..de3448f94 100644 --- a/src/base/bittorrent/torrentinfo.h +++ b/src/base/bittorrent/torrentinfo.h @@ -30,7 +30,6 @@ #define BITTORRENT_TORRENTINFO_H #include -#include #include #include @@ -53,15 +52,7 @@ namespace BitTorrent Q_DECLARE_TR_FUNCTIONS(TorrentInfo) public: -#if (LIBTORRENT_VERSION_NUM < 10200) - using NativeConstPtr = boost::shared_ptr; - using NativePtr = boost::shared_ptr; -#else - using NativeConstPtr = std::shared_ptr; - using NativePtr = std::shared_ptr; -#endif - - explicit TorrentInfo(NativeConstPtr nativeInfo = {}); + explicit TorrentInfo(std::shared_ptr nativeInfo = {}); TorrentInfo(const TorrentInfo &other); static TorrentInfo load(const QByteArray &data, QString *error = nullptr) noexcept; @@ -107,12 +98,12 @@ namespace BitTorrent bool hasRootFolder() const; void stripRootFolder(); - NativePtr nativeInfo() const; + std::shared_ptr nativeInfo() const; private: // returns file index or -1 if fileName is not found int fileIndex(const QString &fileName) const; - NativePtr m_nativeInfo; + std::shared_ptr m_nativeInfo; }; } diff --git a/src/base/bittorrent/trackerentry.cpp b/src/base/bittorrent/trackerentry.cpp index 13015fbf2..e20be6589 100644 --- a/src/base/bittorrent/trackerentry.cpp +++ b/src/base/bittorrent/trackerentry.cpp @@ -30,8 +30,6 @@ #include -#include - #include #include @@ -59,13 +57,6 @@ int TrackerEntry::tier() const TrackerEntry::Status TrackerEntry::status() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - if (nativeEntry().fails > 0) - return NotWorking; - - if (nativeEntry().updating) - return Updating; -#else const auto &endpoints = nativeEntry().endpoints; const bool allFailed = !endpoints.empty() && std::all_of(endpoints.begin(), endpoints.end() @@ -83,7 +74,6 @@ TrackerEntry::Status TrackerEntry::status() const }); if (isUpdating) return Updating; -#endif if (!nativeEntry().verified) return NotContacted; @@ -98,38 +88,26 @@ void TrackerEntry::setTier(const int value) int TrackerEntry::numSeeds() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return nativeEntry().scrape_complete; -#else int value = -1; for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints) value = std::max(value, endpoint.scrape_complete); return value; -#endif } int TrackerEntry::numLeeches() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return nativeEntry().scrape_incomplete; -#else int value = -1; for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints) value = std::max(value, endpoint.scrape_incomplete); return value; -#endif } int TrackerEntry::numDownloaded() const { -#if (LIBTORRENT_VERSION_NUM < 10200) - return nativeEntry().scrape_downloaded; -#else int value = -1; for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints) value = std::max(value, endpoint.scrape_downloaded); return value; -#endif } const lt::announce_entry &TrackerEntry::nativeEntry() const diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index d850ea397..1566f08d8 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -455,11 +455,7 @@ QString Utils::Misc::boostVersionString() QString Utils::Misc::libtorrentVersionString() { // static initialization for usage in signal handler -#if (LIBTORRENT_VERSION_NUM < 10200) - static const auto version {QString::fromLatin1(libtorrent::version())}; -#else static const auto version {QString::fromLatin1(lt::version())}; -#endif return version; }