From 677a419f0b2a1222af4256573bb0d52fca19cd9f Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 7 May 2019 11:22:39 +0800 Subject: [PATCH 1/4] Use upstream defined namespace `lt` namespace is defined since libtorrent 1.1.6 and our master branch requires >= 1.1.10, so there is no need to add #if condition for it. --- src/base/bittorrent/magneturi.cpp | 5 +- src/base/bittorrent/peerinfo.cpp | 55 +- .../bittorrent/private/filterparserthread.cpp | 40 +- src/base/bittorrent/session.cpp | 673 +++++++++--------- src/base/bittorrent/torrentcreatorthread.cpp | 23 +- src/base/bittorrent/torrentinfo.cpp | 23 +- 6 files changed, 406 insertions(+), 413 deletions(-) diff --git a/src/base/bittorrent/magneturi.cpp b/src/base/bittorrent/magneturi.cpp index 52d80b77b..939502414 100644 --- a/src/base/bittorrent/magneturi.cpp +++ b/src/base/bittorrent/magneturi.cpp @@ -56,7 +56,6 @@ namespace } } -namespace libt = libtorrent; using namespace BitTorrent; MagnetUri::MagnetUri(const QString &source) @@ -68,8 +67,8 @@ MagnetUri::MagnetUri(const QString &source) if (isBitTorrentInfoHash(source)) m_url = QLatin1String("magnet:?xt=urn:btih:") + source; - libt::error_code ec; - libt::parse_magnet_uri(m_url.toStdString(), m_addTorrentParams, ec); + lt::error_code ec; + lt::parse_magnet_uri(m_url.toStdString(), m_addTorrentParams, ec); if (ec) return; m_valid = true; diff --git a/src/base/bittorrent/peerinfo.cpp b/src/base/bittorrent/peerinfo.cpp index a7ee09e69..8e4277e4b 100644 --- a/src/base/bittorrent/peerinfo.cpp +++ b/src/base/bittorrent/peerinfo.cpp @@ -33,7 +33,6 @@ #include "base/unicodestrings.h" #include "base/utils/string.h" -namespace libt = libtorrent; using namespace BitTorrent; // PeerAddress @@ -51,7 +50,7 @@ PeerAddress::PeerAddress(const QHostAddress &ip, ushort port) // PeerInfo -PeerInfo::PeerInfo(const TorrentHandle *torrent, const libt::peer_info &nativeInfo) +PeerInfo::PeerInfo(const TorrentHandle *torrent, const lt::peer_info &nativeInfo) : m_nativeInfo(nativeInfo) { calcRelevance(torrent); @@ -60,17 +59,17 @@ PeerInfo::PeerInfo(const TorrentHandle *torrent, const libt::peer_info &nativeIn bool PeerInfo::fromDHT() const { - return static_cast(m_nativeInfo.source & libt::peer_info::dht); + return static_cast(m_nativeInfo.source & lt::peer_info::dht); } bool PeerInfo::fromPeX() const { - return static_cast(m_nativeInfo.source & libt::peer_info::pex); + return static_cast(m_nativeInfo.source & lt::peer_info::pex); } bool PeerInfo::fromLSD() const { - return static_cast(m_nativeInfo.source & libt::peer_info::lsd); + return static_cast(m_nativeInfo.source & lt::peer_info::lsd); } #ifndef DISABLE_COUNTRIES_RESOLUTION @@ -82,102 +81,102 @@ QString PeerInfo::country() const bool PeerInfo::isInteresting() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::interesting); + return static_cast(m_nativeInfo.flags & lt::peer_info::interesting); } bool PeerInfo::isChocked() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::choked); + return static_cast(m_nativeInfo.flags & lt::peer_info::choked); } bool PeerInfo::isRemoteInterested() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::remote_interested); + return static_cast(m_nativeInfo.flags & lt::peer_info::remote_interested); } bool PeerInfo::isRemoteChocked() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::remote_choked); + return static_cast(m_nativeInfo.flags & lt::peer_info::remote_choked); } bool PeerInfo::isSupportsExtensions() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::supports_extensions); + return static_cast(m_nativeInfo.flags & lt::peer_info::supports_extensions); } bool PeerInfo::isLocalConnection() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::local_connection); + return static_cast(m_nativeInfo.flags & lt::peer_info::local_connection); } bool PeerInfo::isHandshake() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::handshake); + return static_cast(m_nativeInfo.flags & lt::peer_info::handshake); } bool PeerInfo::isConnecting() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::connecting); + return static_cast(m_nativeInfo.flags & lt::peer_info::connecting); } bool PeerInfo::isOnParole() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::on_parole); + return static_cast(m_nativeInfo.flags & lt::peer_info::on_parole); } bool PeerInfo::isSeed() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::seed); + return static_cast(m_nativeInfo.flags & lt::peer_info::seed); } bool PeerInfo::optimisticUnchoke() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::optimistic_unchoke); + return static_cast(m_nativeInfo.flags & lt::peer_info::optimistic_unchoke); } bool PeerInfo::isSnubbed() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::snubbed); + return static_cast(m_nativeInfo.flags & lt::peer_info::snubbed); } bool PeerInfo::isUploadOnly() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::upload_only); + return static_cast(m_nativeInfo.flags & lt::peer_info::upload_only); } bool PeerInfo::isEndgameMode() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::endgame_mode); + return static_cast(m_nativeInfo.flags & lt::peer_info::endgame_mode); } bool PeerInfo::isHolepunched() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::holepunched); + return static_cast(m_nativeInfo.flags & lt::peer_info::holepunched); } bool PeerInfo::useI2PSocket() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::i2p_socket); + return static_cast(m_nativeInfo.flags & lt::peer_info::i2p_socket); } bool PeerInfo::useUTPSocket() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::utp_socket); + return static_cast(m_nativeInfo.flags & lt::peer_info::utp_socket); } bool PeerInfo::useSSLSocket() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::ssl_socket); + return static_cast(m_nativeInfo.flags & lt::peer_info::ssl_socket); } bool PeerInfo::isRC4Encrypted() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::rc4_encrypted); + return static_cast(m_nativeInfo.flags & lt::peer_info::rc4_encrypted); } bool PeerInfo::isPlaintextEncrypted() const { - return static_cast(m_nativeInfo.flags & libt::peer_info::plaintext_encrypted); + return static_cast(m_nativeInfo.flags & lt::peer_info::plaintext_encrypted); } PeerAddress PeerInfo::address() const @@ -229,13 +228,13 @@ QBitArray PeerInfo::pieces() const QString PeerInfo::connectionType() const { - if (m_nativeInfo.flags & libt::peer_info::utp_socket) + if (m_nativeInfo.flags & lt::peer_info::utp_socket) return QString::fromUtf8(C_UTP); QString connection; switch (m_nativeInfo.connection_type) { - case libt::peer_info::http_seed: - case libt::peer_info::web_seed: + case lt::peer_info::http_seed: + case lt::peer_info::web_seed: connection = "Web"; break; default: diff --git a/src/base/bittorrent/private/filterparserthread.cpp b/src/base/bittorrent/private/filterparserthread.cpp index 68fae86df..cf7b19b81 100644 --- a/src/base/bittorrent/private/filterparserthread.cpp +++ b/src/base/bittorrent/private/filterparserthread.cpp @@ -35,8 +35,6 @@ #include "base/logger.h" -namespace libt = libtorrent; - namespace { class IPv4Parser @@ -79,24 +77,24 @@ namespace return false; } - libt::address_v4::bytes_type parsed() const + lt::address_v4::bytes_type parsed() const { return m_buf; } private: - libt::address_v4::bytes_type m_buf; + lt::address_v4::bytes_type m_buf; }; - bool parseIPAddress(const char *data, libt::address &address) + bool parseIPAddress(const char *data, lt::address &address) { IPv4Parser parser; boost::system::error_code ec; if (parser.tryParse(data)) - address = libt::address_v4(parser.parsed()); + address = lt::address_v4(parser.parsed()); else - address = libt::address_v6::from_string(data, ec); + address = lt::address_v6::from_string(data, ec); return !ec; } @@ -214,7 +212,7 @@ int FilterParserThread::parseDATFilterFile() continue; } - libt::address startAddr; + lt::address startAddr; int newStart = trim(buffer.data(), start, delimIP - 1); if (!parseIPAddress(buffer.data() + newStart, startAddr)) { ++parseErrorCount; @@ -223,7 +221,7 @@ int FilterParserThread::parseDATFilterFile() continue; } - libt::address endAddr; + lt::address endAddr; newStart = trim(buffer.data(), delimIP + 1, endOfIPRange); if (!parseIPAddress(buffer.data() + newStart, endAddr)) { ++parseErrorCount; @@ -244,7 +242,7 @@ int FilterParserThread::parseDATFilterFile() // Now Add to the filter try { - m_filter.add_rule(startAddr, endAddr, libt::ip_filter::blocked); + m_filter.add_rule(startAddr, endAddr, lt::ip_filter::blocked); ++ruleCount; } catch (std::exception &e) { @@ -353,7 +351,7 @@ int FilterParserThread::parseP2PFilterFile() continue; } - libt::address startAddr; + lt::address startAddr; int newStart = trim(buffer.data(), partsDelimiter + 1, delimIP - 1); if (!parseIPAddress(buffer.data() + newStart, startAddr)) { ++parseErrorCount; @@ -362,7 +360,7 @@ int FilterParserThread::parseP2PFilterFile() continue; } - libt::address endAddr; + lt::address endAddr; newStart = trim(buffer.data(), delimIP + 1, endOfLine); if (!parseIPAddress(buffer.data() + newStart, endAddr)) { ++parseErrorCount; @@ -382,7 +380,7 @@ int FilterParserThread::parseP2PFilterFile() start = endOfLine; try { - m_filter.add_rule(startAddr, endAddr, libt::ip_filter::blocked); + m_filter.add_rule(startAddr, endAddr, lt::ip_filter::blocked); ++ruleCount; } catch (std::exception &e) { @@ -463,11 +461,11 @@ int FilterParserThread::parseP2BFilterFile() // Network byte order to Host byte order // asio address_v4 constructor expects it // that way - const libt::address_v4 first(ntohl(start)); - const libt::address_v4 last(ntohl(end)); + const lt::address_v4 first(ntohl(start)); + const lt::address_v4 last(ntohl(end)); // Apply to bittorrent session try { - m_filter.add_rule(first, last, libt::ip_filter::blocked); + m_filter.add_rule(first, last, lt::ip_filter::blocked); ++ruleCount; } catch (std::exception &) {} @@ -513,11 +511,11 @@ int FilterParserThread::parseP2BFilterFile() // Network byte order to Host byte order // asio address_v4 constructor expects it // that way - const libt::address_v4 first(ntohl(start)); - const libt::address_v4 last(ntohl(end)); + const lt::address_v4 first(ntohl(start)); + const lt::address_v4 last(ntohl(end)); // Apply to bittorrent session try { - m_filter.add_rule(first, last, libt::ip_filter::blocked); + m_filter.add_rule(first, last, lt::ip_filter::blocked); ++ruleCount; } catch (std::exception &) {} @@ -547,12 +545,12 @@ void FilterParserThread::processFilterFile(const QString &filePath) m_abort = false; m_filePath = filePath; - m_filter = libt::ip_filter(); + m_filter = lt::ip_filter(); // Run it start(); } -libt::ip_filter FilterParserThread::IPfilter() +lt::ip_filter FilterParserThread::IPfilter() { return m_filter; } diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 257ed3232..acdecb173 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -97,7 +97,6 @@ static const char PEER_ID[] = "qB"; static const char RESUME_FOLDER[] = "BT_backup"; static const char USER_AGENT[] = "qBittorrent/" QBT_VERSION_2; -namespace libt = libtorrent; using namespace BitTorrent; namespace @@ -115,10 +114,10 @@ namespace bool readFile(const QString &path, QByteArray &buf); bool loadTorrentResumeData(const QByteArray &data, CreateTorrentParams &torrentParams, int &prio, MagnetUri &magnetUri); - void torrentQueuePositionUp(const libt::torrent_handle &handle); - void torrentQueuePositionDown(const libt::torrent_handle &handle); - void torrentQueuePositionTop(const libt::torrent_handle &handle); - void torrentQueuePositionBottom(const libt::torrent_handle &handle); + void torrentQueuePositionUp(const lt::torrent_handle &handle); + void torrentQueuePositionDown(const lt::torrent_handle &handle); + void torrentQueuePositionTop(const lt::torrent_handle &handle); + void torrentQueuePositionBottom(const lt::torrent_handle &handle); #ifdef Q_OS_WIN QString convertIfaceNameToGuid(const QString &name); @@ -161,12 +160,12 @@ namespace return output; } - bool isList(const libt::bdecode_node &entry) + bool isList(const lt::bdecode_node &entry) { - return entry.type() == libt::bdecode_node::list_t; + return entry.type() == lt::bdecode_node::list_t; } - QSet entryListToSet(const libt::bdecode_node &entry) + QSet entryListToSet(const lt::bdecode_node &entry) { return entryListToSetImpl(entry); } @@ -379,42 +378,42 @@ Session::Session(QObject *parent) connect(m_seedingLimitTimer, &QTimer::timeout, this, &Session::processShareLimits); // Set severity level of libtorrent session - const int alertMask = libt::alert::error_notification - | libt::alert::peer_notification - | libt::alert::port_mapping_notification - | libt::alert::storage_notification - | libt::alert::tracker_notification - | libt::alert::status_notification - | libt::alert::ip_block_notification - | libt::alert::file_progress_notification - | libt::alert::stats_notification; - - const std::string peerId = libt::generate_fingerprint(PEER_ID, QBT_VERSION_MAJOR, QBT_VERSION_MINOR, QBT_VERSION_BUGFIX, QBT_VERSION_BUILD); - libt::settings_pack pack; - pack.set_int(libt::settings_pack::alert_mask, alertMask); - pack.set_str(libt::settings_pack::peer_fingerprint, peerId); - pack.set_bool(libt::settings_pack::listen_system_port_fallback, false); - pack.set_str(libt::settings_pack::user_agent, USER_AGENT); - pack.set_bool(libt::settings_pack::use_dht_as_fallback, false); + const int alertMask = lt::alert::error_notification + | lt::alert::peer_notification + | lt::alert::port_mapping_notification + | lt::alert::storage_notification + | lt::alert::tracker_notification + | lt::alert::status_notification + | lt::alert::ip_block_notification + | lt::alert::file_progress_notification + | lt::alert::stats_notification; + + const std::string peerId = lt::generate_fingerprint(PEER_ID, QBT_VERSION_MAJOR, QBT_VERSION_MINOR, QBT_VERSION_BUGFIX, QBT_VERSION_BUILD); + lt::settings_pack pack; + pack.set_int(lt::settings_pack::alert_mask, alertMask); + pack.set_str(lt::settings_pack::peer_fingerprint, peerId); + pack.set_bool(lt::settings_pack::listen_system_port_fallback, false); + pack.set_str(lt::settings_pack::user_agent, USER_AGENT); + pack.set_bool(lt::settings_pack::use_dht_as_fallback, false); // Disable support for SSL torrents for now - pack.set_int(libt::settings_pack::ssl_listen, 0); + pack.set_int(lt::settings_pack::ssl_listen, 0); // To prevent ISPs from blocking seeding - pack.set_bool(libt::settings_pack::lazy_bitfields, true); + pack.set_bool(lt::settings_pack::lazy_bitfields, true); // Speed up exit - pack.set_int(libt::settings_pack::stop_tracker_timeout, 1); - pack.set_int(libt::settings_pack::auto_scrape_interval, 1200); // 20 minutes - pack.set_int(libt::settings_pack::auto_scrape_min_interval, 900); // 15 minutes - pack.set_int(libt::settings_pack::connection_speed, 20); // default is 10 - pack.set_bool(libt::settings_pack::no_connect_privileged_ports, false); + pack.set_int(lt::settings_pack::stop_tracker_timeout, 1); + pack.set_int(lt::settings_pack::auto_scrape_interval, 1200); // 20 minutes + pack.set_int(lt::settings_pack::auto_scrape_min_interval, 900); // 15 minutes + pack.set_int(lt::settings_pack::connection_speed, 20); // default is 10 + pack.set_bool(lt::settings_pack::no_connect_privileged_ports, false); // 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(libt::settings_pack::use_disk_cache_pool, false); + pack.set_bool(lt::settings_pack::use_disk_cache_pool, false); // libtorrent 1.1 enables UPnP & NAT-PMP by default - // turn them off before `libt::session` ctor to avoid split second effects - pack.set_bool(libt::settings_pack::enable_upnp, false); - pack.set_bool(libt::settings_pack::enable_natpmp, false); - pack.set_bool(libt::settings_pack::upnp_ignore_nonrouters, true); + // turn them off before `lt::session` ctor to avoid split second effects + pack.set_bool(lt::settings_pack::enable_upnp, false); + pack.set_bool(lt::settings_pack::enable_natpmp, false); + pack.set_bool(lt::settings_pack::upnp_ignore_nonrouters, true); configure(pack); m_nativeSession = new lt::session {pack, LTSessionFlags {0}}; @@ -426,11 +425,11 @@ Session::Session(QObject *parent) configurePeerClasses(); // Enabling plugins - //m_nativeSession->add_extension(&libt::create_metadata_plugin); - m_nativeSession->add_extension(&libt::create_ut_metadata_plugin); + //m_nativeSession->add_extension(<::create_metadata_plugin); + m_nativeSession->add_extension(<::create_ut_metadata_plugin); if (isPeXEnabled()) - m_nativeSession->add_extension(&libt::create_ut_pex_plugin); - m_nativeSession->add_extension(&libt::create_smart_ban_plugin); + m_nativeSession->add_extension(<::create_ut_pex_plugin); + m_nativeSession->add_extension(<::create_smart_ban_plugin); logger->addMessage(tr("Peer ID: ") + QString::fromStdString(peerId)); logger->addMessage(tr("HTTP User-Agent is '%1'").arg(USER_AGENT)); @@ -451,7 +450,7 @@ Session::Session(QObject *parent) } else { // Add the banned IPs - libt::ip_filter filter; + lt::ip_filter filter; processBannedIPs(filter); m_nativeSession->set_ip_filter(filter); } @@ -982,7 +981,7 @@ Session *Session::instance() void Session::adjustLimits() { if (isQueueingSystemEnabled()) { - libt::settings_pack settingsPack = m_nativeSession->get_settings(); + lt::settings_pack settingsPack = m_nativeSession->get_settings(); adjustLimits(settingsPack); m_nativeSession->apply_settings(settingsPack); } @@ -990,7 +989,7 @@ void Session::adjustLimits() void Session::applyBandwidthLimits() { - libt::settings_pack settingsPack = m_nativeSession->get_settings(); + lt::settings_pack settingsPack = m_nativeSession->get_settings(); applyBandwidthLimits(settingsPack); m_nativeSession->apply_settings(settingsPack); } @@ -999,7 +998,7 @@ void Session::applyBandwidthLimits() void Session::configure() { qDebug("Configuring session"); - libt::settings_pack settingsPack = m_nativeSession->get_settings(); + lt::settings_pack settingsPack = m_nativeSession->get_settings(); configure(settingsPack); m_nativeSession->apply_settings(settingsPack); configurePeerClasses(); @@ -1016,112 +1015,112 @@ void Session::configure() qDebug("Session configured"); } -void Session::processBannedIPs(libt::ip_filter &filter) +void Session::processBannedIPs(lt::ip_filter &filter) { // First, import current filter for (const QString &ip : asConst(m_bannedIPs.value())) { boost::system::error_code ec; - const libt::address addr = libt::address::from_string(ip.toLatin1().constData(), ec); + const lt::address addr = lt::address::from_string(ip.toLatin1().constData(), ec); Q_ASSERT(!ec); if (!ec) - filter.add_rule(addr, addr, libt::ip_filter::blocked); + filter.add_rule(addr, addr, lt::ip_filter::blocked); } } -void Session::adjustLimits(libt::settings_pack &settingsPack) +void Session::adjustLimits(lt::settings_pack &settingsPack) { // Internally increase the queue limits to ensure that the magnet is started const int maxDownloads = maxActiveDownloads(); const int maxActive = maxActiveTorrents(); - settingsPack.set_int(libt::settings_pack::active_downloads + settingsPack.set_int(lt::settings_pack::active_downloads , maxDownloads > -1 ? maxDownloads + m_extraLimit : maxDownloads); - settingsPack.set_int(libt::settings_pack::active_limit + settingsPack.set_int(lt::settings_pack::active_limit , maxActive > -1 ? maxActive + m_extraLimit : maxActive); } void Session::applyBandwidthLimits(libtorrent::settings_pack &settingsPack) { const bool altSpeedLimitEnabled = isAltGlobalSpeedLimitEnabled(); - settingsPack.set_int(libt::settings_pack::download_rate_limit, altSpeedLimitEnabled ? altGlobalDownloadSpeedLimit() : globalDownloadSpeedLimit()); - settingsPack.set_int(libt::settings_pack::upload_rate_limit, altSpeedLimitEnabled ? altGlobalUploadSpeedLimit() : globalUploadSpeedLimit()); + settingsPack.set_int(lt::settings_pack::download_rate_limit, altSpeedLimitEnabled ? altGlobalDownloadSpeedLimit() : globalDownloadSpeedLimit()); + settingsPack.set_int(lt::settings_pack::upload_rate_limit, altSpeedLimitEnabled ? altGlobalUploadSpeedLimit() : globalUploadSpeedLimit()); } void Session::initMetrics() { - m_metricIndices.net.hasIncomingConnections = libt::find_metric_idx("net.has_incoming_connections"); + m_metricIndices.net.hasIncomingConnections = lt::find_metric_idx("net.has_incoming_connections"); Q_ASSERT(m_metricIndices.net.hasIncomingConnections >= 0); - m_metricIndices.net.sentPayloadBytes = libt::find_metric_idx("net.sent_payload_bytes"); + m_metricIndices.net.sentPayloadBytes = lt::find_metric_idx("net.sent_payload_bytes"); Q_ASSERT(m_metricIndices.net.sentPayloadBytes >= 0); - m_metricIndices.net.recvPayloadBytes = libt::find_metric_idx("net.recv_payload_bytes"); + m_metricIndices.net.recvPayloadBytes = lt::find_metric_idx("net.recv_payload_bytes"); Q_ASSERT(m_metricIndices.net.recvPayloadBytes >= 0); - m_metricIndices.net.sentBytes = libt::find_metric_idx("net.sent_bytes"); + m_metricIndices.net.sentBytes = lt::find_metric_idx("net.sent_bytes"); Q_ASSERT(m_metricIndices.net.sentBytes >= 0); - m_metricIndices.net.recvBytes = libt::find_metric_idx("net.recv_bytes"); + m_metricIndices.net.recvBytes = lt::find_metric_idx("net.recv_bytes"); Q_ASSERT(m_metricIndices.net.recvBytes >= 0); - m_metricIndices.net.sentIPOverheadBytes = libt::find_metric_idx("net.sent_ip_overhead_bytes"); + m_metricIndices.net.sentIPOverheadBytes = lt::find_metric_idx("net.sent_ip_overhead_bytes"); Q_ASSERT(m_metricIndices.net.sentIPOverheadBytes >= 0); - m_metricIndices.net.recvIPOverheadBytes = libt::find_metric_idx("net.recv_ip_overhead_bytes"); + m_metricIndices.net.recvIPOverheadBytes = lt::find_metric_idx("net.recv_ip_overhead_bytes"); Q_ASSERT(m_metricIndices.net.recvIPOverheadBytes >= 0); - m_metricIndices.net.sentTrackerBytes = libt::find_metric_idx("net.sent_tracker_bytes"); + m_metricIndices.net.sentTrackerBytes = lt::find_metric_idx("net.sent_tracker_bytes"); Q_ASSERT(m_metricIndices.net.sentTrackerBytes >= 0); - m_metricIndices.net.recvTrackerBytes = libt::find_metric_idx("net.recv_tracker_bytes"); + m_metricIndices.net.recvTrackerBytes = lt::find_metric_idx("net.recv_tracker_bytes"); Q_ASSERT(m_metricIndices.net.recvTrackerBytes >= 0); - m_metricIndices.net.recvRedundantBytes = libt::find_metric_idx("net.recv_redundant_bytes"); + m_metricIndices.net.recvRedundantBytes = lt::find_metric_idx("net.recv_redundant_bytes"); Q_ASSERT(m_metricIndices.net.recvRedundantBytes >= 0); - m_metricIndices.net.recvFailedBytes = libt::find_metric_idx("net.recv_failed_bytes"); + m_metricIndices.net.recvFailedBytes = lt::find_metric_idx("net.recv_failed_bytes"); Q_ASSERT(m_metricIndices.net.recvFailedBytes >= 0); - m_metricIndices.peer.numPeersConnected = libt::find_metric_idx("peer.num_peers_connected"); + m_metricIndices.peer.numPeersConnected = lt::find_metric_idx("peer.num_peers_connected"); Q_ASSERT(m_metricIndices.peer.numPeersConnected >= 0); - m_metricIndices.peer.numPeersDownDisk = libt::find_metric_idx("peer.num_peers_down_disk"); + m_metricIndices.peer.numPeersDownDisk = lt::find_metric_idx("peer.num_peers_down_disk"); Q_ASSERT(m_metricIndices.peer.numPeersDownDisk >= 0); - m_metricIndices.peer.numPeersUpDisk = libt::find_metric_idx("peer.num_peers_up_disk"); + m_metricIndices.peer.numPeersUpDisk = lt::find_metric_idx("peer.num_peers_up_disk"); Q_ASSERT(m_metricIndices.peer.numPeersUpDisk >= 0); - m_metricIndices.dht.dhtBytesIn = libt::find_metric_idx("dht.dht_bytes_in"); + m_metricIndices.dht.dhtBytesIn = lt::find_metric_idx("dht.dht_bytes_in"); Q_ASSERT(m_metricIndices.dht.dhtBytesIn >= 0); - m_metricIndices.dht.dhtBytesOut = libt::find_metric_idx("dht.dht_bytes_out"); + m_metricIndices.dht.dhtBytesOut = lt::find_metric_idx("dht.dht_bytes_out"); Q_ASSERT(m_metricIndices.dht.dhtBytesOut >= 0); - m_metricIndices.dht.dhtNodes = libt::find_metric_idx("dht.dht_nodes"); + m_metricIndices.dht.dhtNodes = lt::find_metric_idx("dht.dht_nodes"); Q_ASSERT(m_metricIndices.dht.dhtNodes >= 0); - m_metricIndices.disk.diskBlocksInUse = libt::find_metric_idx("disk.disk_blocks_in_use"); + m_metricIndices.disk.diskBlocksInUse = lt::find_metric_idx("disk.disk_blocks_in_use"); Q_ASSERT(m_metricIndices.disk.diskBlocksInUse >= 0); - m_metricIndices.disk.numBlocksRead = libt::find_metric_idx("disk.num_blocks_read"); + m_metricIndices.disk.numBlocksRead = lt::find_metric_idx("disk.num_blocks_read"); Q_ASSERT(m_metricIndices.disk.numBlocksRead >= 0); - m_metricIndices.disk.numBlocksCacheHits = libt::find_metric_idx("disk.num_blocks_cache_hits"); + m_metricIndices.disk.numBlocksCacheHits = lt::find_metric_idx("disk.num_blocks_cache_hits"); Q_ASSERT(m_metricIndices.disk.numBlocksCacheHits >= 0); - m_metricIndices.disk.writeJobs = libt::find_metric_idx("disk.num_write_ops"); + m_metricIndices.disk.writeJobs = lt::find_metric_idx("disk.num_write_ops"); Q_ASSERT(m_metricIndices.disk.writeJobs >= 0); - m_metricIndices.disk.readJobs = libt::find_metric_idx("disk.num_read_ops"); + m_metricIndices.disk.readJobs = lt::find_metric_idx("disk.num_read_ops"); Q_ASSERT(m_metricIndices.disk.readJobs >= 0); - m_metricIndices.disk.hashJobs = libt::find_metric_idx("disk.num_blocks_hashed"); + m_metricIndices.disk.hashJobs = lt::find_metric_idx("disk.num_blocks_hashed"); Q_ASSERT(m_metricIndices.disk.hashJobs >= 0); - m_metricIndices.disk.queuedDiskJobs = libt::find_metric_idx("disk.queued_disk_jobs"); + m_metricIndices.disk.queuedDiskJobs = lt::find_metric_idx("disk.queued_disk_jobs"); Q_ASSERT(m_metricIndices.disk.queuedDiskJobs >= 0); - m_metricIndices.disk.diskJobTime = libt::find_metric_idx("disk.disk_job_time"); + m_metricIndices.disk.diskJobTime = lt::find_metric_idx("disk.disk_job_time"); Q_ASSERT(m_metricIndices.disk.diskJobTime >= 0); } @@ -1136,9 +1135,9 @@ void Session::configure(libtorrent::settings_pack &settingsPack) if (m_listenInterfaceChanged) { const ushort port = this->port(); const std::pair ports(port, port); - settingsPack.set_int(libt::settings_pack::max_retry_port_bind, ports.second - ports.first); + settingsPack.set_int(lt::settings_pack::max_retry_port_bind, ports.second - ports.first); for (QString ip : getListeningIPs()) { - libt::error_code ec; + lt::error_code ec; std::string interfacesStr; if (ip.isEmpty()) { @@ -1149,11 +1148,11 @@ void Session::configure(libtorrent::settings_pack &settingsPack) .arg(QString::number(port)) , Log::INFO); - settingsPack.set_str(libt::settings_pack::listen_interfaces, interfacesStr); + settingsPack.set_str(lt::settings_pack::listen_interfaces, interfacesStr); break; } - const libt::address addr = libt::address::from_string(ip.toLatin1().constData(), ec); + const lt::address addr = lt::address::from_string(ip.toLatin1().constData(), ec); if (!ec) { interfacesStr = std::string((addr.is_v6() ? QString("[%1]:%2") : QString("%1:%2")) .arg(ip).arg(port).toLatin1().constData()); @@ -1161,7 +1160,7 @@ void Session::configure(libtorrent::settings_pack &settingsPack) , "e.g: qBittorrent is trying to listen on interface 192.168.0.1 port: TCP/6881") .arg(ip).arg(port) , Log::INFO); - settingsPack.set_str(libt::settings_pack::listen_interfaces, interfacesStr); + settingsPack.set_str(lt::settings_pack::listen_interfaces, interfacesStr); #ifdef Q_OS_WIN chosenIP = ip; #endif @@ -1176,16 +1175,16 @@ void Session::configure(libtorrent::settings_pack &settingsPack) if (!networkInterface().isEmpty()) { const QString guid = convertIfaceNameToGuid(networkInterface()); if (!guid.isEmpty()) { - settingsPack.set_str(libt::settings_pack::outgoing_interfaces, guid.toStdString()); + settingsPack.set_str(lt::settings_pack::outgoing_interfaces, guid.toStdString()); } else { - settingsPack.set_str(libt::settings_pack::outgoing_interfaces, chosenIP.toStdString()); + settingsPack.set_str(lt::settings_pack::outgoing_interfaces, chosenIP.toStdString()); LogMsg(tr("Could not get GUID of configured network interface. Binding to IP %1").arg(chosenIP) , Log::WARNING); } } #else - settingsPack.set_str(libt::settings_pack::outgoing_interfaces, networkInterface().toStdString()); + settingsPack.set_str(lt::settings_pack::outgoing_interfaces, networkInterface().toStdString()); #endif // Q_OS_WIN m_listenInterfaceChanged = false; } @@ -1193,263 +1192,263 @@ void Session::configure(libtorrent::settings_pack &settingsPack) applyBandwidthLimits(settingsPack); // The most secure, rc4 only so that all streams are encrypted - settingsPack.set_int(libt::settings_pack::allowed_enc_level, libt::settings_pack::pe_rc4); - settingsPack.set_bool(libt::settings_pack::prefer_rc4, true); + settingsPack.set_int(lt::settings_pack::allowed_enc_level, lt::settings_pack::pe_rc4); + settingsPack.set_bool(lt::settings_pack::prefer_rc4, true); switch (encryption()) { case 0: // Enabled - settingsPack.set_int(libt::settings_pack::out_enc_policy, libt::settings_pack::pe_enabled); - settingsPack.set_int(libt::settings_pack::in_enc_policy, libt::settings_pack::pe_enabled); + settingsPack.set_int(lt::settings_pack::out_enc_policy, lt::settings_pack::pe_enabled); + settingsPack.set_int(lt::settings_pack::in_enc_policy, lt::settings_pack::pe_enabled); break; case 1: // Forced - settingsPack.set_int(libt::settings_pack::out_enc_policy, libt::settings_pack::pe_forced); - settingsPack.set_int(libt::settings_pack::in_enc_policy, libt::settings_pack::pe_forced); + settingsPack.set_int(lt::settings_pack::out_enc_policy, lt::settings_pack::pe_forced); + settingsPack.set_int(lt::settings_pack::in_enc_policy, lt::settings_pack::pe_forced); break; default: // Disabled - settingsPack.set_int(libt::settings_pack::out_enc_policy, libt::settings_pack::pe_disabled); - settingsPack.set_int(libt::settings_pack::in_enc_policy, libt::settings_pack::pe_disabled); + settingsPack.set_int(lt::settings_pack::out_enc_policy, lt::settings_pack::pe_disabled); + settingsPack.set_int(lt::settings_pack::in_enc_policy, lt::settings_pack::pe_disabled); } const auto proxyManager = Net::ProxyConfigurationManager::instance(); const Net::ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration(); if (m_useProxy || (proxyConfig.type != Net::ProxyType::None)) { if (proxyConfig.type != Net::ProxyType::None) { - settingsPack.set_str(libt::settings_pack::proxy_hostname, proxyConfig.ip.toStdString()); - settingsPack.set_int(libt::settings_pack::proxy_port, proxyConfig.port); + settingsPack.set_str(lt::settings_pack::proxy_hostname, proxyConfig.ip.toStdString()); + settingsPack.set_int(lt::settings_pack::proxy_port, proxyConfig.port); if (proxyManager->isAuthenticationRequired()) { - settingsPack.set_str(libt::settings_pack::proxy_username, proxyConfig.username.toStdString()); - settingsPack.set_str(libt::settings_pack::proxy_password, proxyConfig.password.toStdString()); + settingsPack.set_str(lt::settings_pack::proxy_username, proxyConfig.username.toStdString()); + settingsPack.set_str(lt::settings_pack::proxy_password, proxyConfig.password.toStdString()); } - settingsPack.set_bool(libt::settings_pack::proxy_peer_connections, isProxyPeerConnectionsEnabled()); + settingsPack.set_bool(lt::settings_pack::proxy_peer_connections, isProxyPeerConnectionsEnabled()); } switch (proxyConfig.type) { case Net::ProxyType::HTTP: - settingsPack.set_int(libt::settings_pack::proxy_type, libt::settings_pack::http); + settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http); break; case Net::ProxyType::HTTP_PW: - settingsPack.set_int(libt::settings_pack::proxy_type, libt::settings_pack::http_pw); + settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http_pw); break; case Net::ProxyType::SOCKS4: - settingsPack.set_int(libt::settings_pack::proxy_type, libt::settings_pack::socks4); + settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks4); break; case Net::ProxyType::SOCKS5: - settingsPack.set_int(libt::settings_pack::proxy_type, libt::settings_pack::socks5); + settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5); break; case Net::ProxyType::SOCKS5_PW: - settingsPack.set_int(libt::settings_pack::proxy_type, libt::settings_pack::socks5_pw); + settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5_pw); break; default: - settingsPack.set_int(libt::settings_pack::proxy_type, libt::settings_pack::none); + settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::none); } m_useProxy = (proxyConfig.type != Net::ProxyType::None); } - settingsPack.set_bool(libt::settings_pack::force_proxy, m_useProxy ? isForceProxyEnabled() : false); + settingsPack.set_bool(lt::settings_pack::force_proxy, m_useProxy ? isForceProxyEnabled() : false); - settingsPack.set_bool(libt::settings_pack::announce_to_all_trackers, announceToAllTrackers()); - settingsPack.set_bool(libt::settings_pack::announce_to_all_tiers, announceToAllTiers()); + settingsPack.set_bool(lt::settings_pack::announce_to_all_trackers, announceToAllTrackers()); + settingsPack.set_bool(lt::settings_pack::announce_to_all_tiers, announceToAllTiers()); - settingsPack.set_int(libt::settings_pack::aio_threads, asyncIOThreads()); + settingsPack.set_int(lt::settings_pack::aio_threads, asyncIOThreads()); const int checkingMemUsageSize = checkingMemUsage() * 64; - settingsPack.set_int(libt::settings_pack::checking_mem_usage, checkingMemUsageSize); + settingsPack.set_int(lt::settings_pack::checking_mem_usage, checkingMemUsageSize); const int cacheSize = (diskCacheSize() > -1) ? (diskCacheSize() * 64) : -1; - settingsPack.set_int(libt::settings_pack::cache_size, cacheSize); - settingsPack.set_int(libt::settings_pack::cache_expiry, diskCacheTTL()); + settingsPack.set_int(lt::settings_pack::cache_size, cacheSize); + settingsPack.set_int(lt::settings_pack::cache_expiry, diskCacheTTL()); qDebug() << "Using a disk cache size of" << cacheSize << "MiB"; - libt::settings_pack::io_buffer_mode_t mode = useOSCache() ? libt::settings_pack::enable_os_cache - : libt::settings_pack::disable_os_cache; - settingsPack.set_int(libt::settings_pack::disk_io_read_mode, mode); - settingsPack.set_int(libt::settings_pack::disk_io_write_mode, mode); - settingsPack.set_bool(libt::settings_pack::guided_read_cache, isGuidedReadCacheEnabled()); + lt::settings_pack::io_buffer_mode_t mode = useOSCache() ? lt::settings_pack::enable_os_cache + : lt::settings_pack::disable_os_cache; + settingsPack.set_int(lt::settings_pack::disk_io_read_mode, mode); + settingsPack.set_int(lt::settings_pack::disk_io_write_mode, mode); + settingsPack.set_bool(lt::settings_pack::guided_read_cache, isGuidedReadCacheEnabled()); - settingsPack.set_bool(libt::settings_pack::coalesce_reads, isCoalesceReadWriteEnabled()); - settingsPack.set_bool(libt::settings_pack::coalesce_writes, isCoalesceReadWriteEnabled()); + settingsPack.set_bool(lt::settings_pack::coalesce_reads, isCoalesceReadWriteEnabled()); + settingsPack.set_bool(lt::settings_pack::coalesce_writes, isCoalesceReadWriteEnabled()); - settingsPack.set_int(libt::settings_pack::suggest_mode, isSuggestModeEnabled() - ? libt::settings_pack::suggest_read_cache : libt::settings_pack::no_piece_suggestions); + settingsPack.set_int(lt::settings_pack::suggest_mode, isSuggestModeEnabled() + ? lt::settings_pack::suggest_read_cache : lt::settings_pack::no_piece_suggestions); - settingsPack.set_int(libt::settings_pack::send_buffer_watermark, sendBufferWatermark() * 1024); - settingsPack.set_int(libt::settings_pack::send_buffer_low_watermark, sendBufferLowWatermark() * 1024); - settingsPack.set_int(libt::settings_pack::send_buffer_watermark_factor, sendBufferWatermarkFactor()); + settingsPack.set_int(lt::settings_pack::send_buffer_watermark, sendBufferWatermark() * 1024); + settingsPack.set_int(lt::settings_pack::send_buffer_low_watermark, sendBufferLowWatermark() * 1024); + settingsPack.set_int(lt::settings_pack::send_buffer_watermark_factor, sendBufferWatermarkFactor()); - settingsPack.set_bool(libt::settings_pack::anonymous_mode, isAnonymousModeEnabled()); + settingsPack.set_bool(lt::settings_pack::anonymous_mode, isAnonymousModeEnabled()); // Queueing System if (isQueueingSystemEnabled()) { adjustLimits(settingsPack); - settingsPack.set_int(libt::settings_pack::active_seeds, maxActiveUploads()); - settingsPack.set_bool(libt::settings_pack::dont_count_slow_torrents, ignoreSlowTorrentsForQueueing()); - settingsPack.set_int(libt::settings_pack::inactive_down_rate, downloadRateForSlowTorrents() * 1024); // KiB to Bytes - settingsPack.set_int(libt::settings_pack::inactive_up_rate, uploadRateForSlowTorrents() * 1024); // KiB to Bytes - settingsPack.set_int(libt::settings_pack::auto_manage_startup, slowTorrentsInactivityTimer()); + settingsPack.set_int(lt::settings_pack::active_seeds, maxActiveUploads()); + settingsPack.set_bool(lt::settings_pack::dont_count_slow_torrents, ignoreSlowTorrentsForQueueing()); + settingsPack.set_int(lt::settings_pack::inactive_down_rate, downloadRateForSlowTorrents() * 1024); // KiB to Bytes + settingsPack.set_int(lt::settings_pack::inactive_up_rate, uploadRateForSlowTorrents() * 1024); // KiB to Bytes + settingsPack.set_int(lt::settings_pack::auto_manage_startup, slowTorrentsInactivityTimer()); } else { - settingsPack.set_int(libt::settings_pack::active_downloads, -1); - settingsPack.set_int(libt::settings_pack::active_seeds, -1); - settingsPack.set_int(libt::settings_pack::active_limit, -1); + settingsPack.set_int(lt::settings_pack::active_downloads, -1); + settingsPack.set_int(lt::settings_pack::active_seeds, -1); + settingsPack.set_int(lt::settings_pack::active_limit, -1); } - settingsPack.set_int(libt::settings_pack::active_tracker_limit, -1); - settingsPack.set_int(libt::settings_pack::active_dht_limit, -1); - settingsPack.set_int(libt::settings_pack::active_lsd_limit, -1); - settingsPack.set_int(libt::settings_pack::alert_queue_size, std::numeric_limits::max() / 2); + settingsPack.set_int(lt::settings_pack::active_tracker_limit, -1); + settingsPack.set_int(lt::settings_pack::active_dht_limit, -1); + settingsPack.set_int(lt::settings_pack::active_lsd_limit, -1); + settingsPack.set_int(lt::settings_pack::alert_queue_size, std::numeric_limits::max() / 2); // Outgoing ports - settingsPack.set_int(libt::settings_pack::outgoing_port, outgoingPortsMin()); - settingsPack.set_int(libt::settings_pack::num_outgoing_ports, outgoingPortsMax() - outgoingPortsMin() + 1); + settingsPack.set_int(lt::settings_pack::outgoing_port, outgoingPortsMin()); + settingsPack.set_int(lt::settings_pack::num_outgoing_ports, outgoingPortsMax() - outgoingPortsMin() + 1); // Include overhead in transfer limits - settingsPack.set_bool(libt::settings_pack::rate_limit_ip_overhead, includeOverheadInLimits()); + settingsPack.set_bool(lt::settings_pack::rate_limit_ip_overhead, includeOverheadInLimits()); // IP address to announce to trackers - settingsPack.set_str(libt::settings_pack::announce_ip, announceIP().toStdString()); + settingsPack.set_str(lt::settings_pack::announce_ip, announceIP().toStdString()); // Super seeding - settingsPack.set_bool(libt::settings_pack::strict_super_seeding, isSuperSeedingEnabled()); + settingsPack.set_bool(lt::settings_pack::strict_super_seeding, isSuperSeedingEnabled()); // * Max connections limit - settingsPack.set_int(libt::settings_pack::connections_limit, maxConnections()); + settingsPack.set_int(lt::settings_pack::connections_limit, maxConnections()); // * Global max upload slots - settingsPack.set_int(libt::settings_pack::unchoke_slots_limit, maxUploads()); + settingsPack.set_int(lt::settings_pack::unchoke_slots_limit, maxUploads()); // uTP switch (btProtocol()) { case BTProtocol::Both: default: - settingsPack.set_bool(libt::settings_pack::enable_incoming_tcp, true); - settingsPack.set_bool(libt::settings_pack::enable_outgoing_tcp, true); - settingsPack.set_bool(libt::settings_pack::enable_incoming_utp, true); - settingsPack.set_bool(libt::settings_pack::enable_outgoing_utp, true); + settingsPack.set_bool(lt::settings_pack::enable_incoming_tcp, true); + settingsPack.set_bool(lt::settings_pack::enable_outgoing_tcp, true); + settingsPack.set_bool(lt::settings_pack::enable_incoming_utp, true); + settingsPack.set_bool(lt::settings_pack::enable_outgoing_utp, true); break; case BTProtocol::TCP: - settingsPack.set_bool(libt::settings_pack::enable_incoming_tcp, true); - settingsPack.set_bool(libt::settings_pack::enable_outgoing_tcp, true); - settingsPack.set_bool(libt::settings_pack::enable_incoming_utp, false); - settingsPack.set_bool(libt::settings_pack::enable_outgoing_utp, false); + settingsPack.set_bool(lt::settings_pack::enable_incoming_tcp, true); + settingsPack.set_bool(lt::settings_pack::enable_outgoing_tcp, true); + settingsPack.set_bool(lt::settings_pack::enable_incoming_utp, false); + settingsPack.set_bool(lt::settings_pack::enable_outgoing_utp, false); break; case BTProtocol::UTP: - settingsPack.set_bool(libt::settings_pack::enable_incoming_tcp, false); - settingsPack.set_bool(libt::settings_pack::enable_outgoing_tcp, false); - settingsPack.set_bool(libt::settings_pack::enable_incoming_utp, true); - settingsPack.set_bool(libt::settings_pack::enable_outgoing_utp, true); + settingsPack.set_bool(lt::settings_pack::enable_incoming_tcp, false); + settingsPack.set_bool(lt::settings_pack::enable_outgoing_tcp, false); + settingsPack.set_bool(lt::settings_pack::enable_incoming_utp, true); + settingsPack.set_bool(lt::settings_pack::enable_outgoing_utp, true); break; } switch (utpMixedMode()) { case MixedModeAlgorithm::TCP: default: - settingsPack.set_int(libt::settings_pack::mixed_mode_algorithm, libt::settings_pack::prefer_tcp); + settingsPack.set_int(lt::settings_pack::mixed_mode_algorithm, lt::settings_pack::prefer_tcp); break; case MixedModeAlgorithm::Proportional: - settingsPack.set_int(libt::settings_pack::mixed_mode_algorithm, libt::settings_pack::peer_proportional); + settingsPack.set_int(lt::settings_pack::mixed_mode_algorithm, lt::settings_pack::peer_proportional); break; } - settingsPack.set_bool(libt::settings_pack::allow_multiple_connections_per_ip, multiConnectionsPerIpEnabled()); + settingsPack.set_bool(lt::settings_pack::allow_multiple_connections_per_ip, multiConnectionsPerIpEnabled()); - settingsPack.set_bool(libt::settings_pack::apply_ip_filter_to_trackers, isTrackerFilteringEnabled()); + settingsPack.set_bool(lt::settings_pack::apply_ip_filter_to_trackers, isTrackerFilteringEnabled()); - settingsPack.set_bool(libt::settings_pack::enable_dht, isDHTEnabled()); + settingsPack.set_bool(lt::settings_pack::enable_dht, isDHTEnabled()); if (isDHTEnabled()) - settingsPack.set_str(libt::settings_pack::dht_bootstrap_nodes, "dht.libtorrent.org:25401,router.bittorrent.com:6881,router.utorrent.com:6881,dht.transmissionbt.com:6881,dht.aelitis.com:6881"); - settingsPack.set_bool(libt::settings_pack::enable_lsd, isLSDEnabled()); + settingsPack.set_str(lt::settings_pack::dht_bootstrap_nodes, "dht.libtorrent.org:25401,router.bittorrent.com:6881,router.utorrent.com:6881,dht.transmissionbt.com:6881,dht.aelitis.com:6881"); + settingsPack.set_bool(lt::settings_pack::enable_lsd, isLSDEnabled()); switch (chokingAlgorithm()) { case ChokingAlgorithm::FixedSlots: default: - settingsPack.set_int(libt::settings_pack::choking_algorithm, libt::settings_pack::fixed_slots_choker); + settingsPack.set_int(lt::settings_pack::choking_algorithm, lt::settings_pack::fixed_slots_choker); break; case ChokingAlgorithm::RateBased: - settingsPack.set_int(libt::settings_pack::choking_algorithm, libt::settings_pack::rate_based_choker); + settingsPack.set_int(lt::settings_pack::choking_algorithm, lt::settings_pack::rate_based_choker); break; } switch (seedChokingAlgorithm()) { case SeedChokingAlgorithm::RoundRobin: - settingsPack.set_int(libt::settings_pack::seed_choking_algorithm, libt::settings_pack::round_robin); + settingsPack.set_int(lt::settings_pack::seed_choking_algorithm, lt::settings_pack::round_robin); break; case SeedChokingAlgorithm::FastestUpload: default: - settingsPack.set_int(libt::settings_pack::seed_choking_algorithm, libt::settings_pack::fastest_upload); + settingsPack.set_int(lt::settings_pack::seed_choking_algorithm, lt::settings_pack::fastest_upload); break; case SeedChokingAlgorithm::AntiLeech: - settingsPack.set_int(libt::settings_pack::seed_choking_algorithm, libt::settings_pack::anti_leech); + settingsPack.set_int(lt::settings_pack::seed_choking_algorithm, lt::settings_pack::anti_leech); break; } } void Session::configurePeerClasses() { - libt::ip_filter f; + lt::ip_filter f; // address_v4::from_string("255.255.255.255") crashes on some people's systems // so instead we use address_v4::broadcast() // Proactively do the same for 0.0.0.0 and address_v4::any() - f.add_rule(libt::address_v4::any() - , libt::address_v4::broadcast() - , 1 << libt::session::global_peer_class_id); + f.add_rule(lt::address_v4::any() + , lt::address_v4::broadcast() + , 1 << lt::session::global_peer_class_id); #if TORRENT_USE_IPV6 // IPv6 may not be available on OS and the parsing // would result in an exception -> abnormal program termination // Affects Windows XP try { - f.add_rule(libt::address_v6::from_string("::0") - , libt::address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") - , 1 << libt::session::global_peer_class_id); + f.add_rule(lt::address_v6::from_string("::0") + , lt::address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") + , 1 << lt::session::global_peer_class_id); } catch (std::exception &) {} #endif // TORRENT_USE_IPV6 if (ignoreLimitsOnLAN()) { // local networks - f.add_rule(libt::address_v4::from_string("10.0.0.0") - , libt::address_v4::from_string("10.255.255.255") - , 1 << libt::session::local_peer_class_id); - f.add_rule(libt::address_v4::from_string("172.16.0.0") - , libt::address_v4::from_string("172.31.255.255") - , 1 << libt::session::local_peer_class_id); - f.add_rule(libt::address_v4::from_string("192.168.0.0") - , libt::address_v4::from_string("192.168.255.255") - , 1 << libt::session::local_peer_class_id); + f.add_rule(lt::address_v4::from_string("10.0.0.0") + , lt::address_v4::from_string("10.255.255.255") + , 1 << lt::session::local_peer_class_id); + f.add_rule(lt::address_v4::from_string("172.16.0.0") + , lt::address_v4::from_string("172.31.255.255") + , 1 << lt::session::local_peer_class_id); + f.add_rule(lt::address_v4::from_string("192.168.0.0") + , lt::address_v4::from_string("192.168.255.255") + , 1 << lt::session::local_peer_class_id); // link local - f.add_rule(libt::address_v4::from_string("169.254.0.0") - , libt::address_v4::from_string("169.254.255.255") - , 1 << libt::session::local_peer_class_id); + f.add_rule(lt::address_v4::from_string("169.254.0.0") + , lt::address_v4::from_string("169.254.255.255") + , 1 << lt::session::local_peer_class_id); // loopback - f.add_rule(libt::address_v4::from_string("127.0.0.0") - , libt::address_v4::from_string("127.255.255.255") - , 1 << libt::session::local_peer_class_id); + f.add_rule(lt::address_v4::from_string("127.0.0.0") + , lt::address_v4::from_string("127.255.255.255") + , 1 << lt::session::local_peer_class_id); #if TORRENT_USE_IPV6 // IPv6 may not be available on OS and the parsing // would result in an exception -> abnormal program termination // Affects Windows XP try { // link local - f.add_rule(libt::address_v6::from_string("fe80::") - , libt::address_v6::from_string("febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff") - , 1 << libt::session::local_peer_class_id); + f.add_rule(lt::address_v6::from_string("fe80::") + , lt::address_v6::from_string("febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff") + , 1 << lt::session::local_peer_class_id); // unique local addresses - f.add_rule(libt::address_v6::from_string("fc00::") - , libt::address_v6::from_string("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") - , 1 << libt::session::local_peer_class_id); + f.add_rule(lt::address_v6::from_string("fc00::") + , lt::address_v6::from_string("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") + , 1 << lt::session::local_peer_class_id); // loopback - f.add_rule(libt::address_v6::from_string("::1") - , libt::address_v6::from_string("::1") - , 1 << libt::session::local_peer_class_id); + f.add_rule(lt::address_v6::from_string("::1") + , lt::address_v6::from_string("::1") + , 1 << lt::session::local_peer_class_id); } catch (std::exception &) {} #endif // TORRENT_USE_IPV6 } m_nativeSession->set_peer_class_filter(f); - libt::peer_class_type_filter peerClassTypeFilter; - peerClassTypeFilter.add(libt::peer_class_type_filter::tcp_socket, libt::session::tcp_peer_class_id); - peerClassTypeFilter.add(libt::peer_class_type_filter::ssl_tcp_socket, libt::session::tcp_peer_class_id); - peerClassTypeFilter.add(libt::peer_class_type_filter::i2p_socket, libt::session::tcp_peer_class_id); + lt::peer_class_type_filter peerClassTypeFilter; + peerClassTypeFilter.add(lt::peer_class_type_filter::tcp_socket, lt::session::tcp_peer_class_id); + peerClassTypeFilter.add(lt::peer_class_type_filter::ssl_tcp_socket, lt::session::tcp_peer_class_id); + peerClassTypeFilter.add(lt::peer_class_type_filter::i2p_socket, lt::session::tcp_peer_class_id); if (!isUTPRateLimited()) { - peerClassTypeFilter.disallow(libt::peer_class_type_filter::utp_socket - , libt::session::global_peer_class_id); - peerClassTypeFilter.disallow(libt::peer_class_type_filter::ssl_utp_socket - , libt::session::global_peer_class_id); + peerClassTypeFilter.disallow(lt::peer_class_type_filter::utp_socket + , lt::session::global_peer_class_id); + peerClassTypeFilter.disallow(lt::peer_class_type_filter::ssl_utp_socket + , lt::session::global_peer_class_id); } m_nativeSession->set_peer_class_type_filter(peerClassTypeFilter); } @@ -1603,12 +1602,12 @@ void Session::banIP(const QString &ip) { QStringList bannedIPs = m_bannedIPs; if (!bannedIPs.contains(ip)) { - libt::ip_filter filter = m_nativeSession->get_ip_filter(); + lt::ip_filter filter = m_nativeSession->get_ip_filter(); boost::system::error_code ec; - const libt::address addr = libt::address::from_string(ip.toLatin1().constData(), ec); + const lt::address addr = lt::address::from_string(ip.toLatin1().constData(), ec); Q_ASSERT(!ec); if (ec) return; - filter.add_rule(addr, addr, libt::ip_filter::blocked); + filter.add_rule(addr, addr, lt::ip_filter::blocked); m_nativeSession->set_ip_filter(filter); bannedIPs << ip; @@ -1638,14 +1637,14 @@ bool Session::deleteTorrent(const QString &hash, const bool deleteLocalFiles) m_removingTorrents[torrent->hash()] = {torrent->name(), torrent->savePath(true), deleteLocalFiles}; else m_removingTorrents[torrent->hash()] = {torrent->name(), "", deleteLocalFiles}; - m_nativeSession->remove_torrent(torrent->nativeHandle(), libt::session::delete_files); + m_nativeSession->remove_torrent(torrent->nativeHandle(), lt::session::delete_files); } else { m_removingTorrents[torrent->hash()] = {torrent->name(), "", deleteLocalFiles}; QStringList unwantedFiles; if (torrent->hasMetadata()) unwantedFiles = torrent->absoluteFilePathsUnwanted(); - m_nativeSession->remove_torrent(torrent->nativeHandle(), libt::session::delete_partfile); + m_nativeSession->remove_torrent(torrent->nativeHandle(), lt::session::delete_partfile); // Remove unwanted and incomplete files for (const QString &unwantedFile : asConst(unwantedFiles)) { qDebug("Removing unwanted file: %s", qUtf8Printable(unwantedFile)); @@ -1674,7 +1673,7 @@ bool Session::cancelLoadMetadata(const InfoHash &hash) if (!m_loadedMetadata.contains(hash)) return false; m_loadedMetadata.remove(hash); - const libt::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.status(LTStatusFlags {0}).has_metadata) { @@ -1684,7 +1683,7 @@ bool Session::cancelLoadMetadata(const InfoHash &hash) } // Remove it from session - m_nativeSession->remove_torrent(torrent, libt::session::delete_files); + m_nativeSession->remove_torrent(torrent, lt::session::delete_files); qDebug("Preloaded torrent deleted."); return true; } @@ -1846,7 +1845,7 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne // If empty then Automatic mode, otherwise Manual mode QString savePath = params.savePath.isEmpty() ? categorySavePath(params.category) : params.savePath; - libt::add_torrent_params p; + lt::add_torrent_params p; InfoHash hash; const bool fromMagnetUri = magnetUri.isValid(); @@ -1856,7 +1855,7 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne if (m_loadedMetadata.contains(hash)) { // Adding preloaded torrent m_loadedMetadata.remove(hash); - libt::torrent_handle handle = m_nativeSession->find_torrent(hash); + lt::torrent_handle handle = m_nativeSession->find_torrent(hash); --m_extraLimit; try { @@ -1924,26 +1923,26 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne // Preallocation mode if (isPreallocationEnabled()) - p.storage_mode = libt::storage_mode_allocate; + p.storage_mode = lt::storage_mode_allocate; else - p.storage_mode = libt::storage_mode_sparse; + p.storage_mode = lt::storage_mode_sparse; - p.flags |= libt::add_torrent_params::flag_paused; // Start in pause - p.flags &= ~libt::add_torrent_params::flag_auto_managed; // Because it is added in paused state - p.flags &= ~libt::add_torrent_params::flag_duplicate_is_error; // Already checked + p.flags |= lt::add_torrent_params::flag_paused; // Start in pause + p.flags &= ~lt::add_torrent_params::flag_auto_managed; // Because it is added in paused state + p.flags &= ~lt::add_torrent_params::flag_duplicate_is_error; // Already checked // Seeding mode // Skip checking and directly start seeding (new in libtorrent v0.15) if (params.skipChecking) - p.flags |= libt::add_torrent_params::flag_seed_mode; + p.flags |= lt::add_torrent_params::flag_seed_mode; else - p.flags &= ~libt::add_torrent_params::flag_seed_mode; + p.flags &= ~lt::add_torrent_params::flag_seed_mode; if (!fromMagnetUri) { if (params.restored) { // Set torrent fast resume data p.resume_data = std::vector {fastresumeData.constData(), fastresumeData.constData() + fastresumeData.size()}; - p.flags |= libt::add_torrent_params::flag_use_resume_save_path; + p.flags |= lt::add_torrent_params::flag_use_resume_save_path; } else { Q_ASSERT(p.file_priorities.empty()); @@ -1963,7 +1962,7 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne if (params.restored && !params.paused) { // Make sure the torrent will restored in "paused" state // Then we will start it if needed - p.flags |= libt::add_torrent_params::flag_stop_when_ready; + p.flags |= lt::add_torrent_params::flag_stop_when_ready; } // Limits @@ -2027,14 +2026,14 @@ bool Session::loadMetadata(const MagnetUri &magnetUri) qDebug(" -> Hash: %s", qUtf8Printable(hash)); qDebug(" -> Name: %s", qUtf8Printable(name)); - libt::add_torrent_params p = magnetUri.addTorrentParams(); + lt::add_torrent_params p = magnetUri.addTorrentParams(); // Flags // Preallocation mode if (isPreallocationEnabled()) - p.storage_mode = libt::storage_mode_allocate; + p.storage_mode = lt::storage_mode_allocate; else - p.storage_mode = libt::storage_mode_sparse; + p.storage_mode = lt::storage_mode_sparse; // Limits p.max_connections = maxConnectionsPerTorrent(); @@ -2044,14 +2043,14 @@ bool Session::loadMetadata(const MagnetUri &magnetUri) p.save_path = Utils::Fs::toNativePath(savePath).toStdString(); // Forced start - p.flags &= ~libt::add_torrent_params::flag_paused; - p.flags &= ~libt::add_torrent_params::flag_auto_managed; + 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 |= libt::add_torrent_params::flag_upload_mode; + p.flags |= lt::add_torrent_params::flag_upload_mode; // Adding torrent to BitTorrent session - libt::error_code ec; - libt::torrent_handle h = m_nativeSession->add_torrent(p, ec); + lt::error_code ec; + lt::torrent_handle h = m_nativeSession->add_torrent(p, ec); if (ec) return false; // waiting for metadata... @@ -2111,7 +2110,7 @@ void Session::saveResumeData() generateResumeData(true); while (m_numResumeData > 0) { - std::vector alerts; + std::vector alerts; getPendingAlerts(alerts, 30 * 1000); if (alerts.empty()) { fprintf(stderr, " aborting with %d outstanding torrents to save resume data for\n", m_numResumeData); @@ -2120,8 +2119,8 @@ void Session::saveResumeData() for (const auto a : alerts) { switch (a->type()) { - case libt::save_resume_data_failed_alert::alert_type: - case libt::save_resume_data_alert::alert_type: + case lt::save_resume_data_failed_alert::alert_type: + case lt::save_resume_data_alert::alert_type: dispatchTorrentAlert(a); break; } @@ -3422,7 +3421,7 @@ void Session::handleTorrentResumeDataReady(TorrentHandle *const torrent, const l // isn't cheap too. QByteArray out; - libt::bencode(std::back_inserter(out), data); + lt::bencode(std::back_inserter(out), data); const QString filename = QString("%1.fastresume").arg(torrent->hash()); QMetaObject::invokeMethod(m_resumeDataSavingManager, "save", @@ -3518,7 +3517,7 @@ void Session::disableIPFilter() // Add the banned IPs after the IPFilter disabling // which creates an empty filter and overrides all previously // applied bans. - libt::ip_filter filter; + lt::ip_filter filter; processBannedIPs(filter); m_nativeSession->set_ip_filter(filter); } @@ -3701,7 +3700,7 @@ void Session::refresh() void Session::handleIPFilterParsed(const int ruleCount) { if (m_filterParser) { - libt::ip_filter filter = m_filterParser->IPfilter(); + lt::ip_filter filter = m_filterParser->IPfilter(); processBannedIPs(filter); m_nativeSession->set_ip_filter(filter); } @@ -3711,7 +3710,7 @@ void Session::handleIPFilterParsed(const int ruleCount) void Session::handleIPFilterError() { - libt::ip_filter filter; + lt::ip_filter filter; processBannedIPs(filter); m_nativeSession->set_ip_filter(filter); @@ -3719,12 +3718,12 @@ void Session::handleIPFilterError() emit IPFilterParsed(true, 0); } -void Session::getPendingAlerts(std::vector &out, const ulong time) +void Session::getPendingAlerts(std::vector &out, const ulong time) { Q_ASSERT(out.empty()); if (time > 0) - m_nativeSession->wait_for_alert(libt::milliseconds(time)); + m_nativeSession->wait_for_alert(lt::milliseconds(time)); m_nativeSession->pop_alerts(&out); } @@ -3741,82 +3740,82 @@ void Session::setCreateTorrentSubfolder(const bool value) // Read alerts sent by the BitTorrent session void Session::readAlerts() { - std::vector alerts; + std::vector alerts; getPendingAlerts(alerts); for (const auto a : alerts) handleAlert(a); } -void Session::handleAlert(const libt::alert *a) +void Session::handleAlert(const lt::alert *a) { try { switch (a->type()) { - case libt::stats_alert::alert_type: - case libt::file_renamed_alert::alert_type: - case libt::file_completed_alert::alert_type: - case libt::torrent_finished_alert::alert_type: - case libt::save_resume_data_alert::alert_type: - case libt::save_resume_data_failed_alert::alert_type: - case libt::storage_moved_alert::alert_type: - case libt::storage_moved_failed_alert::alert_type: - case libt::torrent_paused_alert::alert_type: - case libt::torrent_resumed_alert::alert_type: - case libt::tracker_error_alert::alert_type: - case libt::tracker_reply_alert::alert_type: - case libt::tracker_warning_alert::alert_type: - case libt::fastresume_rejected_alert::alert_type: - case libt::torrent_checked_alert::alert_type: + case lt::stats_alert::alert_type: + case lt::file_renamed_alert::alert_type: + case lt::file_completed_alert::alert_type: + case lt::torrent_finished_alert::alert_type: + case lt::save_resume_data_alert::alert_type: + case lt::save_resume_data_failed_alert::alert_type: + case lt::storage_moved_alert::alert_type: + case lt::storage_moved_failed_alert::alert_type: + case lt::torrent_paused_alert::alert_type: + case lt::torrent_resumed_alert::alert_type: + case lt::tracker_error_alert::alert_type: + case lt::tracker_reply_alert::alert_type: + case lt::tracker_warning_alert::alert_type: + case lt::fastresume_rejected_alert::alert_type: + case lt::torrent_checked_alert::alert_type: dispatchTorrentAlert(a); break; - case libt::metadata_received_alert::alert_type: - handleMetadataReceivedAlert(static_cast(a)); + case lt::metadata_received_alert::alert_type: + handleMetadataReceivedAlert(static_cast(a)); dispatchTorrentAlert(a); break; - case libt::state_update_alert::alert_type: - handleStateUpdateAlert(static_cast(a)); + case lt::state_update_alert::alert_type: + handleStateUpdateAlert(static_cast(a)); break; - case libt::session_stats_alert::alert_type: - handleSessionStatsAlert(static_cast(a)); + case lt::session_stats_alert::alert_type: + handleSessionStatsAlert(static_cast(a)); break; - case libt::file_error_alert::alert_type: - handleFileErrorAlert(static_cast(a)); + case lt::file_error_alert::alert_type: + handleFileErrorAlert(static_cast(a)); break; - case libt::add_torrent_alert::alert_type: - handleAddTorrentAlert(static_cast(a)); + case lt::add_torrent_alert::alert_type: + handleAddTorrentAlert(static_cast(a)); break; - case libt::torrent_removed_alert::alert_type: - handleTorrentRemovedAlert(static_cast(a)); + case lt::torrent_removed_alert::alert_type: + handleTorrentRemovedAlert(static_cast(a)); break; - case libt::torrent_deleted_alert::alert_type: - handleTorrentDeletedAlert(static_cast(a)); + case lt::torrent_deleted_alert::alert_type: + handleTorrentDeletedAlert(static_cast(a)); break; - case libt::torrent_delete_failed_alert::alert_type: - handleTorrentDeleteFailedAlert(static_cast(a)); + case lt::torrent_delete_failed_alert::alert_type: + handleTorrentDeleteFailedAlert(static_cast(a)); break; - case libt::portmap_error_alert::alert_type: - handlePortmapWarningAlert(static_cast(a)); + case lt::portmap_error_alert::alert_type: + handlePortmapWarningAlert(static_cast(a)); break; - case libt::portmap_alert::alert_type: - handlePortmapAlert(static_cast(a)); + case lt::portmap_alert::alert_type: + handlePortmapAlert(static_cast(a)); break; - case libt::peer_blocked_alert::alert_type: - handlePeerBlockedAlert(static_cast(a)); + case lt::peer_blocked_alert::alert_type: + handlePeerBlockedAlert(static_cast(a)); break; - case libt::peer_ban_alert::alert_type: - handlePeerBanAlert(static_cast(a)); + case lt::peer_ban_alert::alert_type: + handlePeerBanAlert(static_cast(a)); break; - case libt::url_seed_alert::alert_type: - handleUrlSeedAlert(static_cast(a)); + case lt::url_seed_alert::alert_type: + handleUrlSeedAlert(static_cast(a)); break; - case libt::listen_succeeded_alert::alert_type: - handleListenSucceededAlert(static_cast(a)); + case lt::listen_succeeded_alert::alert_type: + handleListenSucceededAlert(static_cast(a)); break; - case libt::listen_failed_alert::alert_type: - handleListenFailedAlert(static_cast(a)); + case lt::listen_failed_alert::alert_type: + handleListenFailedAlert(static_cast(a)); break; - case libt::external_ip_alert::alert_type: - handleExternalIPAlert(static_cast(a)); + case lt::external_ip_alert::alert_type: + handleExternalIPAlert(static_cast(a)); break; } } @@ -3825,14 +3824,14 @@ void Session::handleAlert(const libt::alert *a) } } -void Session::dispatchTorrentAlert(const libt::alert *a) +void Session::dispatchTorrentAlert(const lt::alert *a) { - TorrentHandle *const torrent = m_torrents.value(static_cast(a)->handle.info_hash()); + TorrentHandle *const torrent = m_torrents.value(static_cast(a)->handle.info_hash()); if (torrent) torrent->handleAlert(a); } -void Session::createTorrentHandle(const libt::torrent_handle &nativeHandle) +void Session::createTorrentHandle(const lt::torrent_handle &nativeHandle) { // Magnet added for preload its metadata if (!m_addingTorrents.contains(nativeHandle.info_hash())) return; @@ -3887,7 +3886,7 @@ void Session::createTorrentHandle(const libt::torrent_handle &nativeHandle) emit torrentNew(torrent); } -void Session::handleAddTorrentAlert(const libt::add_torrent_alert *p) +void Session::handleAddTorrentAlert(const lt::add_torrent_alert *p) { if (p->error) { qDebug("/!\\ Error: Failed to add torrent!"); @@ -3900,7 +3899,7 @@ void Session::handleAddTorrentAlert(const libt::add_torrent_alert *p) } } -void Session::handleTorrentRemovedAlert(const libt::torrent_removed_alert *p) +void Session::handleTorrentRemovedAlert(const lt::torrent_removed_alert *p) { const InfoHash infoHash {p->info_hash}; @@ -3916,7 +3915,7 @@ void Session::handleTorrentRemovedAlert(const libt::torrent_removed_alert *p) } } -void Session::handleTorrentDeletedAlert(const libt::torrent_deleted_alert *p) +void Session::handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p) { const InfoHash infoHash {p->info_hash}; @@ -3928,7 +3927,7 @@ void Session::handleTorrentDeletedAlert(const libt::torrent_deleted_alert *p) LogMsg(tr("'%1' was removed from the transfer list and hard disk.", "'xxx.avi' was removed...").arg(tmpRemovingTorrentData.name)); } -void Session::handleTorrentDeleteFailedAlert(const libt::torrent_delete_failed_alert *p) +void Session::handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_alert *p) { const InfoHash infoHash {p->info_hash}; @@ -3944,7 +3943,7 @@ void Session::handleTorrentDeleteFailedAlert(const libt::torrent_delete_failed_a , Log::CRITICAL); } -void Session::handleMetadataReceivedAlert(const libt::metadata_received_alert *p) +void Session::handleMetadataReceivedAlert(const lt::metadata_received_alert *p) { const InfoHash hash {p->handle.info_hash()}; @@ -3952,11 +3951,11 @@ void Session::handleMetadataReceivedAlert(const libt::metadata_received_alert *p --m_extraLimit; adjustLimits(); m_loadedMetadata[hash] = TorrentInfo(p->handle.torrent_file()); - m_nativeSession->remove_torrent(p->handle, libt::session::delete_files); + m_nativeSession->remove_torrent(p->handle, lt::session::delete_files); } } -void Session::handleFileErrorAlert(const libt::file_error_alert *p) +void Session::handleFileErrorAlert(const lt::file_error_alert *p) { qDebug() << Q_FUNC_INFO; // NOTE: Check this function! @@ -3974,18 +3973,18 @@ void Session::handleFileErrorAlert(const libt::file_error_alert *p) } } -void Session::handlePortmapWarningAlert(const libt::portmap_error_alert *p) +void Session::handlePortmapWarningAlert(const lt::portmap_error_alert *p) { Logger::instance()->addMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(QString::fromStdString(p->message())), Log::CRITICAL); } -void Session::handlePortmapAlert(const libt::portmap_alert *p) +void Session::handlePortmapAlert(const lt::portmap_alert *p) { qDebug("UPnP Success, msg: %s", p->message().c_str()); Logger::instance()->addMessage(tr("UPnP/NAT-PMP: Port mapping successful, message: %1").arg(QString::fromStdString(p->message())), Log::INFO); } -void Session::handlePeerBlockedAlert(const libt::peer_blocked_alert *p) +void Session::handlePeerBlockedAlert(const lt::peer_blocked_alert *p) { boost::system::error_code ec; #if LIBTORRENT_VERSION_NUM < 10200 @@ -3995,22 +3994,22 @@ void Session::handlePeerBlockedAlert(const libt::peer_blocked_alert *p) #endif QString reason; switch (p->reason) { - case libt::peer_blocked_alert::ip_filter: + case lt::peer_blocked_alert::ip_filter: reason = tr("due to IP filter.", "this peer was blocked due to ip filter."); break; - case libt::peer_blocked_alert::port_filter: + case lt::peer_blocked_alert::port_filter: reason = tr("due to port filter.", "this peer was blocked due to port filter."); break; - case libt::peer_blocked_alert::i2p_mixed: + case lt::peer_blocked_alert::i2p_mixed: reason = tr("due to i2p mixed mode restrictions.", "this peer was blocked due to i2p mixed mode restrictions."); break; - case libt::peer_blocked_alert::privileged_ports: + case lt::peer_blocked_alert::privileged_ports: reason = tr("because it has a low port.", "this peer was blocked because it has a low port."); break; - case libt::peer_blocked_alert::utp_disabled: + case lt::peer_blocked_alert::utp_disabled: reason = tr("because %1 is disabled.", "this peer was blocked because uTP is disabled.").arg(QString::fromUtf8(C_UTP)); // don't translate μTP break; - case libt::peer_blocked_alert::tcp_disabled: + case lt::peer_blocked_alert::tcp_disabled: reason = tr("because %1 is disabled.", "this peer was blocked because TCP is disabled.").arg("TCP"); // don't translate TCP break; } @@ -4019,7 +4018,7 @@ void Session::handlePeerBlockedAlert(const libt::peer_blocked_alert *p) Logger::instance()->addPeer(QString::fromLatin1(ip.c_str()), true, reason); } -void Session::handlePeerBanAlert(const libt::peer_ban_alert *p) +void Session::handlePeerBanAlert(const lt::peer_ban_alert *p) { boost::system::error_code ec; const std::string ip = p->ip.address().to_string(ec); @@ -4027,22 +4026,22 @@ void Session::handlePeerBanAlert(const libt::peer_ban_alert *p) Logger::instance()->addPeer(QString::fromLatin1(ip.c_str()), false); } -void Session::handleUrlSeedAlert(const libt::url_seed_alert *p) +void Session::handleUrlSeedAlert(const lt::url_seed_alert *p) { Logger::instance()->addMessage(tr("URL seed lookup failed for URL: '%1', message: %2") .arg(QString::fromStdString(p->server_url())) .arg(QString::fromStdString(p->message())), Log::CRITICAL); } -void Session::handleListenSucceededAlert(const libt::listen_succeeded_alert *p) +void Session::handleListenSucceededAlert(const lt::listen_succeeded_alert *p) { boost::system::error_code ec; QString proto = "TCP"; - if (p->sock_type == libt::listen_succeeded_alert::udp) + if (p->sock_type == lt::listen_succeeded_alert::udp) proto = "UDP"; - else if (p->sock_type == libt::listen_succeeded_alert::tcp) + else if (p->sock_type == lt::listen_succeeded_alert::tcp) proto = "TCP"; - else if (p->sock_type == libt::listen_succeeded_alert::tcp_ssl) + else if (p->sock_type == lt::listen_succeeded_alert::tcp_ssl) proto = "TCP_SSL"; qDebug() << "Successfully listening on " << proto << p->endpoint.address().to_string(ec).c_str() << '/' << p->endpoint.port(); Logger::instance()->addMessage( @@ -4050,26 +4049,26 @@ void Session::handleListenSucceededAlert(const libt::listen_succeeded_alert *p) .arg(p->endpoint.address().to_string(ec).c_str(), proto, QString::number(p->endpoint.port())), Log::INFO); // Force reannounce on all torrents because some trackers blacklist some ports - std::vector torrents = m_nativeSession->get_torrents(); - std::vector::iterator it = torrents.begin(); - std::vector::iterator itend = torrents.end(); + std::vector torrents = m_nativeSession->get_torrents(); + std::vector::iterator it = torrents.begin(); + std::vector::iterator itend = torrents.end(); for ( ; it != itend; ++it) it->force_reannounce(); } -void Session::handleListenFailedAlert(const libt::listen_failed_alert *p) +void Session::handleListenFailedAlert(const lt::listen_failed_alert *p) { boost::system::error_code ec; QString proto = "TCP"; - if (p->sock_type == libt::listen_failed_alert::udp) + if (p->sock_type == lt::listen_failed_alert::udp) proto = "UDP"; - else if (p->sock_type == libt::listen_failed_alert::tcp) + else if (p->sock_type == lt::listen_failed_alert::tcp) proto = "TCP"; - else if (p->sock_type == libt::listen_failed_alert::tcp_ssl) + else if (p->sock_type == lt::listen_failed_alert::tcp_ssl) proto = "TCP_SSL"; - else if (p->sock_type == libt::listen_failed_alert::i2p) + else if (p->sock_type == lt::listen_failed_alert::i2p) proto = "I2P"; - else if (p->sock_type == libt::listen_failed_alert::socks5) + else if (p->sock_type == lt::listen_failed_alert::socks5) proto = "SOCKS5"; qDebug() << "Failed listening on " << proto << p->endpoint.address().to_string(ec).c_str() << '/' << p->endpoint.port(); Logger::instance()->addMessage( @@ -4080,13 +4079,13 @@ void Session::handleListenFailedAlert(const libt::listen_failed_alert *p) , Log::CRITICAL); } -void Session::handleExternalIPAlert(const libt::external_ip_alert *p) +void Session::handleExternalIPAlert(const lt::external_ip_alert *p) { boost::system::error_code ec; Logger::instance()->addMessage(tr("External IP: %1", "e.g. External IP: 192.168.0.1").arg(p->external_address.to_string(ec).c_str()), Log::INFO); } -void Session::handleSessionStatsAlert(const libt::session_stats_alert *p) +void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) { const qreal interval = m_statsUpdateTimer.restart() / 1000.; @@ -4151,9 +4150,9 @@ void Session::handleSessionStatsAlert(const libt::session_stats_alert *p) emit statsUpdated(); } -void Session::handleStateUpdateAlert(const libt::state_update_alert *p) +void Session::handleStateUpdateAlert(const lt::state_update_alert *p) { - for (const libt::torrent_status &status : p->status) { + for (const lt::torrent_status &status : p->status) { TorrentHandle *const torrent = m_torrents.value(status.info_hash); if (torrent) torrent->handleStateUpdate(status); @@ -4202,10 +4201,10 @@ namespace torrentParams.restored = true; torrentParams.skipChecking = false; - libt::error_code ec; - libt::bdecode_node fast; - libt::bdecode(data.constData(), data.constData() + data.size(), fast, ec); - if (ec || (fast.type() != libt::bdecode_node::dict_t)) return false; + lt::error_code ec; + lt::bdecode_node fast; + lt::bdecode(data.constData(), data.constData() + data.size(), fast, ec); + if (ec || (fast.type() != lt::bdecode_node::dict_t)) return false; torrentParams.savePath = Profile::instance().fromPortablePath( Utils::Fs::fromNativePath(fromLTString(fast.dict_find_string_value("qBt-savePath")))); @@ -4245,7 +4244,7 @@ namespace return true; } - void torrentQueuePositionUp(const libt::torrent_handle &handle) + void torrentQueuePositionUp(const lt::torrent_handle &handle) { try { handle.queue_position_up(); @@ -4255,7 +4254,7 @@ namespace } } - void torrentQueuePositionDown(const libt::torrent_handle &handle) + void torrentQueuePositionDown(const lt::torrent_handle &handle) { try { handle.queue_position_down(); @@ -4265,7 +4264,7 @@ namespace } } - void torrentQueuePositionTop(const libt::torrent_handle &handle) + void torrentQueuePositionTop(const lt::torrent_handle &handle) { try { handle.queue_position_top(); @@ -4275,7 +4274,7 @@ namespace } } - void torrentQueuePositionBottom(const libt::torrent_handle &handle) + void torrentQueuePositionBottom(const lt::torrent_handle &handle) { try { handle.queue_position_bottom(); diff --git a/src/base/bittorrent/torrentcreatorthread.cpp b/src/base/bittorrent/torrentcreatorthread.cpp index fff8a15ca..681519fbd 100644 --- a/src/base/bittorrent/torrentcreatorthread.cpp +++ b/src/base/bittorrent/torrentcreatorthread.cpp @@ -62,7 +62,6 @@ namespace } } -namespace libt = libtorrent; using namespace BitTorrent; TorrentCreatorThread::TorrentCreatorThread(QObject *parent) @@ -97,9 +96,9 @@ void TorrentCreatorThread::run() const QString parentPath = Utils::Fs::branchPath(m_params.inputPath) + '/'; // Adding files to the torrent - libt::file_storage fs; + lt::file_storage fs; if (QFileInfo(m_params.inputPath).isFile()) { - libt::add_files(fs, Utils::Fs::toNativePath(m_params.inputPath).toStdString(), fileFilter); + lt::add_files(fs, Utils::Fs::toNativePath(m_params.inputPath).toStdString(), fileFilter); } else { // need to sort the file names by natural sort order @@ -137,8 +136,8 @@ void TorrentCreatorThread::run() if (isInterruptionRequested()) return; - libt::create_torrent newTorrent(fs, m_params.pieceSize, -1 - , (m_params.isAlignmentOptimized ? libt::create_torrent::optimize_alignment : CreateFlags {})); + lt::create_torrent newTorrent(fs, m_params.pieceSize, -1 + , (m_params.isAlignmentOptimized ? lt::create_torrent::optimize_alignment : CreateFlags {})); // Add url seeds for (QString seed : asConst(m_params.urlSeeds)) { @@ -158,7 +157,7 @@ void TorrentCreatorThread::run() if (isInterruptionRequested()) return; // calculate the hash for all pieces - libt::set_piece_hashes(newTorrent, Utils::Fs::toNativePath(parentPath).toStdString() + lt::set_piece_hashes(newTorrent, Utils::Fs::toNativePath(parentPath).toStdString() , [this, &newTorrent](const int n) { sendProgressSignal(n, newTorrent.num_pieces()); }); // Set qBittorrent as creator and add user comment to // torrent_info structure @@ -169,7 +168,7 @@ void TorrentCreatorThread::run() if (isInterruptionRequested()) return; - libt::entry entry = newTorrent.generate(); + lt::entry entry = newTorrent.generate(); // add source field if (!m_params.source.isEmpty()) @@ -190,7 +189,7 @@ void TorrentCreatorThread::run() if (isInterruptionRequested()) return; - libt::bencode(std::ostream_iterator(outfile), entry); + lt::bencode(std::ostream_iterator(outfile), entry); outfile.close(); emit updateProgress(100); @@ -206,9 +205,9 @@ int TorrentCreatorThread::calculateTotalPieces(const QString &inputPath, const i if (inputPath.isEmpty()) return 0; - libt::file_storage fs; - libt::add_files(fs, Utils::Fs::toNativePath(inputPath).toStdString(), fileFilter); + lt::file_storage fs; + lt::add_files(fs, Utils::Fs::toNativePath(inputPath).toStdString(), fileFilter); - return libt::create_torrent(fs, pieceSize, -1 - , (isAlignmentOptimized ? libt::create_torrent::optimize_alignment : CreateFlags {})).num_pieces(); + return lt::create_torrent(fs, pieceSize, -1 + , (isAlignmentOptimized ? lt::create_torrent::optimize_alignment : CreateFlags {})).num_pieces(); } diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index 623bc9875..4f0092980 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -59,15 +59,14 @@ namespace #endif } -namespace libt = libtorrent; using namespace BitTorrent; TorrentInfo::TorrentInfo(NativeConstPtr nativeInfo) { #if (LIBTORRENT_VERSION_NUM < 10200) - m_nativeInfo = boost::const_pointer_cast(nativeInfo); + m_nativeInfo = boost::const_pointer_cast(nativeInfo); #else - m_nativeInfo = std::const_pointer_cast(nativeInfo); + m_nativeInfo = std::const_pointer_cast(nativeInfo); #endif } @@ -88,9 +87,9 @@ TorrentInfo TorrentInfo::load(const QByteArray &data, QString *error) noexcept // used in `torrent_info()` constructor const int depthLimit = 100; const int tokenLimit = 10000000; - libt::error_code ec; + lt::error_code ec; - libt::bdecode_node node; + lt::bdecode_node node; bdecode(data.constData(), (data.constData() + data.size()), node, ec , nullptr, depthLimit, tokenLimit); if (ec) { @@ -99,7 +98,7 @@ TorrentInfo TorrentInfo::load(const QByteArray &data, QString *error) noexcept return TorrentInfo(); } - TorrentInfo info {NativePtr(new libt::torrent_info(node, ec))}; + TorrentInfo info {NativePtr(new lt::torrent_info(node, ec))}; if (ec) { if (error) *error = QString::fromStdString(ec.message()); @@ -270,7 +269,7 @@ QList TorrentInfo::trackers() const if (!isValid()) return {}; QList trackers; - for (const libt::announce_entry &tracker : m_nativeInfo->trackers()) + for (const lt::announce_entry &tracker : m_nativeInfo->trackers()) trackers.append(tracker); return trackers; @@ -281,8 +280,8 @@ QList TorrentInfo::urlSeeds() const if (!isValid()) return {}; QList urlSeeds; - for (const libt::web_seed_entry &webSeed : m_nativeInfo->web_seeds()) - if (webSeed.type == libt::web_seed_entry::url_seed) + for (const lt::web_seed_entry &webSeed : m_nativeInfo->web_seeds()) + if (webSeed.type == lt::web_seed_entry::url_seed) urlSeeds.append(QUrl(webSeed.url.c_str())); return urlSeeds; @@ -312,13 +311,13 @@ QVector TorrentInfo::fileIndicesForPiece(const int pieceIndex) const if (!isValid() || (pieceIndex < 0) || (pieceIndex >= piecesCount())) return {}; - const std::vector files( + const std::vector files( nativeInfo()->map_block(LTPieceIndex {pieceIndex}, 0 , nativeInfo()->piece_size(LTPieceIndex {pieceIndex}))); QVector res; res.reserve(int(files.size())); std::transform(files.begin(), files.end(), std::back_inserter(res), - [](const libt::file_slice &s) { return static_cast(s.file_index); }); + [](const lt::file_slice &s) { return static_cast(s.file_index); }); return res; } @@ -361,7 +360,7 @@ TorrentInfo::PieceRange TorrentInfo::filePieces(const int fileIndex) const return {}; } - const libt::file_storage &files = nativeInfo()->files(); + const lt::file_storage &files = nativeInfo()->files(); const auto fileSize = files.file_size(LTFileIndex {fileIndex}); const auto fileOffset = files.file_offset(LTFileIndex {fileIndex}); return makeInterval(static_cast(fileOffset / pieceLength()), From 4b263f057dfe1e656ebd7f1014efa57fb2616724 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 3 Apr 2019 14:23:35 +0800 Subject: [PATCH 2/4] Use newer libtorrent API This commit covers session.cpp only. --- src/base/bittorrent/session.cpp | 253 ++++++++++++++++++++++++-------- 1 file changed, 189 insertions(+), 64 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index acdecb173..0f5f11d4c 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -395,25 +395,29 @@ Session::Session(QObject *parent) pack.set_bool(lt::settings_pack::listen_system_port_fallback, false); pack.set_str(lt::settings_pack::user_agent, USER_AGENT); pack.set_bool(lt::settings_pack::use_dht_as_fallback, false); - // 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); // Speed up exit pack.set_int(lt::settings_pack::stop_tracker_timeout, 1); pack.set_int(lt::settings_pack::auto_scrape_interval, 1200); // 20 minutes pack.set_int(lt::settings_pack::auto_scrape_min_interval, 900); // 15 minutes pack.set_int(lt::settings_pack::connection_speed, 20); // default is 10 pack.set_bool(lt::settings_pack::no_connect_privileged_ports, false); - // 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); // libtorrent 1.1 enables UPnP & NAT-PMP by default // turn them off before `lt::session` ctor to avoid split second effects pack.set_bool(lt::settings_pack::enable_upnp, false); pack.set_bool(lt::settings_pack::enable_natpmp, false); pack.set_bool(lt::settings_pack::upnp_ignore_nonrouters, true); + +#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 + configure(pack); m_nativeSession = new lt::session {pack, LTSessionFlags {0}}; @@ -1859,7 +1863,11 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne --m_extraLimit; try { +#if (LIBTORRENT_VERSION_NUM < 10200) handle.auto_managed(false); +#else + handle.set_flags(lt::torrent_flags::auto_managed); +#endif handle.pause(); } catch (std::exception &) {} @@ -1927,16 +1935,32 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne else p.storage_mode = lt::storage_mode_sparse; +#if (LIBTORRENT_VERSION_NUM < 10200) p.flags |= lt::add_torrent_params::flag_paused; // Start in pause p.flags &= ~lt::add_torrent_params::flag_auto_managed; // Because it is added in paused state p.flags &= ~lt::add_torrent_params::flag_duplicate_is_error; // Already checked +#else + p.flags |= lt::torrent_flags::paused; // Start in pause + p.flags &= ~lt::torrent_flags::auto_managed; // Because it is added in paused state + p.flags &= ~lt::torrent_flags::duplicate_is_error; // Already checked +#endif // Seeding mode // Skip checking and directly start seeding (new in libtorrent v0.15) - if (params.skipChecking) + if (params.skipChecking) { +#if (LIBTORRENT_VERSION_NUM < 10200) p.flags |= lt::add_torrent_params::flag_seed_mode; - else +#else + p.flags |= lt::torrent_flags::seed_mode; +#endif + } + else { +#if (LIBTORRENT_VERSION_NUM < 10200) p.flags &= ~lt::add_torrent_params::flag_seed_mode; +#else + p.flags &= ~lt::torrent_flags::seed_mode; +#endif +} if (!fromMagnetUri) { if (params.restored) { @@ -1962,7 +1986,11 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne if (params.restored && !params.paused) { // Make sure the torrent will restored in "paused" state // Then we will start it if needed +#if (LIBTORRENT_VERSION_NUM < 10200) p.flags |= lt::add_torrent_params::flag_stop_when_ready; +#else + p.flags |= lt::torrent_flags::stop_when_ready; +#endif } // Limits @@ -2043,10 +2071,19 @@ bool Session::loadMetadata(const MagnetUri &magnetUri) p.save_path = Utils::Fs::toNativePath(savePath).toStdString(); // Forced start +#if (LIBTORRENT_VERSION_NUM < 10200) p.flags &= ~lt::add_torrent_params::flag_paused; p.flags &= ~lt::add_torrent_params::flag_auto_managed; +#else + p.flags &= ~lt::torrent_flags::paused; + p.flags &= ~lt::torrent_flags::auto_managed; +#endif // Solution to avoid accidental file writes +#if (LIBTORRENT_VERSION_NUM < 10200) p.flags |= lt::add_torrent_params::flag_upload_mode; +#else + p.flags |= lt::torrent_flags::upload_mode; +#endif // Adding torrent to BitTorrent session lt::error_code ec; @@ -2690,7 +2727,7 @@ void Session::setMaxConnectionsPerTorrent(int max) m_maxConnectionsPerTorrent = max; // Apply this to all session torrents - for (const auto &handle : m_nativeSession->get_torrents()) { + for (const lt::torrent_handle &handle : m_nativeSession->get_torrents()) { if (!handle.is_valid()) continue; try { handle.set_max_connections(max); @@ -2712,7 +2749,7 @@ void Session::setMaxUploadsPerTorrent(int max) m_maxUploadsPerTorrent = max; // Apply this to all session torrents - for (const auto &handle : m_nativeSession->get_torrents()) { + for (const lt::torrent_handle &handle : m_nativeSession->get_torrents()) { if (!handle.is_valid()) continue; try { handle.set_max_uploads(max); @@ -4021,7 +4058,12 @@ void Session::handlePeerBlockedAlert(const lt::peer_blocked_alert *p) void Session::handlePeerBanAlert(const lt::peer_ban_alert *p) { boost::system::error_code ec; +#if (LIBTORRENT_VERSION_NUM < 10200) const std::string ip = p->ip.address().to_string(ec); +#else + const std::string ip = p->endpoint.address().to_string(ec); +#endif + if (!ec) Logger::instance()->addPeer(QString::fromLatin1(ip.c_str()), false); } @@ -4035,48 +4077,126 @@ void Session::handleUrlSeedAlert(const lt::url_seed_alert *p) void Session::handleListenSucceededAlert(const lt::listen_succeeded_alert *p) { - boost::system::error_code ec; - QString proto = "TCP"; - if (p->sock_type == lt::listen_succeeded_alert::udp) + QString proto = "INVALID"; +#if (LIBTORRENT_VERSION_NUM < 10200) + switch (p->sock_type) + { + case lt::listen_succeeded_alert::udp: proto = "UDP"; - else if (p->sock_type == lt::listen_succeeded_alert::tcp) + break; + case lt::listen_succeeded_alert::tcp: proto = "TCP"; - else if (p->sock_type == lt::listen_succeeded_alert::tcp_ssl) + break; + case lt::listen_succeeded_alert::tcp_ssl: proto = "TCP_SSL"; - qDebug() << "Successfully listening on " << proto << p->endpoint.address().to_string(ec).c_str() << '/' << p->endpoint.port(); - Logger::instance()->addMessage( - tr("qBittorrent is successfully listening on interface %1 port: %2/%3", "e.g: qBittorrent is successfully listening on interface 192.168.0.1 port: TCP/6881") + break; + case lt::listen_succeeded_alert::i2p: + proto = "I2P"; + break; + case lt::listen_succeeded_alert::socks5: + proto = "SOCKS5"; + break; + case lt::listen_succeeded_alert::utp_ssl: + proto = "UTP_SSL"; + break; + } +#else + switch (p->socket_type) + { + case lt::socket_type_t::udp: + proto = "UDP"; + break; + case lt::socket_type_t::tcp: + proto = "TCP"; + break; + case lt::socket_type_t::tcp_ssl: + proto = "TCP_SSL"; + break; + case lt::socket_type_t::i2p: + proto = "I2P"; + break; + case lt::socket_type_t::socks5: + proto = "SOCKS5"; + break; + case lt::socket_type_t::utp_ssl: + proto = "UTP_SSL"; + break; + } +#endif + + boost::system::error_code ec; + LogMsg(tr("qBittorrent is successfully listening on interface %1 port: %2/%3" + , "e.g: qBittorrent is successfully listening on interface 192.168.0.1 port: TCP/6881") +#if (LIBTORRENT_VERSION_NUM < 10200) .arg(p->endpoint.address().to_string(ec).c_str(), proto, QString::number(p->endpoint.port())), Log::INFO); +#else + .arg(p->address.to_string(ec).c_str(), proto, QString::number(p->port)), Log::INFO); +#endif // Force reannounce on all torrents because some trackers blacklist some ports - std::vector torrents = m_nativeSession->get_torrents(); - std::vector::iterator it = torrents.begin(); - std::vector::iterator itend = torrents.end(); - for ( ; it != itend; ++it) - it->force_reannounce(); + for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents()) + torrent.force_reannounce(); } void Session::handleListenFailedAlert(const lt::listen_failed_alert *p) { - boost::system::error_code ec; - QString proto = "TCP"; - if (p->sock_type == lt::listen_failed_alert::udp) + QString proto = "INVALID"; +#if (LIBTORRENT_VERSION_NUM < 10200) + switch (p->sock_type) + { + case lt::listen_failed_alert::udp: proto = "UDP"; - else if (p->sock_type == lt::listen_failed_alert::tcp) + break; + case lt::listen_failed_alert::tcp: proto = "TCP"; - else if (p->sock_type == lt::listen_failed_alert::tcp_ssl) + break; + case lt::listen_failed_alert::tcp_ssl: proto = "TCP_SSL"; - else if (p->sock_type == lt::listen_failed_alert::i2p) + break; + case lt::listen_failed_alert::i2p: + proto = "I2P"; + break; + case lt::listen_failed_alert::socks5: + proto = "SOCKS5"; + break; + case lt::listen_failed_alert::utp_ssl: + proto = "UTP_SSL"; + break; + } +#else + switch (p->socket_type) + { + case lt::socket_type_t::udp: + proto = "UDP"; + break; + case lt::socket_type_t::tcp: + proto = "TCP"; + break; + case lt::socket_type_t::tcp_ssl: + proto = "TCP_SSL"; + break; + case lt::socket_type_t::i2p: proto = "I2P"; - else if (p->sock_type == lt::listen_failed_alert::socks5) + break; + case lt::socket_type_t::socks5: proto = "SOCKS5"; - qDebug() << "Failed listening on " << proto << p->endpoint.address().to_string(ec).c_str() << '/' << p->endpoint.port(); - Logger::instance()->addMessage( - 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.") + break; + case lt::socket_type_t::utp_ssl: + proto = "UTP_SSL"; + break; + } +#endif + + boost::system::error_code ec; + LogMsg(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.") +#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); + , QString::fromLocal8Bit(p->error.message().c_str())), Log::CRITICAL); +#else + .arg(p->address.to_string(ec).c_str(), proto, QString::number(p->port) + , QString::fromLocal8Bit(p->error.message().c_str())), Log::CRITICAL); +#endif } void Session::handleExternalIPAlert(const lt::external_ip_alert *p) @@ -4088,19 +4208,24 @@ void Session::handleExternalIPAlert(const lt::external_ip_alert *p) void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) { const qreal interval = m_statsUpdateTimer.restart() / 1000.; +#if (LIBTORRENT_VERSION_NUM < 10200) + const auto &stats = p->values; +#else + const auto stats = p->counters(); +#endif - m_status.hasIncomingConnections = static_cast(p->values[m_metricIndices.net.hasIncomingConnections]); + m_status.hasIncomingConnections = static_cast(stats[m_metricIndices.net.hasIncomingConnections]); - const auto ipOverheadDownload = p->values[m_metricIndices.net.recvIPOverheadBytes]; - const auto ipOverheadUpload = p->values[m_metricIndices.net.sentIPOverheadBytes]; - const auto totalDownload = p->values[m_metricIndices.net.recvBytes] + ipOverheadDownload; - const auto totalUpload = p->values[m_metricIndices.net.sentBytes] + ipOverheadUpload; - const auto totalPayloadDownload = p->values[m_metricIndices.net.recvPayloadBytes]; - const auto totalPayloadUpload = p->values[m_metricIndices.net.sentPayloadBytes]; - const auto trackerDownload = p->values[m_metricIndices.net.recvTrackerBytes]; - const auto trackerUpload = p->values[m_metricIndices.net.sentTrackerBytes]; - const auto dhtDownload = p->values[m_metricIndices.dht.dhtBytesIn]; - const auto dhtUpload = p->values[m_metricIndices.dht.dhtBytesOut]; + const auto ipOverheadDownload = stats[m_metricIndices.net.recvIPOverheadBytes]; + const auto ipOverheadUpload = stats[m_metricIndices.net.sentIPOverheadBytes]; + const auto totalDownload = stats[m_metricIndices.net.recvBytes] + ipOverheadDownload; + const auto totalUpload = stats[m_metricIndices.net.sentBytes] + ipOverheadUpload; + const auto totalPayloadDownload = stats[m_metricIndices.net.recvPayloadBytes]; + const auto totalPayloadUpload = stats[m_metricIndices.net.sentPayloadBytes]; + const auto trackerDownload = stats[m_metricIndices.net.recvTrackerBytes]; + const auto trackerUpload = stats[m_metricIndices.net.sentTrackerBytes]; + const auto dhtDownload = stats[m_metricIndices.dht.dhtBytesIn]; + const auto dhtUpload = stats[m_metricIndices.dht.dhtBytesOut]; auto calcRate = [interval](const quint64 previous, const quint64 current) { @@ -4129,23 +4254,23 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) m_status.trackerUpload = trackerUpload; m_status.dhtDownload = dhtDownload; m_status.dhtUpload = dhtUpload; - m_status.totalWasted = p->values[m_metricIndices.net.recvRedundantBytes] - + p->values[m_metricIndices.net.recvFailedBytes]; - m_status.dhtNodes = p->values[m_metricIndices.dht.dhtNodes]; - m_status.diskReadQueue = p->values[m_metricIndices.peer.numPeersUpDisk]; - m_status.diskWriteQueue = p->values[m_metricIndices.peer.numPeersDownDisk]; - m_status.peersCount = p->values[m_metricIndices.peer.numPeersConnected]; - - const int numBlocksRead = p->values[m_metricIndices.disk.numBlocksRead]; - const int numBlocksCacheHits = p->values[m_metricIndices.disk.numBlocksCacheHits]; - m_cacheStatus.totalUsedBuffers = p->values[m_metricIndices.disk.diskBlocksInUse]; + m_status.totalWasted = stats[m_metricIndices.net.recvRedundantBytes] + + stats[m_metricIndices.net.recvFailedBytes]; + m_status.dhtNodes = stats[m_metricIndices.dht.dhtNodes]; + m_status.diskReadQueue = stats[m_metricIndices.peer.numPeersUpDisk]; + m_status.diskWriteQueue = stats[m_metricIndices.peer.numPeersDownDisk]; + m_status.peersCount = stats[m_metricIndices.peer.numPeersConnected]; + + const int numBlocksRead = stats[m_metricIndices.disk.numBlocksRead]; + const int numBlocksCacheHits = stats[m_metricIndices.disk.numBlocksCacheHits]; + m_cacheStatus.totalUsedBuffers = stats[m_metricIndices.disk.diskBlocksInUse]; m_cacheStatus.readRatio = static_cast(numBlocksCacheHits) / std::max(numBlocksCacheHits + numBlocksRead, 1); - m_cacheStatus.jobQueueLength = p->values[m_metricIndices.disk.queuedDiskJobs]; + m_cacheStatus.jobQueueLength = stats[m_metricIndices.disk.queuedDiskJobs]; - const quint64 totalJobs = p->values[m_metricIndices.disk.writeJobs] + p->values[m_metricIndices.disk.readJobs] - + p->values[m_metricIndices.disk.hashJobs]; - m_cacheStatus.averageJobTime = totalJobs > 0 - ? (p->values[m_metricIndices.disk.diskJobTime] / totalJobs) : 0; + const quint64 totalJobs = stats[m_metricIndices.disk.writeJobs] + stats[m_metricIndices.disk.readJobs] + + stats[m_metricIndices.disk.hashJobs]; + m_cacheStatus.averageJobTime = (totalJobs > 0) + ? (stats[m_metricIndices.disk.diskJobTime] / totalJobs) : 0; emit statsUpdated(); } From 3955eef50da2ea4fb2dcf37c8287e7bfd7101050 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 9 May 2019 12:45:52 +0800 Subject: [PATCH 3/4] Change to `lt` namespace Quoting from libtorrent doc: > In the future, libtorrent will be the alias and lt the namespace name. --- src/base/bittorrent/infohash.cpp | 8 +-- src/base/bittorrent/infohash.h | 10 ++-- src/base/bittorrent/magneturi.cpp | 4 +- src/base/bittorrent/magneturi.h | 4 +- src/base/bittorrent/peerinfo.h | 4 +- .../bittorrent/private/filterparserthread.h | 4 +- .../bittorrent/private/portforwarderimpl.cpp | 2 +- .../bittorrent/private/portforwarderimpl.h | 2 +- src/base/bittorrent/session.cpp | 14 ++--- src/base/bittorrent/session.h | 54 +++++++++---------- src/base/bittorrent/torrenthandle.cpp | 44 +++++++-------- src/base/bittorrent/torrenthandle.h | 48 ++++++++--------- src/base/bittorrent/torrentinfo.cpp | 2 +- src/base/bittorrent/torrentinfo.h | 8 +-- src/base/bittorrent/tracker.cpp | 24 ++++----- src/base/bittorrent/tracker.h | 9 ++-- src/base/bittorrent/trackerentry.cpp | 6 +-- src/base/bittorrent/trackerentry.h | 6 +-- 18 files changed, 125 insertions(+), 128 deletions(-) diff --git a/src/base/bittorrent/infohash.cpp b/src/base/bittorrent/infohash.cpp index 9a7f51a74..122d4e88f 100644 --- a/src/base/bittorrent/infohash.cpp +++ b/src/base/bittorrent/infohash.cpp @@ -38,7 +38,7 @@ InfoHash::InfoHash() { } -InfoHash::InfoHash(const libtorrent::sha1_hash &nativeHash) +InfoHash::InfoHash(const lt::sha1_hash &nativeHash) : m_valid(true) , m_nativeHash(nativeHash) { @@ -66,7 +66,7 @@ bool InfoHash::isValid() const return m_valid; } -InfoHash::operator libtorrent::sha1_hash() const +InfoHash::operator lt::sha1_hash() const { return m_nativeHash; } @@ -78,8 +78,8 @@ InfoHash::operator QString() const bool BitTorrent::operator==(const InfoHash &left, const InfoHash &right) { - return (static_cast(left) - == static_cast(right)); + return (static_cast(left) + == static_cast(right)); } bool BitTorrent::operator!=(const InfoHash &left, const InfoHash &right) diff --git a/src/base/bittorrent/infohash.h b/src/base/bittorrent/infohash.h index 234549d38..049746fae 100644 --- a/src/base/bittorrent/infohash.h +++ b/src/base/bittorrent/infohash.h @@ -40,27 +40,27 @@ namespace BitTorrent { public: InfoHash(); - InfoHash(const libtorrent::sha1_hash &nativeHash); + InfoHash(const lt::sha1_hash &nativeHash); InfoHash(const QString &hashString); InfoHash(const InfoHash &other) = default; static constexpr int length() { #if (LIBTORRENT_VERSION_NUM < 10200) - return libtorrent::sha1_hash::size; + return lt::sha1_hash::size; #else - return libtorrent::sha1_hash::size(); + return lt::sha1_hash::size(); #endif } bool isValid() const; - operator libtorrent::sha1_hash() const; + operator lt::sha1_hash() const; operator QString() const; private: bool m_valid; - libtorrent::sha1_hash m_nativeHash; + lt::sha1_hash m_nativeHash; QString m_hashString; }; diff --git a/src/base/bittorrent/magneturi.cpp b/src/base/bittorrent/magneturi.cpp index 939502414..f15ff39d0 100644 --- a/src/base/bittorrent/magneturi.cpp +++ b/src/base/bittorrent/magneturi.cpp @@ -76,7 +76,7 @@ MagnetUri::MagnetUri(const QString &source) m_name = QString::fromStdString(m_addTorrentParams.name); for (const std::string &tracker : m_addTorrentParams.trackers) - m_trackers.append(libtorrent::announce_entry {tracker}); + m_trackers.append(lt::announce_entry {tracker}); for (const std::string &urlSeed : m_addTorrentParams.url_seeds) m_urlSeeds.append(QUrl(QString::fromStdString(urlSeed))); @@ -112,7 +112,7 @@ QString MagnetUri::url() const return m_url; } -libtorrent::add_torrent_params MagnetUri::addTorrentParams() const +lt::add_torrent_params MagnetUri::addTorrentParams() const { return m_addTorrentParams; } diff --git a/src/base/bittorrent/magneturi.h b/src/base/bittorrent/magneturi.h index d6e8baa8a..e2b8757c3 100644 --- a/src/base/bittorrent/magneturi.h +++ b/src/base/bittorrent/magneturi.h @@ -52,7 +52,7 @@ namespace BitTorrent QList urlSeeds() const; QString url() const; - libtorrent::add_torrent_params addTorrentParams() const; + lt::add_torrent_params addTorrentParams() const; private: bool m_valid; @@ -61,7 +61,7 @@ namespace BitTorrent QString m_name; QList m_trackers; QList m_urlSeeds; - libtorrent::add_torrent_params m_addTorrentParams; + lt::add_torrent_params m_addTorrentParams; }; } diff --git a/src/base/bittorrent/peerinfo.h b/src/base/bittorrent/peerinfo.h index 9edac8552..6aae66f75 100644 --- a/src/base/bittorrent/peerinfo.h +++ b/src/base/bittorrent/peerinfo.h @@ -53,7 +53,7 @@ namespace BitTorrent Q_DECLARE_TR_FUNCTIONS(PeerInfo) public: - PeerInfo(const TorrentHandle *torrent, const libtorrent::peer_info &nativeInfo); + PeerInfo(const TorrentHandle *torrent, const lt::peer_info &nativeInfo); bool fromDHT() const; bool fromPeX() const; @@ -105,7 +105,7 @@ namespace BitTorrent void calcRelevance(const TorrentHandle *torrent); void determineFlags(); - libtorrent::peer_info m_nativeInfo; + lt::peer_info m_nativeInfo; qreal m_relevance; QString m_flags; QString m_flagsDescription; diff --git a/src/base/bittorrent/private/filterparserthread.h b/src/base/bittorrent/private/filterparserthread.h index ab5f4a6ab..0f374bbf5 100644 --- a/src/base/bittorrent/private/filterparserthread.h +++ b/src/base/bittorrent/private/filterparserthread.h @@ -43,7 +43,7 @@ public: FilterParserThread(QObject *parent = nullptr); ~FilterParserThread(); void processFilterFile(const QString &filePath); - libtorrent::ip_filter IPfilter(); + lt::ip_filter IPfilter(); signals: void IPFilterParsed(int ruleCount); @@ -62,7 +62,7 @@ private: bool m_abort; QString m_filePath; - libtorrent::ip_filter m_filter; + lt::ip_filter m_filter; }; #endif // BITTORRENT_FILTERPARSERTHREAD_H diff --git a/src/base/bittorrent/private/portforwarderimpl.cpp b/src/base/bittorrent/private/portforwarderimpl.cpp index e0282bbf7..23d8d6dbd 100644 --- a/src/base/bittorrent/private/portforwarderimpl.cpp +++ b/src/base/bittorrent/private/portforwarderimpl.cpp @@ -37,7 +37,7 @@ const QString KEY_ENABLED = QStringLiteral("Network/PortForwardingEnabled"); -PortForwarderImpl::PortForwarderImpl(libtorrent::session *provider, QObject *parent) +PortForwarderImpl::PortForwarderImpl(lt::session *provider, QObject *parent) : Net::PortForwarder {parent} , m_active {SettingsStorage::instance()->loadValue(KEY_ENABLED, true).toBool()} , m_provider {provider} diff --git a/src/base/bittorrent/private/portforwarderimpl.h b/src/base/bittorrent/private/portforwarderimpl.h index df353c47c..4889abe67 100644 --- a/src/base/bittorrent/private/portforwarderimpl.h +++ b/src/base/bittorrent/private/portforwarderimpl.h @@ -60,6 +60,6 @@ private: void stop(); bool m_active; - libtorrent::session *m_provider; + lt::session *m_provider; QHash> m_mappedPorts; }; diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 0f5f11d4c..2e8df1759 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -945,12 +945,12 @@ Session::~Session() saveResumeData(); // We must delete FilterParserThread - // before we delete libtorrent::session + // before we delete lt::session if (m_filterParser) delete m_filterParser; // We must delete PortForwarderImpl before - // we delete libtorrent::session + // we delete lt::session delete Net::PortForwarder::instance(); qDebug("Deleting the session"); @@ -1043,7 +1043,7 @@ void Session::adjustLimits(lt::settings_pack &settingsPack) , maxActive > -1 ? maxActive + m_extraLimit : maxActive); } -void Session::applyBandwidthLimits(libtorrent::settings_pack &settingsPack) +void Session::applyBandwidthLimits(lt::settings_pack &settingsPack) { const bool altSpeedLimitEnabled = isAltGlobalSpeedLimitEnabled(); settingsPack.set_int(lt::settings_pack::download_rate_limit, altSpeedLimitEnabled ? altGlobalDownloadSpeedLimit() : globalDownloadSpeedLimit()); @@ -1128,7 +1128,7 @@ void Session::initMetrics() Q_ASSERT(m_metricIndices.disk.diskJobTime >= 0); } -void Session::configure(libtorrent::settings_pack &settingsPack) +void Session::configure(lt::settings_pack &settingsPack) { Logger *const logger = Logger::instance(); @@ -3449,12 +3449,12 @@ void Session::handleTorrentFinished(TorrentHandle *const torrent) emit allTorrentsFinished(); } -void Session::handleTorrentResumeDataReady(TorrentHandle *const torrent, const libtorrent::entry &data) +void Session::handleTorrentResumeDataReady(TorrentHandle *const torrent, const lt::entry &data) { --m_numResumeData; // Separated thread is used for the blocking IO which results in slow processing of many torrents. - // Encoding data in parallel while doing IO saves time. Copying libtorrent::entry objects around + // Encoding data in parallel while doing IO saves time. Copying lt::entry objects around // isn't cheap too. QByteArray out; @@ -3531,7 +3531,7 @@ void Session::enableIPFilter() { qDebug("Enabling IPFilter"); // 1. Parse the IP filter - // 2. In the slot add the manually banned IPs to the provided libtorrent::ip_filter + // 2. In the slot add the manually banned IPs to the provided lt::ip_filter // 3. Set the ip_filter in one go so there isn't a time window where there isn't an ip_filter // set between clearing the old one and setting the new one. if (!m_filterParser) { diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 87c8ec890..55d73bd1c 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -441,7 +441,7 @@ namespace BitTorrent void handleTorrentTrackersChanged(TorrentHandle *const torrent); void handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList &newUrlSeeds); void handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList &urlSeeds); - void handleTorrentResumeDataReady(TorrentHandle *const torrent, const libtorrent::entry &data); + void handleTorrentResumeDataReady(TorrentHandle *const torrent, const lt::entry &data); void handleTorrentResumeDataFailed(TorrentHandle *const torrent); void handleTorrentTrackerReply(TorrentHandle *const torrent, const QString &trackerUrl); void handleTorrentTrackerWarning(TorrentHandle *const torrent, const QString &trackerUrl); @@ -518,14 +518,14 @@ namespace BitTorrent // Session configuration Q_INVOKABLE void configure(); - void configure(libtorrent::settings_pack &settingsPack); + void configure(lt::settings_pack &settingsPack); void configurePeerClasses(); - void adjustLimits(libtorrent::settings_pack &settingsPack); - void applyBandwidthLimits(libtorrent::settings_pack &settingsPack); + void adjustLimits(lt::settings_pack &settingsPack); + void applyBandwidthLimits(lt::settings_pack &settingsPack); void initMetrics(); void adjustLimits(); void applyBandwidthLimits(); - void processBannedIPs(libtorrent::ip_filter &filter); + void processBannedIPs(lt::ip_filter &filter); const QStringList getListeningIPs(); void configureListeningInterface(); void enableTracker(bool enable); @@ -543,35 +543,35 @@ namespace BitTorrent void exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolder folder = TorrentExportFolder::Regular); void saveTorrentResumeData(TorrentHandle *const torrent); - void handleAlert(const libtorrent::alert *a); - void dispatchTorrentAlert(const libtorrent::alert *a); - void handleAddTorrentAlert(const libtorrent::add_torrent_alert *p); - void handleStateUpdateAlert(const libtorrent::state_update_alert *p); - void handleMetadataReceivedAlert(const libtorrent::metadata_received_alert *p); - void handleFileErrorAlert(const libtorrent::file_error_alert *p); - void handleTorrentRemovedAlert(const libtorrent::torrent_removed_alert *p); - void handleTorrentDeletedAlert(const libtorrent::torrent_deleted_alert *p); - void handleTorrentDeleteFailedAlert(const libtorrent::torrent_delete_failed_alert *p); - void handlePortmapWarningAlert(const libtorrent::portmap_error_alert *p); - void handlePortmapAlert(const libtorrent::portmap_alert *p); - void handlePeerBlockedAlert(const libtorrent::peer_blocked_alert *p); - void handlePeerBanAlert(const libtorrent::peer_ban_alert *p); - void handleUrlSeedAlert(const libtorrent::url_seed_alert *p); - void handleListenSucceededAlert(const libtorrent::listen_succeeded_alert *p); - void handleListenFailedAlert(const libtorrent::listen_failed_alert *p); - void handleExternalIPAlert(const libtorrent::external_ip_alert *p); - void handleSessionStatsAlert(const libtorrent::session_stats_alert *p); - - void createTorrentHandle(const libtorrent::torrent_handle &nativeHandle); + void handleAlert(const lt::alert *a); + void dispatchTorrentAlert(const lt::alert *a); + void handleAddTorrentAlert(const lt::add_torrent_alert *p); + void handleStateUpdateAlert(const lt::state_update_alert *p); + void handleMetadataReceivedAlert(const lt::metadata_received_alert *p); + void handleFileErrorAlert(const lt::file_error_alert *p); + void handleTorrentRemovedAlert(const lt::torrent_removed_alert *p); + void handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p); + void handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_alert *p); + void handlePortmapWarningAlert(const lt::portmap_error_alert *p); + void handlePortmapAlert(const lt::portmap_alert *p); + void handlePeerBlockedAlert(const lt::peer_blocked_alert *p); + void handlePeerBanAlert(const lt::peer_ban_alert *p); + void handleUrlSeedAlert(const lt::url_seed_alert *p); + void handleListenSucceededAlert(const lt::listen_succeeded_alert *p); + void handleListenFailedAlert(const lt::listen_failed_alert *p); + void handleExternalIPAlert(const lt::external_ip_alert *p); + void handleSessionStatsAlert(const lt::session_stats_alert *p); + + void createTorrentHandle(const lt::torrent_handle &nativeHandle); void saveResumeData(); void saveTorrentsQueue(); void removeTorrentsQueue(); - void getPendingAlerts(std::vector &out, ulong time = 0); + void getPendingAlerts(std::vector &out, ulong time = 0); // BitTorrent - libtorrent::session *m_nativeSession; + lt::session *m_nativeSession; bool m_deferredConfigureScheduled; bool m_IPFilteringChanged; diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 27c2c1a2f..09847116c 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -165,7 +165,7 @@ const int TorrentHandle::NO_SEEDING_TIME_LIMIT = -1; const qreal TorrentHandle::MAX_RATIO = 9999.; const int TorrentHandle::MAX_SEEDING_TIME = 525600; -TorrentHandle::TorrentHandle(Session *session, const libtorrent::torrent_handle &nativeHandle, +TorrentHandle::TorrentHandle(Session *session, const lt::torrent_handle &nativeHandle, const CreateTorrentParams ¶ms) : QObject(session) , m_session(session) @@ -1509,7 +1509,7 @@ void TorrentHandle::handleStateUpdate(const lt::torrent_status &nativeStatus) updateStatus(nativeStatus); } -void TorrentHandle::handleStorageMovedAlert(const libtorrent::storage_moved_alert *p) +void TorrentHandle::handleStorageMovedAlert(const lt::storage_moved_alert *p) { if (!isMoveInProgress()) { qWarning() << "Unexpected " << Q_FUNC_INFO << " call."; @@ -1550,7 +1550,7 @@ void TorrentHandle::handleStorageMovedAlert(const libtorrent::storage_moved_aler m_moveFinishedTriggers.takeFirst()(); } -void TorrentHandle::handleStorageMovedFailedAlert(const libtorrent::storage_moved_failed_alert *p) +void TorrentHandle::handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p) { if (!isMoveInProgress()) { qWarning() << "Unexpected " << Q_FUNC_INFO << " call."; @@ -1572,7 +1572,7 @@ void TorrentHandle::handleStorageMovedFailedAlert(const libtorrent::storage_move m_moveFinishedTriggers.takeFirst()(); } -void TorrentHandle::handleTrackerReplyAlert(const libtorrent::tracker_reply_alert *p) +void TorrentHandle::handleTrackerReplyAlert(const lt::tracker_reply_alert *p) { const QString trackerUrl(p->tracker_url()); qDebug("Received a tracker reply from %s (Num_peers = %d)", qUtf8Printable(trackerUrl), p->num_peers); @@ -1583,7 +1583,7 @@ void TorrentHandle::handleTrackerReplyAlert(const libtorrent::tracker_reply_aler m_session->handleTorrentTrackerReply(this, trackerUrl); } -void TorrentHandle::handleTrackerWarningAlert(const libtorrent::tracker_warning_alert *p) +void TorrentHandle::handleTrackerWarningAlert(const lt::tracker_warning_alert *p) { const QString trackerUrl = p->tracker_url(); const QString message = p->warning_message(); @@ -1594,7 +1594,7 @@ void TorrentHandle::handleTrackerWarningAlert(const libtorrent::tracker_warning_ m_session->handleTorrentTrackerWarning(this, trackerUrl); } -void TorrentHandle::handleTrackerErrorAlert(const libtorrent::tracker_error_alert *p) +void TorrentHandle::handleTrackerErrorAlert(const lt::tracker_error_alert *p) { const QString trackerUrl = p->tracker_url(); const QString message = p->error_message(); @@ -1604,7 +1604,7 @@ void TorrentHandle::handleTrackerErrorAlert(const libtorrent::tracker_error_aler m_session->handleTorrentTrackerError(this, trackerUrl); } -void TorrentHandle::handleTorrentCheckedAlert(const libtorrent::torrent_checked_alert *p) +void TorrentHandle::handleTorrentCheckedAlert(const lt::torrent_checked_alert *p) { Q_UNUSED(p); qDebug("\"%s\" have just finished checking", qUtf8Printable(name())); @@ -1638,7 +1638,7 @@ void TorrentHandle::handleTorrentCheckedAlert(const libtorrent::torrent_checked_ m_session->handleTorrentChecked(this); } -void TorrentHandle::handleTorrentFinishedAlert(const libtorrent::torrent_finished_alert *p) +void TorrentHandle::handleTorrentFinishedAlert(const lt::torrent_finished_alert *p) { Q_UNUSED(p); qDebug("Got a torrent finished alert for \"%s\"", qUtf8Printable(name())); @@ -1665,7 +1665,7 @@ void TorrentHandle::handleTorrentFinishedAlert(const libtorrent::torrent_finishe } } -void TorrentHandle::handleTorrentPausedAlert(const libtorrent::torrent_paused_alert *p) +void TorrentHandle::handleTorrentPausedAlert(const lt::torrent_paused_alert *p) { Q_UNUSED(p); @@ -1676,7 +1676,7 @@ void TorrentHandle::handleTorrentPausedAlert(const libtorrent::torrent_paused_al } } -void TorrentHandle::handleTorrentResumedAlert(const libtorrent::torrent_resumed_alert *p) +void TorrentHandle::handleTorrentResumedAlert(const lt::torrent_resumed_alert *p) { Q_UNUSED(p); @@ -1686,12 +1686,12 @@ void TorrentHandle::handleTorrentResumedAlert(const libtorrent::torrent_resumed_ m_startupState = Started; } -void TorrentHandle::handleSaveResumeDataAlert(const libtorrent::save_resume_data_alert *p) +void TorrentHandle::handleSaveResumeDataAlert(const lt::save_resume_data_alert *p) { const bool useDummyResumeData = !(p && p->resume_data); - libtorrent::entry dummyEntry; + lt::entry dummyEntry; - libtorrent::entry &resumeData = useDummyResumeData ? dummyEntry : *(p->resume_data); + lt::entry &resumeData = useDummyResumeData ? dummyEntry : *(p->resume_data); if (useDummyResumeData) { resumeData["qBt-magnetUri"] = toMagnetUri().toStdString(); resumeData["qBt-paused"] = isPaused(); @@ -1720,7 +1720,7 @@ void TorrentHandle::handleSaveResumeDataAlert(const libtorrent::save_resume_data m_session->handleTorrentResumeDataReady(this, resumeData); } -void TorrentHandle::handleSaveResumeDataFailedAlert(const libtorrent::save_resume_data_failed_alert *p) +void TorrentHandle::handleSaveResumeDataFailedAlert(const lt::save_resume_data_failed_alert *p) { // if torrent has no metadata we should save dummy fastresume data // containing Magnet URI and qBittorrent own resume data only @@ -1730,7 +1730,7 @@ void TorrentHandle::handleSaveResumeDataFailedAlert(const libtorrent::save_resum m_session->handleTorrentResumeDataFailed(this); } -void TorrentHandle::handleFastResumeRejectedAlert(const libtorrent::fastresume_rejected_alert *p) +void TorrentHandle::handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p) { if (p->error.value() == lt::errors::mismatching_file_size) { // Mismatching file size (files were probably moved) @@ -1743,7 +1743,7 @@ void TorrentHandle::handleFastResumeRejectedAlert(const libtorrent::fastresume_r } } -void TorrentHandle::handleFileRenamedAlert(const libtorrent::file_renamed_alert *p) +void TorrentHandle::handleFileRenamedAlert(const lt::file_renamed_alert *p) { const QString newName = Utils::Fs::fromNativePath(p->new_name()); @@ -1773,7 +1773,7 @@ void TorrentHandle::handleFileRenamedAlert(const libtorrent::file_renamed_alert m_moveFinishedTriggers.takeFirst()(); } -void TorrentHandle::handleFileRenameFailedAlert(const libtorrent::file_rename_failed_alert *p) +void TorrentHandle::handleFileRenameFailedAlert(const lt::file_rename_failed_alert *p) { Q_UNUSED(p); @@ -1782,7 +1782,7 @@ void TorrentHandle::handleFileRenameFailedAlert(const libtorrent::file_rename_fa m_moveFinishedTriggers.takeFirst()(); } -void TorrentHandle::handleFileCompletedAlert(const libtorrent::file_completed_alert *p) +void TorrentHandle::handleFileCompletedAlert(const lt::file_completed_alert *p) { // We don't really need to call updateStatus() in this place. // All we need to do is make sure we have a valid instance of the TorrentInfo object. @@ -1800,7 +1800,7 @@ void TorrentHandle::handleFileCompletedAlert(const libtorrent::file_completed_al } } -void TorrentHandle::handleStatsAlert(const libtorrent::stats_alert *p) +void TorrentHandle::handleStatsAlert(const lt::stats_alert *p) { Q_ASSERT(p->interval >= 1000); const SpeedSample transferred(p->transferred[lt::stats_alert::download_payload] * 1000LL / p->interval, @@ -1854,7 +1854,7 @@ void TorrentHandle::handleAppendExtensionToggled() manageIncompleteFiles(); } -void TorrentHandle::handleAlert(const libtorrent::alert *a) +void TorrentHandle::handleAlert(const lt::alert *a) { switch (a->type()) { case lt::stats_alert::alert_type: @@ -1965,7 +1965,7 @@ void TorrentHandle::adjustActualSavePath_impl() moveStorage(Utils::Fs::toNativePath(path), true); } -libtorrent::torrent_handle TorrentHandle::nativeHandle() const +lt::torrent_handle TorrentHandle::nativeHandle() const { return m_nativeHandle; } @@ -1992,7 +1992,7 @@ void TorrentHandle::updateStatus() updateStatus(m_nativeHandle.status()); } -void TorrentHandle::updateStatus(const libtorrent::torrent_status &nativeStatus) +void TorrentHandle::updateStatus(const lt::torrent_status &nativeStatus) { m_nativeStatus = nativeStatus; diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index 40c3e30ce..f7b9c8519 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -142,7 +142,7 @@ namespace BitTorrent static const qreal MAX_RATIO; static const int MAX_SEEDING_TIME; - TorrentHandle(Session *session, const libtorrent::torrent_handle &nativeHandle, + TorrentHandle(Session *session, const lt::torrent_handle &nativeHandle, const CreateTorrentParams ¶ms); ~TorrentHandle(); @@ -334,10 +334,10 @@ namespace BitTorrent bool needSaveResumeData() const; // Session interface - libtorrent::torrent_handle nativeHandle() const; + lt::torrent_handle nativeHandle() const; - void handleAlert(const libtorrent::alert *a); - void handleStateUpdate(const libtorrent::torrent_status &nativeStatus); + void handleAlert(const lt::alert *a); + void handleStateUpdate(const lt::torrent_status &nativeStatus); void handleTempPathChanged(); void handleCategorySavePathChanged(); void handleAppendExtensionToggled(); @@ -355,27 +355,27 @@ namespace BitTorrent typedef std::function EventTrigger; void updateStatus(); - void updateStatus(const libtorrent::torrent_status &nativeStatus); + void updateStatus(const lt::torrent_status &nativeStatus); void updateState(); void updateTorrentInfo(); - void handleStorageMovedAlert(const libtorrent::storage_moved_alert *p); - void handleStorageMovedFailedAlert(const libtorrent::storage_moved_failed_alert *p); - void handleTrackerReplyAlert(const libtorrent::tracker_reply_alert *p); - void handleTrackerWarningAlert(const libtorrent::tracker_warning_alert *p); - void handleTrackerErrorAlert(const libtorrent::tracker_error_alert *p); - void handleTorrentCheckedAlert(const libtorrent::torrent_checked_alert *p); - void handleTorrentFinishedAlert(const libtorrent::torrent_finished_alert *p); - void handleTorrentPausedAlert(const libtorrent::torrent_paused_alert *p); - void handleTorrentResumedAlert(const libtorrent::torrent_resumed_alert *p); - void handleSaveResumeDataAlert(const libtorrent::save_resume_data_alert *p); - void handleSaveResumeDataFailedAlert(const libtorrent::save_resume_data_failed_alert *p); - void handleFastResumeRejectedAlert(const libtorrent::fastresume_rejected_alert *p); - void handleFileRenamedAlert(const libtorrent::file_renamed_alert *p); - void handleFileRenameFailedAlert(const libtorrent::file_rename_failed_alert *p); - void handleFileCompletedAlert(const libtorrent::file_completed_alert *p); - void handleMetadataReceivedAlert(const libtorrent::metadata_received_alert *p); - void handleStatsAlert(const libtorrent::stats_alert *p); + void handleStorageMovedAlert(const lt::storage_moved_alert *p); + void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p); + void handleTrackerReplyAlert(const lt::tracker_reply_alert *p); + void handleTrackerWarningAlert(const lt::tracker_warning_alert *p); + void handleTrackerErrorAlert(const lt::tracker_error_alert *p); + void handleTorrentCheckedAlert(const lt::torrent_checked_alert *p); + void handleTorrentFinishedAlert(const lt::torrent_finished_alert *p); + void handleTorrentPausedAlert(const lt::torrent_paused_alert *p); + void handleTorrentResumedAlert(const lt::torrent_resumed_alert *p); + void handleSaveResumeDataAlert(const lt::save_resume_data_alert *p); + void handleSaveResumeDataFailedAlert(const lt::save_resume_data_failed_alert *p); + void handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p); + void handleFileRenamedAlert(const lt::file_renamed_alert *p); + void handleFileRenameFailedAlert(const lt::file_rename_failed_alert *p); + void handleFileCompletedAlert(const lt::file_completed_alert *p); + void handleMetadataReceivedAlert(const lt::metadata_received_alert *p); + void handleStatsAlert(const lt::stats_alert *p); void resume_impl(bool forced); bool isMoveInProgress() const; @@ -394,8 +394,8 @@ namespace BitTorrent void setFirstLastPiecePriorityImpl(bool enabled, const QVector &updatedFilePrio = {}); Session *const m_session; - libtorrent::torrent_handle m_nativeHandle; - libtorrent::torrent_status m_nativeStatus; + lt::torrent_handle m_nativeHandle; + lt::torrent_status m_nativeStatus; TorrentState m_state; TorrentInfo m_torrentInfo; SpeedMonitor m_speedMonitor; diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index 4f0092980..7123a6e12 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -413,7 +413,7 @@ void TorrentInfo::stripRootFolder() { if (!hasRootFolder()) return; - libtorrent::file_storage files = m_nativeInfo->files(); + lt::file_storage files = m_nativeInfo->files(); // Solution for case of renamed root folder const std::string testName = filePath(0).split('/').value(0).toStdString(); diff --git a/src/base/bittorrent/torrentinfo.h b/src/base/bittorrent/torrentinfo.h index ea6216abe..bedefd2b9 100644 --- a/src/base/bittorrent/torrentinfo.h +++ b/src/base/bittorrent/torrentinfo.h @@ -56,11 +56,11 @@ namespace BitTorrent public: #if (LIBTORRENT_VERSION_NUM < 10200) - using NativeConstPtr = boost::shared_ptr; - using NativePtr = boost::shared_ptr; + using NativeConstPtr = boost::shared_ptr; + using NativePtr = boost::shared_ptr; #else - using NativeConstPtr = std::shared_ptr; - using NativePtr = std::shared_ptr; + using NativeConstPtr = std::shared_ptr; + using NativePtr = std::shared_ptr; #endif explicit TorrentInfo(NativeConstPtr nativeInfo = {}); diff --git a/src/base/bittorrent/tracker.cpp b/src/base/bittorrent/tracker.cpp index db7ac6e47..d52280727 100644 --- a/src/base/bittorrent/tracker.cpp +++ b/src/base/bittorrent/tracker.cpp @@ -58,15 +58,15 @@ QString Peer::uid() const return ip.toString() + ':' + QString::number(port); } -libtorrent::entry Peer::toEntry(const bool noPeerId) const +lt::entry Peer::toEntry(const bool noPeerId) const { - libtorrent::entry::dictionary_type peerMap; + lt::entry::dictionary_type peerMap; if (!noPeerId) - peerMap["id"] = libtorrent::entry(peerId.toStdString()); - peerMap["ip"] = libtorrent::entry(ip.toString().toStdString()); - peerMap["port"] = libtorrent::entry(port); + peerMap["id"] = lt::entry(peerId.toStdString()); + peerMap["ip"] = lt::entry(ip.toString().toStdString()); + peerMap["port"] = lt::entry(port); - return libtorrent::entry(peerMap); + return lt::entry(peerMap); } // Tracker @@ -247,18 +247,18 @@ void Tracker::unregisterPeer(const TrackerAnnounceRequest &announceReq) void Tracker::replyWithPeerList(const TrackerAnnounceRequest &announceReq) { // Prepare the entry for bencoding - libtorrent::entry::dictionary_type replyDict; - replyDict["interval"] = libtorrent::entry(ANNOUNCE_INTERVAL); + lt::entry::dictionary_type replyDict; + replyDict["interval"] = lt::entry(ANNOUNCE_INTERVAL); - libtorrent::entry::list_type peerList; + lt::entry::list_type peerList; for (const Peer &p : m_torrents.value(announceReq.infoHash)) peerList.push_back(p.toEntry(announceReq.noPeerId)); - replyDict["peers"] = libtorrent::entry(peerList); + replyDict["peers"] = lt::entry(peerList); - const libtorrent::entry replyEntry(replyDict); + const lt::entry replyEntry(replyDict); // bencode QByteArray reply; - libtorrent::bencode(std::back_inserter(reply), replyEntry); + lt::bencode(std::back_inserter(reply), replyEntry); qDebug("Tracker: reply with the following bencoded data:\n %s", reply.constData()); // HTTP reply diff --git a/src/base/bittorrent/tracker.h b/src/base/bittorrent/tracker.h index 02e799908..dff8c908c 100644 --- a/src/base/bittorrent/tracker.h +++ b/src/base/bittorrent/tracker.h @@ -30,6 +30,8 @@ #ifndef BITTORRENT_TRACKER_H #define BITTORRENT_TRACKER_H +#include + #include #include #include @@ -37,11 +39,6 @@ #include "base/http/irequesthandler.h" #include "base/http/responsebuilder.h" -namespace libtorrent -{ - class entry; -} - namespace Http { class Server; @@ -58,7 +55,7 @@ namespace BitTorrent bool operator!=(const Peer &other) const; bool operator==(const Peer &other) const; QString uid() const; - libtorrent::entry toEntry(bool noPeerId) const; + lt::entry toEntry(bool noPeerId) const; }; struct TrackerAnnounceRequest diff --git a/src/base/bittorrent/trackerentry.cpp b/src/base/bittorrent/trackerentry.cpp index 885dd8e72..5522dcebc 100644 --- a/src/base/bittorrent/trackerentry.cpp +++ b/src/base/bittorrent/trackerentry.cpp @@ -42,7 +42,7 @@ TrackerEntry::TrackerEntry(const QString &url) { } -TrackerEntry::TrackerEntry(const libtorrent::announce_entry &nativeEntry) +TrackerEntry::TrackerEntry(const lt::announce_entry &nativeEntry) : m_nativeEntry(nativeEntry) { } @@ -72,7 +72,7 @@ int TrackerEntry::tier() const TrackerEntry::Status TrackerEntry::status() const { - // libtorrent::announce_entry::is_working() returns + // lt::announce_entry::is_working() returns // true when the tracker hasn't been tried yet. if (m_nativeEntry.verified && isWorking()) return Working; @@ -119,7 +119,7 @@ int TrackerEntry::numDownloaded() const #endif } -libtorrent::announce_entry TrackerEntry::nativeEntry() const +lt::announce_entry TrackerEntry::nativeEntry() const { return m_nativeEntry; } diff --git a/src/base/bittorrent/trackerentry.h b/src/base/bittorrent/trackerentry.h index 8806a1f16..e99389cf8 100644 --- a/src/base/bittorrent/trackerentry.h +++ b/src/base/bittorrent/trackerentry.h @@ -48,7 +48,7 @@ namespace BitTorrent }; TrackerEntry(const QString &url); - TrackerEntry(const libtorrent::announce_entry &nativeEntry); + TrackerEntry(const lt::announce_entry &nativeEntry); TrackerEntry(const TrackerEntry &other) = default; TrackerEntry &operator=(const TrackerEntry &other) = default; @@ -63,10 +63,10 @@ namespace BitTorrent int numLeeches() const; int numDownloaded() const; - libtorrent::announce_entry nativeEntry() const; + lt::announce_entry nativeEntry() const; private: - libtorrent::announce_entry m_nativeEntry; + lt::announce_entry m_nativeEntry; }; bool operator==(const TrackerEntry &left, const TrackerEntry &right); From 5aaf0403001411963d16e3f484d67baa0a1fb7d7 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 9 May 2019 12:58:04 +0800 Subject: [PATCH 4/4] Remove libtorrentfwd.h --- src/base/CMakeLists.txt | 1 - src/base/base.pri | 1 - src/base/bittorrent/private/libtorrentfwd.h | 81 ------------------- .../bittorrent/private/portforwarderimpl.h | 5 +- src/base/bittorrent/session.h | 3 +- src/base/bittorrent/torrenthandle.h | 2 +- src/base/bittorrent/torrentinfo.h | 2 +- 7 files changed, 8 insertions(+), 87 deletions(-) delete mode 100644 src/base/bittorrent/private/libtorrentfwd.h diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index cba9ce9c0..1a736ede2 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -9,7 +9,6 @@ bittorrent/infohash.h bittorrent/magneturi.h bittorrent/peerinfo.h bittorrent/private/bandwidthscheduler.h -bittorrent/private/libtorrentfwd.h bittorrent/private/filterparserthread.h bittorrent/private/portforwarderimpl.h bittorrent/private/resumedatasavingmanager.h diff --git a/src/base/base.pri b/src/base/base.pri index 791217f26..f5a0b025d 100644 --- a/src/base/base.pri +++ b/src/base/base.pri @@ -9,7 +9,6 @@ HEADERS += \ $$PWD/bittorrent/peerinfo.h \ $$PWD/bittorrent/private/bandwidthscheduler.h \ $$PWD/bittorrent/private/filterparserthread.h \ - $$PWD/bittorrent/private/libtorrentfwd.h \ $$PWD/bittorrent/private/portforwarderimpl.h \ $$PWD/bittorrent/private/resumedatasavingmanager.h \ $$PWD/bittorrent/private/speedmonitor.h \ diff --git a/src/base/bittorrent/private/libtorrentfwd.h b/src/base/bittorrent/private/libtorrentfwd.h deleted file mode 100644 index 5bbaf9ff1..000000000 --- a/src/base/bittorrent/private/libtorrentfwd.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2019 Vladimir Golovnev - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * In addition, as a special exception, the copyright holders give permission to - * link this program with the OpenSSL project's "OpenSSL" library (or with - * modified versions of it that use the same license as the "OpenSSL" library), - * and distribute the linked executables. You must obey the GNU General Public - * License in all respects for all of the code used other than "OpenSSL". If you - * modify file(s), you may extend this exception to your version of the file(s), - * but you are not obligated to do so. If you do not wish to do so, delete this - * exception statement from your version. - */ - -#pragma once - -#include - -#if (LIBTORRENT_VERSION_NUM < 10200) -namespace libtorrent -{ - class entry; - class session; - struct ip_filter; - struct settings_pack; - struct torrent_handle; - - class alert; - struct add_torrent_alert; - struct external_ip_alert; - struct fastresume_rejected_alert; - struct file_completed_alert; - struct file_error_alert; - struct file_rename_failed_alert; - struct file_renamed_alert; - struct listen_failed_alert; - struct listen_succeeded_alert; - struct metadata_received_alert; - struct peer_ban_alert; - struct peer_blocked_alert; - struct portmap_alert; - struct portmap_error_alert; - struct save_resume_data_alert; - struct save_resume_data_failed_alert; - struct session_stats_alert; - struct state_update_alert; - struct stats_alert; - struct storage_moved_alert; - struct storage_moved_failed_alert; - struct torrent_alert; - struct torrent_checked_alert; - struct torrent_delete_failed_alert; - struct torrent_deleted_alert; - struct torrent_finished_alert; - struct torrent_paused_alert; - struct torrent_removed_alert; - struct torrent_resumed_alert; - struct tracker_error_alert; - struct tracker_reply_alert; - struct tracker_warning_alert; - struct url_seed_alert; -} - -namespace lt = libtorrent; -#else -#include -#endif diff --git a/src/base/bittorrent/private/portforwarderimpl.h b/src/base/bittorrent/private/portforwarderimpl.h index 4889abe67..aa6527814 100644 --- a/src/base/bittorrent/private/portforwarderimpl.h +++ b/src/base/bittorrent/private/portforwarderimpl.h @@ -29,10 +29,13 @@ #pragma once #include + +#include +#include + #include #include "base/net/portforwarder.h" -#include "libtorrentfwd.h" #if (LIBTORRENT_VERSION_NUM < 10200) using LTPortMapping = int; diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 55d73bd1c..d2c91b7e8 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -32,6 +32,8 @@ #include +#include + #include #include #include @@ -43,7 +45,6 @@ #include "base/settingvalue.h" #include "base/tristatebool.h" #include "base/types.h" -#include "private/libtorrentfwd.h" #include "addtorrentparams.h" #include "cachestatus.h" #include "sessionstatus.h" diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index f7b9c8519..725ff24f6 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -32,6 +32,7 @@ #include +#include #include #include @@ -42,7 +43,6 @@ #include #include -#include "private/libtorrentfwd.h" #include "private/speedmonitor.h" #include "downloadpriority.h" #include "infohash.h" diff --git a/src/base/bittorrent/torrentinfo.h b/src/base/bittorrent/torrentinfo.h index bedefd2b9..207736954 100644 --- a/src/base/bittorrent/torrentinfo.h +++ b/src/base/bittorrent/torrentinfo.h @@ -29,6 +29,7 @@ #ifndef BITTORRENT_TORRENTINFO_H #define BITTORRENT_TORRENTINFO_H +#include #include #include @@ -37,7 +38,6 @@ #include #include "base/indexrange.h" -#include "private/libtorrentfwd.h" class QByteArray; class QDateTime;