mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-06 05:01:25 -07:00
parent
06e1b07274
commit
40e432b127
25 changed files with 92 additions and 756 deletions
48
.travis.yml
48
.travis.yml
|
@ -12,10 +12,6 @@ env:
|
||||||
- libt_branch=RC_1_2 gui=false build_system=qmake
|
- 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=true build_system=cmake
|
||||||
- libt_branch=RC_1_2 gui=false 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:
|
global:
|
||||||
- secure: "OI9CUjj4lTb0HwwIZU5PbECU3hLlAL6KC8KsbwohG8/O3j5fLcnmDsK4Ad9us5cC39sS11Jcd1kDP2qRcCuST/glVNhLkcjKkiQerOfd5nQ/qL4JYfz/1mfP5mdpz9jHKzpLUIG+TXkbSTjP6VVmsb5KPT+3pKEdRFZB+Pu9+J8="
|
- secure: "OI9CUjj4lTb0HwwIZU5PbECU3hLlAL6KC8KsbwohG8/O3j5fLcnmDsK4Ad9us5cC39sS11Jcd1kDP2qRcCuST/glVNhLkcjKkiQerOfd5nQ/qL4JYfz/1mfP5mdpz9jHKzpLUIG+TXkbSTjP6VVmsb5KPT+3pKEdRFZB+Pu9+J8="
|
||||||
- coverity_branch: coverity_scan
|
- coverity_branch: coverity_scan
|
||||||
|
@ -24,8 +20,6 @@ matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- env: libt_branch=RC_1_2 gui=true build_system=cmake
|
- 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_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:
|
branches:
|
||||||
except:
|
except:
|
||||||
|
@ -129,53 +123,11 @@ install:
|
||||||
ccache -M 512M
|
ccache -M 512M
|
||||||
ccache -V && ccache --show-stats && ccache --zero-stats
|
ccache -V && ccache --show-stats && ccache --zero-stats
|
||||||
fi
|
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
|
if [ "$libt_branch" = "RC_1_2" ] && [ "$TRAVIS_OS_NAME" = "linux" ]; then
|
||||||
# Will install latest 1.2.x daily build from the PPA
|
# Will install latest 1.2.x daily build from the PPA
|
||||||
sudo apt-get -y install libtorrent-rasterbar-dev
|
sudo apt-get -y install libtorrent-rasterbar-dev
|
||||||
fi
|
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
|
if [ "$libt_branch" = "RC_1_2" ] && [ "$TRAVIS_OS_NAME" = "osx" ]; then
|
||||||
wget https://builds.shiki.hu/travis/brew/version
|
wget https://builds.shiki.hu/travis/brew/version
|
||||||
|
|
|
@ -48,7 +48,7 @@ include(FeatureSummary)
|
||||||
set(requiredBoostVersion 1.40)
|
set(requiredBoostVersion 1.40)
|
||||||
set(requiredQtVersion 5.9.0)
|
set(requiredQtVersion 5.9.0)
|
||||||
set(requiredOpensslVersion 1.0)
|
set(requiredOpensslVersion 1.0)
|
||||||
set(requiredLibtorrentVersion 1.1.10)
|
set(requiredLibtorrentVersion 1.2)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
include(winconf)
|
include(winconf)
|
||||||
|
|
2
INSTALL
2
INSTALL
|
@ -5,7 +5,7 @@ qBittorrent - A BitTorrent client in C++ / Qt
|
||||||
|
|
||||||
- Boost >= 1.40
|
- Boost >= 1.40
|
||||||
|
|
||||||
- libtorrent-rasterbar >= 1.1.10 (by Arvid Norberg)
|
- libtorrent-rasterbar >= 1.2 (by Arvid Norberg)
|
||||||
* https://www.libtorrent.org/
|
* https://www.libtorrent.org/
|
||||||
* Be careful: another library (the one used by rTorrent) uses a similar name
|
* Be careful: another library (the one used by rTorrent) uses a similar name
|
||||||
|
|
||||||
|
|
18
configure
vendored
18
configure
vendored
|
@ -5292,12 +5292,12 @@ if test -n "$libtorrent_CFLAGS"; then
|
||||||
pkg_cv_libtorrent_CFLAGS="$libtorrent_CFLAGS"
|
pkg_cv_libtorrent_CFLAGS="$libtorrent_CFLAGS"
|
||||||
elif test -n "$PKG_CONFIG"; then
|
elif test -n "$PKG_CONFIG"; then
|
||||||
if test -n "$PKG_CONFIG" && \
|
if test -n "$PKG_CONFIG" && \
|
||||||
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libtorrent-rasterbar >= 1.1.10\""; } >&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.1.10") 2>&5
|
($PKG_CONFIG --exists --print-errors "libtorrent-rasterbar >= 1.2") 2>&5
|
||||||
ac_status=$?
|
ac_status=$?
|
||||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||||
test $ac_status = 0; }; then
|
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
|
test "x$?" != "x0" && pkg_failed=yes
|
||||||
else
|
else
|
||||||
pkg_failed=yes
|
pkg_failed=yes
|
||||||
|
@ -5309,12 +5309,12 @@ if test -n "$libtorrent_LIBS"; then
|
||||||
pkg_cv_libtorrent_LIBS="$libtorrent_LIBS"
|
pkg_cv_libtorrent_LIBS="$libtorrent_LIBS"
|
||||||
elif test -n "$PKG_CONFIG"; then
|
elif test -n "$PKG_CONFIG"; then
|
||||||
if test -n "$PKG_CONFIG" && \
|
if test -n "$PKG_CONFIG" && \
|
||||||
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libtorrent-rasterbar >= 1.1.10\""; } >&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.1.10") 2>&5
|
($PKG_CONFIG --exists --print-errors "libtorrent-rasterbar >= 1.2") 2>&5
|
||||||
ac_status=$?
|
ac_status=$?
|
||||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||||
test $ac_status = 0; }; then
|
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
|
test "x$?" != "x0" && pkg_failed=yes
|
||||||
else
|
else
|
||||||
pkg_failed=yes
|
pkg_failed=yes
|
||||||
|
@ -5335,14 +5335,14 @@ else
|
||||||
_pkg_short_errors_supported=no
|
_pkg_short_errors_supported=no
|
||||||
fi
|
fi
|
||||||
if test $_pkg_short_errors_supported = yes; then
|
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
|
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
|
fi
|
||||||
# Put the nasty error message in config.log where it belongs
|
# Put the nasty error message in config.log where it belongs
|
||||||
echo "$libtorrent_PKG_ERRORS" >&5
|
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
|
$libtorrent_PKG_ERRORS
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,7 @@ AC_MSG_NOTICE([Boost.System LIB: "$BOOST_SYSTEM_LIB"])
|
||||||
LIBS="$BOOST_SYSTEM_LIB $LIBS"
|
LIBS="$BOOST_SYSTEM_LIB $LIBS"
|
||||||
|
|
||||||
PKG_CHECK_MODULES(libtorrent,
|
PKG_CHECK_MODULES(libtorrent,
|
||||||
[libtorrent-rasterbar >= 1.1.10],
|
[libtorrent-rasterbar >= 1.2],
|
||||||
[CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS"
|
[CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS"
|
||||||
LIBS="$libtorrent_LIBS $LIBS"])
|
LIBS="$libtorrent_LIBS $LIBS"])
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
|
|
||||||
#include "customstorage.h"
|
#include "customstorage.h"
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 10200)
|
|
||||||
#include <libtorrent/download_priority.hpp>
|
#include <libtorrent/download_priority.hpp>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
@ -99,4 +98,3 @@ void CustomStorage::handleCompleteFiles(const QString &savePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
|
@ -28,9 +28,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <libtorrent/version.hpp>
|
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 10200)
|
|
||||||
#include <libtorrent/aux_/vector.hpp>
|
#include <libtorrent/aux_/vector.hpp>
|
||||||
#include <libtorrent/fwd.hpp>
|
#include <libtorrent/fwd.hpp>
|
||||||
#include <libtorrent/storage.hpp>
|
#include <libtorrent/storage.hpp>
|
||||||
|
@ -54,4 +51,3 @@ private:
|
||||||
lt::aux::vector<lt::download_priority_t, lt::file_index_t> m_filePriorities;
|
lt::aux::vector<lt::download_priority_t, lt::file_index_t> m_filePriorities;
|
||||||
QString m_savePath;
|
QString m_savePath;
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
|
@ -89,9 +89,5 @@ bool BitTorrent::operator!=(const InfoHash &left, const InfoHash &right)
|
||||||
|
|
||||||
uint BitTorrent::qHash(const InfoHash &key, const uint seed)
|
uint BitTorrent::qHash(const InfoHash &key, const uint seed)
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return ::qHash(static_cast<QString>(key), seed);
|
|
||||||
#else
|
|
||||||
return ::qHash((std::hash<lt::sha1_hash> {})(key), seed);
|
return ::qHash((std::hash<lt::sha1_hash> {})(key), seed);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#define BITTORRENT_INFOHASH_H
|
#define BITTORRENT_INFOHASH_H
|
||||||
|
|
||||||
#include <libtorrent/sha1_hash.hpp>
|
#include <libtorrent/sha1_hash.hpp>
|
||||||
#include <libtorrent/version.hpp>
|
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
@ -46,11 +45,7 @@ namespace BitTorrent
|
||||||
|
|
||||||
static constexpr int length()
|
static constexpr int length()
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return lt::sha1_hash::size;
|
|
||||||
#else
|
|
||||||
return lt::sha1_hash::size();
|
return lt::sha1_hash::size();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
|
@ -37,17 +37,12 @@ namespace
|
||||||
void handleFastresumeRejectedAlert(const lt::fastresume_rejected_alert *alert)
|
void handleFastresumeRejectedAlert(const lt::fastresume_rejected_alert *alert)
|
||||||
{
|
{
|
||||||
if (alert->error.value() == lt::errors::mismatching_file_size) {
|
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);
|
alert->handle.unset_flags(lt::torrent_flags::auto_managed);
|
||||||
#endif
|
|
||||||
alert->handle.pause();
|
alert->handle.pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 10200)
|
|
||||||
lt::feature_flags_t NativeSessionExtension::implemented_features()
|
lt::feature_flags_t NativeSessionExtension::implemented_features()
|
||||||
{
|
{
|
||||||
return alert_feature;
|
return alert_feature;
|
||||||
|
@ -57,12 +52,6 @@ std::shared_ptr<lt::torrent_plugin> NativeSessionExtension::new_torrent(const lt
|
||||||
{
|
{
|
||||||
return std::make_shared<NativeTorrentExtension>(torrentHandle);
|
return std::make_shared<NativeTorrentExtension>(torrentHandle);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
boost::shared_ptr<lt::torrent_plugin> NativeSessionExtension::new_torrent(const lt::torrent_handle &torrentHandle, ClientData)
|
|
||||||
{
|
|
||||||
return boost::make_shared<NativeTorrentExtension>(torrentHandle);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void NativeSessionExtension::on_alert(const lt::alert *alert)
|
void NativeSessionExtension::on_alert(const lt::alert *alert)
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,11 +39,7 @@ class NativeSessionExtension final : public lt::plugin
|
||||||
using ClientData = void *;
|
using ClientData = void *;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 10200)
|
|
||||||
lt::feature_flags_t implemented_features() override;
|
lt::feature_flags_t implemented_features() override;
|
||||||
std::shared_ptr<lt::torrent_plugin> new_torrent(const lt::torrent_handle &torrentHandle, ClientData) override;
|
std::shared_ptr<lt::torrent_plugin> new_torrent(const lt::torrent_handle &torrentHandle, ClientData) override;
|
||||||
#else
|
|
||||||
boost::shared_ptr<lt::torrent_plugin> new_torrent(const lt::torrent_handle &torrentHandle, ClientData) override;
|
|
||||||
#endif
|
|
||||||
void on_alert(const lt::alert *alert) override;
|
void on_alert(const lt::alert *alert) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,21 +34,13 @@ namespace
|
||||||
{
|
{
|
||||||
bool isPaused(const lt::torrent_status &torrentStatus)
|
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)
|
return ((torrentStatus.flags & lt::torrent_flags::paused)
|
||||||
&& !(torrentStatus.flags & lt::torrent_flags::auto_managed));
|
&& !(torrentStatus.flags & lt::torrent_flags::auto_managed));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isAutoManaged(const lt::torrent_status &torrentStatus)
|
bool isAutoManaged(const lt::torrent_status &torrentStatus)
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return torrentStatus.auto_managed;
|
|
||||||
#else
|
|
||||||
return static_cast<bool>(torrentStatus.flags & lt::torrent_flags::auto_managed);
|
return static_cast<bool>(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
|
// 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)
|
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
|
// 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).
|
// (really we just allow libtorrent to resume it by enabling auto management for it).
|
||||||
if (state == lt::torrent_status::checking_files) {
|
if (state == lt::torrent_status::checking_files) {
|
||||||
if (isPaused(m_torrentHandle.status({}))) {
|
if (isPaused(m_torrentHandle.status({})))
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
m_torrentHandle.stop_when_ready(true);
|
|
||||||
m_torrentHandle.auto_managed(true);
|
|
||||||
#else
|
|
||||||
m_torrentHandle.set_flags(lt::torrent_flags::stop_when_ready | lt::torrent_flags::auto_managed);
|
m_torrentHandle.set_flags(lt::torrent_flags::stop_when_ready | lt::torrent_flags::auto_managed);
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeTorrentExtension::on_pause()
|
bool NativeTorrentExtension::on_pause()
|
||||||
{
|
{
|
||||||
if (!isAutoManaged(m_torrentHandle.status({}))) {
|
if (!isAutoManaged(m_torrentHandle.status({})))
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
m_torrentHandle.stop_when_ready(false);
|
|
||||||
#else
|
|
||||||
m_torrentHandle.unset_flags(lt::torrent_flags::stop_when_ready);
|
m_torrentHandle.unset_flags(lt::torrent_flags::stop_when_ready);
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// return `false` to allow standard handler
|
// return `false` to allow standard handler
|
||||||
// and other extensions to be also invoked.
|
// and other extensions to be also invoked.
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include <libtorrent/extensions.hpp>
|
#include <libtorrent/extensions.hpp>
|
||||||
#include <libtorrent/torrent_handle.hpp>
|
#include <libtorrent/torrent_handle.hpp>
|
||||||
#include <libtorrent/version.hpp>
|
|
||||||
|
|
||||||
class NativeTorrentExtension final : public lt::torrent_plugin
|
class NativeTorrentExtension final : public lt::torrent_plugin
|
||||||
{
|
{
|
||||||
|
@ -38,11 +37,7 @@ public:
|
||||||
explicit NativeTorrentExtension(const lt::torrent_handle &torrentHandle);
|
explicit NativeTorrentExtension(const lt::torrent_handle &torrentHandle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
void on_state(int state) override;
|
|
||||||
#else
|
|
||||||
void on_state(lt::torrent_status::state_t state) override;
|
void on_state(lt::torrent_status::state_t state) override;
|
||||||
#endif
|
|
||||||
bool on_pause() override;
|
bool on_pause() override;
|
||||||
|
|
||||||
lt::torrent_handle m_torrentHandle;
|
lt::torrent_handle m_torrentHandle;
|
||||||
|
|
|
@ -28,8 +28,6 @@
|
||||||
|
|
||||||
#include "peerinfo.h"
|
#include "peerinfo.h"
|
||||||
|
|
||||||
#include <libtorrent/version.hpp>
|
|
||||||
|
|
||||||
#include <QBitArray>
|
#include <QBitArray>
|
||||||
|
|
||||||
#include "base/bittorrent/torrenthandle.h"
|
#include "base/bittorrent/torrenthandle.h"
|
||||||
|
@ -211,15 +209,9 @@ qlonglong PeerInfo::totalDownload() const
|
||||||
|
|
||||||
QBitArray PeerInfo::pieces() 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());
|
QBitArray result(m_nativeInfo.pieces.size());
|
||||||
for (int i = 0; i < result.size(); ++i) {
|
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);
|
result.setBit(i, true);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -82,7 +82,7 @@ void PortForwarderImpl::deletePort(const quint16 port)
|
||||||
{
|
{
|
||||||
if (m_mappedPorts.contains(port)) {
|
if (m_mappedPorts.contains(port)) {
|
||||||
if (isEnabled()) {
|
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_provider->delete_port_mapping(portMapping);
|
||||||
}
|
}
|
||||||
m_mappedPorts.remove(port);
|
m_mappedPorts.remove(port);
|
||||||
|
|
|
@ -31,19 +31,12 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <libtorrent/fwd.hpp>
|
#include <libtorrent/fwd.hpp>
|
||||||
#include <libtorrent/version.hpp>
|
#include <libtorrent/portmap.hpp>
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
|
||||||
#include "base/net/portforwarder.h"
|
#include "base/net/portforwarder.h"
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
using LTPortMapping = int;
|
|
||||||
#else
|
|
||||||
#include <libtorrent/portmap.hpp>
|
|
||||||
using LTPortMapping = lt::port_mapping_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class PortForwarderImpl final : public Net::PortForwarder
|
class PortForwarderImpl final : public Net::PortForwarder
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -65,5 +58,5 @@ private:
|
||||||
|
|
||||||
bool m_active;
|
bool m_active;
|
||||||
lt::session *m_provider;
|
lt::session *m_provider;
|
||||||
QHash<quint16, std::vector<LTPortMapping>> m_mappedPorts;
|
QHash<quint16, std::vector<lt::port_mapping_t>> m_mappedPorts;
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,20 +44,16 @@
|
||||||
#include <libtorrent/bdecode.hpp>
|
#include <libtorrent/bdecode.hpp>
|
||||||
#include <libtorrent/bencode.hpp>
|
#include <libtorrent/bencode.hpp>
|
||||||
#include <libtorrent/error_code.hpp>
|
#include <libtorrent/error_code.hpp>
|
||||||
|
#include <libtorrent/extensions/smart_ban.hpp>
|
||||||
#include <libtorrent/extensions/ut_metadata.hpp>
|
#include <libtorrent/extensions/ut_metadata.hpp>
|
||||||
#include <libtorrent/extensions/ut_pex.hpp>
|
#include <libtorrent/extensions/ut_pex.hpp>
|
||||||
#include <libtorrent/extensions/smart_ban.hpp>
|
|
||||||
#include <libtorrent/ip_filter.hpp>
|
#include <libtorrent/ip_filter.hpp>
|
||||||
#include <libtorrent/magnet_uri.hpp>
|
#include <libtorrent/magnet_uri.hpp>
|
||||||
|
#include <libtorrent/read_resume_data.hpp>
|
||||||
#include <libtorrent/session.hpp>
|
#include <libtorrent/session.hpp>
|
||||||
#include <libtorrent/session_stats.hpp>
|
#include <libtorrent/session_stats.hpp>
|
||||||
#include <libtorrent/session_status.hpp>
|
#include <libtorrent/session_status.hpp>
|
||||||
#include <libtorrent/torrent_info.hpp>
|
#include <libtorrent/torrent_info.hpp>
|
||||||
#include <libtorrent/version.hpp>
|
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 10200)
|
|
||||||
#include <libtorrent/read_resume_data.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
@ -115,24 +111,6 @@ using namespace BitTorrent;
|
||||||
|
|
||||||
namespace
|
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 <typename LTStr>
|
template <typename LTStr>
|
||||||
QString fromLTString(const LTStr &str)
|
QString fromLTString(const LTStr &str)
|
||||||
{
|
{
|
||||||
|
@ -186,11 +164,7 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
lt::error_code ec;
|
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);
|
root = lt::bdecode(data, ec);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -202,10 +176,7 @@ namespace
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
lt::error_code ec;
|
lt::error_code ec;
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
#if defined(NEED_TO_FIX_BROKEN_PATH)
|
||||||
lt::bdecode_node root;
|
|
||||||
lt::bdecode(data.constData(), (data.constData() + data.size()), root, ec);
|
|
||||||
#elif defined(NEED_TO_FIX_BROKEN_PATH)
|
|
||||||
// TODO: Remove together with fixBrokenSavePath()
|
// TODO: Remove together with fixBrokenSavePath()
|
||||||
lt::bdecode_node root = lt::bdecode(data, ec);
|
lt::bdecode_node root = lt::bdecode(data, ec);
|
||||||
#else
|
#else
|
||||||
|
@ -236,7 +207,7 @@ namespace
|
||||||
torrentParams.paused = root.dict_find_int_value("qBt-paused", (isPaused && !isAutoManaged));
|
torrentParams.paused = root.dict_find_int_value("qBt-paused", (isPaused && !isAutoManaged));
|
||||||
torrentParams.forced = root.dict_find_int_value("qBt-forced", (!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())
|
if (ratioLimitString.empty())
|
||||||
torrentParams.ratioLimit = root.dict_find_int_value("qBt-ratioLimit", TorrentHandle::USE_GLOBAL_RATIO * 1000) / 1000.0;
|
torrentParams.ratioLimit = root.dict_find_int_value("qBt-ratioLimit", TorrentHandle::USE_GLOBAL_RATIO * 1000) / 1000.0;
|
||||||
else
|
else
|
||||||
|
@ -1135,7 +1106,7 @@ void Session::configureComponents()
|
||||||
|
|
||||||
void Session::initializeNativeSession()
|
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::file_progress_notification
|
||||||
| lt::alert::ip_block_notification
|
| lt::alert::ip_block_notification
|
||||||
| lt::alert::peer_notification
|
| lt::alert::peer_notification
|
||||||
|
@ -1165,19 +1136,8 @@ void Session::initializeNativeSession()
|
||||||
pack.set_bool(lt::settings_pack::upnp_ignore_nonrouters, true);
|
pack.set_bool(lt::settings_pack::upnp_ignore_nonrouters, true);
|
||||||
#endif
|
#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);
|
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("Peer ID: ") + QString::fromStdString(peerId));
|
||||||
LogMsg(tr("HTTP User-Agent is '%1'").arg(USER_AGENT));
|
LogMsg(tr("HTTP User-Agent is '%1'").arg(USER_AGENT));
|
||||||
|
@ -1203,11 +1163,7 @@ void Session::initializeNativeSession()
|
||||||
if (isPeXEnabled())
|
if (isPeXEnabled())
|
||||||
m_nativeSession->add_extension(<::create_ut_pex_plugin);
|
m_nativeSession->add_extension(<::create_ut_pex_plugin);
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
m_nativeSession->add_extension(boost::shared_ptr<lt::plugin> {new NativeSessionExtension});
|
|
||||||
#else
|
|
||||||
m_nativeSession->add_extension(std::make_shared<NativeSessionExtension>());
|
m_nativeSession->add_extension(std::make_shared<NativeSessionExtension>());
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::processBannedIPs(lt::ip_filter &filter)
|
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()
|
// Proactively do the same for 0.0.0.0 and address_v4::any()
|
||||||
f.add_rule(lt::address_v4::any()
|
f.add_rule(lt::address_v4::any()
|
||||||
, lt::address_v4::broadcast()
|
, lt::address_v4::broadcast()
|
||||||
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::global_peer_class_id));
|
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::global_peer_class_id));
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 10200) || TORRENT_USE_IPV6
|
|
||||||
// IPv6 may not be available on OS and the parsing
|
// IPv6 may not be available on OS and the parsing
|
||||||
// would result in an exception -> abnormal program termination
|
// would result in an exception -> abnormal program termination
|
||||||
// Affects Windows XP
|
// Affects Windows XP
|
||||||
try {
|
try {
|
||||||
f.add_rule(lt::address_v6::any()
|
f.add_rule(lt::address_v6::any()
|
||||||
, lt::address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
|
, lt::address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
|
||||||
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::global_peer_class_id));
|
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::global_peer_class_id));
|
||||||
}
|
}
|
||||||
catch (const std::exception &) {}
|
catch (const std::exception &) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (ignoreLimitsOnLAN()) {
|
if (ignoreLimitsOnLAN()) {
|
||||||
// local networks
|
// local networks
|
||||||
f.add_rule(lt::address_v4::from_string("10.0.0.0")
|
f.add_rule(lt::address_v4::from_string("10.0.0.0")
|
||||||
, lt::address_v4::from_string("10.255.255.255")
|
, lt::address_v4::from_string("10.255.255.255")
|
||||||
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
|
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
|
||||||
f.add_rule(lt::address_v4::from_string("172.16.0.0")
|
f.add_rule(lt::address_v4::from_string("172.16.0.0")
|
||||||
, lt::address_v4::from_string("172.31.255.255")
|
, lt::address_v4::from_string("172.31.255.255")
|
||||||
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
|
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
|
||||||
f.add_rule(lt::address_v4::from_string("192.168.0.0")
|
f.add_rule(lt::address_v4::from_string("192.168.0.0")
|
||||||
, lt::address_v4::from_string("192.168.255.255")
|
, lt::address_v4::from_string("192.168.255.255")
|
||||||
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
|
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
|
||||||
// link local
|
// link local
|
||||||
f.add_rule(lt::address_v4::from_string("169.254.0.0")
|
f.add_rule(lt::address_v4::from_string("169.254.0.0")
|
||||||
, lt::address_v4::from_string("169.254.255.255")
|
, lt::address_v4::from_string("169.254.255.255")
|
||||||
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
|
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
|
||||||
// loopback
|
// loopback
|
||||||
f.add_rule(lt::address_v4::from_string("127.0.0.0")
|
f.add_rule(lt::address_v4::from_string("127.0.0.0")
|
||||||
, lt::address_v4::from_string("127.255.255.255")
|
, lt::address_v4::from_string("127.255.255.255")
|
||||||
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
|
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 10200) || TORRENT_USE_IPV6
|
|
||||||
// IPv6 may not be available on OS and the parsing
|
// IPv6 may not be available on OS and the parsing
|
||||||
// would result in an exception -> abnormal program termination
|
// would result in an exception -> abnormal program termination
|
||||||
// Affects Windows XP
|
// Affects Windows XP
|
||||||
|
@ -1635,18 +1588,17 @@ void Session::configurePeerClasses()
|
||||||
// link local
|
// link local
|
||||||
f.add_rule(lt::address_v6::from_string("fe80::")
|
f.add_rule(lt::address_v6::from_string("fe80::")
|
||||||
, lt::address_v6::from_string("febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
|
, lt::address_v6::from_string("febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
|
||||||
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
|
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
|
||||||
// unique local addresses
|
// unique local addresses
|
||||||
f.add_rule(lt::address_v6::from_string("fc00::")
|
f.add_rule(lt::address_v6::from_string("fc00::")
|
||||||
, lt::address_v6::from_string("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
|
, lt::address_v6::from_string("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
|
||||||
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
|
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
|
||||||
// loopback
|
// loopback
|
||||||
f.add_rule(lt::address_v6::loopback()
|
f.add_rule(lt::address_v6::loopback()
|
||||||
, lt::address_v6::loopback()
|
, lt::address_v6::loopback()
|
||||||
, 1 << static_cast<LTUnderlyingType<LTPeerClass>>(lt::session::local_peer_class_id));
|
, 1 << static_cast<LTUnderlyingType<lt::peer_class_t>>(lt::session::local_peer_class_id));
|
||||||
}
|
}
|
||||||
catch (const std::exception &) {}
|
catch (const std::exception &) {}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
m_nativeSession->set_peer_class_filter(f);
|
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()) {
|
if (iter != m_moveStorageQueue.end()) {
|
||||||
// We shouldn't actually remove torrent until existing "move storage jobs" are done
|
// We shouldn't actually remove torrent until existing "move storage jobs" are done
|
||||||
torrentQueuePositionBottom(nativeHandle);
|
torrentQueuePositionBottom(nativeHandle);
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
nativeHandle.auto_managed(false);
|
|
||||||
#else
|
|
||||||
nativeHandle.unset_flags(lt::torrent_flags::auto_managed);
|
nativeHandle.unset_flags(lt::torrent_flags::auto_managed);
|
||||||
#endif
|
|
||||||
nativeHandle.pause();
|
nativeHandle.pause();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1917,7 +1865,7 @@ bool Session::cancelLoadMetadata(const InfoHash &hash)
|
||||||
const lt::torrent_handle torrent = m_nativeSession->find_torrent(hash);
|
const lt::torrent_handle torrent = m_nativeSession->find_torrent(hash);
|
||||||
if (!torrent.is_valid()) return false;
|
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...
|
// if hidden torrent is still loading metadata...
|
||||||
--m_extraLimit;
|
--m_extraLimit;
|
||||||
adjustLimits();
|
adjustLimits();
|
||||||
|
@ -2081,187 +2029,6 @@ bool Session::addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams
|
||||||
bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magnetUri,
|
bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magnetUri,
|
||||||
TorrentInfo torrentInfo, const QByteArray &fastresumeData)
|
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<char> {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<boost::uint8_t>(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, "");
|
params.savePath = normalizeSavePath(params.savePath, "");
|
||||||
|
|
||||||
if (!params.category.isEmpty()) {
|
if (!params.category.isEmpty()) {
|
||||||
|
@ -2433,7 +2200,6 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne
|
||||||
m_nativeSession->async_add_torrent(p);
|
m_nativeSession->async_add_torrent(p);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Session::findIncompleteFiles(TorrentInfo &torrentInfo, QString &savePath) const
|
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<QString>(hash);
|
const QString savePath = Utils::Fs::tempPath() + static_cast<QString>(hash);
|
||||||
p.save_path = Utils::Fs::toNativePath(savePath).toStdString();
|
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
|
// Forced start
|
||||||
p.flags &= ~lt::torrent_flags::paused;
|
p.flags &= ~lt::torrent_flags::paused;
|
||||||
p.flags &= ~lt::torrent_flags::auto_managed;
|
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.flags |= lt::torrent_flags::upload_mode;
|
||||||
|
|
||||||
p.storage = customStorageConstructor;
|
p.storage = customStorageConstructor;
|
||||||
#endif
|
|
||||||
|
|
||||||
// Adding torrent to BitTorrent session
|
// Adding torrent to BitTorrent session
|
||||||
lt::error_code ec;
|
lt::error_code ec;
|
||||||
|
@ -2606,7 +2363,7 @@ void Session::saveTorrentsQueue()
|
||||||
QMap<int, QString> queue; // Use QMap since it should be ordered by key
|
QMap<int, QString> queue; // Use QMap since it should be ordered by key
|
||||||
for (const TorrentHandleImpl *torrent : asConst(m_torrents)) {
|
for (const TorrentHandleImpl *torrent : asConst(m_torrents)) {
|
||||||
// We require actual (non-cached) queue position here!
|
// We require actual (non-cached) queue position here!
|
||||||
const int queuePos = static_cast<LTUnderlyingType<LTQueuePosition>>(torrent->nativeHandle().queue_position());
|
const int queuePos = static_cast<LTUnderlyingType<lt::queue_position_t>>(torrent->nativeHandle().queue_position());
|
||||||
if (queuePos >= 0)
|
if (queuePos >= 0)
|
||||||
queue[queuePos] = torrent->hash();
|
queue[queuePos] = torrent->hash();
|
||||||
}
|
}
|
||||||
|
@ -4088,11 +3845,7 @@ void Session::moveTorrentStorage(const MoveStorageJob &job) const
|
||||||
|
|
||||||
job.torrentHandle.move_storage(job.path.toUtf8().constData()
|
job.torrentHandle.move_storage(job.path.toUtf8().constData()
|
||||||
, ((job.mode == MoveStorageMode::Overwrite)
|
, ((job.mode == MoveStorageMode::Overwrite)
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
? lt::move_flags_t::always_replace_files : lt::move_flags_t::dont_replace));
|
||||||
? lt::always_replace_files : lt::dont_replace));
|
|
||||||
#else
|
|
||||||
? lt::move_flags_t::always_replace_files : lt::move_flags_t::dont_replace));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleMoveTorrentStorageJobFinished(const QString &errorMessage)
|
void Session::handleMoveTorrentStorageJobFinished(const QString &errorMessage)
|
||||||
|
@ -4496,11 +4249,9 @@ void Session::handleAlert(const lt::alert *a)
|
||||||
case lt::external_ip_alert::alert_type:
|
case lt::external_ip_alert::alert_type:
|
||||||
handleExternalIPAlert(static_cast<const lt::external_ip_alert*>(a));
|
handleExternalIPAlert(static_cast<const lt::external_ip_alert*>(a));
|
||||||
break;
|
break;
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 10200)
|
|
||||||
case lt::alerts_dropped_alert::alert_type:
|
case lt::alerts_dropped_alert::alert_type:
|
||||||
handleAlertsDroppedAlert(static_cast<const lt::alerts_dropped_alert *>(a));
|
handleAlertsDroppedAlert(static_cast<const lt::alerts_dropped_alert *>(a));
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
case lt::storage_moved_alert::alert_type:
|
case lt::storage_moved_alert::alert_type:
|
||||||
handleStorageMovedAlert(static_cast<const lt::storage_moved_alert*>(a));
|
handleStorageMovedAlert(static_cast<const lt::storage_moved_alert*>(a));
|
||||||
break;
|
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);
|
LogMsg(tr("Torrent errored. Torrent: \"%1\". Error: %2.").arg(torrent->name(), torrent->error()), Log::WARNING);
|
||||||
|
|
||||||
// Check if file(s) exist when using seed mode
|
// Check if file(s) exist when using seed mode
|
||||||
if (params.skipChecking && torrent->hasMetadata()) {
|
if (params.skipChecking && torrent->hasMetadata())
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
nativeHandle.read_piece(0);
|
|
||||||
#else
|
|
||||||
nativeHandle.read_piece(lt::piece_index_t(0));
|
nativeHandle.read_piece(lt::piece_index_t(0));
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleAddTorrentAlert(const lt::add_torrent_alert *p)
|
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
|
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) {
|
if (p->error) {
|
||||||
p->handle.unset_flags(lt::torrent_flags::auto_managed);
|
p->handle.unset_flags(lt::torrent_flags::auto_managed);
|
||||||
p->handle.force_recheck();
|
p->handle.force_recheck();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handlePortmapWarningAlert(const lt::portmap_error_alert *p)
|
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)
|
void Session::handlePeerBlockedAlert(const lt::peer_blocked_alert *p)
|
||||||
{
|
{
|
||||||
lt::error_code ec;
|
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);
|
const std::string ip = p->endpoint.address().to_string(ec);
|
||||||
#endif
|
|
||||||
QString reason;
|
QString reason;
|
||||||
switch (p->reason) {
|
switch (p->reason) {
|
||||||
case lt::peer_blocked_alert::ip_filter:
|
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)
|
void Session::handlePeerBanAlert(const lt::peer_ban_alert *p)
|
||||||
{
|
{
|
||||||
lt::error_code ec;
|
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);
|
const std::string ip = p->endpoint.address().to_string(ec);
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!ec)
|
if (!ec)
|
||||||
Logger::instance()->addPeer(QString::fromLatin1(ip.c_str()), false);
|
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)
|
void Session::handleListenSucceededAlert(const lt::listen_succeeded_alert *p)
|
||||||
{
|
{
|
||||||
QString proto = "INVALID";
|
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)
|
switch (p->socket_type)
|
||||||
{
|
{
|
||||||
case lt::socket_type_t::udp:
|
case lt::socket_type_t::udp:
|
||||||
|
@ -4842,16 +4550,11 @@ void Session::handleListenSucceededAlert(const lt::listen_succeeded_alert *p)
|
||||||
proto = "UTP_SSL";
|
proto = "UTP_SSL";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
lt::error_code ec;
|
lt::error_code ec;
|
||||||
LogMsg(tr("Successfully listening on IP: %1, port: %2/%3"
|
LogMsg(tr("Successfully listening on IP: %1, port: %2/%3"
|
||||||
, "e.g: Successfully listening on IP: 192.168.0.1, port: TCP/6881")
|
, "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);
|
.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
|
// Force reannounce on all torrents because some trackers blacklist some ports
|
||||||
for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents())
|
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)
|
void Session::handleListenFailedAlert(const lt::listen_failed_alert *p)
|
||||||
{
|
{
|
||||||
QString proto = "INVALID";
|
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)
|
switch (p->socket_type)
|
||||||
{
|
{
|
||||||
case lt::socket_type_t::udp:
|
case lt::socket_type_t::udp:
|
||||||
|
@ -4905,18 +4585,12 @@ void Session::handleListenFailedAlert(const lt::listen_failed_alert *p)
|
||||||
proto = "UTP_SSL";
|
proto = "UTP_SSL";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
lt::error_code ec;
|
lt::error_code ec;
|
||||||
LogMsg(tr("Failed to listen on IP: %1, port: %2/%3. Reason: %4"
|
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")
|
, "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)
|
.arg(p->address.to_string(ec).c_str(), proto, QString::number(p->port)
|
||||||
, QString::fromLocal8Bit(p->error.message().c_str())), Log::CRITICAL);
|
, QString::fromLocal8Bit(p->error.message().c_str())), Log::CRITICAL);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleExternalIPAlert(const lt::external_ip_alert *p)
|
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.;
|
const qreal interval = lt::total_milliseconds(p->timestamp() - m_statsLastTimestamp) / 1000.;
|
||||||
m_statsLastTimestamp = p->timestamp();
|
m_statsLastTimestamp = p->timestamp();
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
const auto &stats = p->values;
|
|
||||||
#else
|
|
||||||
const auto stats = p->counters();
|
const auto stats = p->counters();
|
||||||
#endif
|
|
||||||
|
|
||||||
m_status.hasIncomingConnections = static_cast<bool>(stats[m_metricIndices.net.hasIncomingConnections]);
|
m_status.hasIncomingConnections = static_cast<bool>(stats[m_metricIndices.net.hasIncomingConnections]);
|
||||||
|
|
||||||
|
@ -4998,13 +4668,11 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p)
|
||||||
emit statsUpdated();
|
emit statsUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 10200)
|
|
||||||
void Session::handleAlertsDroppedAlert(const lt::alerts_dropped_alert *p) const
|
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")
|
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);
|
.arg(QString::fromStdString(p->dropped_alerts.to_string()), QString::fromStdString(p->message())), Log::CRITICAL);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void Session::handleStorageMovedAlert(const lt::storage_moved_alert *p)
|
void Session::handleStorageMovedAlert(const lt::storage_moved_alert *p)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
#include <libtorrent/fwd.hpp>
|
#include <libtorrent/fwd.hpp>
|
||||||
#include <libtorrent/torrent_handle.hpp>
|
#include <libtorrent/torrent_handle.hpp>
|
||||||
|
#include <libtorrent/version.hpp>
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
@ -600,9 +601,7 @@ namespace BitTorrent
|
||||||
void handleListenFailedAlert(const lt::listen_failed_alert *p);
|
void handleListenFailedAlert(const lt::listen_failed_alert *p);
|
||||||
void handleExternalIPAlert(const lt::external_ip_alert *p);
|
void handleExternalIPAlert(const lt::external_ip_alert *p);
|
||||||
void handleSessionStatsAlert(const lt::session_stats_alert *p);
|
void handleSessionStatsAlert(const lt::session_stats_alert *p);
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 10200)
|
|
||||||
void handleAlertsDroppedAlert(const lt::alerts_dropped_alert *p) const;
|
void handleAlertsDroppedAlert(const lt::alerts_dropped_alert *p) const;
|
||||||
#endif
|
|
||||||
void handleStorageMovedAlert(const lt::storage_moved_alert *p);
|
void handleStorageMovedAlert(const lt::storage_moved_alert *p);
|
||||||
void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p);
|
void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p);
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 10204)
|
#if (LIBTORRENT_VERSION_NUM >= 10204)
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
#include <libtorrent/create_torrent.hpp>
|
#include <libtorrent/create_torrent.hpp>
|
||||||
#include <libtorrent/file_storage.hpp>
|
#include <libtorrent/file_storage.hpp>
|
||||||
#include <libtorrent/torrent_info.hpp>
|
#include <libtorrent/torrent_info.hpp>
|
||||||
#include <libtorrent/version.hpp>
|
|
||||||
|
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
@ -50,14 +49,6 @@
|
||||||
|
|
||||||
namespace
|
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
|
// do not include files and folders whose
|
||||||
// name starts with a .
|
// name starts with a .
|
||||||
bool fileFilter(const std::string &f)
|
bool fileFilter(const std::string &f)
|
||||||
|
@ -141,7 +132,7 @@ void TorrentCreatorThread::run()
|
||||||
if (isInterruptionRequested()) return;
|
if (isInterruptionRequested()) return;
|
||||||
|
|
||||||
lt::create_torrent newTorrent(fs, m_params.pieceSize, m_params.paddedFileSizeLimit
|
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
|
// Add url seeds
|
||||||
for (QString seed : asConst(m_params.urlSeeds)) {
|
for (QString seed : asConst(m_params.urlSeeds)) {
|
||||||
|
@ -162,9 +153,9 @@ void TorrentCreatorThread::run()
|
||||||
|
|
||||||
// calculate the hash for all pieces
|
// calculate the hash for all pieces
|
||||||
lt::set_piece_hashes(newTorrent, Utils::Fs::toNativePath(parentPath).toStdString()
|
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<LTUnderlyingType<LTPieceIndex>>(n), newTorrent.num_pieces());
|
sendProgressSignal(static_cast<LTUnderlyingType<lt::piece_index_t>>(n), newTorrent.num_pieces());
|
||||||
});
|
});
|
||||||
// Set qBittorrent as creator and add user comment to
|
// Set qBittorrent as creator and add user comment to
|
||||||
// torrent_info structure
|
// 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);
|
lt::add_files(fs, Utils::Fs::toNativePath(inputPath).toStdString(), fileFilter);
|
||||||
|
|
||||||
return lt::create_torrent(fs, pieceSize, paddedFileSizeLimit
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,15 +41,10 @@
|
||||||
#include <libtorrent/alert_types.hpp>
|
#include <libtorrent/alert_types.hpp>
|
||||||
#include <libtorrent/entry.hpp>
|
#include <libtorrent/entry.hpp>
|
||||||
#include <libtorrent/magnet_uri.hpp>
|
#include <libtorrent/magnet_uri.hpp>
|
||||||
|
#include <libtorrent/storage_defs.hpp>
|
||||||
#include <libtorrent/time.hpp>
|
#include <libtorrent/time.hpp>
|
||||||
#include <libtorrent/version.hpp>
|
#include <libtorrent/version.hpp>
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 10200)
|
|
||||||
#include <libtorrent/storage_defs.hpp>
|
|
||||||
#include <libtorrent/write_resume_data.hpp>
|
#include <libtorrent/write_resume_data.hpp>
|
||||||
#else
|
|
||||||
#include <libtorrent/storage.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <QBitArray>
|
#include <QBitArray>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
@ -77,7 +72,6 @@ const QString QB_EXT {QStringLiteral(".!qB")};
|
||||||
|
|
||||||
using namespace BitTorrent;
|
using namespace BitTorrent;
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 10200)
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
namespace aux
|
namespace aux
|
||||||
|
@ -89,30 +83,19 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
std::vector<lt::download_priority_t> toLTDownloadPriorities(const QVector<DownloadPriority> &priorities)
|
||||||
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<LTDownloadPriority> toLTDownloadPriorities(const QVector<DownloadPriority> &priorities)
|
|
||||||
{
|
{
|
||||||
std::vector<LTDownloadPriority> out;
|
std::vector<lt::download_priority_t> out;
|
||||||
out.reserve(priorities.size());
|
out.reserve(priorities.size());
|
||||||
|
|
||||||
std::transform(priorities.cbegin(), priorities.cend()
|
std::transform(priorities.cbegin(), priorities.cend()
|
||||||
, std::back_inserter(out), [](BitTorrent::DownloadPriority priority)
|
, std::back_inserter(out), [](BitTorrent::DownloadPriority priority)
|
||||||
{
|
{
|
||||||
return static_cast<LTDownloadPriority>(
|
return static_cast<lt::download_priority_t>(
|
||||||
static_cast<LTUnderlyingType<LTDownloadPriority>>(priority));
|
static_cast<LTUnderlyingType<lt::download_priority_t>>(priority));
|
||||||
});
|
});
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -371,23 +354,15 @@ QString TorrentHandleImpl::actualStorageLocation() const
|
||||||
|
|
||||||
bool TorrentHandleImpl::isAutoManaged() const
|
bool TorrentHandleImpl::isAutoManaged() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return m_nativeStatus.auto_managed;
|
|
||||||
#else
|
|
||||||
return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::auto_managed);
|
return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::auto_managed);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandleImpl::setAutoManaged(const bool enable)
|
void TorrentHandleImpl::setAutoManaged(const bool enable)
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
m_nativeHandle.auto_managed(enable);
|
|
||||||
#else
|
|
||||||
if (enable)
|
if (enable)
|
||||||
m_nativeHandle.set_flags(lt::torrent_flags::auto_managed);
|
m_nativeHandle.set_flags(lt::torrent_flags::auto_managed);
|
||||||
else
|
else
|
||||||
m_nativeHandle.unset_flags(lt::torrent_flags::auto_managed);
|
m_nativeHandle.unset_flags(lt::torrent_flags::auto_managed);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<TrackerEntry> TorrentHandleImpl::trackers() const
|
QVector<TrackerEntry> TorrentHandleImpl::trackers() const
|
||||||
|
@ -526,22 +501,14 @@ void TorrentHandleImpl::clearPeers()
|
||||||
bool TorrentHandleImpl::connectPeer(const PeerAddress &peerAddress)
|
bool TorrentHandleImpl::connectPeer(const PeerAddress &peerAddress)
|
||||||
{
|
{
|
||||||
lt::error_code ec;
|
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);
|
const lt::address addr = lt::make_address(peerAddress.ip.toString().toStdString(), ec);
|
||||||
#endif
|
|
||||||
if (ec) return false;
|
if (ec) return false;
|
||||||
|
|
||||||
const lt::tcp::endpoint endpoint(addr, peerAddress.port);
|
const lt::tcp::endpoint endpoint(addr, peerAddress.port);
|
||||||
try {
|
try {
|
||||||
m_nativeHandle.connect_peer(endpoint);
|
m_nativeHandle.connect_peer(endpoint);
|
||||||
}
|
}
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
catch (const boost::system::system_error &err) {
|
|
||||||
#else
|
|
||||||
catch (const lt::system_error &err) {
|
catch (const lt::system_error &err) {
|
||||||
#endif
|
|
||||||
LogMsg(tr("Failed to add peer \"%1\" to torrent \"%2\". Reason: %3")
|
LogMsg(tr("Failed to add peer \"%1\" to torrent \"%2\". Reason: %3")
|
||||||
.arg(peerAddress.toString(), name(), QString::fromLocal8Bit(err.what())), Log::WARNING);
|
.arg(peerAddress.toString(), name(), QString::fromLocal8Bit(err.what())), Log::WARNING);
|
||||||
return false;
|
return false;
|
||||||
|
@ -699,16 +666,12 @@ QStringList TorrentHandleImpl::absoluteFilePaths() const
|
||||||
|
|
||||||
QVector<DownloadPriority> TorrentHandleImpl::filePriorities() const
|
QVector<DownloadPriority> TorrentHandleImpl::filePriorities() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
const std::vector<lt::download_priority_t> fp = m_nativeHandle.get_file_priorities();
|
||||||
const std::vector<LTDownloadPriority> fp = m_nativeHandle.file_priorities();
|
|
||||||
#else
|
|
||||||
const std::vector<LTDownloadPriority> fp = m_nativeHandle.get_file_priorities();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QVector<DownloadPriority> ret;
|
QVector<DownloadPriority> 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<DownloadPriority>(static_cast<LTUnderlyingType<LTDownloadPriority>>(priority));
|
return static_cast<DownloadPriority>(static_cast<LTUnderlyingType<lt::download_priority_t>>(priority));
|
||||||
});
|
});
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -720,12 +683,8 @@ TorrentInfo TorrentHandleImpl::info() const
|
||||||
|
|
||||||
bool TorrentHandleImpl::isPaused() const
|
bool TorrentHandleImpl::isPaused() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return (m_nativeStatus.paused && !isAutoManaged());
|
|
||||||
#else
|
|
||||||
return ((m_nativeStatus.flags & lt::torrent_flags::paused)
|
return ((m_nativeStatus.flags & lt::torrent_flags::paused)
|
||||||
&& !isAutoManaged());
|
&& !isAutoManaged());
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentHandleImpl::isResumed() const
|
bool TorrentHandleImpl::isResumed() const
|
||||||
|
@ -735,12 +694,8 @@ bool TorrentHandleImpl::isResumed() const
|
||||||
|
|
||||||
bool TorrentHandleImpl::isQueued() const
|
bool TorrentHandleImpl::isQueued() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return (m_nativeStatus.paused && isAutoManaged());
|
|
||||||
#else
|
|
||||||
return ((m_nativeStatus.flags & lt::torrent_flags::paused)
|
return ((m_nativeStatus.flags & lt::torrent_flags::paused)
|
||||||
&& isAutoManaged());
|
&& isAutoManaged());
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentHandleImpl::isChecking() const
|
bool TorrentHandleImpl::isChecking() const
|
||||||
|
@ -818,21 +773,13 @@ bool TorrentHandleImpl::isSeed() const
|
||||||
|
|
||||||
bool TorrentHandleImpl::isForced() const
|
bool TorrentHandleImpl::isForced() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return (!m_nativeStatus.paused && !isAutoManaged());
|
|
||||||
#else
|
|
||||||
return (!(m_nativeStatus.flags & lt::torrent_flags::paused)
|
return (!(m_nativeStatus.flags & lt::torrent_flags::paused)
|
||||||
&& !isAutoManaged());
|
&& !isAutoManaged());
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentHandleImpl::isSequentialDownload() const
|
bool TorrentHandleImpl::isSequentialDownload() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return m_nativeStatus.sequential_download;
|
|
||||||
#else
|
|
||||||
return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::sequential_download);
|
return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::sequential_download);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentHandleImpl::hasFirstLastPiecePriority() const
|
bool TorrentHandleImpl::hasFirstLastPiecePriority() const
|
||||||
|
@ -840,19 +787,15 @@ bool TorrentHandleImpl::hasFirstLastPiecePriority() const
|
||||||
if (!hasMetadata())
|
if (!hasMetadata())
|
||||||
return m_needsToSetFirstLastPiecePriority;
|
return m_needsToSetFirstLastPiecePriority;
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
const std::vector<lt::download_priority_t> filePriorities = nativeHandle().get_file_priorities();
|
||||||
const std::vector<LTDownloadPriority> filePriorities = nativeHandle().file_priorities();
|
|
||||||
#else
|
|
||||||
const std::vector<LTDownloadPriority> filePriorities = nativeHandle().get_file_priorities();
|
|
||||||
#endif
|
|
||||||
for (int i = 0; i < static_cast<int>(filePriorities.size()); ++i) {
|
for (int i = 0; i < static_cast<int>(filePriorities.size()); ++i) {
|
||||||
if (filePriorities[i] <= LTDownloadPriority {0})
|
if (filePriorities[i] <= lt::download_priority_t {0})
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const TorrentInfo::PieceRange extremities = info().filePieces(i);
|
const TorrentInfo::PieceRange extremities = info().filePieces(i);
|
||||||
const LTDownloadPriority firstPiecePrio = nativeHandle().piece_priority(LTPieceIndex {extremities.first()});
|
const lt::download_priority_t firstPiecePrio = nativeHandle().piece_priority(lt::piece_index_t {extremities.first()});
|
||||||
const LTDownloadPriority lastPiecePrio = nativeHandle().piece_priority(LTPieceIndex {extremities.last()});
|
const lt::download_priority_t lastPiecePrio = nativeHandle().piece_priority(lt::piece_index_t {extremities.last()});
|
||||||
return ((firstPiecePrio == LTDownloadPriority {7}) && (lastPiecePrio == LTDownloadPriority {7}));
|
return ((firstPiecePrio == lt::download_priority_t {7}) && (lastPiecePrio == lt::download_priority_t {7}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -931,20 +874,16 @@ bool TorrentHandleImpl::hasError() const
|
||||||
|
|
||||||
bool TorrentHandleImpl::hasFilteredPieces() const
|
bool TorrentHandleImpl::hasFilteredPieces() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
const std::vector<lt::download_priority_t> pp = m_nativeHandle.get_piece_priorities();
|
||||||
const std::vector<LTDownloadPriority> pp = m_nativeHandle.piece_priorities();
|
return std::any_of(pp.cbegin(), pp.cend(), [](const lt::download_priority_t priority)
|
||||||
#else
|
|
||||||
const std::vector<LTDownloadPriority> pp = m_nativeHandle.get_piece_priorities();
|
|
||||||
#endif
|
|
||||||
return std::any_of(pp.cbegin(), pp.cend(), [](const LTDownloadPriority priority)
|
|
||||||
{
|
{
|
||||||
return (priority == LTDownloadPriority {0});
|
return (priority == lt::download_priority_t {0});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
int TorrentHandleImpl::queuePosition() const
|
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<int>(m_nativeStatus.queue_position) + 1;
|
return static_cast<int>(m_nativeStatus.queue_position) + 1;
|
||||||
}
|
}
|
||||||
|
@ -966,29 +905,17 @@ qlonglong TorrentHandleImpl::totalUpload() const
|
||||||
|
|
||||||
qlonglong TorrentHandleImpl::activeTime() const
|
qlonglong TorrentHandleImpl::activeTime() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return m_nativeStatus.active_time;
|
|
||||||
#else
|
|
||||||
return lt::total_seconds(m_nativeStatus.active_duration);
|
return lt::total_seconds(m_nativeStatus.active_duration);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qlonglong TorrentHandleImpl::finishedTime() const
|
qlonglong TorrentHandleImpl::finishedTime() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return m_nativeStatus.finished_time;
|
|
||||||
#else
|
|
||||||
return lt::total_seconds(m_nativeStatus.finished_duration);
|
return lt::total_seconds(m_nativeStatus.finished_duration);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qlonglong TorrentHandleImpl::seedingTime() const
|
qlonglong TorrentHandleImpl::seedingTime() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return m_nativeStatus.seeding_time;
|
|
||||||
#else
|
|
||||||
return lt::total_seconds(m_nativeStatus.seeding_duration);
|
return lt::total_seconds(m_nativeStatus.seeding_duration);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qlonglong TorrentHandleImpl::eta() const
|
qlonglong TorrentHandleImpl::eta() const
|
||||||
|
@ -1031,11 +958,7 @@ qlonglong TorrentHandleImpl::eta() const
|
||||||
|
|
||||||
QVector<qreal> TorrentHandleImpl::filesProgress() const
|
QVector<qreal> TorrentHandleImpl::filesProgress() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
std::vector<boost::int64_t> fp;
|
|
||||||
#else
|
|
||||||
std::vector<int64_t> fp;
|
std::vector<int64_t> fp;
|
||||||
#endif
|
|
||||||
m_nativeHandle.file_progress(fp, lt::torrent_handle::piece_granularity);
|
m_nativeHandle.file_progress(fp, lt::torrent_handle::piece_granularity);
|
||||||
|
|
||||||
const int count = static_cast<int>(fp.size());
|
const int count = static_cast<int>(fp.size());
|
||||||
|
@ -1113,24 +1036,16 @@ QDateTime TorrentHandleImpl::completedTime() const
|
||||||
|
|
||||||
qlonglong TorrentHandleImpl::timeSinceUpload() 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)
|
if (m_nativeStatus.last_upload.time_since_epoch().count() == 0)
|
||||||
return -1;
|
return -1;
|
||||||
return lt::total_seconds(lt::clock_type::now() - m_nativeStatus.last_upload);
|
return lt::total_seconds(lt::clock_type::now() - m_nativeStatus.last_upload);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qlonglong TorrentHandleImpl::timeSinceDownload() const
|
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)
|
if (m_nativeStatus.last_download.time_since_epoch().count() == 0)
|
||||||
return -1;
|
return -1;
|
||||||
return lt::total_seconds(lt::clock_type::now() - m_nativeStatus.last_download);
|
return lt::total_seconds(lt::clock_type::now() - m_nativeStatus.last_download);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qlonglong TorrentHandleImpl::timeSinceActivity() const
|
qlonglong TorrentHandleImpl::timeSinceActivity() const
|
||||||
|
@ -1154,11 +1069,7 @@ int TorrentHandleImpl::uploadLimit() const
|
||||||
|
|
||||||
bool TorrentHandleImpl::superSeeding() const
|
bool TorrentHandleImpl::superSeeding() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return m_nativeStatus.super_seeding;
|
|
||||||
#else
|
|
||||||
return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::super_seeding);
|
return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::super_seeding);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<PeerInfo> TorrentHandleImpl::peers() const
|
QVector<PeerInfo> TorrentHandleImpl::peers() const
|
||||||
|
@ -1177,7 +1088,7 @@ QBitArray TorrentHandleImpl::pieces() const
|
||||||
{
|
{
|
||||||
QBitArray result(m_nativeStatus.pieces.size());
|
QBitArray result(m_nativeStatus.pieces.size());
|
||||||
for (int i = 0; i < result.size(); ++i) {
|
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);
|
result.setBit(i, true);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -1191,11 +1102,7 @@ QBitArray TorrentHandleImpl::downloadingPieces() const
|
||||||
m_nativeHandle.get_download_queue(queue);
|
m_nativeHandle.get_download_queue(queue);
|
||||||
|
|
||||||
for (const lt::partial_piece_info &info : queue)
|
for (const lt::partial_piece_info &info : queue)
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
result.setBit(static_cast<LTUnderlyingType<lt::piece_index_t>>(info.piece_index));
|
||||||
result.setBit(info.piece_index);
|
|
||||||
#else
|
|
||||||
result.setBit(static_cast<LTUnderlyingType<LTPieceIndex>>(info.piece_index));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1231,19 +1138,11 @@ int TorrentHandleImpl::maxSeedingTime() const
|
||||||
|
|
||||||
qreal TorrentHandleImpl::realRatio() 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;
|
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
|
// 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))
|
const int64_t download = (m_nativeStatus.all_time_download < (m_nativeStatus.total_done * 0.01))
|
||||||
? m_nativeStatus.total_done
|
? m_nativeStatus.total_done
|
||||||
: m_nativeStatus.all_time_download;
|
: m_nativeStatus.all_time_download;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (download == 0)
|
if (download == 0)
|
||||||
return (upload == 0) ? 0 : MAX_RATIO;
|
return (upload == 0) ? 0 : MAX_RATIO;
|
||||||
|
@ -1365,10 +1264,6 @@ void TorrentHandleImpl::forceRecheck()
|
||||||
|
|
||||||
void TorrentHandleImpl::setSequentialDownload(const bool enable)
|
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) {
|
if (enable) {
|
||||||
m_nativeHandle.set_flags(lt::torrent_flags::sequential_download);
|
m_nativeHandle.set_flags(lt::torrent_flags::sequential_download);
|
||||||
m_nativeStatus.flags |= lt::torrent_flags::sequential_download; // prevent return cached value
|
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_nativeHandle.unset_flags(lt::torrent_flags::sequential_download);
|
||||||
m_nativeStatus.flags &= ~lt::torrent_flags::sequential_download; // prevent return cached value
|
m_nativeStatus.flags &= ~lt::torrent_flags::sequential_download; // prevent return cached value
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
saveResumeData();
|
saveResumeData();
|
||||||
}
|
}
|
||||||
|
@ -1396,24 +1290,19 @@ void TorrentHandleImpl::setFirstLastPiecePriorityImpl(const bool enabled, const
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
const std::vector<lt::download_priority_t> filePriorities = !updatedFilePrio.isEmpty() ? toLTDownloadPriorities(updatedFilePrio)
|
||||||
const std::vector<LTDownloadPriority> filePriorities = !updatedFilePrio.isEmpty() ? toLTDownloadPriorities(updatedFilePrio)
|
|
||||||
: nativeHandle().file_priorities();
|
|
||||||
std::vector<LTDownloadPriority> piecePriorities = nativeHandle().piece_priorities();
|
|
||||||
#else
|
|
||||||
const std::vector<LTDownloadPriority> filePriorities = !updatedFilePrio.isEmpty() ? toLTDownloadPriorities(updatedFilePrio)
|
|
||||||
: nativeHandle().get_file_priorities();
|
: nativeHandle().get_file_priorities();
|
||||||
std::vector<LTDownloadPriority> piecePriorities = nativeHandle().get_piece_priorities();
|
std::vector<lt::download_priority_t> piecePriorities = nativeHandle().get_piece_priorities();
|
||||||
#endif
|
|
||||||
// Updating file priorities is an async operation in libtorrent, when we just updated it and immediately query it
|
// 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.
|
// we might get the old/wrong values, so we rely on `updatedFilePrio` in this case.
|
||||||
for (int index = 0; index < static_cast<int>(filePriorities.size()); ++index) {
|
for (int index = 0; index < static_cast<int>(filePriorities.size()); ++index) {
|
||||||
const LTDownloadPriority filePrio = filePriorities[index];
|
const lt::download_priority_t filePrio = filePriorities[index];
|
||||||
if (filePrio <= LTDownloadPriority {0})
|
if (filePrio <= lt::download_priority_t {0})
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Determine the priority to set
|
// 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);
|
const TorrentInfo::PieceRange extremities = info().filePieces(index);
|
||||||
|
|
||||||
// worst case: AVI index = 1% of total file size (at the end of the file)
|
// 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)
|
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_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)
|
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)
|
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<lt::entry>(useDummyResumeData
|
|
||||||
? lt::entry {}
|
|
||||||
: *(p->resume_data));
|
|
||||||
#else
|
|
||||||
const bool useDummyResumeData = !p;
|
const bool useDummyResumeData = !p;
|
||||||
auto resumeDataPtr = std::make_shared<lt::entry>(useDummyResumeData
|
auto resumeDataPtr = std::make_shared<lt::entry>(useDummyResumeData
|
||||||
? lt::entry {}
|
? lt::entry {}
|
||||||
: lt::write_resume_data(p->params));
|
: lt::write_resume_data(p->params));
|
||||||
#endif
|
|
||||||
lt::entry &resumeData = *resumeDataPtr;
|
lt::entry &resumeData = *resumeDataPtr;
|
||||||
|
|
||||||
updateStatus();
|
updateStatus();
|
||||||
|
@ -1653,11 +1535,7 @@ void TorrentHandleImpl::handleSaveResumeDataAlert(const lt::save_resume_data_ale
|
||||||
resumeData["qBt-queuePosition"] = (static_cast<int>(nativeHandle().queue_position()) + 1); // qBt starts queue at 1
|
resumeData["qBt-queuePosition"] = (static_cast<int>(nativeHandle().queue_position()) + 1); // qBt starts queue at 1
|
||||||
resumeData["qBt-hasRootFolder"] = m_hasRootFolder;
|
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) {
|
if (m_nativeStatus.flags & lt::torrent_flags::stop_when_ready) {
|
||||||
#endif
|
|
||||||
// We need to redefine these values when torrent starting/rechecking
|
// We need to redefine these values when torrent starting/rechecking
|
||||||
// in "paused" state since native values can be logically wrong
|
// in "paused" state since native values can be logically wrong
|
||||||
// (torrent can be not paused and auto_managed when it is checking).
|
// (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)
|
void TorrentHandleImpl::handleFileRenameFailedAlert(const lt::file_rename_failed_alert *p)
|
||||||
{
|
{
|
||||||
LogMsg(tr("File rename failed. Torrent: \"%1\", file: \"%2\", reason: \"%3\"")
|
LogMsg(tr("File rename failed. Torrent: \"%1\", file: \"%2\", reason: \"%3\"")
|
||||||
.arg(name(), filePath(static_cast<LTUnderlyingType<LTFileIndex>>(p->index))
|
.arg(name(), filePath(static_cast<LTUnderlyingType<lt::file_index_t>>(p->index))
|
||||||
, QString::fromLocal8Bit(p->error.message().c_str())), Log::WARNING);
|
, QString::fromLocal8Bit(p->error.message().c_str())), Log::WARNING);
|
||||||
|
|
||||||
m_oldPath[p->index].removeFirst();
|
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()));
|
qDebug("A file completed download in torrent \"%s\"", qUtf8Printable(name()));
|
||||||
if (m_session->isAppendExtensionEnabled()) {
|
if (m_session->isAppendExtensionEnabled()) {
|
||||||
QString name = filePath(static_cast<LTUnderlyingType<LTFileIndex>>(p->index));
|
QString name = filePath(static_cast<LTUnderlyingType<lt::file_index_t>>(p->index));
|
||||||
if (name.endsWith(QB_EXT)) {
|
if (name.endsWith(QB_EXT)) {
|
||||||
const QString oldName = name;
|
const QString oldName = name;
|
||||||
name.chop(QB_EXT.size());
|
name.chop(QB_EXT.size());
|
||||||
qDebug("Renaming %s to %s", qUtf8Printable(oldName), qUtf8Printable(name));
|
qDebug("Renaming %s to %s", qUtf8Printable(oldName), qUtf8Printable(name));
|
||||||
renameFile(static_cast<LTUnderlyingType<LTFileIndex>>(p->index), name);
|
renameFile(static_cast<LTUnderlyingType<lt::file_index_t>>(p->index), name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2027,14 +1905,10 @@ void TorrentHandleImpl::setDownloadLimit(const int limit)
|
||||||
|
|
||||||
void TorrentHandleImpl::setSuperSeeding(const bool enable)
|
void TorrentHandleImpl::setSuperSeeding(const bool enable)
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
m_nativeHandle.super_seeding(enable);
|
|
||||||
#else
|
|
||||||
if (enable)
|
if (enable)
|
||||||
m_nativeHandle.set_flags(lt::torrent_flags::super_seeding);
|
m_nativeHandle.set_flags(lt::torrent_flags::super_seeding);
|
||||||
else
|
else
|
||||||
m_nativeHandle.unset_flags(lt::torrent_flags::super_seeding);
|
m_nativeHandle.unset_flags(lt::torrent_flags::super_seeding);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandleImpl::flushCache() const
|
void TorrentHandleImpl::flushCache() const
|
||||||
|
|
|
@ -259,12 +259,6 @@ namespace BitTorrent
|
||||||
private:
|
private:
|
||||||
typedef std::function<void ()> EventTrigger;
|
typedef std::function<void ()> EventTrigger;
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
using LTFileIndex = int;
|
|
||||||
#else
|
|
||||||
using LTFileIndex = lt::file_index_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
void updateStatus(const lt::torrent_status &nativeStatus);
|
void updateStatus(const lt::torrent_status &nativeStatus);
|
||||||
void updateState();
|
void updateState();
|
||||||
|
@ -315,7 +309,7 @@ namespace BitTorrent
|
||||||
|
|
||||||
// Until libtorrent provide an "old_name" field in `file_renamed_alert`
|
// Until libtorrent provide an "old_name" field in `file_renamed_alert`
|
||||||
// we will rely on this workaround to remove empty leftover folders
|
// we will rely on this workaround to remove empty leftover folders
|
||||||
QHash<LTFileIndex, QVector<QString>> m_oldPath;
|
QHash<lt::file_index_t, QVector<QString>> m_oldPath;
|
||||||
|
|
||||||
QHash<QString, TrackerInfo> m_trackerInfos;
|
QHash<QString, TrackerInfo> m_trackerInfos;
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,6 @@
|
||||||
|
|
||||||
#include "torrentinfo.h"
|
#include "torrentinfo.h"
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
#include <boost/optional.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <libtorrent/bencode.hpp>
|
#include <libtorrent/bencode.hpp>
|
||||||
#include <libtorrent/create_torrent.hpp>
|
#include <libtorrent/create_torrent.hpp>
|
||||||
#include <libtorrent/error_code.hpp>
|
#include <libtorrent/error_code.hpp>
|
||||||
|
@ -52,26 +48,11 @@
|
||||||
#include "infohash.h"
|
#include "infohash.h"
|
||||||
#include "trackerentry.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;
|
using namespace BitTorrent;
|
||||||
|
|
||||||
TorrentInfo::TorrentInfo(NativeConstPtr nativeInfo)
|
TorrentInfo::TorrentInfo(std::shared_ptr<const lt::torrent_info> nativeInfo)
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
m_nativeInfo = boost::const_pointer_cast<lt::torrent_info>(nativeInfo);
|
|
||||||
#else
|
|
||||||
m_nativeInfo = std::const_pointer_cast<lt::torrent_info>(nativeInfo);
|
m_nativeInfo = std::const_pointer_cast<lt::torrent_info>(nativeInfo);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentInfo::TorrentInfo(const TorrentInfo &other)
|
TorrentInfo::TorrentInfo(const TorrentInfo &other)
|
||||||
|
@ -93,21 +74,15 @@ TorrentInfo TorrentInfo::load(const QByteArray &data, QString *error) noexcept
|
||||||
const int tokenLimit = 10000000;
|
const int tokenLimit = 10000000;
|
||||||
|
|
||||||
lt::error_code ec;
|
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
|
const lt::bdecode_node node = lt::bdecode(data, ec
|
||||||
, nullptr, depthLimit, tokenLimit);
|
, nullptr, depthLimit, tokenLimit);
|
||||||
#endif
|
|
||||||
if (ec) {
|
if (ec) {
|
||||||
if (error)
|
if (error)
|
||||||
*error = QString::fromStdString(ec.message());
|
*error = QString::fromStdString(ec.message());
|
||||||
return TorrentInfo();
|
return TorrentInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentInfo info {NativePtr(new lt::torrent_info(node, ec))};
|
TorrentInfo info {std::shared_ptr<lt::torrent_info>(new lt::torrent_info(node, ec))};
|
||||||
if (ec) {
|
if (ec) {
|
||||||
if (error)
|
if (error)
|
||||||
*error = QString::fromStdString(ec.message());
|
*error = QString::fromStdString(ec.message());
|
||||||
|
@ -160,11 +135,7 @@ void TorrentInfo::saveToFile(const QString &path) const
|
||||||
if (!isValid())
|
if (!isValid())
|
||||||
throw RuntimeError {tr("Invalid metadata.")};
|
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()));
|
const lt::create_torrent torrentCreator = lt::create_torrent(*(nativeInfo()));
|
||||||
#endif
|
|
||||||
const lt::entry torrentEntry = torrentCreator.generate();
|
const lt::entry torrentEntry = torrentCreator.generate();
|
||||||
|
|
||||||
QFile torrentFile {path};
|
QFile torrentFile {path};
|
||||||
|
@ -197,13 +168,8 @@ QDateTime TorrentInfo::creationDate() const
|
||||||
{
|
{
|
||||||
if (!isValid()) return {};
|
if (!isValid()) return {};
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
const boost::optional<time_t> date = m_nativeInfo->creation_date();
|
|
||||||
return (date ? QDateTime::fromSecsSinceEpoch(*date) : QDateTime());
|
|
||||||
#else
|
|
||||||
const std::time_t date = m_nativeInfo->creation_date();
|
const std::time_t date = m_nativeInfo->creation_date();
|
||||||
return ((date != 0) ? QDateTime::fromSecsSinceEpoch(date) : QDateTime());
|
return ((date != 0) ? QDateTime::fromSecsSinceEpoch(date) : QDateTime());
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TorrentInfo::creator() const
|
QString TorrentInfo::creator() const
|
||||||
|
@ -245,7 +211,7 @@ int TorrentInfo::pieceLength() const
|
||||||
int TorrentInfo::pieceLength(const int index) const
|
int TorrentInfo::pieceLength(const int index) const
|
||||||
{
|
{
|
||||||
if (!isValid()) return -1;
|
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
|
int TorrentInfo::piecesCount() const
|
||||||
|
@ -258,7 +224,7 @@ QString TorrentInfo::filePath(const int index) const
|
||||||
{
|
{
|
||||||
if (!isValid()) return {};
|
if (!isValid()) return {};
|
||||||
return Utils::Fs::toUniformPath(
|
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
|
QStringList TorrentInfo::filePaths() const
|
||||||
|
@ -279,19 +245,19 @@ QString TorrentInfo::origFilePath(const int index) const
|
||||||
{
|
{
|
||||||
if (!isValid()) return {};
|
if (!isValid()) return {};
|
||||||
return Utils::Fs::toUniformPath(
|
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
|
qlonglong TorrentInfo::fileSize(const int index) const
|
||||||
{
|
{
|
||||||
if (!isValid()) return -1;
|
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
|
qlonglong TorrentInfo::fileOffset(const int index) const
|
||||||
{
|
{
|
||||||
if (!isValid()) return -1;
|
if (!isValid()) return -1;
|
||||||
return m_nativeInfo->files().file_offset(LTFileIndex {index});
|
return m_nativeInfo->files().file_offset(lt::file_index_t {index});
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<TrackerEntry> TorrentInfo::trackers() const
|
QVector<TrackerEntry> TorrentInfo::trackers() const
|
||||||
|
@ -350,8 +316,8 @@ QVector<int> TorrentInfo::fileIndicesForPiece(const int pieceIndex) const
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const std::vector<lt::file_slice> files(
|
const std::vector<lt::file_slice> files(
|
||||||
nativeInfo()->map_block(LTPieceIndex {pieceIndex}, 0
|
nativeInfo()->map_block(lt::piece_index_t {pieceIndex}, 0
|
||||||
, nativeInfo()->piece_size(LTPieceIndex {pieceIndex})));
|
, nativeInfo()->piece_size(lt::piece_index_t {pieceIndex})));
|
||||||
QVector<int> res;
|
QVector<int> res;
|
||||||
res.reserve(int(files.size()));
|
res.reserve(int(files.size()));
|
||||||
std::transform(files.begin(), files.end(), std::back_inserter(res),
|
std::transform(files.begin(), files.end(), std::back_inserter(res),
|
||||||
|
@ -370,7 +336,7 @@ QVector<QByteArray> TorrentInfo::pieceHashes() const
|
||||||
hashes.reserve(count);
|
hashes.reserve(count);
|
||||||
|
|
||||||
for (int i = 0; i < count; ++i)
|
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;
|
return hashes;
|
||||||
}
|
}
|
||||||
|
@ -399,8 +365,8 @@ TorrentInfo::PieceRange TorrentInfo::filePieces(const int fileIndex) const
|
||||||
}
|
}
|
||||||
|
|
||||||
const lt::file_storage &files = nativeInfo()->files();
|
const lt::file_storage &files = nativeInfo()->files();
|
||||||
const auto fileSize = files.file_size(LTFileIndex {fileIndex});
|
const auto fileSize = files.file_size(lt::file_index_t {fileIndex});
|
||||||
const auto fileOffset = files.file_offset(LTFileIndex {fileIndex});
|
const auto fileOffset = files.file_offset(lt::file_index_t {fileIndex});
|
||||||
|
|
||||||
const int beginIdx = (fileOffset / pieceLength());
|
const int beginIdx = (fileOffset / pieceLength());
|
||||||
const int endIdx = ((fileOffset + fileSize - 1) / 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)
|
void TorrentInfo::renameFile(const int index, const QString &newPath)
|
||||||
{
|
{
|
||||||
if (!isValid()) return;
|
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
|
int BitTorrent::TorrentInfo::fileIndex(const QString &fileName) const
|
||||||
|
@ -464,14 +430,14 @@ void TorrentInfo::stripRootFolder()
|
||||||
if (files.name() != newName) {
|
if (files.name() != newName) {
|
||||||
files.set_name(newName);
|
files.set_name(newName);
|
||||||
for (int i = 0; i < files.num_files(); ++i)
|
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("");
|
files.set_name("");
|
||||||
m_nativeInfo->remap_files(files);
|
m_nativeInfo->remap_files(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentInfo::NativePtr TorrentInfo::nativeInfo() const
|
std::shared_ptr<lt::torrent_info> TorrentInfo::nativeInfo() const
|
||||||
{
|
{
|
||||||
return m_nativeInfo;
|
return m_nativeInfo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#define BITTORRENT_TORRENTINFO_H
|
#define BITTORRENT_TORRENTINFO_H
|
||||||
|
|
||||||
#include <libtorrent/torrent_info.hpp>
|
#include <libtorrent/torrent_info.hpp>
|
||||||
#include <libtorrent/version.hpp>
|
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
@ -53,15 +52,7 @@ namespace BitTorrent
|
||||||
Q_DECLARE_TR_FUNCTIONS(TorrentInfo)
|
Q_DECLARE_TR_FUNCTIONS(TorrentInfo)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
explicit TorrentInfo(std::shared_ptr<const lt::torrent_info> nativeInfo = {});
|
||||||
using NativeConstPtr = boost::shared_ptr<const lt::torrent_info>;
|
|
||||||
using NativePtr = boost::shared_ptr<lt::torrent_info>;
|
|
||||||
#else
|
|
||||||
using NativeConstPtr = std::shared_ptr<const lt::torrent_info>;
|
|
||||||
using NativePtr = std::shared_ptr<lt::torrent_info>;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
explicit TorrentInfo(NativeConstPtr nativeInfo = {});
|
|
||||||
TorrentInfo(const TorrentInfo &other);
|
TorrentInfo(const TorrentInfo &other);
|
||||||
|
|
||||||
static TorrentInfo load(const QByteArray &data, QString *error = nullptr) noexcept;
|
static TorrentInfo load(const QByteArray &data, QString *error = nullptr) noexcept;
|
||||||
|
@ -107,12 +98,12 @@ namespace BitTorrent
|
||||||
bool hasRootFolder() const;
|
bool hasRootFolder() const;
|
||||||
void stripRootFolder();
|
void stripRootFolder();
|
||||||
|
|
||||||
NativePtr nativeInfo() const;
|
std::shared_ptr<lt::torrent_info> nativeInfo() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// returns file index or -1 if fileName is not found
|
// returns file index or -1 if fileName is not found
|
||||||
int fileIndex(const QString &fileName) const;
|
int fileIndex(const QString &fileName) const;
|
||||||
NativePtr m_nativeInfo;
|
std::shared_ptr<lt::torrent_info> m_nativeInfo;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,6 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <libtorrent/version.hpp>
|
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
@ -59,13 +57,6 @@ int TrackerEntry::tier() const
|
||||||
|
|
||||||
TrackerEntry::Status TrackerEntry::status() 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 auto &endpoints = nativeEntry().endpoints;
|
||||||
|
|
||||||
const bool allFailed = !endpoints.empty() && std::all_of(endpoints.begin(), endpoints.end()
|
const bool allFailed = !endpoints.empty() && std::all_of(endpoints.begin(), endpoints.end()
|
||||||
|
@ -83,7 +74,6 @@ TrackerEntry::Status TrackerEntry::status() const
|
||||||
});
|
});
|
||||||
if (isUpdating)
|
if (isUpdating)
|
||||||
return Updating;
|
return Updating;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!nativeEntry().verified)
|
if (!nativeEntry().verified)
|
||||||
return NotContacted;
|
return NotContacted;
|
||||||
|
@ -98,38 +88,26 @@ void TrackerEntry::setTier(const int value)
|
||||||
|
|
||||||
int TrackerEntry::numSeeds() const
|
int TrackerEntry::numSeeds() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return nativeEntry().scrape_complete;
|
|
||||||
#else
|
|
||||||
int value = -1;
|
int value = -1;
|
||||||
for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints)
|
for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints)
|
||||||
value = std::max(value, endpoint.scrape_complete);
|
value = std::max(value, endpoint.scrape_complete);
|
||||||
return value;
|
return value;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int TrackerEntry::numLeeches() const
|
int TrackerEntry::numLeeches() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return nativeEntry().scrape_incomplete;
|
|
||||||
#else
|
|
||||||
int value = -1;
|
int value = -1;
|
||||||
for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints)
|
for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints)
|
||||||
value = std::max(value, endpoint.scrape_incomplete);
|
value = std::max(value, endpoint.scrape_incomplete);
|
||||||
return value;
|
return value;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int TrackerEntry::numDownloaded() const
|
int TrackerEntry::numDownloaded() const
|
||||||
{
|
{
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
|
||||||
return nativeEntry().scrape_downloaded;
|
|
||||||
#else
|
|
||||||
int value = -1;
|
int value = -1;
|
||||||
for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints)
|
for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints)
|
||||||
value = std::max(value, endpoint.scrape_downloaded);
|
value = std::max(value, endpoint.scrape_downloaded);
|
||||||
return value;
|
return value;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const lt::announce_entry &TrackerEntry::nativeEntry() const
|
const lt::announce_entry &TrackerEntry::nativeEntry() const
|
||||||
|
|
|
@ -455,11 +455,7 @@ QString Utils::Misc::boostVersionString()
|
||||||
QString Utils::Misc::libtorrentVersionString()
|
QString Utils::Misc::libtorrentVersionString()
|
||||||
{
|
{
|
||||||
// static initialization for usage in signal handler
|
// 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())};
|
static const auto version {QString::fromLatin1(lt::version())};
|
||||||
#endif
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue