Advertisement
nick43ui

Untitled

Jun 17th, 2020
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. // This session.cpp
  2. #include "session.h"
  3.  
  4. #include <libtorrent/alert_types.hpp>
  5. #include <libtorrent/bdecode.hpp>
  6. #include <libtorrent/bencode.hpp>
  7. #include <libtorrent/disk_io_thread.hpp>
  8. #include <libtorrent/error_code.hpp>
  9. #include <libtorrent/extensions/ut_metadata.hpp>
  10. #include <libtorrent/extensions/ut_pex.hpp>
  11. #include <libtorrent/extensions/smart_ban.hpp>
  12. #include <libtorrent/identify_client.hpp>
  13. #include <libtorrent/ip_filter.hpp>
  14. #include <libtorrent/magnet_uri.hpp>
  15. #include <libtorrent/session.hpp>
  16. #include <libtorrent/session_stats.hpp>
  17. #include <libtorrent/session_status.hpp>
  18. #include <libtorrent/torrent_info.hpp>
  19. #include <libtorrent/version.hpp>
  20. #include "libtorrent/extensions.hpp"
  21. #include "libtorrent/aux_/session_impl.hpp"
  22. #include "libtorrent/aux_/session_call.hpp"
  23. #include "libtorrent/config.hpp"
  24.  
  25. #include <QDir>
  26.  
  27. using namespace BitTorrent;
  28.  
  29. Session* Session::instance_ = nullptr;
  30.  
  31. Session::Session(QObject* parent)
  32. : QObject{parent}
  33. {
  34. initResumeFolder();
  35.  
  36. // Set severity level of libtorrent session
  37. const int alertMask = lt::alert::error_notification
  38. | lt::alert::port_mapping_notification
  39. | lt::alert::storage_notification
  40. | lt::alert::tracker_notification
  41. | lt::alert::status_notification
  42. | lt::alert::ip_block_notification
  43. | lt::alert::file_progress_notification
  44. | lt::alert::stats_notification;
  45.  
  46. lt::settings_pack pack;
  47. pack.set_int(lt::settings_pack::alert_mask, alertMask);
  48. pack.set_bool(lt::settings_pack::listen_system_port_fallback, false);
  49. pack.set_bool(lt::settings_pack::use_dht_as_fallback, false);
  50. // Disable support for SSL torrents for now
  51. pack.set_int(lt::settings_pack::ssl_listen, 0);
  52. // To prevent ISPs from blocking seeding
  53. pack.set_bool(lt::settings_pack::lazy_bitfields, true);
  54. // Speed up exit
  55. pack.set_int(lt::settings_pack::stop_tracker_timeout, 1);
  56. pack.set_int(lt::settings_pack::auto_scrape_interval, 1200); // 20 minutes
  57. pack.set_int(lt::settings_pack::auto_scrape_min_interval, 900); // 15 minutes
  58. pack.set_int(lt::settings_pack::connection_speed, 20); // default is 10
  59. pack.set_bool(lt::settings_pack::no_connect_privileged_ports, false);
  60. pack.set_bool(lt::settings_pack::use_disk_cache_pool, false);
  61.  
  62. pack.set_bool(lt::settings_pack::enable_upnp, true);
  63. pack.set_bool(lt::settings_pack::enable_natpmp, true);
  64. pack.set_bool(lt::settings_pack::upnp_ignore_nonrouters, true);
  65. pack.set_bool(lt::settings_pack::allow_multiple_connections_per_ip, true);
  66. pack.set_bool(lt::settings_pack::enable_dht, true);
  67. pack.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");
  68. pack.set_bool(lt::settings_pack::enable_lsd, true);
  69.  
  70. native_session_ = new lt::session {pack, int{0}};
  71. native_session_->set_alert_notify([this]()
  72. {
  73. QMetaObject::invokeMethod(this, "readAlerts", Qt::QueuedConnection);
  74. });
  75.  
  76.  
  77. // Enabling plugins
  78. //m_nativeSession->add_extension(&lt::create_metadata_plugin);
  79. native_session_->add_extension(&lt::create_ut_metadata_plugin);
  80. // if (isPeXEnabled())
  81. native_session_->add_extension(&lt::create_ut_pex_plugin);
  82. // native_session_->add_extension(&lt::create_smart_ban_plugin);
  83. qDebug("* BitTorrent Session constructed");
  84. }
  85.  
  86. void Session::initResumeFolder()
  87. {
  88. // resume_folder_path_ = Utils::Fs::expandPathAbs(specialFolderLocation(SpecialFolder::Data) + RESUME_FOLDER);
  89. // const QDir resumeFolderDir(resume_folder_path_);
  90. // if (resumeFolderDir.exists() || resumeFolderDir.mkpath(resumeFolderDir.absolutePath())) {
  91. // resumeFolderLock.setFileName(resumeFolderDir.absoluteFilePath("session.lock"));
  92. // if (!m_resumeFolderLock.open(QFile::WriteOnly)) {
  93. // throw RuntimeError {tr("Cannot write to torrent resume folder.")};
  94. // }
  95. // }
  96. // else {
  97. // throw RuntimeError {tr("Cannot create torrent resume folder.")};
  98. // }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement