Add libtorrent v1.1 basic support

This commit is contained in:
Vladimir Golovnev (Glassez) 2016-01-20 10:15:10 +03:00
parent c93ada1e7b
commit decfae7b8a
8 changed files with 60 additions and 2 deletions

View File

@ -26,6 +26,7 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include <libtorrent/version.hpp>
#include "cachestatus.h" #include "cachestatus.h"
using namespace BitTorrent; using namespace BitTorrent;
@ -50,7 +51,11 @@ qreal CacheStatus::readRatio() const
int CacheStatus::jobQueueLength() const int CacheStatus::jobQueueLength() const
{ {
#if LIBTORRENT_VERSION_NUM < 10100
return m_nativeStatus.job_queue_length; return m_nativeStatus.job_queue_length;
#else
return m_nativeStatus.queued_jobs;
#endif
} }
int CacheStatus::averageJobTime() const int CacheStatus::averageJobTime() const

View File

@ -29,8 +29,8 @@
#ifndef BITTORRENT_CACHESTATUS_H #ifndef BITTORRENT_CACHESTATUS_H
#define BITTORRENT_CACHESTATUS_H #define BITTORRENT_CACHESTATUS_H
#include <libtorrent/disk_io_thread.hpp>
#include <QtGlobal> #include <QtGlobal>
#include <libtorrent/disk_io_thread.hpp>
namespace BitTorrent namespace BitTorrent
{ {

View File

@ -360,7 +360,12 @@ void Session::setSessionSettings()
sessionSettings.active_lsd_limit = -1; sessionSettings.active_lsd_limit = -1;
// Outgoing ports // Outgoing ports
#if LIBTORRENT_VERSION_NUM < 10100
sessionSettings.outgoing_ports = std::make_pair(pref->outgoingPortsMin(), pref->outgoingPortsMax()); sessionSettings.outgoing_ports = std::make_pair(pref->outgoingPortsMin(), pref->outgoingPortsMax());
#else
sessionSettings.outgoing_port = pref->outgoingPortsMin();
sessionSettings.num_outgoing_ports = pref->outgoingPortsMax() - pref->outgoingPortsMin();
#endif
// Ignore limits on LAN // Ignore limits on LAN
qDebug() << "Ignore limits on LAN" << pref->getIgnoreLimitsOnLAN(); qDebug() << "Ignore limits on LAN" << pref->getIgnoreLimitsOnLAN();
sessionSettings.ignore_limits_on_local_network = pref->getIgnoreLimitsOnLAN(); sessionSettings.ignore_limits_on_local_network = pref->getIgnoreLimitsOnLAN();
@ -2261,7 +2266,6 @@ void Session::handleListenSucceededAlert(libt::listen_succeeded_alert *p)
void Session::handleListenFailedAlert(libt::listen_failed_alert *p) void Session::handleListenFailedAlert(libt::listen_failed_alert *p)
{ {
boost::system::error_code ec;
QString proto = "TCP"; QString proto = "TCP";
if (p->sock_type == libt::listen_failed_alert::udp) if (p->sock_type == libt::listen_failed_alert::udp)
proto = "UDP"; proto = "UDP";
@ -2273,12 +2277,24 @@ void Session::handleListenFailedAlert(libt::listen_failed_alert *p)
proto = "I2P"; proto = "I2P";
else if (p->sock_type == libt::listen_failed_alert::socks5) else if (p->sock_type == libt::listen_failed_alert::socks5)
proto = "SOCKS5"; proto = "SOCKS5";
#if LIBTORRENT_VERSION_NUM < 10100
boost::system::error_code ec;
qDebug() << "Failed listening on " << proto << p->endpoint.address().to_string(ec).c_str() << "/" << p->endpoint.port(); qDebug() << "Failed listening on " << proto << p->endpoint.address().to_string(ec).c_str() << "/" << p->endpoint.port();
Logger::instance()->addMessage( Logger::instance()->addMessage(
tr("qBittorrent failed listening on interface %1 port: %2/%3. Reason: %4.", tr("qBittorrent failed listening on interface %1 port: %2/%3. Reason: %4.",
"e.g: qBittorrent failed listening on interface 192.168.0.1 port: TCP/6881. Reason: already in use.") "e.g: qBittorrent failed listening on interface 192.168.0.1 port: TCP/6881. Reason: already in use.")
.arg(p->endpoint.address().to_string(ec).c_str()).arg(proto).arg(QString::number(p->endpoint.port())) .arg(p->endpoint.address().to_string(ec).c_str()).arg(proto).arg(QString::number(p->endpoint.port()))
.arg(QString::fromLocal8Bit(p->error.message().c_str())), Log::CRITICAL); .arg(QString::fromLocal8Bit(p->error.message().c_str())), Log::CRITICAL);
#else
qDebug() << "Failed listening on " << proto << p->listen_interface();
Logger::instance()->addMessage(
tr("qBittorrent failed listening on interface %1 [%2]. Reason: %3.",
"e.g: qBittorrent failed listening on interface 192.168.0.1 [TCP]. Reason: already in use.")
.arg(QString::fromUtf8(p->listen_interface()))
.arg(proto)
.arg(Utils::String::fromStdString(p->error.message())), Log::CRITICAL);
#endif
} }
void Session::handleExternalIPAlert(libt::external_ip_alert *p) void Session::handleExternalIPAlert(libt::external_ip_alert *p)

View File

@ -38,6 +38,8 @@
#include <QWaitCondition> #include <QWaitCondition>
#include <QNetworkConfigurationManager> #include <QNetworkConfigurationManager>
#include <libtorrent/version.hpp>
#include "base/tristatebool.h" #include "base/tristatebool.h"
#include "base/types.h" #include "base/types.h"
#include "torrentinfo.h" #include "torrentinfo.h"
@ -52,7 +54,16 @@ namespace libtorrent
struct session_settings; struct session_settings;
struct session_status; struct session_status;
#if LIBTORRENT_VERSION_NUM < 10100
struct proxy_settings; struct proxy_settings;
#else
namespace aux
{
struct proxy_settings;
}
typedef aux::proxy_settings proxy_settings;
#endif
class alert; class alert;
struct torrent_alert; struct torrent_alert;

View File

@ -40,6 +40,9 @@
#include <libtorrent/alert_types.hpp> #include <libtorrent/alert_types.hpp>
#include <libtorrent/create_torrent.hpp> #include <libtorrent/create_torrent.hpp>
#include <libtorrent/magnet_uri.hpp> #include <libtorrent/magnet_uri.hpp>
#if LIBTORRENT_VERSION_NUM >= 10100
#include <libtorrent/time.hpp>
#endif
#include <boost/bind.hpp> #include <boost/bind.hpp>
@ -1067,7 +1070,11 @@ int TorrentHandle::connectionsLimit() const
qlonglong TorrentHandle::nextAnnounce() const qlonglong TorrentHandle::nextAnnounce() const
{ {
#if LIBTORRENT_VERSION_NUM < 10100
return m_nativeStatus.next_announce.total_seconds(); return m_nativeStatus.next_announce.total_seconds();
#else
return libt::duration_cast<libt::seconds>(m_nativeStatus.next_announce).count();
#endif
} }
void TorrentHandle::setName(const QString &name) void TorrentHandle::setName(const QString &name)
@ -1690,7 +1697,11 @@ libtorrent::torrent_handle TorrentHandle::nativeHandle() const
void TorrentHandle::updateTorrentInfo() void TorrentHandle::updateTorrentInfo()
{ {
if (!hasMetadata()) return; if (!hasMetadata()) return;
#if LIBTORRENT_VERSION_NUM < 10100
m_torrentInfo = TorrentInfo(m_nativeStatus.torrent_file); m_torrentInfo = TorrentInfo(m_nativeStatus.torrent_file);
#else
m_torrentInfo = TorrentInfo(m_nativeStatus.torrent_file.lock());
#endif
} }
void TorrentHandle::initialize() void TorrentHandle::initialize()

View File

@ -38,6 +38,11 @@
#include <QHash> #include <QHash>
#include <libtorrent/torrent_handle.hpp> #include <libtorrent/torrent_handle.hpp>
#include <libtorrent/version.hpp>
#if LIBTORRENT_VERSION_NUM >= 10100
#include <libtorrent/torrent_status.hpp>
#endif
#include <boost/function.hpp> #include <boost/function.hpp>
#include "base/tristatebool.h" #include "base/tristatebool.h"

View File

@ -32,6 +32,7 @@
#include <QtGlobal> #include <QtGlobal>
#include <libtorrent/torrent_info.hpp> #include <libtorrent/torrent_info.hpp>
#include <libtorrent/version.hpp>
class QString; class QString;
class QUrl; class QUrl;
@ -48,8 +49,13 @@ namespace BitTorrent
class TorrentInfo class TorrentInfo
{ {
public: public:
#if LIBTORRENT_VERSION_NUM < 10100
typedef boost::intrusive_ptr<const libtorrent::torrent_info> NativeConstPtr; typedef boost::intrusive_ptr<const libtorrent::torrent_info> NativeConstPtr;
typedef boost::intrusive_ptr<libtorrent::torrent_info> NativePtr; typedef boost::intrusive_ptr<libtorrent::torrent_info> NativePtr;
#else
typedef boost::shared_ptr<const libtorrent::torrent_info> NativeConstPtr;
typedef boost::shared_ptr<libtorrent::torrent_info> NativePtr;
#endif
explicit TorrentInfo(NativeConstPtr nativeInfo = NativeConstPtr()); explicit TorrentInfo(NativeConstPtr nativeInfo = NativeConstPtr());
TorrentInfo(const TorrentInfo &other); TorrentInfo(const TorrentInfo &other);

View File

@ -30,6 +30,10 @@
#define BITTORRENT_TRACKERENTRY_H #define BITTORRENT_TRACKERENTRY_H
#include <libtorrent/torrent_info.hpp> #include <libtorrent/torrent_info.hpp>
#include <libtorrent/version.hpp>
#if LIBTORRENT_VERSION_NUM >= 10100
#include <libtorrent/announce_entry.hpp>
#endif
class QString; class QString;