2009-01-07 06:53:29 +00:00
|
|
|
/*
|
2011-01-19 13:48:47 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2007-12-25 05:37:32 +00:00
|
|
|
*
|
2010-12-27 19:18:17 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
2012-12-05 17:29:46 +00:00
|
|
|
* Transmission project are granted a special exemption to clause 2 (b)
|
2009-08-12 14:40:32 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2009-01-07 06:53:29 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2007-12-25 05:37:32 +00:00
|
|
|
*
|
2009-01-07 06:53:29 +00:00
|
|
|
* $Id$
|
|
|
|
*/
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
2009-01-07 06:53:29 +00:00
|
|
|
#error only libtransmission should #include this header.
|
2008-11-24 20:17:36 +00:00
|
|
|
#endif
|
|
|
|
|
2007-12-25 05:37:32 +00:00
|
|
|
#ifndef TR_TORRENT_H
|
|
|
|
#define TR_TORRENT_H 1
|
|
|
|
|
2011-03-31 14:53:22 +00:00
|
|
|
#include "bandwidth.h" /* tr_bandwidth */
|
2009-01-02 17:01:55 +00:00
|
|
|
#include "completion.h" /* tr_completion */
|
2012-12-05 17:29:46 +00:00
|
|
|
#include "session.h" /* tr_sessionLock (), tr_sessionUnlock () */
|
2009-08-13 17:25:26 +00:00
|
|
|
#include "utils.h" /* TR_GNUC_PRINTF */
|
2009-01-02 17:01:55 +00:00
|
|
|
|
2009-09-25 21:05:59 +00:00
|
|
|
struct tr_torrent_tiers;
|
2009-11-24 02:16:31 +00:00
|
|
|
struct tr_magnet_info;
|
2008-11-06 02:56:51 +00:00
|
|
|
|
2008-10-20 16:00:14 +00:00
|
|
|
/**
|
|
|
|
*** Package-visible ctor API
|
|
|
|
**/
|
|
|
|
|
2012-12-14 20:04:37 +00:00
|
|
|
void tr_torrentFree (tr_torrent * tor);
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_ctorSetSave (tr_ctor * ctor,
|
|
|
|
bool saveMetadataInOurTorrentsDir);
|
2008-10-20 16:00:14 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
int tr_ctorGetSave (const tr_ctor * ctor);
|
2008-10-20 16:00:14 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_ctorInitTorrentPriorities (const tr_ctor * ctor, tr_torrent * tor);
|
2009-04-02 20:43:42 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_ctorInitTorrentWanted (const tr_ctor * ctor, tr_torrent * tor);
|
2009-04-02 20:43:42 +00:00
|
|
|
|
2008-10-20 16:00:14 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2007-12-25 05:37:32 +00:00
|
|
|
/* just like tr_torrentSetFileDLs but doesn't trigger a fastresume save */
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentInitFileDLs (tr_torrent * tor,
|
2010-05-12 03:03:29 +00:00
|
|
|
const tr_file_index_t * files,
|
2011-03-22 15:19:54 +00:00
|
|
|
tr_file_index_t fileCount,
|
2012-12-05 17:29:46 +00:00
|
|
|
bool do_download);
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentRecheckCompleteness (tr_torrent *);
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentSetHasPiece (tr_torrent * tor,
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_piece_index_t pieceIndex,
|
2012-12-05 17:29:46 +00:00
|
|
|
bool has);
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentChangeMyPort (tr_torrent * session);
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_torrent* tr_torrentFindFromHashString (tr_session * session,
|
|
|
|
const char * hashString);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_torrent* tr_torrentFindFromObfuscatedHash (tr_session * session,
|
|
|
|
const uint8_t * hash);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2012-12-14 20:04:37 +00:00
|
|
|
bool tr_torrentIsPieceTransferAllowed (const tr_torrent * torrent,
|
|
|
|
tr_direction direction);
|
2008-11-07 04:10:27 +00:00
|
|
|
|
2009-02-13 18:23:56 +00:00
|
|
|
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
#define tr_block(a, b) _tr_block (tor, a, b)
|
|
|
|
tr_block_index_t _tr_block (const tr_torrent * tor,
|
2008-03-22 18:10:59 +00:00
|
|
|
tr_piece_index_t index,
|
2012-12-05 17:29:46 +00:00
|
|
|
uint32_t offset);
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
bool tr_torrentReqIsValid (const tr_torrent * tor,
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_piece_index_t index,
|
|
|
|
uint32_t offset,
|
2012-12-05 17:29:46 +00:00
|
|
|
uint32_t length);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
uint64_t tr_pieceOffset (const tr_torrent * tor,
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_piece_index_t index,
|
|
|
|
uint32_t offset,
|
2012-12-05 17:29:46 +00:00
|
|
|
uint32_t length);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentGetBlockLocation (const tr_torrent * tor,
|
2011-02-23 03:54:04 +00:00
|
|
|
tr_block_index_t block,
|
2011-03-04 23:26:10 +00:00
|
|
|
tr_piece_index_t * piece,
|
2011-02-23 03:54:04 +00:00
|
|
|
uint32_t * offset,
|
2012-12-05 17:29:46 +00:00
|
|
|
uint32_t * length);
|
2011-02-23 03:54:04 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torGetFileBlockRange (const tr_torrent * tor,
|
2011-02-23 03:54:04 +00:00
|
|
|
const tr_file_index_t file,
|
|
|
|
tr_block_index_t * first,
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_block_index_t * last);
|
2011-02-23 03:54:04 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torGetPieceBlockRange (const tr_torrent * tor,
|
2011-02-23 03:54:04 +00:00
|
|
|
const tr_piece_index_t piece,
|
|
|
|
tr_block_index_t * first,
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_block_index_t * last);
|
2011-02-23 03:54:04 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentInitFilePriority (tr_torrent * tor,
|
2008-10-26 15:39:04 +00:00
|
|
|
tr_file_index_t fileIndex,
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_priority_t priority);
|
2008-03-06 13:24:44 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentSetPieceChecked (tr_torrent * tor,
|
|
|
|
tr_piece_index_t piece);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentSetChecked (tr_torrent * tor, time_t when);
|
2008-04-14 11:52:50 +00:00
|
|
|
|
2012-12-05 17:29:46 +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 */
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentSave (tr_torrent * tor);
|
2009-08-13 14:47:56 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentSetLocalError (tr_torrent * tor, const char * fmt, ...) TR_GNUC_PRINTF (2, 3);
|
2009-08-13 17:25:26 +00:00
|
|
|
|
2009-03-01 13:56:22 +00:00
|
|
|
|
2009-01-13 16:39:19 +00:00
|
|
|
|
2007-12-25 05:37:32 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
TR_VERIFY_NONE,
|
|
|
|
TR_VERIFY_WAIT,
|
|
|
|
TR_VERIFY_NOW
|
2007-12-25 05:37:32 +00:00
|
|
|
}
|
2008-02-15 16:00:46 +00:00
|
|
|
tr_verify_state;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentSetVerifyState (tr_torrent * tor,
|
|
|
|
tr_verify_state state);
|
2009-03-26 18:06:54 +00:00
|
|
|
|
2012-12-12 20:22:57 +00:00
|
|
|
tr_torrent_activity tr_torrentGetActivity (const tr_torrent * 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 */
|
2007-12-25 05:37:32 +00:00
|
|
|
struct tr_torrent
|
|
|
|
{
|
2008-10-02 15:53:33 +00:00
|
|
|
tr_session * session;
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_info info;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2009-01-30 00:41:08 +00:00
|
|
|
int magicNumber;
|
|
|
|
|
2009-08-05 01:25:36 +00:00
|
|
|
tr_stat_errtype error;
|
2008-09-23 19:11:04 +00:00
|
|
|
char errorString[128];
|
2010-05-19 19:02:25 +00:00
|
|
|
char errorTracker[128];
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
uint8_t obfuscatedHash[SHA_DIGEST_LENGTH];
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2009-11-24 02:16:31 +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;
|
|
|
|
|
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.
|
|
|
|
*/
|
2011-03-10 12:35:23 +00:00
|
|
|
uint8_t peer_id[PEER_ID_LEN+1];
|
2008-12-04 05:27:59 +00:00
|
|
|
|
2009-10-19 05:05:00 +00:00
|
|
|
/* Where the files will be when it's complete */
|
2008-12-04 05:27:59 +00:00
|
|
|
char * downloadDir;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-10-19 05:05:00 +00:00
|
|
|
/* Where the files are when the torrent is incomplete */
|
|
|
|
char * incompleteDir;
|
|
|
|
|
2010-06-16 03:05:23 +00:00
|
|
|
/* Length, in bytes, of the "info" dict in the .torrent file. */
|
2009-11-24 02:16:31 +00:00
|
|
|
int infoDictLength;
|
|
|
|
|
2010-06-16 03:05:23 +00:00
|
|
|
/* Offset, in bytes, of the beginning of the "info" dict in the .torrent file.
|
|
|
|
*
|
|
|
|
* Used by the torrent-magnet code for serving metainfo to peers.
|
|
|
|
* This field is lazy-generated and might not be initialized yet. */
|
2009-11-24 02:16:31 +00:00
|
|
|
int infoDictOffset;
|
|
|
|
|
2009-10-19 05:05:00 +00:00
|
|
|
/* Where the files are now.
|
|
|
|
* This pointer will be equal to downloadDir or incompleteDir */
|
|
|
|
const char * currentDir;
|
|
|
|
|
2007-12-25 05:37:32 +00:00
|
|
|
/* How many bytes we ask for per request */
|
2008-03-22 18:10:59 +00:00
|
|
|
uint32_t blockSize;
|
|
|
|
tr_block_index_t blockCount;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-03-22 18:10:59 +00:00
|
|
|
uint32_t lastBlockSize;
|
|
|
|
uint32_t lastPieceSize;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2010-06-30 16:40:19 +00:00
|
|
|
uint16_t blockCountInPiece;
|
|
|
|
uint16_t blockCountInLastPiece;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2009-01-02 17:01:55 +00:00
|
|
|
struct tr_completion completion;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-20 17:54:56 +00:00
|
|
|
tr_completeness completeness;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2009-09-25 21:05:59 +00:00
|
|
|
struct tr_torrent_tiers * tiers;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2009-05-19 18:38:26 +00:00
|
|
|
time_t dhtAnnounceAt;
|
2009-11-24 01:59:51 +00:00
|
|
|
time_t dhtAnnounce6At;
|
2011-03-22 15:19:54 +00:00
|
|
|
bool dhtAnnounceInProgress;
|
|
|
|
bool dhtAnnounce6InProgress;
|
2010-12-12 16:43:19 +00:00
|
|
|
|
2010-05-08 08:42:45 +00:00
|
|
|
time_t lpdAnnounceAt;
|
2009-05-19 18:38:26 +00:00
|
|
|
|
2007-12-25 05:37:32 +00:00
|
|
|
uint64_t downloadedCur;
|
|
|
|
uint64_t downloadedPrev;
|
|
|
|
uint64_t uploadedCur;
|
|
|
|
uint64_t uploadedPrev;
|
|
|
|
uint64_t corruptCur;
|
|
|
|
uint64_t corruptPrev;
|
|
|
|
|
2009-10-25 02:42:57 +00:00
|
|
|
uint64_t etaDLSpeedCalculatedAt;
|
2013-01-06 20:15:11 +00:00
|
|
|
unsigned int etaDLSpeed_Bps;
|
2009-10-25 02:42:57 +00:00
|
|
|
uint64_t etaULSpeedCalculatedAt;
|
2013-01-06 20:15:11 +00:00
|
|
|
unsigned int etaULSpeed_Bps;
|
2009-07-02 01:50:07 +00:00
|
|
|
|
2008-06-02 04:41:55 +00:00
|
|
|
time_t addedDate;
|
2008-05-23 20:04:41 +00:00
|
|
|
time_t activityDate;
|
2008-06-03 19:16:12 +00:00
|
|
|
time_t doneDate;
|
|
|
|
time_t startDate;
|
2009-03-26 18:06:54 +00:00
|
|
|
time_t anyDate;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2011-02-26 15:01:07 +00:00
|
|
|
int secondsDownloading;
|
|
|
|
int secondsSeeding;
|
2010-12-23 19:32:59 +00:00
|
|
|
|
2011-08-01 22:24:24 +00:00
|
|
|
int queuePosition;
|
|
|
|
|
2009-11-26 17:58:44 +00:00
|
|
|
tr_torrent_metadata_func * metadata_func;
|
|
|
|
void * metadata_func_user_data;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2009-11-26 17:58:44 +00:00
|
|
|
tr_torrent_completeness_func * completeness_func;
|
|
|
|
void * completeness_func_user_data;
|
|
|
|
|
|
|
|
tr_torrent_ratio_limit_hit_func * ratio_limit_hit_func;
|
|
|
|
void * ratio_limit_hit_func_user_data;
|
2009-02-13 18:23:56 +00:00
|
|
|
|
2010-07-24 02:57:39 +00:00
|
|
|
tr_torrent_idle_limit_hit_func * idle_limit_hit_func;
|
|
|
|
void * idle_limit_hit_func_user_data;
|
2010-07-16 03:12:57 +00:00
|
|
|
|
2011-08-03 23:40:51 +00:00
|
|
|
void * queue_started_user_data;
|
2012-12-05 17:29:46 +00:00
|
|
|
void (* queue_started_callback)(tr_torrent *, void * queue_started_user_data);
|
2011-08-03 03:14:57 +00:00
|
|
|
|
2011-03-22 15:19:54 +00:00
|
|
|
bool isRunning;
|
|
|
|
bool isStopping;
|
|
|
|
bool isDeleting;
|
|
|
|
bool startAfterVerify;
|
|
|
|
bool isDirty;
|
2011-08-02 03:59:54 +00:00
|
|
|
bool isQueued;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2011-03-22 15:19:54 +00:00
|
|
|
bool infoDictOffsetIsCached;
|
2010-06-16 03:05:23 +00:00
|
|
|
|
2007-12-25 05:37:32 +00:00
|
|
|
uint16_t maxConnectedPeers;
|
|
|
|
|
2008-03-31 19:34:20 +00:00
|
|
|
tr_verify_state verifyState;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
|
|
|
time_t lastStatTime;
|
2008-03-31 19:34:20 +00:00
|
|
|
tr_stat stats;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_torrent * next;
|
2008-05-12 00:41:55 +00:00
|
|
|
|
|
|
|
int uniqueId;
|
2008-09-17 19:44:24 +00:00
|
|
|
|
2011-03-31 14:53:22 +00:00
|
|
|
struct tr_bandwidth bandwidth;
|
2009-06-16 19:31:17 +00:00
|
|
|
|
2013-01-27 21:03:52 +00:00
|
|
|
struct tr_swarm * swarm;
|
2009-02-13 18:23:56 +00:00
|
|
|
|
2011-03-31 16:08:31 +00:00
|
|
|
float desiredRatio;
|
2009-02-13 18:23:56 +00:00
|
|
|
tr_ratiolimit ratioLimitMode;
|
2009-08-13 17:50:41 +00:00
|
|
|
|
2010-07-24 02:57:39 +00:00
|
|
|
uint16_t idleLimitMinutes;
|
|
|
|
tr_idlelimit idleLimitMode;
|
2011-03-22 15:19:54 +00:00
|
|
|
bool finishedSeedingByIdle;
|
2007-12-25 05:37:32 +00:00
|
|
|
};
|
|
|
|
|
2011-01-29 18:54:43 +00:00
|
|
|
static inline tr_torrent*
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_torrentNext (tr_session * session, tr_torrent * current)
|
2011-01-29 18:54:43 +00:00
|
|
|
{
|
|
|
|
return current ? current->next : session->torrentList;
|
|
|
|
}
|
|
|
|
|
2009-01-02 06:28:22 +00:00
|
|
|
/* what piece index is this block in? */
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline tr_piece_index_t
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_torBlockPiece (const tr_torrent * tor, const tr_block_index_t block)
|
2009-01-02 06:28:22 +00:00
|
|
|
{
|
|
|
|
return block / tor->blockCountInPiece;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* how many bytes are in this piece? */
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline uint32_t
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_torPieceCountBytes (const tr_torrent * tor, const tr_piece_index_t piece)
|
2009-01-02 06:28:22 +00:00
|
|
|
{
|
2011-02-01 21:32:03 +00:00
|
|
|
return piece + 1 == tor->info.pieceCount ? tor->lastPieceSize
|
2009-01-02 06:28:22 +00:00
|
|
|
: tor->info.pieceSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* how many bytes are in this block? */
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline uint32_t
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_torBlockCountBytes (const tr_torrent * tor, const tr_block_index_t block)
|
2009-01-02 06:28:22 +00:00
|
|
|
{
|
2011-02-01 21:32:03 +00:00
|
|
|
return block + 1 == tor->blockCount ? tor->lastBlockSize
|
2009-01-02 06:28:22 +00:00
|
|
|
: tor->blockSize;
|
|
|
|
}
|
|
|
|
|
2012-12-14 20:04:37 +00:00
|
|
|
static inline void tr_torrentLock (const tr_torrent * tor)
|
|
|
|
{
|
|
|
|
tr_sessionLock (tor->session);
|
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
static inline bool tr_torrentIsLocked (const tr_torrent * tor)
|
2011-01-18 23:44:36 +00:00
|
|
|
{
|
2012-12-14 20:04:37 +00:00
|
|
|
return tr_sessionIsLocked (tor->session);
|
2011-01-18 23:44:36 +00:00
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
static inline void tr_torrentUnlock (const tr_torrent * tor)
|
2009-01-02 17:01:55 +00:00
|
|
|
{
|
2012-12-14 20:04:37 +00:00
|
|
|
tr_sessionUnlock (tor->session);
|
2009-01-02 17:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-03-22 15:19:54 +00:00
|
|
|
static inline bool
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_torrentExists (const tr_session * session, const uint8_t * torrentHash)
|
2009-01-02 17:01:55 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
return tr_torrentFindFromHash ((tr_session*)session, torrentHash) != NULL;
|
2009-01-02 17:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-03-22 15:19:54 +00:00
|
|
|
static inline bool
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_torrentIsSeed (const tr_torrent * tor)
|
2009-01-03 00:25:27 +00:00
|
|
|
{
|
|
|
|
return tor->completeness != TR_LEECH;
|
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
static inline bool tr_torrentIsPrivate (const tr_torrent * tor)
|
2009-01-03 00:25:27 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
return (tor != NULL) && tor->info.isPrivate;
|
2009-01-03 00:25:27 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
static inline bool tr_torrentAllowsPex (const tr_torrent * tor)
|
2009-01-03 00:25:27 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
return (tor != NULL)
|
|
|
|
&& (tor->session->isPexEnabled)
|
|
|
|
&& (!tr_torrentIsPrivate (tor));
|
2009-01-03 00:25:27 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
static inline bool tr_torrentAllowsDHT (const tr_torrent * tor)
|
2009-05-19 18:38:26 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
return (tor != NULL)
|
|
|
|
&& (tr_sessionAllowsDHT (tor->session))
|
|
|
|
&& (!tr_torrentIsPrivate (tor));
|
2009-05-19 18:38:26 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
static inline bool tr_torrentAllowsLPD (const tr_torrent * tor)
|
2010-05-01 16:04:00 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
return (tor != NULL)
|
|
|
|
&& (tr_sessionAllowsLPD (tor->session))
|
|
|
|
&& (!tr_torrentIsPrivate (tor));
|
2010-05-01 16:04:00 +00:00
|
|
|
}
|
|
|
|
|
2009-01-30 00:41:08 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TORRENT_MAGIC_NUMBER = 95549
|
|
|
|
};
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
static inline bool tr_isTorrent (const tr_torrent * tor)
|
2009-01-30 00:41:08 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
return (tor != NULL)
|
|
|
|
&& (tor->magicNumber == TORRENT_MAGIC_NUMBER)
|
|
|
|
&& (tr_isSession (tor->session));
|
2009-01-30 00:41:08 +00:00
|
|
|
}
|
|
|
|
|
2009-08-07 05:29:37 +00:00
|
|
|
/* set a flag indicating that the torrent's .resume file
|
|
|
|
* needs to be saved when the torrent is closed */
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentSetDirty (tr_torrent * tor)
|
2009-08-07 05:29:37 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
assert (tr_isTorrent (tor));
|
2009-08-07 05:29:37 +00:00
|
|
|
|
2011-03-22 15:19:54 +00:00
|
|
|
tor->isDirty = true;
|
2009-08-07 05:29:37 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
uint32_t tr_getBlockSize (uint32_t pieceSize);
|
2010-06-24 20:36:05 +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
|
|
|
*/
|
2013-01-26 23:08:51 +00:00
|
|
|
void tr_torrentGotBlock (tr_torrent * tor, tr_block_index_t blockIndex);
|
|
|
|
|
2009-10-19 05:05:00 +00:00
|
|
|
|
|
|
|
|
2009-10-20 04:43:51 +00:00
|
|
|
/**
|
2012-12-05 17:29:46 +00:00
|
|
|
* @brief Like tr_torrentFindFile (), but splits the filename into base and subpath;
|
2009-10-20 04:43:51 +00:00
|
|
|
*
|
2012-12-05 17:29:46 +00:00
|
|
|
* If the file is found, "tr_buildPath (base, subpath, NULL)"
|
2009-10-20 04:43:51 +00:00
|
|
|
* will generate the complete filename.
|
|
|
|
*
|
|
|
|
* @return true if the file is found, false otherwise.
|
|
|
|
*
|
|
|
|
* @param base if the torrent is found, this will be either
|
|
|
|
* tor->downloadDir or tor->incompleteDir
|
|
|
|
* @param subpath on success, this pointer is assigned a newly-allocated
|
|
|
|
* string holding the second half of the filename.
|
|
|
|
*/
|
2012-12-05 17:29:46 +00:00
|
|
|
bool tr_torrentFindFile2 (const tr_torrent *, tr_file_index_t fileNo,
|
|
|
|
const char ** base, char ** subpath, time_t * mtime);
|
2009-10-20 03:14:44 +00:00
|
|
|
|
|
|
|
|
2009-10-20 04:43:51 +00:00
|
|
|
/* Returns a newly-allocated version of the tr_file.name string
|
|
|
|
* that's been modified to denote that it's not a complete file yet.
|
|
|
|
* In the current implementation this is done by appending ".part"
|
|
|
|
* a la Firefox. */
|
2012-12-05 17:29:46 +00:00
|
|
|
char* tr_torrentBuildPartial (const tr_torrent *, tr_file_index_t fileNo);
|
2009-10-20 03:14:44 +00:00
|
|
|
|
2009-11-24 02:16:31 +00:00
|
|
|
/* for when the info dict has been fundamentally changed wrt files,
|
|
|
|
* piece size, etc. such as in BEP 9 where peers exchange metadata */
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentGotNewInfoDict (tr_torrent * tor);
|
2009-10-20 03:14:44 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_torrentSetSpeedLimit_Bps (tr_torrent *, tr_direction, unsigned int Bps);
|
|
|
|
unsigned int tr_torrentGetSpeedLimit_Bps (const tr_torrent *, tr_direction);
|
2010-07-04 06:07:21 +00:00
|
|
|
|
2010-12-09 20:43:23 +00:00
|
|
|
/**
|
|
|
|
* @return true if this piece needs to be tested
|
|
|
|
*/
|
2012-12-05 17:29:46 +00:00
|
|
|
bool tr_torrentPieceNeedsCheck (const tr_torrent * tor, tr_piece_index_t pieceIndex);
|
2010-12-09 20:43:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Test a piece against its info dict checksum
|
|
|
|
* @return true if the piece's passes the checksum test
|
2010-12-12 16:43:19 +00:00
|
|
|
*/
|
2012-12-05 17:29:46 +00:00
|
|
|
bool tr_torrentCheckPiece (tr_torrent * tor, tr_piece_index_t pieceIndex);
|
2010-12-09 20:43:23 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
time_t tr_torrentGetFileMTime (const tr_torrent * tor, tr_file_index_t i);
|
2011-02-02 21:17:16 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
uint64_t tr_torrentGetCurrentSizeOnDisk (const tr_torrent * tor);
|
2010-12-09 20:43:23 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
bool tr_torrentIsStalled (const tr_torrent * tor);
|
2011-08-01 22:24:24 +00:00
|
|
|
|
|
|
|
static inline bool
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_torrentIsQueued (const tr_torrent * tor)
|
2011-08-01 22:24:24 +00:00
|
|
|
{
|
2011-08-02 03:59:54 +00:00
|
|
|
return tor->isQueued;
|
2011-08-01 22:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline tr_direction
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_torrentGetQueueDirection (const tr_torrent * tor)
|
2011-08-01 22:24:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
return tr_torrentIsSeed (tor) ? TR_UP : TR_DOWN;
|
2011-08-01 22:24:24 +00:00
|
|
|
}
|
2010-07-04 06:07:21 +00:00
|
|
|
|
2007-12-25 05:37:32 +00:00
|
|
|
#endif
|