25
25
#ifndef TR_TORRENT_H
26
26
#define TR_TORRENT_H 1
28
struct tr_ratecontrol;
31
*** Package-visible ctor API
34
void tr_ctorSetSave( tr_ctor * ctor,
35
int saveMetadataInOurTorrentsDir );
37
int tr_ctorGetSave( const tr_ctor * ctor );
28
43
/* just like tr_torrentSetFileDLs but doesn't trigger a fastresume save */
29
void tr_torrentInitFileDLs( tr_torrent * tor,
30
tr_file_index_t * files,
31
tr_file_index_t fileCount,
34
int tr_torrentIsPrivate( const tr_torrent * );
36
void tr_torrentRecheckCompleteness( tr_torrent * );
38
void tr_torrentResetTransferStats( tr_torrent * );
40
void tr_torrentSetHasPiece( tr_torrent * tor,
41
tr_piece_index_t pieceIndex,
44
void tr_torrentLock ( const tr_torrent * );
45
void tr_torrentUnlock ( const tr_torrent * );
47
int tr_torrentIsSeed ( const tr_torrent * );
49
void tr_torrentChangeMyPort ( tr_torrent * );
51
int tr_torrentExists( const tr_handle *, const uint8_t * );
52
tr_torrent* tr_torrentFindFromId( tr_handle *, int id );
53
tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * );
54
tr_torrent* tr_torrentFindFromHashString( tr_handle *, const char * );
55
tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* );
57
void tr_torrentGetRates( const tr_torrent *, float * toClient, float * toPeer );
59
int tr_torrentAllowsPex( const tr_torrent * );
44
void tr_torrentInitFileDLs( tr_torrent * tor,
45
tr_file_index_t * files,
46
tr_file_index_t fileCount,
49
int tr_torrentIsPrivate( const tr_torrent * );
51
void tr_torrentRecheckCompleteness( tr_torrent * );
53
void tr_torrentResetTransferStats( tr_torrent * );
55
void tr_torrentSetHasPiece( tr_torrent * tor,
56
tr_piece_index_t pieceIndex,
59
void tr_torrentLock( const tr_torrent * session );
61
void tr_torrentUnlock( const tr_torrent * session );
63
int tr_torrentIsSeed( const tr_torrent * session );
65
void tr_torrentChangeMyPort( tr_torrent * session );
67
int tr_torrentExists( const tr_session * session,
68
const uint8_t * hash );
70
tr_torrent* tr_torrentFindFromId( tr_session * session,
73
tr_torrent* tr_torrentFindFromHash( tr_session * session,
74
const uint8_t * hash );
76
tr_torrent* tr_torrentFindFromHashString( tr_session * session,
77
const char * hashString );
79
tr_torrent* tr_torrentFindFromObfuscatedHash( tr_session * session,
80
const uint8_t * hash );
82
int tr_torrentAllowsPex( const tr_torrent * );
84
int tr_torrentIsPieceTransferAllowed( const tr_torrent * torrent,
85
tr_direction direction );
61
87
/* get the index of this piece's first block */
62
#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
88
#define tr_torPieceFirstBlock( tor, piece ) ( ( piece ) *\
89
( tor )->blockCountInPiece )
64
91
/* what piece index is this block in? */
65
#define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece )
92
#define tr_torBlockPiece( tor, block ) ( ( block ) /\
93
( tor )->blockCountInPiece )
67
95
/* how many blocks are in this piece? */
68
#define tr_torPieceCountBlocks(tor,piece) \
69
( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece )
96
#define tr_torPieceCountBlocks( tor, piece ) \
98
( ( tor )->info.pieceCount - \
99
1 ) ) ? ( tor )->blockCountInLastPiece : ( tor )->blockCountInPiece )
71
101
/* how many bytes are in this piece? */
72
#define tr_torPieceCountBytes(tor,piece) \
73
( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize )
102
#define tr_torPieceCountBytes( tor, piece ) \
104
( ( tor )->info.pieceCount - \
105
1 ) ) ? ( tor )->lastPieceSize : ( tor )->info.pieceSize )
75
107
/* how many bytes are in this block? */
76
#define tr_torBlockCountBytes(tor,block) \
77
( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize )
108
#define tr_torBlockCountBytes( tor, block ) \
110
( ( tor )->blockCount - \
111
1 ) ) ? ( tor )->lastBlockSize : ( tor )->blockSize )
79
#define tr_block(a,b) _tr_block(tor,a,b)
113
#define tr_block( a, b ) _tr_block( tor, a, b )
80
114
tr_block_index_t _tr_block( const tr_torrent * tor,
81
115
tr_piece_index_t index,
82
116
uint32_t offset );
84
int tr_torrentReqIsValid( const tr_torrent * tor,
85
tr_piece_index_t index,
89
uint64_t tr_pieceOffset( const tr_torrent * tor,
90
tr_piece_index_t index,
94
void tr_torrentInitFilePriority( tr_torrent * tor,
95
tr_file_index_t fileIndex,
96
tr_priority_t priority );
99
int tr_torrentCountUncheckedPieces( const tr_torrent * );
100
int tr_torrentIsPieceChecked ( const tr_torrent *, tr_piece_index_t piece );
101
int tr_torrentIsFileChecked ( const tr_torrent *, tr_file_index_t file );
102
void tr_torrentSetPieceChecked ( tr_torrent *, tr_piece_index_t piece, int isChecked );
103
void tr_torrentSetFileChecked ( tr_torrent *, tr_file_index_t file, int isChecked );
104
void tr_torrentUncheck ( tr_torrent * );
106
int tr_torrentPromoteTracker ( tr_torrent *, int trackerIndex );
108
time_t* tr_torrentGetMTimes ( const tr_torrent *, int * setmeCount );
118
int tr_torrentReqIsValid( const tr_torrent * tor,
119
tr_piece_index_t index,
123
uint64_t tr_pieceOffset( const tr_torrent * tor,
124
tr_piece_index_t index,
128
void tr_torrentInitFilePriority( tr_torrent * tor,
129
tr_file_index_t fileIndex,
130
tr_priority_t priority );
133
int tr_torrentCountUncheckedPieces( const tr_torrent * );
135
int tr_torrentIsPieceChecked( const tr_torrent * tor,
136
tr_piece_index_t piece );
138
int tr_torrentIsFileChecked( const tr_torrent * tor,
139
tr_file_index_t file );
141
void tr_torrentSetPieceChecked( tr_torrent * tor,
142
tr_piece_index_t piece,
145
void tr_torrentSetFileChecked( tr_torrent * tor,
146
tr_file_index_t file,
149
void tr_torrentUncheck( tr_torrent * tor );
151
int tr_torrentPromoteTracker( tr_torrent * tor,
154
time_t* tr_torrentGetMTimes( const tr_torrent * tor,
155
size_t * setmeCount );
118
165
struct tr_torrent
123
tr_speedlimit uploadLimitMode;
124
tr_speedlimit downloadLimitMode;
125
struct tr_ratecontrol * upload;
126
struct tr_ratecontrol * download;
127
struct tr_ratecontrol * swarmSpeed;
130
char errorString[128];
132
uint8_t obfuscatedHash[SHA_DIGEST_LENGTH];
167
tr_session * session;
171
tr_speedlimit uploadLimitMode;
173
tr_speedlimit downloadLimitMode;
175
struct tr_ratecontrol * swarmSpeed;
178
char errorString[128];
180
uint8_t obfuscatedHash[SHA_DIGEST_LENGTH];
134
182
/* Where to download */
137
185
/* How many bytes we ask for per request */
138
186
uint32_t blockSize;
139
187
tr_block_index_t blockCount;