Skip to content

Commit

Permalink
Merge pull request qbittorrent#13068 from Chocobo1/libt
Browse files Browse the repository at this point in the history
Bump requirement to libtorrent 1.2
  • Loading branch information
Chocobo1 authored and IceCodeNew committed Aug 28, 2020
1 parent 8a0a999 commit 5fd4671
Show file tree
Hide file tree
Showing 27 changed files with 178 additions and 727 deletions.
91 changes: 83 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@ os:

dist: bionic

env:
matrix:
- libt_branch=RC_1_2 gui=true 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=false build_system=cmake
global:
- secure: "OI9CUjj4lTb0HwwIZU5PbECU3hLlAL6KC8KsbwohG8/O3j5fLcnmDsK4Ad9us5cC39sS11Jcd1kDP2qRcCuST/glVNhLkcjKkiQerOfd5nQ/qL4JYfz/1mfP5mdpz9jHKzpLUIG+TXkbSTjP6VVmsb5KPT+3pKEdRFZB+Pu9+J8="
- coverity_branch: coverity_scan

matrix:
allow_failures:
- env: libt_branch=RC_1_2 gui=true build_system=cmake
- env: libt_branch=RC_1_2 gui=false build_system=cmake

branches:
except:
- search_encoding_windows
- v2_9_x

notifications:
email:
on_success: change
on_failure: change

cache:
ccache: true
directories:
- $HOME/travis/deb
- $HOME/travis/brew

addons:
apt:
sources:
Expand Down Expand Up @@ -60,14 +91,58 @@ before_install:
- echo $cmake_conf

install:
- curl -sSkL --compressed https://raw.githubusercontent.com/engnr/qt-downloader/master/qt-downloader | python3 - linux desktop latest gcc_64 -o "${HOME}/Qt" -m qtbase qttools qtsvg icu
- export QT_BASE_DIR="$(ls -rd "${HOME}/Qt"/*/gcc_64 | head -1)"
- export QTDIR=$QT_BASE_DIR
- export PATH=$QT_BASE_DIR/bin:$PATH
- export LD_LIBRARY_PATH=$QT_BASE_DIR/lib:$LD_LIBRARY_PATH
- export PKG_CONFIG_PATH=$QT_BASE_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
- export QT_QMAKE="${QT_BASE_DIR}/bin"
- sed -i.bak 's/Enterprise/OpenSource/g;s/licheck.*//g' "${QT_BASE_DIR}/mkspecs/qconfig.pri"
- |
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
# dependencies
PATH="/usr/local/opt/ccache/libexec:$PATH"
brew update > /dev/null
brew upgrade cmake
brew install ccache colormake boost openssl qt zlib
brew link --force qt zlib
if [ "$build_system" = "cmake" ]; then
sudo ln -s /usr/local/opt/qt/mkspecs /usr/local/mkspecs
sudo ln -s /usr/local/opt/qt/plugins /usr/local/plugins
fi
fi
- |
if [ "$TRAVIS_BRANCH" != "$coverity_branch" ]; then
export use_ccache=true
ccache -M 512M
ccache -V && ccache --show-stats && ccache --zero-stats
fi
- |
if [ "$libt_branch" = "RC_1_2" ] && [ "$TRAVIS_OS_NAME" = "linux" ]; then
# Will install latest 1.2.x daily build from the PPA
sudo apt-get -y install libtorrent-rasterbar-dev
fi
- |
if [ "$libt_branch" = "RC_1_2" ] && [ "$TRAVIS_OS_NAME" = "osx" ]; then
wget https://builds.shiki.hu/travis/brew/version
if ! cmp --quiet "version" "$HOME/travis/brew/version" ; then
echo "Cached files are different from server. Downloading new ones."
# First delete old files
rm -r "$HOME/travis/brew"
mkdir "$HOME/travis/brew"
cp "version" $HOME/travis/brew
cd "$HOME/travis/brew"
wget https://builds.shiki.hu/travis/brew/libtorrent-rasterbar.rb
wget https://builds.shiki.hu/travis/brew/f01f8d840b6eaf05df8df811815128ae6e7227977b1cba4825f0a1fb73a4d9f0--libtorrent-rasterbar-1.2.6.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/f01f8d840b6eaf05df8df811815128ae6e7227977b1cba4825f0a1fb73a4d9f0--libtorrent-rasterbar-1.2.6.high_sierra.bottle.tar.gz" "$(brew --cache)/downloads"
brew uninstall libtorrent-rasterbar
brew install "$HOME/travis/brew/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.2.6.high_sierra.bottle.tar.gz
fi
script:
- mkdir -p /tmp/libtorrent-rasterbar
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ include(FeatureSummary)
set(requiredBoostVersion 1.40)
set(requiredQtVersion 5.9.0)
set(requiredOpensslVersion 1.0)
set(requiredLibtorrentVersion 1.1.10)
set(requiredLibtorrentVersion 1.2)

if (WIN32)
include(winconf)
Expand Down
2 changes: 1 addition & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ qBittorrent - A BitTorrent client in C++ / Qt

- Boost >= 1.40

- libtorrent-rasterbar >= 1.1.10 (by Arvid Norberg)
- libtorrent-rasterbar >= 1.2 (by Arvid Norberg)
* https://www.libtorrent.org/
* Be careful: another library (the one used by rTorrent) uses a similar name

Expand Down
18 changes: 9 additions & 9 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -5292,12 +5292,12 @@ if test -n "$libtorrent_CFLAGS"; then
pkg_cv_libtorrent_CFLAGS="$libtorrent_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libtorrent-rasterbar >= 1.1.10\""; } >&5
($PKG_CONFIG --exists --print-errors "libtorrent-rasterbar >= 1.1.10") 2>&5
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libtorrent-rasterbar >= 1.2\""; } >&5
($PKG_CONFIG --exists --print-errors "libtorrent-rasterbar >= 1.2") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_libtorrent_CFLAGS=`$PKG_CONFIG --cflags "libtorrent-rasterbar >= 1.1.10" 2>/dev/null`
pkg_cv_libtorrent_CFLAGS=`$PKG_CONFIG --cflags "libtorrent-rasterbar >= 1.2" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
Expand All @@ -5309,12 +5309,12 @@ if test -n "$libtorrent_LIBS"; then
pkg_cv_libtorrent_LIBS="$libtorrent_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libtorrent-rasterbar >= 1.1.10\""; } >&5
($PKG_CONFIG --exists --print-errors "libtorrent-rasterbar >= 1.1.10") 2>&5
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libtorrent-rasterbar >= 1.2\""; } >&5
($PKG_CONFIG --exists --print-errors "libtorrent-rasterbar >= 1.2") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_libtorrent_LIBS=`$PKG_CONFIG --libs "libtorrent-rasterbar >= 1.1.10" 2>/dev/null`
pkg_cv_libtorrent_LIBS=`$PKG_CONFIG --libs "libtorrent-rasterbar >= 1.2" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
Expand All @@ -5335,14 +5335,14 @@ else
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
libtorrent_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libtorrent-rasterbar >= 1.1.10" 2>&1`
libtorrent_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libtorrent-rasterbar >= 1.2" 2>&1`
else
libtorrent_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libtorrent-rasterbar >= 1.1.10" 2>&1`
libtorrent_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libtorrent-rasterbar >= 1.2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
echo "$libtorrent_PKG_ERRORS" >&5

as_fn_error $? "Package requirements (libtorrent-rasterbar >= 1.1.10) were not met:
as_fn_error $? "Package requirements (libtorrent-rasterbar >= 1.2) were not met:
$libtorrent_PKG_ERRORS
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ AC_MSG_NOTICE([Boost.System LIB: "$BOOST_SYSTEM_LIB"])
LIBS="$BOOST_SYSTEM_LIB $LIBS"

PKG_CHECK_MODULES(libtorrent,
[libtorrent-rasterbar >= 1.1.10],
[libtorrent-rasterbar >= 1.2],
[CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS"
LIBS="$libtorrent_LIBS $LIBS"])

Expand Down
8 changes: 0 additions & 8 deletions src/app/qtlocalpeer/qtlockedfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@
QtLockedFile::QtLockedFile()
: QFile()
{
#ifdef Q_OS_WIN
wmutex = 0;
rmutex = 0;
#endif
m_lock_mode = NoLock;
}

Expand All @@ -128,10 +124,6 @@ QtLockedFile::QtLockedFile()
QtLockedFile::QtLockedFile(const QString &name)
: QFile(name)
{
#ifdef Q_OS_WIN
wmutex = 0;
rmutex = 0;
#endif
m_lock_mode = NoLock;
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/qtlocalpeer/qtlockedfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ namespace QtLP_Private
Qt::HANDLE getMutexHandle(int idx, bool doCreate);
bool waitMutex(Qt::HANDLE mutex, bool doBlock);

Qt::HANDLE wmutex;
Qt::HANDLE rmutex;
Qt::HANDLE wmutex = nullptr;
Qt::HANDLE rmutex = nullptr;
QVector<Qt::HANDLE> rmutexes;
QString mutexname;
#endif
Expand Down
4 changes: 1 addition & 3 deletions src/base/bittorrent/customstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include "customstorage.h"

#if (LIBTORRENT_VERSION_NUM >= 10200)
#include <libtorrent/download_priority.hpp>

#include <QDir>
Expand All @@ -43,8 +42,8 @@ lt::storage_interface *customStorageConstructor(const lt::storage_params &params

CustomStorage::CustomStorage(const lt::storage_params &params, lt::file_pool &filePool)
: lt::default_storage {params, filePool}
, m_savePath {Utils::Fs::expandPathAbs(QString::fromStdString(params.path))}
{
m_savePath = Utils::Fs::expandPathAbs(QString::fromStdString(params.path));
}

bool CustomStorage::verify_resume_data(const lt::add_torrent_params &rd, const lt::aux::vector<std::string, lt::file_index_t> &links, lt::storage_error &ec)
Expand Down Expand Up @@ -99,4 +98,3 @@ void CustomStorage::handleCompleteFiles(const QString &savePath)
}
}
}
#endif
4 changes: 0 additions & 4 deletions src/base/bittorrent/customstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

#pragma once

#include <libtorrent/version.hpp>

#if (LIBTORRENT_VERSION_NUM >= 10200)
#include <libtorrent/aux_/vector.hpp>
#include <libtorrent/fwd.hpp>
#include <libtorrent/storage.hpp>
Expand All @@ -54,4 +51,3 @@ class CustomStorage final : public lt::default_storage
lt::aux::vector<lt::download_priority_t, lt::file_index_t> m_filePriorities;
QString m_savePath;
};
#endif
4 changes: 0 additions & 4 deletions src/base/bittorrent/infohash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,5 @@ bool BitTorrent::operator!=(const InfoHash &left, const InfoHash &right)

uint BitTorrent::qHash(const InfoHash &key, const uint seed)
{
#if (LIBTORRENT_VERSION_NUM < 10200)
return ::qHash(static_cast<QString>(key), seed);
#else
return ::qHash((std::hash<lt::sha1_hash> {})(key), seed);
#endif
}
5 changes: 0 additions & 5 deletions src/base/bittorrent/infohash.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#define BITTORRENT_INFOHASH_H

#include <libtorrent/sha1_hash.hpp>
#include <libtorrent/version.hpp>

#include <QString>

Expand All @@ -46,11 +45,7 @@ namespace BitTorrent

static constexpr int length()
{
#if (LIBTORRENT_VERSION_NUM < 10200)
return lt::sha1_hash::size;
#else
return lt::sha1_hash::size();
#endif
}

bool isValid() const;
Expand Down
11 changes: 0 additions & 11 deletions src/base/bittorrent/nativesessionextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,12 @@ namespace
void handleFastresumeRejectedAlert(const lt::fastresume_rejected_alert *alert)
{
if (alert->error.value() == lt::errors::mismatching_file_size) {
#if (LIBTORRENT_VERSION_NUM < 10200)
alert->handle.auto_managed(false);
#else
alert->handle.unset_flags(lt::torrent_flags::auto_managed);
#endif
alert->handle.pause();
}
}
}

#if (LIBTORRENT_VERSION_NUM >= 10200)
lt::feature_flags_t NativeSessionExtension::implemented_features()
{
return alert_feature;
Expand All @@ -57,12 +52,6 @@ std::shared_ptr<lt::torrent_plugin> NativeSessionExtension::new_torrent(const lt
{
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)
{
Expand Down
4 changes: 0 additions & 4 deletions src/base/bittorrent/nativesessionextension.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ class NativeSessionExtension final : public lt::plugin
using ClientData = void *;
#endif

#if (LIBTORRENT_VERSION_NUM >= 10200)
lt::feature_flags_t implemented_features() override;
std::shared_ptr<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;
};
27 changes: 2 additions & 25 deletions src/base/bittorrent/nativetorrentextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,13 @@ namespace
{
bool isPaused(const lt::torrent_status &torrentStatus)
{
#if (LIBTORRENT_VERSION_NUM < 10200)
return (torrentStatus.paused && !torrentStatus.auto_managed);
#else
return ((torrentStatus.flags & lt::torrent_flags::paused)
&& !(torrentStatus.flags & lt::torrent_flags::auto_managed));
#endif
}

bool isAutoManaged(const lt::torrent_status &torrentStatus)
{
#if (LIBTORRENT_VERSION_NUM < 10200)
return torrentStatus.auto_managed;
#else
return static_cast<bool>(torrentStatus.flags & lt::torrent_flags::auto_managed);
#endif
}
}

Expand All @@ -58,35 +50,20 @@ NativeTorrentExtension::NativeTorrentExtension(const lt::torrent_handle &torrent
}

// This method is called when state of torrent is changed
#if (LIBTORRENT_VERSION_NUM < 10200)
void NativeTorrentExtension::on_state(const int state)
#else
void NativeTorrentExtension::on_state(const lt::torrent_status::state_t state)
#endif
{
// When a torrent enters "checking files" state while paused, we temporarily resume it
// (really we just allow libtorrent to resume it by enabling auto management for it).
if (state == lt::torrent_status::checking_files) {
if (isPaused(m_torrentHandle.status({}))) {
#if (LIBTORRENT_VERSION_NUM < 10200)
m_torrentHandle.stop_when_ready(true);
m_torrentHandle.auto_managed(true);
#else
if (isPaused(m_torrentHandle.status({})))
m_torrentHandle.set_flags(lt::torrent_flags::stop_when_ready | lt::torrent_flags::auto_managed);
#endif
}
}
}

bool NativeTorrentExtension::on_pause()
{
if (!isAutoManaged(m_torrentHandle.status({}))) {
#if (LIBTORRENT_VERSION_NUM < 10200)
m_torrentHandle.stop_when_ready(false);
#else
if (!isAutoManaged(m_torrentHandle.status({})))
m_torrentHandle.unset_flags(lt::torrent_flags::stop_when_ready);
#endif
}

// return `false` to allow standard handler
// and other extensions to be also invoked.
Expand Down
Loading

0 comments on commit 5fd4671

Please sign in to comment.