2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2009-2022 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2007-12-25 05:37:32 +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
|
|
|
|
|
2021-12-16 09:43:51 +00:00
|
|
|
#include <cstddef> // size_t
|
2021-12-15 21:25:42 +00:00
|
|
|
#include <ctime>
|
2021-10-22 02:40:55 +00:00
|
|
|
#include <optional>
|
2021-09-29 19:52:19 +00:00
|
|
|
#include <string>
|
2021-10-20 02:30:50 +00:00
|
|
|
#include <string_view>
|
2021-10-16 14:04:19 +00:00
|
|
|
#include <vector>
|
2021-09-29 19:52:19 +00:00
|
|
|
|
2021-11-24 14:48:52 +00:00
|
|
|
#include "transmission.h"
|
|
|
|
|
2021-12-14 20:59:40 +00:00
|
|
|
#include "announce-list.h"
|
2021-11-09 03:30:03 +00:00
|
|
|
#include "bandwidth.h"
|
2021-10-29 18:24:30 +00:00
|
|
|
#include "bitfield.h"
|
2021-11-24 14:48:52 +00:00
|
|
|
#include "block-info.h"
|
2021-11-09 03:30:03 +00:00
|
|
|
#include "completion.h"
|
2021-11-29 01:12:54 +00:00
|
|
|
#include "file-piece-map.h"
|
2021-12-23 17:16:05 +00:00
|
|
|
#include "interned-string.h"
|
2022-03-11 21:09:22 +00:00
|
|
|
#include "log.h"
|
2021-11-09 03:30:03 +00:00
|
|
|
#include "session.h"
|
2022-01-15 19:33:57 +00:00
|
|
|
#include "torrent-metainfo.h"
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "tr-macros.h"
|
2009-01-02 17:01:55 +00:00
|
|
|
|
2021-10-10 00:13:40 +00:00
|
|
|
class tr_swarm;
|
2021-12-15 21:25:42 +00:00
|
|
|
struct tr_error;
|
2021-11-09 03:30:03 +00:00
|
|
|
struct tr_magnet_info;
|
2021-11-12 16:42:51 +00:00
|
|
|
struct tr_metainfo_parsed;
|
2021-11-09 03:30:03 +00:00
|
|
|
struct tr_session;
|
2021-10-29 18:24:30 +00:00
|
|
|
struct tr_torrent;
|
2022-01-23 05:41:01 +00:00
|
|
|
struct tr_torrent_announcer;
|
2008-11-06 02:56:51 +00:00
|
|
|
|
2008-10-20 16:00:14 +00:00
|
|
|
/**
|
|
|
|
*** Package-visible ctor API
|
|
|
|
**/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_torrentFree(tr_torrent* tor);
|
2012-12-14 20:04:37 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_ctorInitTorrentPriorities(tr_ctor const* ctor, tr_torrent* tor);
|
2009-04-02 20:43:42 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_ctorInitTorrentWanted(tr_ctor const* ctor, tr_torrent* tor);
|
2009-04-02 20:43:42 +00:00
|
|
|
|
2022-03-28 22:13:32 +00:00
|
|
|
bool tr_ctorSaveContents(tr_ctor const* ctor, std::string_view filename, tr_error** error);
|
2022-02-24 21:52:29 +00:00
|
|
|
|
2021-12-05 01:32:35 +00:00
|
|
|
tr_session* tr_ctorGetSession(tr_ctor const* ctor);
|
|
|
|
|
|
|
|
bool tr_ctorGetIncompleteDir(tr_ctor const* ctor, char const** setmeIncompleteDir);
|
|
|
|
|
2008-10-20 16:00:14 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2022-08-03 06:15:37 +00:00
|
|
|
void tr_torrentChangeMyPort(tr_torrent* tor);
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2021-12-21 22:14:15 +00:00
|
|
|
tr_torrent* tr_torrentFindFromObfuscatedHash(tr_session* session, tr_sha1_digest_t const& hash);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_torrentReqIsValid(tr_torrent const* tor, tr_piece_index_t index, uint32_t offset, uint32_t length);
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2022-01-08 23:41:05 +00:00
|
|
|
tr_block_span_t tr_torGetFileBlockSpan(tr_torrent const* tor, tr_file_index_t file);
|
2011-02-23 03:54:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_torrentCheckSeedLimit(tr_torrent* tor);
|
2009-03-01 13:56:22 +00:00
|
|
|
|
2009-08-13 14:47:56 +00:00
|
|
|
/** save a torrent's .resume file if it's changed since the last time it was saved */
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_torrentSave(tr_torrent* tor);
|
2009-03-01 13:56:22 +00:00
|
|
|
|
2022-04-28 01:06:51 +00:00
|
|
|
enum tr_verify_state : uint8_t
|
2007-12-25 05:37:32 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
TR_VERIFY_NONE,
|
|
|
|
TR_VERIFY_WAIT,
|
|
|
|
TR_VERIFY_NOW
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2017-04-21 07:40:57 +00:00
|
|
|
tr_torrent_activity tr_torrentGetActivity(tr_torrent const* tor);
|
2010-05-01 16:04:00 +00:00
|
|
|
|
2009-11-24 02:16:31 +00:00
|
|
|
struct tr_incomplete_metadata;
|
|
|
|
|
2010-01-19 19:37:00 +00:00
|
|
|
/** @brief Torrent object */
|
2022-04-28 13:44:24 +00:00
|
|
|
struct tr_torrent final : public tr_completion::torrent_view
|
2007-12-25 05:37:32 +00:00
|
|
|
{
|
2021-11-15 20:53:53 +00:00
|
|
|
public:
|
2022-01-15 19:33:57 +00:00
|
|
|
explicit tr_torrent(tr_torrent_metainfo&& tm)
|
|
|
|
: metainfo_{ std::move(tm) }
|
|
|
|
, completion{ this, &this->metainfo_.blockInfo() }
|
2021-11-25 18:26:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-01-07 19:13:37 +00:00
|
|
|
~tr_torrent() override = default;
|
2021-11-25 18:26:51 +00:00
|
|
|
|
2021-11-15 20:53:53 +00:00
|
|
|
void setLocation(
|
|
|
|
std::string_view location,
|
2022-08-03 06:15:37 +00:00
|
|
|
bool move_from_old_path,
|
2021-11-15 20:53:53 +00:00
|
|
|
double volatile* setme_progress,
|
|
|
|
int volatile* setme_state);
|
2021-11-12 16:42:51 +00:00
|
|
|
|
2021-11-16 04:10:36 +00:00
|
|
|
void renamePath(
|
|
|
|
std::string_view oldpath,
|
|
|
|
std::string_view newname,
|
|
|
|
tr_torrent_rename_done_func callback,
|
|
|
|
void* callback_user_data);
|
|
|
|
|
2021-11-12 16:42:51 +00:00
|
|
|
tr_sha1_digest_t pieceHash(tr_piece_index_t i) const
|
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.pieceHash(i);
|
2021-11-12 16:42:51 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 20:53:53 +00:00
|
|
|
// these functions should become private when possible,
|
|
|
|
// but more refactoring is needed before that can happen
|
|
|
|
// because much of tr_torrent's impl is in the non-member C bindings
|
2022-01-15 19:33:57 +00:00
|
|
|
|
|
|
|
void setMetainfo(tr_torrent_metainfo const& tm);
|
2021-10-29 18:24:30 +00:00
|
|
|
|
2022-01-23 05:41:01 +00:00
|
|
|
[[nodiscard]] auto unique_lock() const
|
2021-11-20 21:20:45 +00:00
|
|
|
{
|
|
|
|
return session->unique_lock();
|
|
|
|
}
|
|
|
|
|
2021-12-16 08:49:04 +00:00
|
|
|
/// SPEED LIMIT
|
|
|
|
|
|
|
|
void setSpeedLimitBps(tr_direction, unsigned int Bps);
|
|
|
|
|
2022-01-23 05:41:01 +00:00
|
|
|
[[nodiscard]] unsigned int speedLimitBps(tr_direction) const;
|
2021-12-16 08:49:04 +00:00
|
|
|
|
2022-01-07 19:13:37 +00:00
|
|
|
/// BLOCK INFO
|
|
|
|
|
|
|
|
[[nodiscard]] constexpr auto const& blockInfo() const
|
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.blockInfo();
|
2022-01-07 19:13:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] constexpr auto blockCount() const noexcept
|
2022-01-07 19:13:37 +00:00
|
|
|
{
|
2022-01-24 00:53:35 +00:00
|
|
|
return metainfo_.blockCount();
|
2022-01-07 19:13:37 +00:00
|
|
|
}
|
2022-02-18 23:17:19 +00:00
|
|
|
[[nodiscard]] auto byteLoc(uint64_t byte) const
|
2022-01-07 19:13:37 +00:00
|
|
|
{
|
2022-02-18 23:17:19 +00:00
|
|
|
return metainfo_.byteLoc(byte);
|
2022-01-07 19:13:37 +00:00
|
|
|
}
|
2022-02-18 23:17:19 +00:00
|
|
|
[[nodiscard]] auto blockLoc(tr_block_index_t block) const
|
2022-01-07 19:13:37 +00:00
|
|
|
{
|
2022-02-18 23:17:19 +00:00
|
|
|
return metainfo_.blockLoc(block);
|
|
|
|
}
|
2022-02-19 16:07:08 +00:00
|
|
|
[[nodiscard]] auto pieceLoc(tr_piece_index_t piece, uint32_t offset = 0, uint32_t length = 0) const
|
2022-02-18 23:17:19 +00:00
|
|
|
{
|
|
|
|
return metainfo_.pieceLoc(piece, offset, length);
|
2022-01-07 19:13:37 +00:00
|
|
|
}
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] constexpr auto blockSize(tr_block_index_t block) const noexcept
|
2022-01-07 19:13:37 +00:00
|
|
|
{
|
2022-01-24 00:53:35 +00:00
|
|
|
return metainfo_.blockSize(block);
|
2022-01-07 19:13:37 +00:00
|
|
|
}
|
2022-04-14 01:22:59 +00:00
|
|
|
[[nodiscard]] auto blockSpanForPiece(tr_piece_index_t piece) const
|
2022-01-07 19:13:37 +00:00
|
|
|
{
|
2022-01-24 00:53:35 +00:00
|
|
|
return metainfo_.blockSpanForPiece(piece);
|
2022-01-07 19:13:37 +00:00
|
|
|
}
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] constexpr auto pieceCount() const noexcept
|
2022-01-07 19:13:37 +00:00
|
|
|
{
|
2022-01-24 00:53:35 +00:00
|
|
|
return metainfo_.pieceCount();
|
2022-01-07 19:13:37 +00:00
|
|
|
}
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] constexpr auto pieceSize() const noexcept
|
2022-01-07 19:13:37 +00:00
|
|
|
{
|
2022-01-24 00:53:35 +00:00
|
|
|
return metainfo_.pieceSize();
|
2022-01-07 19:13:37 +00:00
|
|
|
}
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] constexpr auto pieceSize(tr_piece_index_t piece) const noexcept
|
2022-01-07 19:13:37 +00:00
|
|
|
{
|
2022-01-24 00:53:35 +00:00
|
|
|
return metainfo_.pieceSize(piece);
|
2022-01-07 19:13:37 +00:00
|
|
|
}
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] constexpr auto totalSize() const noexcept
|
2022-01-07 19:13:37 +00:00
|
|
|
{
|
2022-01-24 00:53:35 +00:00
|
|
|
return metainfo_.totalSize();
|
2022-01-07 19:13:37 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 18:26:51 +00:00
|
|
|
/// COMPLETION
|
2021-11-15 20:53:53 +00:00
|
|
|
|
2022-03-17 18:41:48 +00:00
|
|
|
[[nodiscard]] auto leftUntilDone() const
|
2021-11-25 18:26:51 +00:00
|
|
|
{
|
|
|
|
return completion.leftUntilDone();
|
|
|
|
}
|
2021-11-15 20:53:53 +00:00
|
|
|
|
2022-03-17 18:41:48 +00:00
|
|
|
[[nodiscard]] auto sizeWhenDone() const
|
|
|
|
{
|
|
|
|
return completion.sizeWhenDone();
|
|
|
|
}
|
|
|
|
|
2022-03-29 04:29:35 +00:00
|
|
|
[[nodiscard]] auto hasMetainfo() const noexcept
|
|
|
|
{
|
2022-04-01 13:49:54 +00:00
|
|
|
return completion.hasMetainfo();
|
2022-03-29 04:29:35 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto hasAll() const noexcept
|
2021-11-25 18:26:51 +00:00
|
|
|
{
|
|
|
|
return completion.hasAll();
|
|
|
|
}
|
2021-11-15 20:53:53 +00:00
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto hasNone() const noexcept
|
2021-11-25 18:26:51 +00:00
|
|
|
{
|
|
|
|
return completion.hasNone();
|
|
|
|
}
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2022-03-17 18:41:48 +00:00
|
|
|
[[nodiscard]] auto hasPiece(tr_piece_index_t piece) const
|
2021-11-25 18:26:51 +00:00
|
|
|
{
|
|
|
|
return completion.hasPiece(piece);
|
|
|
|
}
|
2021-10-29 18:24:30 +00:00
|
|
|
|
2022-03-17 18:41:48 +00:00
|
|
|
[[nodiscard]] auto hasBlock(tr_block_index_t block) const
|
2021-11-25 18:26:51 +00:00
|
|
|
{
|
|
|
|
return completion.hasBlock(block);
|
|
|
|
}
|
|
|
|
|
2022-03-17 18:41:48 +00:00
|
|
|
[[nodiscard]] auto countMissingBlocksInPiece(tr_piece_index_t piece) const
|
2021-11-25 18:26:51 +00:00
|
|
|
{
|
|
|
|
return completion.countMissingBlocksInPiece(piece);
|
|
|
|
}
|
|
|
|
|
2022-03-17 18:41:48 +00:00
|
|
|
[[nodiscard]] auto countMissingBytesInPiece(tr_piece_index_t piece) const
|
2021-11-25 18:26:51 +00:00
|
|
|
{
|
|
|
|
return completion.countMissingBytesInPiece(piece);
|
|
|
|
}
|
|
|
|
|
2022-03-17 18:41:48 +00:00
|
|
|
[[nodiscard]] auto hasTotal() const
|
2021-11-25 18:26:51 +00:00
|
|
|
{
|
|
|
|
return completion.hasTotal();
|
|
|
|
}
|
|
|
|
|
2022-03-17 18:41:48 +00:00
|
|
|
[[nodiscard]] auto createPieceBitfield() const
|
2021-11-25 18:26:51 +00:00
|
|
|
{
|
|
|
|
return completion.createPieceBitfield();
|
|
|
|
}
|
|
|
|
|
2022-04-02 00:48:09 +00:00
|
|
|
[[nodiscard]] constexpr bool isDone() const noexcept
|
2021-11-25 18:26:51 +00:00
|
|
|
{
|
2021-12-15 07:04:26 +00:00
|
|
|
return completeness != TR_LEECH;
|
2021-11-25 18:26:51 +00:00
|
|
|
}
|
2021-10-29 18:24:30 +00:00
|
|
|
|
2022-04-02 00:48:09 +00:00
|
|
|
[[nodiscard]] constexpr bool isSeed() const noexcept
|
2021-12-16 08:49:04 +00:00
|
|
|
{
|
|
|
|
return completeness == TR_SEED;
|
|
|
|
}
|
|
|
|
|
2022-04-02 00:48:09 +00:00
|
|
|
[[nodiscard]] constexpr bool isPartialSeed() const noexcept
|
2021-12-16 08:49:04 +00:00
|
|
|
{
|
|
|
|
return completeness == TR_PARTIAL_SEED;
|
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] tr_bitfield const& blocks() const noexcept
|
2021-11-25 18:26:51 +00:00
|
|
|
{
|
|
|
|
return completion.blocks();
|
|
|
|
}
|
|
|
|
|
|
|
|
void amountDoneBins(float* tab, int n_tabs) const
|
|
|
|
{
|
|
|
|
return completion.amountDone(tab, n_tabs);
|
|
|
|
}
|
|
|
|
|
2021-12-16 22:58:58 +00:00
|
|
|
void setBlocks(tr_bitfield blocks);
|
2021-11-25 18:26:51 +00:00
|
|
|
|
|
|
|
void setHasPiece(tr_piece_index_t piece, bool has)
|
|
|
|
{
|
|
|
|
completion.setHasPiece(piece, has);
|
|
|
|
}
|
|
|
|
|
2021-11-29 01:12:54 +00:00
|
|
|
/// FILE <-> PIECE
|
|
|
|
|
2021-12-16 08:49:04 +00:00
|
|
|
[[nodiscard]] auto piecesInFile(tr_file_index_t file) const
|
2021-10-29 18:24:30 +00:00
|
|
|
{
|
2021-11-29 01:12:54 +00:00
|
|
|
return fpm_.pieceSpan(file);
|
2021-10-29 18:24:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-19 16:07:08 +00:00
|
|
|
[[nodiscard]] auto fileOffset(tr_block_info::Location loc) const
|
2021-12-24 06:39:55 +00:00
|
|
|
{
|
2022-02-19 16:07:08 +00:00
|
|
|
return fpm_.fileOffset(loc.byte);
|
2021-12-24 06:39:55 +00:00
|
|
|
}
|
|
|
|
|
2022-06-20 04:08:58 +00:00
|
|
|
[[nodiscard]] auto byteSpan(tr_file_index_t file) const
|
|
|
|
{
|
|
|
|
return fpm_.byteSpan(file);
|
|
|
|
}
|
|
|
|
|
2021-11-29 01:12:54 +00:00
|
|
|
/// WANTED
|
2021-10-29 18:24:30 +00:00
|
|
|
|
2021-12-16 08:49:04 +00:00
|
|
|
[[nodiscard]] bool pieceIsWanted(tr_piece_index_t piece) const final
|
2021-10-29 18:24:30 +00:00
|
|
|
{
|
2021-11-29 01:12:54 +00:00
|
|
|
return files_wanted_.pieceWanted(piece);
|
|
|
|
}
|
2021-10-29 18:24:30 +00:00
|
|
|
|
2021-12-16 08:49:04 +00:00
|
|
|
[[nodiscard]] bool fileIsWanted(tr_file_index_t file) const
|
2021-11-29 01:12:54 +00:00
|
|
|
{
|
|
|
|
return files_wanted_.fileWanted(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
void initFilesWanted(tr_file_index_t const* files, size_t n_files, bool wanted)
|
|
|
|
{
|
|
|
|
setFilesWanted(files, n_files, wanted, /*is_bootstrapping*/ true);
|
2021-10-29 18:24:30 +00:00
|
|
|
}
|
|
|
|
|
2021-11-29 01:12:54 +00:00
|
|
|
void setFilesWanted(tr_file_index_t const* files, size_t n_files, bool wanted)
|
|
|
|
{
|
|
|
|
setFilesWanted(files, n_files, wanted, /*is_bootstrapping*/ false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void recheckCompleteness(); // TODO(ckerr): should be private
|
|
|
|
|
|
|
|
/// PRIORITIES
|
|
|
|
|
2021-12-16 08:49:04 +00:00
|
|
|
[[nodiscard]] tr_priority_t piecePriority(tr_piece_index_t piece) const
|
2021-10-29 18:24:30 +00:00
|
|
|
{
|
2021-11-29 01:12:54 +00:00
|
|
|
return file_priorities_.piecePriority(piece);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setFilePriorities(tr_file_index_t const* files, tr_file_index_t fileCount, tr_priority_t priority)
|
|
|
|
{
|
|
|
|
file_priorities_.set(files, fileCount, priority);
|
|
|
|
setDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setFilePriority(tr_file_index_t file, tr_priority_t priority)
|
|
|
|
{
|
|
|
|
file_priorities_.set(file, priority);
|
|
|
|
setDirty();
|
2021-10-29 18:24:30 +00:00
|
|
|
}
|
|
|
|
|
2021-12-23 17:16:05 +00:00
|
|
|
/// LOCATION
|
|
|
|
|
2022-04-02 00:48:09 +00:00
|
|
|
[[nodiscard]] constexpr tr_interned_string currentDir() const noexcept
|
2021-12-23 17:16:05 +00:00
|
|
|
{
|
|
|
|
return this->current_dir;
|
|
|
|
}
|
|
|
|
|
2022-04-02 00:48:09 +00:00
|
|
|
[[nodiscard]] constexpr tr_interned_string downloadDir() const noexcept
|
2021-12-23 17:16:05 +00:00
|
|
|
{
|
|
|
|
return this->download_dir;
|
|
|
|
}
|
|
|
|
|
2022-04-02 00:48:09 +00:00
|
|
|
[[nodiscard]] constexpr tr_interned_string incompleteDir() const noexcept
|
2021-12-23 17:16:05 +00:00
|
|
|
{
|
|
|
|
return this->incomplete_dir;
|
|
|
|
}
|
|
|
|
|
2021-12-15 05:48:56 +00:00
|
|
|
/// METAINFO - FILES
|
2021-12-07 04:18:17 +00:00
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] tr_file_index_t fileCount() const noexcept
|
2021-12-07 04:18:17 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.fileCount();
|
2021-12-07 04:18:17 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 18:53:35 +00:00
|
|
|
[[nodiscard]] std::string const& fileSubpath(tr_file_index_t i) const
|
2021-12-07 04:18:17 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.fileSubpath(i);
|
2021-12-07 04:18:17 +00:00
|
|
|
}
|
|
|
|
|
2022-01-02 01:25:25 +00:00
|
|
|
[[nodiscard]] auto fileSize(tr_file_index_t i) const
|
2021-12-07 04:18:17 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.fileSize(i);
|
2021-12-07 04:18:17 +00:00
|
|
|
}
|
|
|
|
|
2022-01-15 19:33:57 +00:00
|
|
|
void setFileSubpath(tr_file_index_t i, std::string_view subpath)
|
|
|
|
{
|
|
|
|
metainfo_.setFileSubpath(i, subpath);
|
|
|
|
}
|
2022-01-02 01:25:25 +00:00
|
|
|
|
2022-04-15 23:39:04 +00:00
|
|
|
[[nodiscard]] std::optional<tr_torrent_files::FoundFile> findFile(tr_file_index_t file_index) const;
|
2022-04-02 14:06:02 +00:00
|
|
|
|
2022-04-14 02:41:06 +00:00
|
|
|
[[nodiscard]] bool hasAnyLocalData() const;
|
2021-12-07 04:18:17 +00:00
|
|
|
|
2021-12-15 05:48:56 +00:00
|
|
|
/// METAINFO - TRACKERS
|
2021-12-14 20:59:40 +00:00
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto const& announceList() const noexcept
|
2022-01-07 19:13:37 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.announceList();
|
2022-01-07 19:13:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto& announceList() noexcept
|
2022-01-07 19:13:37 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.announceList();
|
2022-01-07 19:13:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto trackerCount() const noexcept
|
2021-12-14 20:59:40 +00:00
|
|
|
{
|
2022-01-07 19:13:37 +00:00
|
|
|
return std::size(this->announceList());
|
2021-12-14 20:59:40 +00:00
|
|
|
}
|
|
|
|
|
2021-12-16 08:49:04 +00:00
|
|
|
[[nodiscard]] auto const& tracker(size_t i) const
|
2021-12-14 20:59:40 +00:00
|
|
|
{
|
2022-01-07 19:13:37 +00:00
|
|
|
return this->announceList().at(i);
|
2021-12-14 20:59:40 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 17:52:01 +00:00
|
|
|
[[nodiscard]] auto trackerList() const
|
|
|
|
{
|
|
|
|
return this->announceList().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool setTrackerList(std::string_view text);
|
|
|
|
|
2021-12-15 05:48:56 +00:00
|
|
|
/// METAINFO - WEBSEEDS
|
2021-12-07 18:11:28 +00:00
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto webseedCount() const noexcept
|
2021-12-07 18:11:28 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.webseedCount();
|
2021-12-07 18:11:28 +00:00
|
|
|
}
|
|
|
|
|
2021-12-16 08:49:04 +00:00
|
|
|
[[nodiscard]] auto const& webseed(size_t i) const
|
2021-12-07 18:11:28 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.webseed(i);
|
2021-12-07 18:11:28 +00:00
|
|
|
}
|
|
|
|
|
2021-12-15 15:53:20 +00:00
|
|
|
/// METAINFO - OTHER
|
|
|
|
|
2022-01-15 19:33:57 +00:00
|
|
|
void setName(std::string_view name)
|
|
|
|
{
|
|
|
|
metainfo_.setName(name);
|
|
|
|
}
|
2021-12-24 21:12:33 +00:00
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto const& name() const noexcept
|
2022-01-08 23:41:05 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.name();
|
2022-01-08 23:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto const& infoHash() const noexcept
|
2021-12-21 22:14:15 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.infoHash();
|
2021-12-21 22:14:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto isPrivate() const noexcept
|
2021-12-15 15:53:20 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.isPrivate();
|
2021-12-15 15:53:20 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto isPublic() const noexcept
|
2021-12-15 15:53:20 +00:00
|
|
|
{
|
|
|
|
return !this->isPrivate();
|
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto const& infoHashString() const noexcept
|
2022-01-08 23:41:05 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.infoHashString();
|
2022-01-08 23:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto dateCreated() const noexcept
|
2021-12-15 15:53:20 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.dateCreated();
|
2021-12-15 15:53:20 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 05:14:00 +00:00
|
|
|
[[nodiscard]] auto torrentFile() const
|
2021-12-15 15:53:20 +00:00
|
|
|
{
|
2022-07-23 07:13:18 +00:00
|
|
|
return metainfo_.torrentFile(session->torrentDir());
|
2022-01-15 19:33:57 +00:00
|
|
|
}
|
|
|
|
|
2022-02-24 21:52:29 +00:00
|
|
|
[[nodiscard]] auto magnetFile() const
|
|
|
|
{
|
2022-07-23 07:13:18 +00:00
|
|
|
return metainfo_.magnetFile(session->torrentDir());
|
2022-02-24 21:52:29 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 05:14:00 +00:00
|
|
|
[[nodiscard]] auto resumeFile() const
|
2022-01-15 19:33:57 +00:00
|
|
|
{
|
2022-07-23 07:13:18 +00:00
|
|
|
return metainfo_.resumeFile(session->resumeDir());
|
2022-01-08 23:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-24 21:52:29 +00:00
|
|
|
[[nodiscard]] auto magnet() const
|
|
|
|
{
|
|
|
|
return metainfo_.magnet();
|
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto const& comment() const noexcept
|
2022-01-08 23:41:05 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.comment();
|
2022-01-08 23:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto const& creator() const noexcept
|
2022-01-08 23:41:05 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.creator();
|
2022-01-08 23:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto const& source() const noexcept
|
2022-01-08 23:41:05 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.source();
|
2021-12-15 15:53:20 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto infoDictSize() const noexcept
|
2021-12-24 21:12:33 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.infoDictSize();
|
2022-01-08 20:05:38 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto infoDictOffset() const noexcept
|
2022-01-08 20:05:38 +00:00
|
|
|
{
|
2022-01-15 19:33:57 +00:00
|
|
|
return metainfo_.infoDictOffset();
|
2021-12-24 21:12:33 +00:00
|
|
|
}
|
|
|
|
|
2022-03-18 21:31:25 +00:00
|
|
|
/// METAINFO - PIECE CHECKSUMS
|
|
|
|
|
|
|
|
[[nodiscard]] bool isPieceChecked(tr_piece_index_t piece) const
|
|
|
|
{
|
|
|
|
return checked_pieces_.test(piece);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] bool checkPiece(tr_piece_index_t piece);
|
2021-10-29 18:24:30 +00:00
|
|
|
|
2022-01-15 19:33:57 +00:00
|
|
|
[[nodiscard]] bool ensurePieceIsChecked(tr_piece_index_t piece);
|
2021-10-29 18:24:30 +00:00
|
|
|
|
2022-01-15 19:33:57 +00:00
|
|
|
void initCheckedPieces(tr_bitfield const& checked, time_t const* mtimes /*fileCount()*/);
|
2021-10-29 18:24:30 +00:00
|
|
|
|
2021-12-15 05:48:56 +00:00
|
|
|
///
|
|
|
|
|
2022-04-02 00:48:09 +00:00
|
|
|
[[nodiscard]] constexpr auto isQueued() const noexcept
|
2021-12-16 08:49:04 +00:00
|
|
|
{
|
|
|
|
return this->is_queued;
|
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] constexpr auto queueDirection() const noexcept
|
2021-12-15 07:04:26 +00:00
|
|
|
{
|
|
|
|
return this->isDone() ? TR_UP : TR_DOWN;
|
|
|
|
}
|
|
|
|
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] auto allowsPex() const noexcept
|
2021-12-15 05:48:56 +00:00
|
|
|
{
|
|
|
|
return this->isPublic() && this->session->isPexEnabled;
|
|
|
|
}
|
|
|
|
|
2021-12-16 08:49:04 +00:00
|
|
|
[[nodiscard]] auto allowsDht() const
|
2021-12-15 05:48:56 +00:00
|
|
|
{
|
|
|
|
return this->isPublic() && tr_sessionAllowsDHT(this->session);
|
|
|
|
}
|
|
|
|
|
2021-12-16 08:49:04 +00:00
|
|
|
[[nodiscard]] auto allowsLpd() const // local peer discovery
|
2021-12-15 05:48:56 +00:00
|
|
|
{
|
|
|
|
return this->isPublic() && tr_sessionAllowsLPD(this->session);
|
|
|
|
}
|
|
|
|
|
2021-12-17 04:51:53 +00:00
|
|
|
[[nodiscard]] bool isPieceTransferAllowed(tr_direction direction) const;
|
|
|
|
|
|
|
|
[[nodiscard]] bool clientCanDownload() const
|
|
|
|
{
|
|
|
|
return this->isPieceTransferAllowed(TR_PEER_TO_CLIENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] bool clientCanUpload() const
|
|
|
|
{
|
|
|
|
return this->isPieceTransferAllowed(TR_CLIENT_TO_PEER);
|
|
|
|
}
|
|
|
|
|
2021-12-23 17:16:05 +00:00
|
|
|
void setLocalError(std::string_view errmsg)
|
|
|
|
{
|
|
|
|
this->error = TR_STAT_LOCAL_ERROR;
|
|
|
|
this->error_announce_url = TR_KEY_NONE;
|
|
|
|
this->error_string = errmsg;
|
|
|
|
}
|
|
|
|
|
2022-04-15 23:39:04 +00:00
|
|
|
void setDownloadDir(std::string_view path)
|
|
|
|
{
|
|
|
|
download_dir = path;
|
|
|
|
markEdited();
|
|
|
|
setDirty();
|
|
|
|
refreshCurrentDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
void refreshCurrentDir();
|
|
|
|
|
2021-12-16 09:43:51 +00:00
|
|
|
void setVerifyState(tr_verify_state state);
|
|
|
|
|
2022-04-25 03:43:26 +00:00
|
|
|
[[nodiscard]] constexpr auto verifyState() const noexcept
|
|
|
|
{
|
|
|
|
return verify_state_;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr void setVerifyProgress(float f) noexcept
|
|
|
|
{
|
|
|
|
verify_progress_ = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] constexpr std::optional<float> verifyProgress() const noexcept
|
|
|
|
{
|
|
|
|
if (verify_state_ == TR_VERIFY_NOW)
|
|
|
|
{
|
|
|
|
return verify_progress_;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
[[nodiscard]] constexpr auto id() const noexcept
|
|
|
|
{
|
|
|
|
return unique_id_;
|
|
|
|
}
|
|
|
|
|
2021-12-16 22:58:58 +00:00
|
|
|
void setDateActive(time_t t);
|
2021-12-16 09:43:51 +00:00
|
|
|
|
2022-06-16 22:08:42 +00:00
|
|
|
void setLabels(std::vector<tr_quark> const& new_labels);
|
2022-04-18 05:53:48 +00:00
|
|
|
|
2021-12-16 09:43:51 +00:00
|
|
|
/** Return the mime-type (e.g. "audio/x-flac") that matches more of the
|
|
|
|
torrent's content than any other mime-type. */
|
2022-04-05 03:51:56 +00:00
|
|
|
[[nodiscard]] std::string_view primaryMimeType() const;
|
2021-12-16 09:43:51 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
void setDirty()
|
|
|
|
{
|
|
|
|
this->isDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void markEdited();
|
|
|
|
void markChanged();
|
|
|
|
|
|
|
|
void setBandwidthGroup(std::string_view group_name) noexcept;
|
|
|
|
|
|
|
|
[[nodiscard]] constexpr tr_interned_string const& bandwidthGroup() const noexcept
|
|
|
|
{
|
|
|
|
return bandwidth_group_;
|
|
|
|
}
|
|
|
|
|
2022-01-15 19:33:57 +00:00
|
|
|
tr_torrent_metainfo metainfo_;
|
2021-11-25 18:26:51 +00:00
|
|
|
|
2022-06-29 20:08:58 +00:00
|
|
|
tr_bandwidth bandwidth_;
|
2022-04-28 13:44:24 +00:00
|
|
|
|
|
|
|
tr_stat stats = {};
|
|
|
|
|
2021-11-25 18:26:51 +00:00
|
|
|
// TODO(ckerr): make private once some of torrent.cc's `tr_torrentFoo()` methods are member functions
|
|
|
|
tr_completion completion;
|
|
|
|
|
2022-04-28 16:52:07 +00:00
|
|
|
// true iff the piece was verified more recently than any of the piece's
|
|
|
|
// files' mtimes (file_mtimes_). If checked_pieces_.test(piece) is false,
|
|
|
|
// it means that piece needs to be checked before its data is used.
|
|
|
|
tr_bitfield checked_pieces_ = tr_bitfield{ 0 };
|
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
tr_file_piece_map fpm_ = tr_file_piece_map{ metainfo_ };
|
|
|
|
tr_file_priorities file_priorities_{ &fpm_ };
|
|
|
|
tr_files_wanted files_wanted_{ &fpm_ };
|
2021-10-29 18:24:30 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
std::string error_string;
|
2021-11-25 18:26:51 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
using labels_t = std::vector<tr_quark>;
|
|
|
|
labels_t labels;
|
2021-11-25 18:26:51 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
// when Transmission thinks the torrent's files were last changed
|
|
|
|
std::vector<time_t> file_mtimes_;
|
2021-11-25 18:26:51 +00:00
|
|
|
|
2021-12-21 22:14:15 +00:00
|
|
|
tr_sha1_digest_t obfuscated_hash = {};
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-12-04 05:27:59 +00:00
|
|
|
/* If the initiator of the connection receives a handshake in which the
|
|
|
|
* peer_id does not match the expected peerid, then the initiator is
|
|
|
|
* expected to drop the connection. Note that the initiator presumably
|
|
|
|
* received the peer information from the tracker, which includes the
|
|
|
|
* peer_id that was registered by the peer. The peer_id from the tracker
|
|
|
|
* and in the handshake are expected to match.
|
|
|
|
*/
|
2022-04-28 13:44:24 +00:00
|
|
|
tr_peer_id_t peer_id_;
|
2013-02-02 13:42:50 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
tr_session* session = nullptr;
|
2008-12-04 05:27:59 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
tr_torrent_announcer* torrent_announcer = nullptr;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
tr_swarm* swarm = nullptr;
|
2021-11-25 18:26:51 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
/* Used when the torrent has been created with a magnet link
|
|
|
|
* and we're in the process of downloading the metainfo from
|
|
|
|
* other peers */
|
|
|
|
struct tr_incomplete_metadata* incompleteMetadata = nullptr;
|
2009-10-19 05:05:00 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
time_t peer_id_creation_time_ = 0;
|
2009-10-19 05:05:00 +00:00
|
|
|
|
2021-11-25 18:26:51 +00:00
|
|
|
time_t dhtAnnounceAt = 0;
|
|
|
|
time_t dhtAnnounce6At = 0;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-11-25 18:26:51 +00:00
|
|
|
time_t lpdAnnounceAt = 0;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
time_t activityDate = 0;
|
|
|
|
time_t addedDate = 0;
|
|
|
|
time_t anyDate = 0;
|
|
|
|
time_t doneDate = 0;
|
|
|
|
time_t editDate = 0;
|
|
|
|
time_t startDate = 0;
|
|
|
|
|
|
|
|
time_t lastStatTime = 0;
|
|
|
|
|
2021-11-25 18:26:51 +00:00
|
|
|
uint64_t downloadedCur = 0;
|
|
|
|
uint64_t downloadedPrev = 0;
|
|
|
|
uint64_t uploadedCur = 0;
|
|
|
|
uint64_t uploadedPrev = 0;
|
|
|
|
uint64_t corruptCur = 0;
|
2021-11-26 00:14:25 +00:00
|
|
|
uint64_t corruptPrev = 0;
|
2010-12-12 16:43:19 +00:00
|
|
|
|
2022-04-28 16:52:07 +00:00
|
|
|
uint64_t etaSpeedCalculatedAt = 0;
|
2022-04-28 13:44:24 +00:00
|
|
|
|
|
|
|
tr_interned_string error_announce_url;
|
|
|
|
|
|
|
|
// Where the files are when the torrent is complete.
|
|
|
|
tr_interned_string download_dir;
|
|
|
|
|
|
|
|
// Where the files are when the torrent is incomplete.
|
|
|
|
// a value of TR_KEY_NONE indicates the 'incomplete_dir' feature is unused
|
|
|
|
tr_interned_string incomplete_dir;
|
|
|
|
|
|
|
|
// Where the files are now.
|
|
|
|
// Will equal either download_dir or incomplete_dir
|
|
|
|
tr_interned_string current_dir;
|
|
|
|
|
|
|
|
tr_stat_errtype error = TR_STAT_OK;
|
|
|
|
|
2022-04-28 16:52:07 +00:00
|
|
|
unsigned int etaSpeed_Bps = 0;
|
2009-05-19 18:38:26 +00:00
|
|
|
|
2021-11-25 18:26:51 +00:00
|
|
|
int secondsDownloading = 0;
|
|
|
|
int secondsSeeding = 0;
|
2009-07-02 01:50:07 +00:00
|
|
|
|
2021-11-25 18:26:51 +00:00
|
|
|
int queuePosition = 0;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
tr_torrent_id_t unique_id_ = 0;
|
2010-12-23 19:32:59 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
tr_completeness completeness = TR_LEECH;
|
2011-08-01 22:24:24 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
float desiredRatio = 0.0F;
|
|
|
|
tr_ratiolimit ratioLimitMode = TR_RATIOLIMIT_GLOBAL;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
tr_idlelimit idleLimitMode = TR_IDLELIMIT_GLOBAL;
|
2009-11-26 17:58:44 +00:00
|
|
|
|
2022-04-28 13:44:24 +00:00
|
|
|
uint16_t max_connected_peers = TR_DEFAULT_PEER_LIMIT_TORRENT;
|
|
|
|
|
|
|
|
uint16_t idleLimitMinutes = 0;
|
|
|
|
|
|
|
|
bool finishedSeedingByIdle = false;
|
2009-02-13 18:23:56 +00:00
|
|
|
|
2021-11-25 18:26:51 +00:00
|
|
|
bool isDeleting = false;
|
|
|
|
bool isDirty = false;
|
2021-12-16 08:49:04 +00:00
|
|
|
bool is_queued = false;
|
2021-11-25 18:26:51 +00:00
|
|
|
bool isRunning = false;
|
|
|
|
bool isStopping = false;
|
|
|
|
bool startAfterVerify = false;
|
2010-07-16 03:12:57 +00:00
|
|
|
|
2021-11-25 18:26:51 +00:00
|
|
|
bool magnetVerify = false;
|
2011-08-03 03:14:57 +00:00
|
|
|
|
2021-11-12 16:42:51 +00:00
|
|
|
private:
|
2022-04-25 03:43:26 +00:00
|
|
|
tr_verify_state verify_state_ = TR_VERIFY_NONE;
|
|
|
|
float verify_progress_ = -1;
|
2022-04-28 13:44:24 +00:00
|
|
|
tr_interned_string bandwidth_group_;
|
2022-04-25 03:43:26 +00:00
|
|
|
|
2021-11-29 01:12:54 +00:00
|
|
|
void setFilesWanted(tr_file_index_t const* files, size_t n_files, bool wanted, bool is_bootstrapping)
|
|
|
|
{
|
|
|
|
auto const lock = unique_lock();
|
|
|
|
|
|
|
|
files_wanted_.set(files, n_files, wanted);
|
|
|
|
completion.invalidateSizeWhenDone();
|
|
|
|
|
|
|
|
if (!is_bootstrapping)
|
|
|
|
{
|
|
|
|
setDirty();
|
|
|
|
recheckCompleteness();
|
|
|
|
}
|
|
|
|
}
|
2007-12-25 05:37:32 +00:00
|
|
|
};
|
|
|
|
|
2009-01-30 00:41:08 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr bool tr_isTorrent(tr_torrent const* tor)
|
2009-01-30 00:41:08 +00:00
|
|
|
{
|
2022-04-16 15:48:51 +00:00
|
|
|
return tor != nullptr && tr_isSession(tor->session);
|
2009-01-30 00:41:08 +00:00
|
|
|
}
|
|
|
|
|
2009-10-19 05:05:00 +00:00
|
|
|
/**
|
2013-01-26 23:08:51 +00:00
|
|
|
* Tell the tr_torrent that it's gotten a block
|
2009-10-19 05:05:00 +00:00
|
|
|
*/
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_torrentGotBlock(tr_torrent* tor, tr_block_index_t blockIndex);
|
2009-10-19 05:05:00 +00:00
|
|
|
|
2021-10-22 02:40:55 +00:00
|
|
|
tr_peer_id_t const& tr_torrentGetPeerId(tr_torrent* tor);
|
2021-12-26 16:25:07 +00:00
|
|
|
|
2022-04-01 20:28:55 +00:00
|
|
|
tr_torrent_metainfo tr_ctorStealMetainfo(tr_ctor* ctor);
|
2022-01-15 19:33:57 +00:00
|
|
|
|
2022-06-11 20:46:40 +00:00
|
|
|
bool tr_ctorSetMetainfoFromFile(tr_ctor* ctor, std::string_view filename, tr_error** error = nullptr);
|
2022-08-03 06:15:37 +00:00
|
|
|
bool tr_ctorSetMetainfoFromMagnetLink(tr_ctor* ctor, std::string_view magnet_link, tr_error** error = nullptr);
|
2022-04-18 05:53:48 +00:00
|
|
|
void tr_ctorSetLabels(tr_ctor* ctor, tr_quark const* labels, size_t n_labels);
|
|
|
|
tr_torrent::labels_t const& tr_ctorGetLabels(tr_ctor const* ctor);
|
2022-03-11 21:09:22 +00:00
|
|
|
|
2022-03-17 22:39:06 +00:00
|
|
|
#define tr_logAddCriticalTor(tor, msg) tr_logAddCritical(msg, (tor)->name())
|
|
|
|
#define tr_logAddErrorTor(tor, msg) tr_logAddError(msg, (tor)->name())
|
|
|
|
#define tr_logAddWarnTor(tor, msg) tr_logAddWarn(msg, (tor)->name())
|
|
|
|
#define tr_logAddInfoTor(tor, msg) tr_logAddInfo(msg, (tor)->name())
|
|
|
|
#define tr_logAddDebugTor(tor, msg) tr_logAddDebug(msg, (tor)->name())
|
|
|
|
#define tr_logAddTraceTor(tor, msg) tr_logAddTrace(msg, (tor)->name())
|