2009-01-07 06:53:29 +00:00
|
|
|
/*
|
2009-12-05 02:19:24 +00:00
|
|
|
* This file Copyright (C) 2009 Mnemosyne LLC
|
2007-12-25 05:37:32 +00:00
|
|
|
*
|
2009-01-07 06:53:29 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* 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 */
|
|
|
|
#include "session.h" /* tr_globalLock(), tr_globalUnlock() */
|
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-11-24 02:16:31 +00:00
|
|
|
int tr_ctorGetMagnet( const tr_ctor * ctor, const struct tr_magnet_info ** setme );
|
|
|
|
|
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 */
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_torrentInitFileDLs( tr_torrent * tor,
|
|
|
|
tr_file_index_t * files,
|
|
|
|
tr_file_index_t fileCount,
|
2008-12-13 23:39:12 +00:00
|
|
|
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-09-23 19:11:04 +00:00
|
|
|
int tr_torrentCountUncheckedPieces( const tr_torrent * );
|
2007-12-25 06:37:21 +00:00
|
|
|
|
2008-12-13 23:39:12 +00:00
|
|
|
tr_bool tr_torrentIsFileChecked( const tr_torrent * tor,
|
2008-10-26 15:39:04 +00:00
|
|
|
tr_file_index_t file );
|
2008-01-02 18:05:05 +00:00
|
|
|
|
2008-10-26 15:39:04 +00:00
|
|
|
void tr_torrentSetPieceChecked( tr_torrent * tor,
|
|
|
|
tr_piece_index_t piece,
|
2008-12-13 23:39:12 +00:00
|
|
|
tr_bool isChecked );
|
2008-05-05 19:51:53 +00:00
|
|
|
|
2008-10-26 15:39:04 +00:00
|
|
|
void tr_torrentSetFileChecked( tr_torrent * tor,
|
|
|
|
tr_file_index_t file,
|
2008-12-13 23:39:12 +00:00
|
|
|
tr_bool isChecked );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-26 15:39:04 +00:00
|
|
|
void tr_torrentUncheck( tr_torrent * tor );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-26 15:39:04 +00:00
|
|
|
int tr_torrentPromoteTracker( tr_torrent * tor,
|
|
|
|
int trackerIndex );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-26 15:39:04 +00:00
|
|
|
time_t* tr_torrentGetMTimes( const tr_torrent * tor,
|
|
|
|
size_t * setmeCount );
|
2008-04-14 11:52:50 +00:00
|
|
|
|
2009-01-13 16:39:19 +00:00
|
|
|
tr_torrent* tr_torrentNext( tr_session * session,
|
|
|
|
tr_torrent * current );
|
|
|
|
|
2009-03-01 13:56:22 +00:00
|
|
|
void tr_torrentCheckSeedRatio( tr_torrent * tor );
|
|
|
|
|
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 );
|
|
|
|
|
2009-11-24 02:16:31 +00:00
|
|
|
struct tr_incomplete_metadata;
|
|
|
|
|
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];
|
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;
|
|
|
|
|
2009-11-24 02:16:31 +00:00
|
|
|
/* Length, in bytes, of the "info" dict in the .torrent file */
|
|
|
|
int infoDictLength;
|
|
|
|
|
|
|
|
/* Offset, in bytes, of the beginning of the "info" dict in the .torrent file */
|
|
|
|
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
|
|
|
|
2008-03-22 18:10:59 +00:00
|
|
|
uint32_t blockCountInPiece;
|
|
|
|
uint32_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-12-29 09:51:54 +00:00
|
|
|
struct tr_bitfield checkedPieces;
|
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;
|
|
|
|
struct tr_publisher_tag * tiersSubscription;
|
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;
|
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;
|
|
|
|
double etaDLSpeed;
|
|
|
|
uint64_t etaULSpeedCalculatedAt;
|
|
|
|
double etaULSpeed;
|
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
|
|
|
|
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
|
|
|
|
2008-11-28 22:11:41 +00:00
|
|
|
tr_bool isRunning;
|
|
|
|
tr_bool isDeleting;
|
2009-04-09 14:10:31 +00:00
|
|
|
tr_bool needsSeedRatioCheck;
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
uint64_t preVerifyTotal;
|
2007-12-25 05:37:32 +00:00
|
|
|
};
|
|
|
|
|
2009-01-02 06:28:22 +00:00
|
|
|
/* get the index of this piece's first block */
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_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? */
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_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? */
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE uint32_t
|
2009-01-02 06:28:22 +00:00
|
|
|
tr_torPieceCountBlocks( const tr_torrent * tor, const tr_piece_index_t piece )
|
|
|
|
{
|
|
|
|
return piece == tor->info.pieceCount - 1 ? tor->blockCountInLastPiece
|
|
|
|
: tor->blockCountInPiece;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* how many bytes are in this piece? */
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE uint32_t
|
2009-01-02 06:28:22 +00:00
|
|
|
tr_torPieceCountBytes( const tr_torrent * tor, const tr_piece_index_t piece )
|
|
|
|
{
|
|
|
|
return piece == tor->info.pieceCount - 1 ? tor->lastPieceSize
|
|
|
|
: tor->info.pieceSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* how many bytes are in this block? */
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE uint32_t
|
2009-01-02 06:28:22 +00:00
|
|
|
tr_torBlockCountBytes( const tr_torrent * tor, const tr_block_index_t block )
|
|
|
|
{
|
|
|
|
return block == tor->blockCount - 1 ? tor->lastBlockSize
|
|
|
|
: tor->blockSize;
|
|
|
|
}
|
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE void tr_torrentLock( const tr_torrent * tor )
|
2009-01-02 17:01:55 +00:00
|
|
|
{
|
|
|
|
tr_globalLock( tor->session );
|
|
|
|
}
|
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE void tr_torrentUnlock( const tr_torrent * tor )
|
2009-01-02 17:01:55 +00:00
|
|
|
{
|
|
|
|
tr_globalUnlock( tor->session );
|
|
|
|
}
|
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_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;
|
|
|
|
}
|
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE tr_bool
|
2009-01-03 00:25:27 +00:00
|
|
|
tr_torrentIsSeed( const tr_torrent * tor )
|
|
|
|
{
|
|
|
|
return tor->completeness != TR_LEECH;
|
|
|
|
}
|
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE tr_bool tr_torrentIsPrivate( const tr_torrent * tor )
|
2009-01-03 00:25:27 +00:00
|
|
|
{
|
|
|
|
return ( tor != NULL ) && tor->info.isPrivate;
|
|
|
|
}
|
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_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
|
|
|
}
|
|
|
|
|
2009-05-19 18:38:26 +00:00
|
|
|
static TR_INLINE tr_bool tr_torrentAllowsDHT( const tr_torrent * tor )
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2009-06-21 08:57:26 +00:00
|
|
|
static TR_INLINE tr_bool tr_torrentIsPieceChecked( const tr_torrent * tor,
|
|
|
|
tr_piece_index_t i )
|
2009-01-03 00:25:27 +00:00
|
|
|
{
|
2009-04-11 03:24:36 +00:00
|
|
|
return tr_bitfieldHasFast( &tor->checkedPieces, i );
|
2009-01-03 00:25:27 +00:00
|
|
|
}
|
2009-01-02 17:01:55 +00:00
|
|
|
|
2009-01-30 00:41:08 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TORRENT_MAGIC_NUMBER = 95549
|
|
|
|
};
|
|
|
|
|
2009-09-17 03:24:35 +00:00
|
|
|
static TR_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 */
|
2009-11-24 02:16:31 +00:00
|
|
|
static TR_INLINE
|
|
|
|
void tr_torrentSetDirty( tr_torrent * tor )
|
2009-08-07 05:29:37 +00:00
|
|
|
{
|
|
|
|
assert( tr_isTorrent( tor ) );
|
|
|
|
|
|
|
|
tor->isDirty = TRUE;
|
|
|
|
}
|
|
|
|
|
2009-11-24 02:16:31 +00:00
|
|
|
static TR_INLINE
|
|
|
|
const char * tr_torrentName( const tr_torrent * tor )
|
2009-09-17 03:24:35 +00:00
|
|
|
{
|
|
|
|
assert( tr_isTorrent( tor ) );
|
|
|
|
|
|
|
|
return tor->info.name;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2007-12-25 05:37:32 +00:00
|
|
|
#endif
|