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
|
2009-01-07 06:53:29 +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
|
|
|
|
|
2009-01-02 17:01:55 +00:00
|
|
|
#include "completion.h" /* tr_completion */
|
2010-01-04 09:05:02 +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
|
|
|
|
2008-11-24 04:21:23 +00:00
|
|
|
struct tr_bandwidth;
|
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
|
|
|
|
**/
|
|
|
|
|
|
|
|
void tr_ctorSetSave( tr_ctor * ctor,
|
2008-12-03 04:55:10 +00:00
|
|
|
tr_bool saveMetadataInOurTorrentsDir );
|
2008-10-20 16:00:14 +00:00
|
|
|
|
|
|
|
int tr_ctorGetSave( const tr_ctor * ctor );
|
|
|
|
|
2009-04-02 20:43:42 +00:00
|
|
|
void tr_ctorInitTorrentPriorities( const tr_ctor * ctor, tr_torrent * tor );
|
|
|
|
|
|
|
|
void tr_ctorInitTorrentWanted( const tr_ctor * ctor, tr_torrent * tor );
|
|
|
|
|
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 */
|
2010-05-12 03:03:29 +00:00
|
|
|
void tr_torrentInitFileDLs( tr_torrent * tor,
|
|
|
|
const tr_file_index_t * files,
|
|
|
|
tr_file_index_t fileCount,
|
|
|
|
tr_bool do_download );
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_torrentRecheckCompleteness( tr_torrent * );
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_torrentSetHasPiece( tr_torrent * tor,
|
|
|
|
tr_piece_index_t pieceIndex,
|
2008-12-13 23:39:12 +00:00
|
|
|
tr_bool has );
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-10-02 15:53:33 +00:00
|
|
|
void tr_torrentChangeMyPort( tr_torrent * session );
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-10-02 15:53:33 +00:00
|
|
|
tr_torrent* tr_torrentFindFromHashString( tr_session * session,
|
|
|
|
const char * hashString );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-02 15:53:33 +00:00
|
|
|
tr_torrent* tr_torrentFindFromObfuscatedHash( tr_session * session,
|
|
|
|
const uint8_t * hash );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-12-13 23:39:12 +00:00
|
|
|
tr_bool tr_torrentIsPieceTransferAllowed( const tr_torrent * torrent,
|
2008-11-07 04:10:27 +00:00
|
|
|
tr_direction direction );
|
|
|
|
|
2009-02-13 18:23:56 +00:00
|
|
|
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
#define tr_block( a, b ) _tr_block( tor, a, b )
|
2008-03-22 18:10:59 +00:00
|
|
|
tr_block_index_t _tr_block( const tr_torrent * tor,
|
|
|
|
tr_piece_index_t index,
|
|
|
|
uint32_t offset );
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-12-13 23:39:12 +00:00
|
|
|
tr_bool tr_torrentReqIsValid( const tr_torrent * tor,
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_piece_index_t index,
|
|
|
|
uint32_t offset,
|
|
|
|
uint32_t length );
|
|
|
|
|
|
|
|
uint64_t tr_pieceOffset( const tr_torrent * tor,
|
|
|
|
tr_piece_index_t index,
|
|
|
|
uint32_t offset,
|
|
|
|
uint32_t length );
|
|
|
|
|
2008-10-26 15:39:04 +00:00
|
|
|
void tr_torrentInitFilePriority( tr_torrent * tor,
|
|
|
|
tr_file_index_t fileIndex,
|
|
|
|
tr_priority_t priority );
|
2008-03-06 13:24:44 +00:00
|
|
|
|
2008-10-26 15:39:04 +00:00
|
|
|
void tr_torrentSetPieceChecked( tr_torrent * tor,
|
2010-12-09 20:43:23 +00:00
|
|
|
tr_piece_index_t piece );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2010-12-09 20:43:23 +00:00
|
|
|
void tr_torrentSetChecked( tr_torrent * tor, time_t when );
|
2008-04-14 11:52:50 +00:00
|
|
|
|
2010-07-16 03:12:57 +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 */
|
|
|
|
void tr_torrentSave( tr_torrent * tor );
|
|
|
|
|
2009-08-13 17:25:26 +00:00
|
|
|
void tr_torrentSetLocalError( tr_torrent * tor, const char * fmt, ... ) TR_GNUC_PRINTF( 2, 3 );
|
|
|
|
|
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
|
|
|
|
2009-03-26 18:06:54 +00:00
|
|
|
void tr_torrentSetVerifyState( tr_torrent * tor,
|
|
|
|
tr_verify_state state );
|
|
|
|
|
2010-05-01 16:04:00 +00:00
|
|
|
tr_torrent_activity tr_torrentGetActivity( tr_torrent * tor );
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
uint8_t * peer_id;
|
|
|
|
|
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;
|
2009-05-19 18:38:26 +00:00
|
|
|
tr_bool dhtAnnounceInProgress;
|
2009-11-24 01:59:51 +00:00
|
|
|
tr_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;
|
2010-07-04 06:07:21 +00:00
|
|
|
double etaDLSpeed_KBps;
|
2009-10-25 02:42:57 +00:00
|
|
|
uint64_t etaULSpeedCalculatedAt;
|
2010-07-04 06:07:21 +00:00
|
|
|
double etaULSpeed_KBps;
|
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
|
|
|
|
2010-12-23 19:32:59 +00:00
|
|
|
time_t secondsDownloading;
|
|
|
|
time_t secondsSeeding;
|
|
|
|
|
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
|
|
|
|
2008-11-28 22:11:41 +00:00
|
|
|
tr_bool isRunning;
|
2010-06-25 06:57:34 +00:00
|
|
|
tr_bool isStopping;
|
2008-11-28 22:11:41 +00:00
|
|
|
tr_bool isDeleting;
|
2009-05-13 15:54:04 +00:00
|
|
|
tr_bool startAfterVerify;
|
2009-08-07 05:29:37 +00:00
|
|
|
tr_bool isDirty;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2010-06-16 03:05:23 +00:00
|
|
|
tr_bool infoDictOffsetIsCached;
|
|
|
|
|
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
|
|
|
|
2009-06-16 19:31:17 +00:00
|
|
|
struct tr_bandwidth * bandwidth;
|
|
|
|
|
2009-01-13 21:00:05 +00:00
|
|
|
struct tr_torrent_peers * torrentPeers;
|
2009-02-13 18:23:56 +00:00
|
|
|
|
|
|
|
double desiredRatio;
|
|
|
|
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;
|
2010-09-12 18:58:49 +00:00
|
|
|
tr_bool finishedSeedingByIdle;
|
2007-12-25 05:37:32 +00:00
|
|
|
};
|
|
|
|
|
2011-01-29 18:54:43 +00:00
|
|
|
static inline tr_torrent*
|
|
|
|
tr_torrentNext( tr_session * session, tr_torrent * current )
|
|
|
|
{
|
|
|
|
return current ? current->next : session->torrentList;
|
|
|
|
}
|
|
|
|
|
2009-01-02 06:28:22 +00:00
|
|
|
/* get the index of this piece's first block */
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline tr_block_index_t
|
2009-01-02 06:28:22 +00:00
|
|
|
tr_torPieceFirstBlock( const tr_torrent * tor, const tr_piece_index_t piece )
|
|
|
|
{
|
|
|
|
return piece * tor->blockCountInPiece;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* what piece index is this block in? */
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline tr_piece_index_t
|
2009-01-02 06:28:22 +00:00
|
|
|
tr_torBlockPiece( const tr_torrent * tor, const tr_block_index_t block )
|
|
|
|
{
|
|
|
|
return block / tor->blockCountInPiece;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* how many blocks are in this piece? */
|
2010-06-30 16:40:19 +00:00
|
|
|
static inline uint16_t
|
2009-01-02 06:28:22 +00:00
|
|
|
tr_torPieceCountBlocks( const tr_torrent * tor, const tr_piece_index_t piece )
|
|
|
|
{
|
2011-02-01 21:32:03 +00:00
|
|
|
return piece + 1 == tor->info.pieceCount ? tor->blockCountInLastPiece
|
|
|
|
: tor->blockCountInPiece;
|
2009-01-02 06:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* how many bytes are in this piece? */
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline uint32_t
|
2009-01-02 06:28:22 +00:00
|
|
|
tr_torPieceCountBytes( const tr_torrent * tor, const tr_piece_index_t piece )
|
|
|
|
{
|
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
|
2009-01-02 06:28:22 +00:00
|
|
|
tr_torBlockCountBytes( const tr_torrent * tor, const tr_block_index_t block )
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline void tr_torrentLock( const tr_torrent * tor )
|
2009-01-02 17:01:55 +00:00
|
|
|
{
|
2010-01-04 09:05:02 +00:00
|
|
|
tr_sessionLock( tor->session );
|
2009-01-02 17:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-01-18 23:44:36 +00:00
|
|
|
static inline tr_bool tr_torrentIsLocked( const tr_torrent * tor )
|
|
|
|
{
|
|
|
|
return tr_sessionIsLocked( tor->session );
|
|
|
|
}
|
|
|
|
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline void tr_torrentUnlock( const tr_torrent * tor )
|
2009-01-02 17:01:55 +00:00
|
|
|
{
|
2010-01-04 09:05:02 +00:00
|
|
|
tr_sessionUnlock( tor->session );
|
2009-01-02 17:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline tr_bool
|
2009-01-02 17:01:55 +00:00
|
|
|
tr_torrentExists( const tr_session * session, const uint8_t * torrentHash )
|
|
|
|
{
|
|
|
|
return tr_torrentFindFromHash( (tr_session*)session, torrentHash ) != NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline tr_bool
|
2009-01-03 00:25:27 +00:00
|
|
|
tr_torrentIsSeed( const tr_torrent * tor )
|
|
|
|
{
|
|
|
|
return tor->completeness != TR_LEECH;
|
|
|
|
}
|
|
|
|
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline tr_bool tr_torrentIsPrivate( const tr_torrent * tor )
|
2009-01-03 00:25:27 +00:00
|
|
|
{
|
|
|
|
return ( tor != NULL ) && tor->info.isPrivate;
|
|
|
|
}
|
|
|
|
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline tr_bool tr_torrentAllowsPex( const tr_torrent * tor )
|
2009-01-03 00:25:27 +00:00
|
|
|
{
|
2009-06-21 08:57:26 +00:00
|
|
|
return ( tor != NULL )
|
|
|
|
&& ( tor->session->isPexEnabled )
|
|
|
|
&& ( !tr_torrentIsPrivate( tor ) );
|
2009-01-03 00:25:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline tr_bool tr_torrentAllowsDHT( const tr_torrent * tor )
|
2009-05-19 18:38:26 +00:00
|
|
|
{
|
2009-06-21 08:57:26 +00:00
|
|
|
return ( tor != NULL )
|
|
|
|
&& ( tr_sessionAllowsDHT( tor->session ) )
|
|
|
|
&& ( !tr_torrentIsPrivate( tor ) );
|
2009-05-19 18:38:26 +00:00
|
|
|
}
|
|
|
|
|
2010-05-08 08:42:45 +00:00
|
|
|
static inline tr_bool tr_torrentAllowsLPD( const tr_torrent * tor )
|
2010-05-01 16:04:00 +00:00
|
|
|
{
|
|
|
|
return ( tor != NULL )
|
2010-05-08 08:42:45 +00:00
|
|
|
&& ( tr_sessionAllowsLPD( tor->session ) )
|
2010-05-01 16:04:00 +00:00
|
|
|
&& ( !tr_torrentIsPrivate( tor ) );
|
|
|
|
}
|
|
|
|
|
2009-01-30 00:41:08 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TORRENT_MAGIC_NUMBER = 95549
|
|
|
|
};
|
|
|
|
|
2010-01-01 22:26:35 +00:00
|
|
|
static inline tr_bool tr_isTorrent( const tr_torrent * tor )
|
2009-01-30 00:41:08 +00:00
|
|
|
{
|
|
|
|
return ( tor != NULL )
|
|
|
|
&& ( tor->magicNumber == TORRENT_MAGIC_NUMBER )
|
|
|
|
&& ( tr_isSession( tor->session ) );
|
|
|
|
}
|
|
|
|
|
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
|
2009-11-24 02:16:31 +00:00
|
|
|
void tr_torrentSetDirty( tr_torrent * tor )
|
2009-08-07 05:29:37 +00:00
|
|
|
{
|
|
|
|
assert( tr_isTorrent( tor ) );
|
|
|
|
|
|
|
|
tor->isDirty = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-06-24 20:36:05 +00:00
|
|
|
uint32_t tr_getBlockSize( uint32_t pieceSize );
|
|
|
|
|
2009-10-19 05:05:00 +00:00
|
|
|
/**
|
|
|
|
* Tell the tr_torrent that one of its files has become complete
|
|
|
|
*/
|
|
|
|
void tr_torrentFileCompleted( tr_torrent * tor, tr_file_index_t fileNo );
|
|
|
|
|
|
|
|
|
2009-10-20 04:43:51 +00:00
|
|
|
/**
|
|
|
|
* @brief Like tr_torrentFindFile(), but splits the filename into base and subpath;
|
|
|
|
*
|
|
|
|
* If the file is found, "tr_buildPath( base, subpath, NULL )"
|
|
|
|
* 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.
|
|
|
|
*/
|
2009-10-20 03:14:44 +00:00
|
|
|
tr_bool tr_torrentFindFile2( const tr_torrent *, tr_file_index_t fileNo,
|
|
|
|
const char ** base, char ** subpath );
|
|
|
|
|
|
|
|
|
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. */
|
2009-10-20 03:14:44 +00:00
|
|
|
char* tr_torrentBuildPartial( const tr_torrent *, tr_file_index_t fileNo );
|
|
|
|
|
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 */
|
|
|
|
void tr_torrentGotNewInfoDict( tr_torrent * tor );
|
2009-10-20 03:14:44 +00:00
|
|
|
|
2010-07-04 06:07:21 +00:00
|
|
|
void tr_torrentSetSpeedLimit_Bps ( tr_torrent *, tr_direction, int Bps );
|
|
|
|
int tr_torrentGetSpeedLimit_Bps ( const tr_torrent *, tr_direction );
|
|
|
|
|
2010-12-09 20:43:23 +00:00
|
|
|
/**
|
|
|
|
* @return true if this piece needs to be tested
|
|
|
|
*/
|
|
|
|
tr_bool tr_torrentPieceNeedsCheck( const tr_torrent * tor, tr_piece_index_t pieceIndex );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
*/
|
2010-12-09 20:43:23 +00:00
|
|
|
tr_bool tr_torrentCheckPiece( tr_torrent * tor, tr_piece_index_t pieceIndex );
|
|
|
|
|
2011-02-02 21:17:16 +00:00
|
|
|
time_t tr_torrentGetFileMTime( const tr_torrent * tor, tr_file_index_t i );
|
|
|
|
|
2010-12-09 20:43:23 +00:00
|
|
|
uint64_t tr_torrentGetCurrentSizeOnDisk( const tr_torrent * tor );
|
|
|
|
|
2010-07-04 06:07:21 +00:00
|
|
|
|
2007-12-25 05:37:32 +00:00
|
|
|
#endif
|