2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2008-2022 Mnemosyne LLC.
|
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0), GPLv3 (SPDX: GPL-3.0),
|
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2017-11-14 20:21:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
2017-04-19 12:04:45 +00:00
|
|
|
#error only libtransmission should #include this header.
|
2008-11-24 20:17:36 +00:00
|
|
|
#endif
|
|
|
|
|
2007-07-29 18:11:21 +00:00
|
|
|
#define TR_NAME "Transmission"
|
2007-03-23 08:28:01 +00:00
|
|
|
|
2021-10-13 03:46:12 +00:00
|
|
|
#include <array>
|
2021-12-16 09:43:51 +00:00
|
|
|
#include <cstddef> // size_t
|
|
|
|
#include <cstdint> // uintX_t
|
2021-12-15 21:25:42 +00:00
|
|
|
#include <ctime>
|
2021-09-27 18:28:41 +00:00
|
|
|
#include <list>
|
2021-09-24 23:31:02 +00:00
|
|
|
#include <map>
|
2021-11-14 21:14:37 +00:00
|
|
|
#include <memory>
|
2021-12-16 09:43:51 +00:00
|
|
|
#include <mutex>
|
2021-10-13 03:46:12 +00:00
|
|
|
#include <string>
|
2021-11-02 00:18:09 +00:00
|
|
|
#include <string_view>
|
2022-02-14 04:07:12 +00:00
|
|
|
#include <tuple>
|
2021-09-24 23:31:02 +00:00
|
|
|
#include <unordered_set>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-11-14 06:02:45 +00:00
|
|
|
#include "transmission.h"
|
|
|
|
|
2022-02-20 19:00:52 +00:00
|
|
|
#include "announce-list.h"
|
2022-01-13 02:13:58 +00:00
|
|
|
#include "net.h" // tr_socket_t
|
2022-02-14 04:07:12 +00:00
|
|
|
#include "quark.h"
|
2022-02-16 18:33:50 +00:00
|
|
|
#include "web.h"
|
2008-09-17 19:44:24 +00:00
|
|
|
|
2021-10-06 14:26:07 +00:00
|
|
|
enum tr_auto_switch_state_t
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2012-09-18 00:58:10 +00:00
|
|
|
TR_AUTO_SWITCH_UNUSED,
|
|
|
|
TR_AUTO_SWITCH_ON,
|
|
|
|
TR_AUTO_SWITCH_OFF,
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2012-09-18 00:58:10 +00:00
|
|
|
|
2021-10-22 02:40:55 +00:00
|
|
|
tr_peer_id_t tr_peerIdInit();
|
2007-07-16 11:19:44 +00:00
|
|
|
|
2010-12-24 08:58:41 +00:00
|
|
|
struct event_base;
|
2011-03-13 00:18:11 +00:00
|
|
|
struct evdns_base;
|
|
|
|
|
2021-11-09 03:30:03 +00:00
|
|
|
class tr_bitfield;
|
2021-12-15 21:25:42 +00:00
|
|
|
class tr_rpc_server;
|
2022-02-16 18:33:50 +00:00
|
|
|
class tr_web;
|
2021-12-15 21:25:42 +00:00
|
|
|
struct Bandwidth;
|
2008-12-02 03:41:58 +00:00
|
|
|
struct tr_address;
|
2009-09-25 21:05:59 +00:00
|
|
|
struct tr_announcer;
|
2011-03-13 00:18:11 +00:00
|
|
|
struct tr_announcer_udp;
|
2009-05-14 13:42:29 +00:00
|
|
|
struct tr_bindsockets;
|
2021-09-27 18:28:41 +00:00
|
|
|
struct tr_blocklistFile;
|
2010-06-19 14:25:11 +00:00
|
|
|
struct tr_cache;
|
2021-11-09 03:30:03 +00:00
|
|
|
struct tr_fdInfo;
|
2008-11-06 02:56:51 +00:00
|
|
|
|
2022-01-21 15:44:45 +00:00
|
|
|
struct tr_bindinfo
|
|
|
|
{
|
|
|
|
int socket;
|
|
|
|
tr_address addr;
|
|
|
|
struct event* ev;
|
|
|
|
};
|
|
|
|
|
2010-02-04 23:39:50 +00:00
|
|
|
struct tr_turtle_info
|
|
|
|
{
|
|
|
|
/* TR_UP and TR_DOWN speed limits */
|
2012-07-01 02:17:35 +00:00
|
|
|
unsigned int speedLimit_Bps[2];
|
2010-02-04 23:39:50 +00:00
|
|
|
|
|
|
|
/* is turtle mode on right now? */
|
2011-03-22 15:19:54 +00:00
|
|
|
bool isEnabled;
|
2010-02-04 23:39:50 +00:00
|
|
|
|
|
|
|
/* does turtle mode turn itself on and off at given times? */
|
2011-03-22 15:19:54 +00:00
|
|
|
bool isClockEnabled;
|
2010-02-04 23:39:50 +00:00
|
|
|
|
|
|
|
/* when clock mode is on, minutes after midnight to turn on turtle mode */
|
|
|
|
int beginMinute;
|
|
|
|
|
|
|
|
/* when clock mode is on, minutes after midnight to turn off turtle mode */
|
|
|
|
int endMinute;
|
|
|
|
|
|
|
|
/* only use clock mode on these days of the week */
|
|
|
|
tr_sched_day days;
|
|
|
|
|
|
|
|
/* called when isEnabled changes */
|
2013-09-08 17:08:18 +00:00
|
|
|
tr_altSpeedFunc callback;
|
2010-02-04 23:39:50 +00:00
|
|
|
|
|
|
|
/* the callback's user_data argument */
|
2017-04-19 12:04:45 +00:00
|
|
|
void* callbackUserData;
|
2010-02-04 23:39:50 +00:00
|
|
|
|
|
|
|
/* the callback's changedByUser argument.
|
|
|
|
* indicates whether the change came from the user or from the clock. */
|
2011-03-22 15:19:54 +00:00
|
|
|
bool changedByUser;
|
2010-02-04 23:39:50 +00:00
|
|
|
|
2010-03-12 19:35:28 +00:00
|
|
|
/* bitfield of all the minutes in a week.
|
|
|
|
* Each bit's value indicates whether the scheduler wants turtle
|
|
|
|
* limits on or off at that given minute in the week. */
|
2021-10-11 17:29:14 +00:00
|
|
|
// Changed to non-owning pointer temporarily till tr_turtle_info becomes C++-constructible and destructible
|
|
|
|
// TODO: remove * and own the value
|
2021-10-24 20:43:36 +00:00
|
|
|
tr_bitfield* minutes = nullptr;
|
2012-09-18 00:58:10 +00:00
|
|
|
|
|
|
|
/* recent action that was done by turtle's automatic switch */
|
|
|
|
tr_auto_switch_state_t autoTurtleState;
|
2010-02-04 23:39:50 +00:00
|
|
|
};
|
|
|
|
|
2010-01-06 00:18:33 +00:00
|
|
|
/** @brief handle to an active libtransmission session */
|
2008-12-22 19:14:43 +00:00
|
|
|
struct tr_session
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2021-11-13 18:09:14 +00:00
|
|
|
public:
|
2022-01-23 05:41:01 +00:00
|
|
|
[[nodiscard]] auto unique_lock() const
|
2021-11-20 21:20:45 +00:00
|
|
|
{
|
|
|
|
return std::unique_lock(session_mutex_);
|
|
|
|
}
|
|
|
|
|
2022-01-23 05:41:01 +00:00
|
|
|
[[nodiscard]] bool isClosing() const
|
2021-11-18 18:19:55 +00:00
|
|
|
{
|
|
|
|
return is_closing_;
|
|
|
|
}
|
|
|
|
|
2021-12-21 22:14:15 +00:00
|
|
|
[[nodiscard]] auto const* getTorrent(tr_sha1_digest_t const& info_dict_hash) const
|
2021-12-17 04:51:53 +00:00
|
|
|
{
|
|
|
|
auto& src = this->torrentsByHash;
|
|
|
|
auto it = src.find(info_dict_hash);
|
|
|
|
return it == std::end(src) ? nullptr : it->second;
|
|
|
|
}
|
|
|
|
|
2021-12-21 22:14:15 +00:00
|
|
|
[[nodiscard]] auto* getTorrent(tr_sha1_digest_t const& info_dict_hash)
|
2021-12-17 04:51:53 +00:00
|
|
|
{
|
|
|
|
auto& src = this->torrentsByHash;
|
|
|
|
auto it = src.find(info_dict_hash);
|
|
|
|
return it == std::end(src) ? nullptr : it->second;
|
|
|
|
}
|
|
|
|
|
2022-01-13 02:13:58 +00:00
|
|
|
[[nodiscard]] tr_torrent* getTorrent(std::string_view info_dict_hash_string);
|
2021-12-17 04:51:53 +00:00
|
|
|
|
2021-12-21 22:14:15 +00:00
|
|
|
[[nodiscard]] auto contains(tr_sha1_digest_t const& info_dict_hash) const
|
2021-12-17 04:51:53 +00:00
|
|
|
{
|
|
|
|
return getTorrent(info_dict_hash) != nullptr;
|
|
|
|
}
|
|
|
|
|
2021-11-14 01:09:33 +00:00
|
|
|
// download dir
|
|
|
|
|
2021-11-13 18:09:14 +00:00
|
|
|
std::string const& downloadDir() const
|
|
|
|
{
|
|
|
|
return download_dir_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDownloadDir(std::string_view dir)
|
|
|
|
{
|
|
|
|
download_dir_ = dir;
|
|
|
|
}
|
|
|
|
|
2022-02-20 17:54:20 +00:00
|
|
|
// default trackers
|
2022-02-20 19:00:52 +00:00
|
|
|
// (trackers to apply automatically to public torrents)
|
2022-02-20 17:54:20 +00:00
|
|
|
|
2022-02-20 19:00:52 +00:00
|
|
|
auto const& defaultTrackersStr() const
|
2022-02-20 17:54:20 +00:00
|
|
|
{
|
|
|
|
return default_trackers_str_;
|
|
|
|
}
|
|
|
|
|
2022-02-20 19:00:52 +00:00
|
|
|
auto const& defaultTrackers() const
|
|
|
|
{
|
|
|
|
return default_trackers_;
|
|
|
|
}
|
|
|
|
|
2022-02-20 17:54:20 +00:00
|
|
|
void setDefaultTrackers(std::string_view trackers);
|
|
|
|
|
2021-11-14 01:09:33 +00:00
|
|
|
// incomplete dir
|
|
|
|
|
2021-11-13 20:49:10 +00:00
|
|
|
std::string const& incompleteDir() const
|
|
|
|
{
|
|
|
|
return incomplete_dir_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setIncompleteDir(std::string_view dir)
|
|
|
|
{
|
|
|
|
incomplete_dir_ = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool useIncompleteDir() const
|
|
|
|
{
|
|
|
|
return incomplete_dir_enabled_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void useIncompleteDir(bool enabled)
|
|
|
|
{
|
|
|
|
incomplete_dir_enabled_ = enabled;
|
|
|
|
}
|
|
|
|
|
2021-11-14 01:09:33 +00:00
|
|
|
// scripts
|
|
|
|
|
2021-11-13 23:33:18 +00:00
|
|
|
void useScript(TrScript i, bool enabled)
|
|
|
|
{
|
|
|
|
scripts_enabled_[i] = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool useScript(TrScript i) const
|
|
|
|
{
|
|
|
|
return scripts_enabled_[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
void setScript(TrScript i, std::string_view path)
|
|
|
|
{
|
|
|
|
scripts_[i] = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string const& script(TrScript i) const
|
|
|
|
{
|
|
|
|
return scripts_[i];
|
|
|
|
}
|
|
|
|
|
2021-11-14 01:09:33 +00:00
|
|
|
// blocklist
|
|
|
|
|
|
|
|
bool useBlocklist() const
|
|
|
|
{
|
|
|
|
return blocklist_enabled_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void useBlocklist(bool enabled);
|
|
|
|
|
|
|
|
std::string const& blocklistUrl() const
|
|
|
|
{
|
|
|
|
return blocklist_url_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setBlocklistUrl(std::string_view url)
|
|
|
|
{
|
|
|
|
blocklist_url_ = url;
|
|
|
|
}
|
|
|
|
|
2021-11-14 06:02:45 +00:00
|
|
|
// RPC
|
|
|
|
|
2021-12-15 21:25:42 +00:00
|
|
|
void setRpcWhitelist(std::string_view whitelist) const;
|
2021-11-14 06:02:45 +00:00
|
|
|
|
2021-12-15 21:25:42 +00:00
|
|
|
std::string const& rpcWhitelist() const;
|
2021-11-14 06:02:45 +00:00
|
|
|
|
2021-12-15 21:25:42 +00:00
|
|
|
void useRpcWhitelist(bool enabled) const;
|
2021-11-14 06:02:45 +00:00
|
|
|
|
2021-12-15 21:25:42 +00:00
|
|
|
bool useRpcWhitelist() const;
|
2021-11-14 06:02:45 +00:00
|
|
|
|
2021-11-14 06:41:44 +00:00
|
|
|
// peer networking
|
|
|
|
|
|
|
|
std::string const& peerCongestionAlgorithm() const
|
|
|
|
{
|
|
|
|
return peer_congestion_algorithm_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPeerCongestionAlgorithm(std::string_view algorithm)
|
|
|
|
{
|
|
|
|
peer_congestion_algorithm_ = algorithm;
|
|
|
|
}
|
|
|
|
|
2022-02-14 05:44:38 +00:00
|
|
|
void setSocketTOS(tr_socket_t sock, tr_address_type type) const
|
2021-11-14 06:41:44 +00:00
|
|
|
{
|
2022-02-10 21:35:28 +00:00
|
|
|
tr_netSetTOS(sock, peer_socket_tos_, type);
|
2021-11-14 06:41:44 +00:00
|
|
|
}
|
|
|
|
|
2021-11-13 18:09:14 +00:00
|
|
|
public:
|
2022-02-14 04:07:12 +00:00
|
|
|
static constexpr std::array<std::tuple<tr_quark, tr_quark, TrScript>, 3> Scripts{
|
|
|
|
{ { TR_KEY_script_torrent_added_enabled, TR_KEY_script_torrent_added_filename, TR_SCRIPT_ON_TORRENT_ADDED },
|
|
|
|
{ TR_KEY_script_torrent_done_enabled, TR_KEY_script_torrent_done_filename, TR_SCRIPT_ON_TORRENT_DONE },
|
|
|
|
{ TR_KEY_script_torrent_done_seeding_enabled,
|
|
|
|
TR_KEY_script_torrent_done_seeding_filename,
|
|
|
|
TR_SCRIPT_ON_TORRENT_DONE_SEEDING } }
|
|
|
|
};
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
bool isPortRandom;
|
|
|
|
bool isPexEnabled;
|
|
|
|
bool isDHTEnabled;
|
|
|
|
bool isUTPEnabled;
|
|
|
|
bool isLPDEnabled;
|
|
|
|
bool isPrefetchEnabled;
|
2021-11-18 18:19:55 +00:00
|
|
|
bool is_closing_ = false;
|
2017-04-19 12:04:45 +00:00
|
|
|
bool isClosed;
|
|
|
|
bool isRatioLimited;
|
|
|
|
bool isIdleLimited;
|
2021-11-13 20:49:10 +00:00
|
|
|
bool isIncompleteFileNamingEnabled;
|
2017-04-19 12:04:45 +00:00
|
|
|
bool pauseAddedTorrent;
|
|
|
|
bool deleteSourceTorrent;
|
|
|
|
bool scrapePausedTorrents;
|
|
|
|
|
|
|
|
uint8_t peer_id_ttl_hours;
|
|
|
|
|
2021-10-29 23:49:15 +00:00
|
|
|
// torrent id, time removed
|
|
|
|
std::vector<std::pair<int, time_t>> removed_torrents;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
bool stalledEnabled;
|
|
|
|
bool queueEnabled[2];
|
|
|
|
int queueSize[2];
|
|
|
|
int queueStalledMinutes;
|
|
|
|
|
|
|
|
int umask;
|
2013-02-02 13:42:50 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
unsigned int speedLimit_Bps[2];
|
|
|
|
bool speedLimitEnabled[2];
|
2009-03-28 16:47:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct tr_turtle_info turtle;
|
2009-03-25 19:18:00 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct tr_fdInfo* fdInfo;
|
2009-03-25 19:18:00 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int magicNumber;
|
2008-12-13 22:52:15 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_encryption_mode encryptionMode;
|
2008-04-05 16:49:26 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_preallocation_mode preallocationMode;
|
2009-01-16 16:38:16 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct event_base* event_base;
|
|
|
|
struct evdns_base* evdns_base;
|
|
|
|
struct tr_event_handle* events;
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
uint16_t peerLimit;
|
|
|
|
uint16_t peerLimitPerTorrent;
|
2008-12-13 23:17:36 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int uploadSlotsPerTorrent;
|
2009-01-09 15:45:44 +00:00
|
|
|
|
2011-01-09 21:48:36 +00:00
|
|
|
/* The UDP sockets used for the DHT and uTP. */
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_port udp_port;
|
|
|
|
tr_socket_t udp_socket;
|
|
|
|
tr_socket_t udp6_socket;
|
|
|
|
unsigned char* udp6_bound;
|
|
|
|
struct event* udp_event;
|
|
|
|
struct event* udp6_event;
|
2011-01-09 21:48:36 +00:00
|
|
|
|
2017-07-02 10:31:33 +00:00
|
|
|
struct event* utp_timer;
|
|
|
|
|
2010-07-05 21:04:17 +00:00
|
|
|
/* The open port on the local machine for incoming peer requests */
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_port private_peer_port;
|
2010-07-05 21:04:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The open port on the public device for incoming peer requests.
|
|
|
|
* This is usually the same as private_peer_port but can differ
|
|
|
|
* if the public device is a router and it decides to use a different
|
|
|
|
* port than the one requested by Transmission.
|
|
|
|
*/
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_port public_peer_port;
|
2010-07-05 21:04:17 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_port randomPortLow;
|
|
|
|
tr_port randomPortHigh;
|
2008-12-13 23:17:36 +00:00
|
|
|
|
2021-09-24 23:31:02 +00:00
|
|
|
std::unordered_set<tr_torrent*> torrents;
|
|
|
|
std::map<int, tr_torrent*> torrentsById;
|
2021-12-21 22:14:15 +00:00
|
|
|
std::map<tr_sha1_digest_t, tr_torrent*> torrentsByHash;
|
2008-04-12 00:29:49 +00:00
|
|
|
|
2022-01-02 17:51:59 +00:00
|
|
|
std::string config_dir;
|
|
|
|
std::string resume_dir;
|
|
|
|
std::string torrent_dir;
|
2007-05-16 02:03:18 +00:00
|
|
|
|
2021-09-27 18:28:41 +00:00
|
|
|
std::list<tr_blocklistFile*> blocklists;
|
2017-04-19 12:04:45 +00:00
|
|
|
struct tr_peerMgr* peerMgr;
|
|
|
|
struct tr_shared* shared;
|
2007-05-16 02:03:18 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct tr_cache* cache;
|
2010-06-19 14:25:11 +00:00
|
|
|
|
2022-02-16 18:33:50 +00:00
|
|
|
class WebController final : public tr_web::Controller
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit WebController(tr_session* session)
|
|
|
|
: session_{ session }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
~WebController() override = default;
|
|
|
|
|
|
|
|
[[nodiscard]] std::optional<std::string> cookieFile() const override;
|
|
|
|
[[nodiscard]] std::optional<std::string> publicAddress() const override;
|
|
|
|
[[nodiscard]] std::optional<std::string> userAgent() const override;
|
|
|
|
[[nodiscard]] unsigned int clamp(int bandwidth_tag, unsigned int byte_count) const override;
|
|
|
|
void notifyBandwidthConsumed(int torrent_id, size_t byte_count) override;
|
|
|
|
// runs the tr_web::fetch response callback in the libtransmission thread
|
2022-02-17 23:35:57 +00:00
|
|
|
void run(tr_web::FetchDoneFunc&& func, tr_web::FetchResponse&& response) const override;
|
2022-02-16 18:33:50 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
tr_session* const session_;
|
|
|
|
};
|
|
|
|
|
|
|
|
WebController web_controller{ this };
|
|
|
|
std::unique_ptr<tr_web> web;
|
2008-04-24 01:42:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct tr_session_id* session_id;
|
2021-11-14 21:14:37 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_rpc_func rpc_func;
|
|
|
|
void* rpc_func_user_data;
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct tr_stats_handle* sessionStats;
|
2009-09-25 21:05:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct tr_announcer* announcer;
|
|
|
|
struct tr_announcer_udp* announcer_udp;
|
2007-02-06 04:26:40 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct event* nowTimer;
|
|
|
|
struct event* saveTimer;
|
2009-03-25 19:18:00 +00:00
|
|
|
|
2008-11-24 04:21:23 +00:00
|
|
|
/* monitors the "global pool" speeds */
|
2021-10-09 12:52:09 +00:00
|
|
|
// Changed to non-owning pointer temporarily till tr_session becomes C++-constructible and destructible
|
|
|
|
// TODO: change tr_bandwidth* to owning pointer to the bandwidth, or remove * and own the value
|
2021-10-10 01:12:03 +00:00
|
|
|
Bandwidth* bandwidth;
|
2009-02-13 18:23:56 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
float desiredRatio;
|
2010-12-12 16:43:19 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
uint16_t idleLimitMinutes;
|
2009-05-14 13:42:29 +00:00
|
|
|
|
2021-05-19 20:45:03 +00:00
|
|
|
struct tr_bindinfo* bind_ipv4;
|
|
|
|
struct tr_bindinfo* bind_ipv6;
|
2021-11-13 18:09:14 +00:00
|
|
|
|
2021-11-14 21:14:37 +00:00
|
|
|
std::unique_ptr<tr_rpc_server> rpc_server_;
|
|
|
|
|
2022-02-20 19:00:52 +00:00
|
|
|
tr_announce_list default_trackers_;
|
2022-02-20 17:54:20 +00:00
|
|
|
|
2022-02-10 21:35:28 +00:00
|
|
|
// One of <netinet/ip.h>'s IPTOS_ values.
|
|
|
|
// See tr_netTos*() in libtransmission/net.h for more info
|
|
|
|
// Only session.cc should use this.
|
|
|
|
int peer_socket_tos_ = *tr_netTosFromName(TR_DEFAULT_PEER_SOCKET_TOS_STR);
|
|
|
|
|
2021-11-13 18:09:14 +00:00
|
|
|
private:
|
2021-11-20 21:20:45 +00:00
|
|
|
static std::recursive_mutex session_mutex_;
|
|
|
|
|
2021-11-13 23:33:18 +00:00
|
|
|
std::array<std::string, TR_SCRIPT_N_TYPES> scripts_;
|
2021-11-14 01:09:33 +00:00
|
|
|
std::string blocklist_url_;
|
2021-11-13 18:09:14 +00:00
|
|
|
std::string download_dir_;
|
2022-02-20 17:54:20 +00:00
|
|
|
std::string default_trackers_str_;
|
2021-11-14 01:09:33 +00:00
|
|
|
std::string incomplete_dir_;
|
2021-11-14 06:41:44 +00:00
|
|
|
std::string peer_congestion_algorithm_;
|
|
|
|
|
2021-11-13 23:33:18 +00:00
|
|
|
std::array<bool, TR_SCRIPT_N_TYPES> scripts_enabled_;
|
2021-11-14 01:09:33 +00:00
|
|
|
bool blocklist_enabled_ = false;
|
2021-11-13 20:49:10 +00:00
|
|
|
bool incomplete_dir_enabled_ = false;
|
2006-07-16 19:39:23 +00:00
|
|
|
};
|
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr tr_port tr_sessionGetPublicPeerPort(tr_session const* session)
|
2010-07-05 21:04:17 +00:00
|
|
|
{
|
|
|
|
return session->public_peer_port;
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_sessionAllowsDHT(tr_session const* session);
|
2010-05-01 16:04:00 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_sessionAllowsLPD(tr_session const* session);
|
2008-04-24 01:42:53 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_sessionIsAddressBlocked(tr_session const* session, struct tr_address const* addr);
|
2008-06-11 16:15:45 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
struct tr_address const* tr_sessionGetPublicAddress(tr_session const* session, int tr_af_type, bool* is_default_value);
|
2009-05-14 13:42:29 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct tr_bindsockets* tr_sessionGetBindSockets(tr_session*);
|
2009-05-14 13:42:29 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
int tr_sessionCountTorrents(tr_session const* session);
|
2010-04-29 23:08:11 +00:00
|
|
|
|
2021-09-24 23:31:02 +00:00
|
|
|
std::vector<tr_torrent*> tr_sessionGetTorrents(tr_session* session);
|
2013-07-20 15:37:13 +00:00
|
|
|
|
2009-01-29 16:56:43 +00:00
|
|
|
enum
|
|
|
|
{
|
2010-02-23 07:20:57 +00:00
|
|
|
SESSION_MAGIC_NUMBER = 3845,
|
2009-01-29 16:56:43 +00:00
|
|
|
};
|
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr bool tr_isSession(tr_session const* session)
|
2009-01-29 16:56:43 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
return session != nullptr && session->magicNumber == SESSION_MAGIC_NUMBER;
|
2009-01-29 16:56:43 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr bool tr_isPreallocationMode(tr_preallocation_mode m)
|
2009-05-29 19:17:12 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
return m == TR_PREALLOCATE_NONE || m == TR_PREALLOCATE_SPARSE || m == TR_PREALLOCATE_FULL;
|
2009-05-29 19:17:12 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr bool tr_isEncryptionMode(tr_encryption_mode m)
|
2009-05-29 19:17:12 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
return m == TR_CLEAR_PREFERRED || m == TR_ENCRYPTION_PREFERRED || m == TR_ENCRYPTION_REQUIRED;
|
2009-05-29 19:17:12 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr bool tr_isPriority(tr_priority_t p)
|
2009-05-29 19:17:12 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
return p == TR_PRI_LOW || p == TR_PRI_NORMAL || p == TR_PRI_HIGH;
|
2009-05-29 19:17:12 +00:00
|
|
|
}
|
|
|
|
|
2010-07-04 06:07:21 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
unsigned int tr_sessionGetSpeedLimit_Bps(tr_session const*, tr_direction);
|
|
|
|
unsigned int tr_sessionGetPieceSpeed_Bps(tr_session const*, tr_direction);
|
2010-07-04 06:07:21 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_sessionGetActiveSpeedLimit_Bps(tr_session const* session, tr_direction dir, unsigned int* setme);
|
2011-08-01 22:24:24 +00:00
|
|
|
|
2021-09-29 22:21:04 +00:00
|
|
|
std::vector<tr_torrent*> tr_sessionGetNextQueuedTorrents(tr_session* session, tr_direction dir, size_t numwanted);
|
2011-08-01 22:24:24 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int tr_sessionCountQueueFreeSlots(tr_session* session, tr_direction);
|
2020-08-11 18:11:55 +00:00
|
|
|
|
2021-09-09 05:22:29 +00:00
|
|
|
void tr_sessionAddTorrent(tr_session* session, tr_torrent* tor);
|
|
|
|
void tr_sessionRemoveTorrent(tr_session* session, tr_torrent* tor);
|