Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions conf.pri.windows
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ DEFINES += BOOST_SYSTEM_STATIC_LINK
# Enable if linking dynamically against libtorrent
#DEFINES += TORRENT_LINKING_SHARED

# Enable this if compiling with libtorrent 2.x
#DEFINES += QBT_USES_LIBTORRENT2

# Enable stack trace support
CONFIG += stacktrace

Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -6279,7 +6279,7 @@ else
libtorrent_LIBS=$pkg_cv_libtorrent_LIBS
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS"
CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS" QBT_ADD_DEFINES="$QBT_ADD_DEFINES QBT_USES_LIBTORRENT2"
fi


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_COMPILE_IFELSE([DETECT_BOOST_VERSION_PROGRAM(106000)], [],

PKG_CHECK_MODULES(libtorrent,
[libtorrent-rasterbar >= 2.0.4],
[CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS"],
[CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS" QBT_ADD_DEFINES="$QBT_ADD_DEFINES QBT_USES_LIBTORRENT2"],
[PKG_CHECK_MODULES(libtorrent,
[libtorrent-rasterbar >= 1.2.14 libtorrent-rasterbar < 2],
[CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS"])])
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ endmacro()
find_libtorrent(${minLibtorrent1Version})
if (LibtorrentRasterbar_FOUND AND (LibtorrentRasterbar_VERSION VERSION_GREATER_EQUAL 2.0))
find_libtorrent(${minLibtorrentVersion})
target_compile_definitions(qbt_common_cfg PUBLIC QBT_USES_LIBTORRENT2)
endif()

# force variable type so that it always shows up in ccmake/cmake-gui frontends
Expand Down
2 changes: 1 addition & 1 deletion src/base/bittorrent/customstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "base/utils/fs.h"
#include "common.h"

#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
#include <libtorrent/session.hpp>

std::unique_ptr<lt::disk_interface> customDiskIOConstructor(
Expand Down
5 changes: 2 additions & 3 deletions src/base/bittorrent/customstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@

#include <libtorrent/aux_/vector.hpp>
#include <libtorrent/fwd.hpp>
#include <libtorrent/version.hpp>

#include <QString>

#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
#include <libtorrent/disk_interface.hpp>
#include <libtorrent/file_storage.hpp>
#include <libtorrent/io_context.hpp>
Expand All @@ -46,7 +45,7 @@
#include <libtorrent/storage.hpp>
#endif

#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
std::unique_ptr<lt::disk_interface> customDiskIOConstructor(
lt::io_context &ioContext, lt::settings_interface const &settings, lt::counters &counters);

Expand Down
6 changes: 3 additions & 3 deletions src/base/bittorrent/infohash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool BitTorrent::InfoHash::isValid() const

SHA1Hash BitTorrent::InfoHash::v1() const
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
return (m_nativeHash.has_v1() ? SHA1Hash(m_nativeHash.v1) : SHA1Hash());
#else
return {m_nativeHash};
Expand All @@ -52,7 +52,7 @@ SHA1Hash BitTorrent::InfoHash::v1() const

SHA256Hash BitTorrent::InfoHash::v2() const
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
return (m_nativeHash.has_v2() ? SHA256Hash(m_nativeHash.v2) : SHA256Hash());
#else
return {};
Expand All @@ -61,7 +61,7 @@ SHA256Hash BitTorrent::InfoHash::v2() const

BitTorrent::TorrentID BitTorrent::InfoHash::toTorrentID() const
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
return m_nativeHash.get_best();
#else
return {m_nativeHash};
Expand Down
5 changes: 2 additions & 3 deletions src/base/bittorrent/infohash.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

#pragma once

#include <libtorrent/version.hpp>
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
#include <libtorrent/info_hash.hpp>
#endif

Expand Down Expand Up @@ -58,7 +57,7 @@ namespace BitTorrent
class InfoHash
{
public:
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
using WrappedType = lt::info_hash_t;
#else
using WrappedType = lt::sha1_hash;
Expand Down
2 changes: 1 addition & 1 deletion src/base/bittorrent/magneturi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ MagnetUri::MagnetUri(const QString &source)

m_valid = true;

#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
m_infoHash = m_addTorrentParams.info_hashes;
#else
m_infoHash = m_addTorrentParams.info_hash;
Expand Down
3 changes: 1 addition & 2 deletions src/base/bittorrent/nativesessionextension.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
#pragma once

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

class NativeSessionExtension final : public lt::plugin
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
using ClientData = lt::client_data_t;
#else
using ClientData = void *;
Expand Down
52 changes: 26 additions & 26 deletions src/base/bittorrent/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace
{
switch (socketType)
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
case lt::socket_type_t::http:
return QLatin1String("HTTP");
case lt::socket_type_t::http_ssl:
Expand All @@ -220,15 +220,15 @@ namespace
return QLatin1String("I2P");
case lt::socket_type_t::socks5:
return QLatin1String("SOCKS5");
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
case lt::socket_type_t::socks5_ssl:
return QLatin1String("SOCKS5_SSL");
#endif
case lt::socket_type_t::tcp:
return QLatin1String("TCP");
case lt::socket_type_t::tcp_ssl:
return QLatin1String("TCP_SSL");
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
case lt::socket_type_t::utp:
return QLatin1String("UTP");
#else
Expand Down Expand Up @@ -1077,14 +1077,14 @@ void Session::initializeNativeSession()
pack.set_bool(lt::settings_pack::enable_upnp, false);
pack.set_bool(lt::settings_pack::enable_natpmp, false);

#if (LIBTORRENT_VERSION_NUM > 20000)
#ifdef QBT_USES_LIBTORRENT2
// preserve the same behavior as in earlier libtorrent versions
pack.set_bool(lt::settings_pack::enable_set_file_valid_data, true);
#endif

loadLTSettings(pack);
lt::session_params sessionParams {pack, {}};
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
sessionParams.disk_io_constructor = customDiskIOConstructor;
#endif
m_nativeSession = new lt::session {sessionParams};
Expand Down Expand Up @@ -1176,7 +1176,7 @@ void Session::initMetrics()

m_metricIndices.disk.diskBlocksInUse = findMetricIndex("disk.disk_blocks_in_use");
m_metricIndices.disk.numBlocksRead = findMetricIndex("disk.num_blocks_read");
#if (LIBTORRENT_VERSION_NUM < 20000)
#ifndef QBT_USES_LIBTORRENT2
m_metricIndices.disk.numBlocksCacheHits = findMetricIndex("disk.num_blocks_cache_hits");
#endif
m_metricIndices.disk.writeJobs = findMetricIndex("disk.num_write_ops");
Expand Down Expand Up @@ -1263,15 +1263,15 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack)
settingsPack.set_int(lt::settings_pack::peer_turnover_interval, peerTurnoverInterval());

settingsPack.set_int(lt::settings_pack::aio_threads, asyncIOThreads());
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
settingsPack.set_int(lt::settings_pack::hashing_threads, hashingThreads());
#endif
settingsPack.set_int(lt::settings_pack::file_pool_size, filePoolSize());

const int checkingMemUsageSize = checkingMemUsage() * 64;
settingsPack.set_int(lt::settings_pack::checking_mem_usage, checkingMemUsageSize);

#if (LIBTORRENT_VERSION_NUM < 20000)
#ifndef QBT_USES_LIBTORRENT2
const int cacheSize = (diskCacheSize() > -1) ? (diskCacheSize() * 64) : -1;
settingsPack.set_int(lt::settings_pack::cache_size, cacheSize);
settingsPack.set_int(lt::settings_pack::cache_expiry, diskCacheTTL());
Expand All @@ -1282,7 +1282,7 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack)
settingsPack.set_int(lt::settings_pack::disk_io_read_mode, mode);
settingsPack.set_int(lt::settings_pack::disk_io_write_mode, mode);

#if (LIBTORRENT_VERSION_NUM < 20000)
#ifndef QBT_USES_LIBTORRENT2
settingsPack.set_bool(lt::settings_pack::coalesce_reads, isCoalesceReadWriteEnabled());
settingsPack.set_bool(lt::settings_pack::coalesce_writes, isCoalesceReadWriteEnabled());
#endif
Expand Down Expand Up @@ -2215,15 +2215,15 @@ bool Session::loadTorrent(LoadTorrentParams params)
{
lt::add_torrent_params &p = params.ltAddTorrentParams;

#if (LIBTORRENT_VERSION_NUM < 20000)
#ifndef QBT_USES_LIBTORRENT2
p.storage = customStorageConstructor;
#endif
// Limits
p.max_connections = maxConnectionsPerTorrent();
p.max_uploads = maxUploadsPerTorrent();

const bool hasMetadata = (p.ti && p.ti->is_valid());
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(hasMetadata ? p.ti->info_hashes() : p.info_hashes);
#else
const auto id = TorrentID::fromInfoHash(hasMetadata ? p.ti->info_hash() : p.info_hash);
Expand Down Expand Up @@ -2290,7 +2290,7 @@ bool Session::downloadMetadata(const MagnetUri &magnetUri)
// Solution to avoid accidental file writes
p.flags |= lt::torrent_flags::upload_mode;

#if (LIBTORRENT_VERSION_NUM < 20000)
#ifndef QBT_USES_LIBTORRENT2
p.storage = customStorageConstructor;
#endif

Expand Down Expand Up @@ -3905,7 +3905,7 @@ void Session::handleTorrentMetadataReceived(TorrentImpl *const torrent)
// Copy the torrent file to the export folder
if (!torrentExportDirectory().isEmpty())
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
const TorrentInfo torrentInfo {torrent->nativeHandle().torrent_file_with_hashes()};
#else
const TorrentInfo torrentInfo {torrent->nativeHandle().torrent_file()};
Expand Down Expand Up @@ -3963,7 +3963,7 @@ void Session::handleTorrentFinished(TorrentImpl *const torrent)
// Move .torrent file to another folder
if (!finishedTorrentExportDirectory().isEmpty())
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
const TorrentInfo torrentInfo {torrent->nativeHandle().torrent_file_with_hashes()};
#else
const TorrentInfo torrentInfo {torrent->nativeHandle().torrent_file()};
Expand Down Expand Up @@ -4048,7 +4048,7 @@ bool Session::addMoveTorrentStorageJob(TorrentImpl *torrent, const QString &newP

void Session::moveTorrentStorage(const MoveStorageJob &job) const
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(job.torrentHandle.info_hashes());
#else
const auto id = TorrentID::fromInfoHash(job.torrentHandle.info_hash());
Expand Down Expand Up @@ -4347,7 +4347,7 @@ void Session::handleAlert(const lt::alert *a)
{
switch (a->type())
{
#if (LIBTORRENT_VERSION_NUM >= 20003)
#ifdef QBT_USES_LIBTORRENT2
case lt::file_prio_alert::alert_type:
#endif
case lt::file_renamed_alert::alert_type:
Expand Down Expand Up @@ -4449,7 +4449,7 @@ void Session::dispatchTorrentAlert(const lt::alert *a)

void Session::createTorrent(const lt::torrent_handle &nativeHandle)
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
const auto torrentID = TorrentID::fromInfoHash(nativeHandle.info_hashes());
#else
const auto torrentID = TorrentID::fromInfoHash(nativeHandle.info_hash());
Expand Down Expand Up @@ -4515,7 +4515,7 @@ void Session::handleAddTorrentAlert(const lt::add_torrent_alert *p)

const lt::add_torrent_params &params = p->params;
const bool hasMetadata = (params.ti && params.ti->is_valid());
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(hasMetadata ? params.ti->info_hashes() : params.info_hashes);
#else
const auto id = TorrentID::fromInfoHash(hasMetadata ? params.ti->info_hash() : params.info_hash);
Expand All @@ -4530,7 +4530,7 @@ void Session::handleAddTorrentAlert(const lt::add_torrent_alert *p)

void Session::handleTorrentRemovedAlert(const lt::torrent_removed_alert *p)
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(p->info_hashes);
#else
const auto id = TorrentID::fromInfoHash(p->info_hash);
Expand All @@ -4549,7 +4549,7 @@ void Session::handleTorrentRemovedAlert(const lt::torrent_removed_alert *p)

void Session::handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p)
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(p->info_hashes);
#else
const auto id = TorrentID::fromInfoHash(p->info_hash);
Expand All @@ -4567,7 +4567,7 @@ void Session::handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p)

void Session::handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_alert *p)
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(p->info_hashes);
#else
const auto id = TorrentID::fromInfoHash(p->info_hash);
Expand Down Expand Up @@ -4597,7 +4597,7 @@ void Session::handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_ale

void Session::handleMetadataReceivedAlert(const lt::metadata_received_alert *p)
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(p->handle.info_hashes());
#else
const auto id = TorrentID::fromInfoHash(p->handle.info_hash());
Expand Down Expand Up @@ -4800,7 +4800,7 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p)
m_cacheStatus.totalUsedBuffers = stats[m_metricIndices.disk.diskBlocksInUse];
m_cacheStatus.jobQueueLength = stats[m_metricIndices.disk.queuedDiskJobs];

#if (LIBTORRENT_VERSION_NUM < 20000)
#ifndef QBT_USES_LIBTORRENT2
const int64_t numBlocksRead = stats[m_metricIndices.disk.numBlocksRead];
const int64_t numBlocksCacheHits = stats[m_metricIndices.disk.numBlocksCacheHits];
m_cacheStatus.readRatio = static_cast<qreal>(numBlocksCacheHits) / std::max<int64_t>((numBlocksCacheHits + numBlocksRead), 1);
Expand Down Expand Up @@ -4835,7 +4835,7 @@ void Session::handleStorageMovedAlert(const lt::storage_moved_alert *p)
const QString newPath {p->storage_path()};
Q_ASSERT(newPath == currentJob.path);

#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(currentJob.torrentHandle.info_hashes());
#else
const auto id = TorrentID::fromInfoHash(currentJob.torrentHandle.info_hash());
Expand All @@ -4855,7 +4855,7 @@ void Session::handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert
const MoveStorageJob &currentJob = m_moveStorageQueue.first();
Q_ASSERT(currentJob.torrentHandle == p->handle);

#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(currentJob.torrentHandle.info_hashes());
#else
const auto id = TorrentID::fromInfoHash(currentJob.torrentHandle.info_hash());
Expand All @@ -4878,7 +4878,7 @@ void Session::handleStateUpdateAlert(const lt::state_update_alert *p)

for (const lt::torrent_status &status : p->status)
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
#ifdef QBT_USES_LIBTORRENT2
const auto id = TorrentID::fromInfoHash(status.info_hashes);
#else
const auto id = TorrentID::fromInfoHash(status.info_hash);
Expand Down
3 changes: 1 addition & 2 deletions src/base/bittorrent/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <libtorrent/add_torrent_params.hpp>
#include <libtorrent/fwd.hpp>
#include <libtorrent/torrent_handle.hpp>
#include <libtorrent/version.hpp>

#include <QHash>
#include <QPointer>
Expand Down Expand Up @@ -191,7 +190,7 @@ namespace BitTorrent
{
int diskBlocksInUse = -1;
int numBlocksRead = -1;
#if (LIBTORRENT_VERSION_NUM < 20000)
#ifndef QBT_USES_LIBTORRENT2
int numBlocksCacheHits = -1;
#endif
int writeJobs = -1;
Expand Down
Loading