2007-12-25 05:37:32 +00:00
|
|
|
/******************************************************************************
|
2008-03-06 13:24:44 +00:00
|
|
|
* $Id$
|
2007-12-25 05:37:32 +00:00
|
|
|
*
|
2008-01-01 17:20:20 +00:00
|
|
|
* Copyright (c) 2005-2008 Transmission authors and contributors
|
2007-12-25 05:37:32 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef TR_TORRENT_H
|
|
|
|
#define TR_TORRENT_H 1
|
|
|
|
|
2008-11-06 02:56:51 +00:00
|
|
|
struct tr_ratecontrol;
|
|
|
|
|
2008-10-20 16:00:14 +00:00
|
|
|
/**
|
|
|
|
*** Package-visible ctor API
|
|
|
|
**/
|
|
|
|
|
|
|
|
void tr_ctorSetSave( tr_ctor * ctor,
|
|
|
|
int saveMetadataInOurTorrentsDir );
|
|
|
|
|
|
|
|
int tr_ctorGetSave( const tr_ctor * ctor );
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
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,
|
|
|
|
int do_download );
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
int tr_torrentIsPrivate( const tr_torrent * );
|
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_torrentResetTransferStats( 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,
|
|
|
|
int has );
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-10-02 15:53:33 +00:00
|
|
|
void tr_torrentLock( const tr_torrent * session );
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-10-02 15:53:33 +00:00
|
|
|
void tr_torrentUnlock( const tr_torrent * session );
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-10-02 15:53:33 +00:00
|
|
|
int tr_torrentIsSeed( const tr_torrent * session );
|
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
|
|
|
int tr_torrentExists( const tr_session * session,
|
|
|
|
const uint8_t * hash );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-02 15:53:33 +00:00
|
|
|
tr_torrent* tr_torrentFindFromId( tr_session * session,
|
|
|
|
int id );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-10-02 15:53:33 +00:00
|
|
|
tr_torrent* tr_torrentFindFromHash( tr_session * session,
|
|
|
|
const uint8_t * hash );
|
2008-09-23 19:11:04 +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
|
|
|
|
|
|
|
int tr_torrentAllowsPex( const tr_torrent * );
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-11-07 05:37:59 +00:00
|
|
|
int tr_torrentIsPieceTransferAllowed( const tr_torrent * torrent,
|
2008-11-07 04:10:27 +00:00
|
|
|
tr_direction direction );
|
|
|
|
|
2007-12-25 05:37:32 +00:00
|
|
|
/* get the index of this piece's first block */
|
2008-09-23 19:11:04 +00:00
|
|
|
#define tr_torPieceFirstBlock( tor, piece ) ( ( piece ) *\
|
|
|
|
( tor )->blockCountInPiece )
|
2007-12-25 05:37:32 +00:00
|
|
|
|
|
|
|
/* what piece index is this block in? */
|
2008-09-23 19:11:04 +00:00
|
|
|
#define tr_torBlockPiece( tor, block ) ( ( block ) /\
|
|
|
|
( tor )->blockCountInPiece )
|
2007-12-25 05:37:32 +00:00
|
|
|
|
|
|
|
/* how many blocks are in this piece? */
|
2008-09-23 19:11:04 +00:00
|
|
|
#define tr_torPieceCountBlocks( tor, piece ) \
|
|
|
|
( ( ( piece ) ==\
|
|
|
|
( ( tor )->info.pieceCount - \
|
|
|
|
1 ) ) ? ( tor )->blockCountInLastPiece : ( tor )->blockCountInPiece )
|
2007-12-25 05:37:32 +00:00
|
|
|
|
|
|
|
/* how many bytes are in this piece? */
|
2008-09-23 19:11:04 +00:00
|
|
|
#define tr_torPieceCountBytes( tor, piece ) \
|
|
|
|
( ( ( piece ) ==\
|
|
|
|
( ( tor )->info.pieceCount - \
|
|
|
|
1 ) ) ? ( tor )->lastPieceSize : ( tor )->info.pieceSize )
|
2007-12-25 05:37:32 +00:00
|
|
|
|
|
|
|
/* how many bytes are in this block? */
|
2008-09-23 19:11:04 +00:00
|
|
|
#define tr_torBlockCountBytes( tor, block ) \
|
|
|
|
( ( ( block ) ==\
|
|
|
|
( ( tor )->blockCount - \
|
|
|
|
1 ) ) ? ( tor )->lastBlockSize : ( tor )->blockSize )
|
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-09-23 19:11:04 +00:00
|
|
|
int tr_torrentReqIsValid( const tr_torrent * tor,
|
|
|
|
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
|
|
|
|
2007-12-25 05:37:32 +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-10-26 15:39:04 +00:00
|
|
|
int tr_torrentIsPieceChecked( const tr_torrent * tor,
|
|
|
|
tr_piece_index_t piece );
|
2007-12-25 06:37:21 +00:00
|
|
|
|
2008-10-26 15:39:04 +00:00
|
|
|
int tr_torrentIsFileChecked( const tr_torrent * tor,
|
|
|
|
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,
|
|
|
|
int 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,
|
|
|
|
int 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
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
int uploadLimit;
|
|
|
|
tr_speedlimit uploadLimitMode;
|
|
|
|
int downloadLimit;
|
|
|
|
tr_speedlimit downloadLimitMode;
|
2008-09-17 19:44:24 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
struct tr_ratecontrol * swarmSpeed;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
int error;
|
|
|
|
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
|
|
|
|
|
|
|
/* Where to download */
|
2008-09-23 19:11:04 +00:00
|
|
|
char * downloadDir;
|
|
|
|
|
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
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
struct tr_completion * completion;
|
|
|
|
|
|
|
|
struct tr_bitfield * checkedPieces;
|
2008-10-20 17:54:56 +00:00
|
|
|
tr_completeness completeness;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
struct tr_tracker * tracker;
|
|
|
|
struct tr_publisher_tag * trackerSubscription;
|
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;
|
|
|
|
|
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;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-10-20 17:54:56 +00:00
|
|
|
tr_torrent_completeness_func * completeness_func;
|
|
|
|
void * completeness_func_user_data;
|
2007-12-25 05:37:32 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
unsigned int isRunning : 1;
|
2008-02-19 05:03:56 +00:00
|
|
|
unsigned int isDeleting : 1;
|
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
|
|
|
|
2008-11-06 02:56:51 +00:00
|
|
|
/* the rate at which pieces are being transferred between client and
|
|
|
|
* its peers. protocol overhead is NOT included; only the piece data */
|
|
|
|
struct tr_ratecontrol * pieceSpeed[2];
|
2008-11-08 02:49:04 +00:00
|
|
|
|
|
|
|
/* the rate at which bytes are being sent between client and peers */
|
|
|
|
struct tr_ratecontrol * rawSpeed[2];
|
2007-12-25 05:37:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|