1 | /****************************************************************************** |
---|
2 | * $Id: torrent.h 5796 2008-05-10 00:19:00Z charles $ |
---|
3 | * |
---|
4 | * Copyright (c) 2005-2008 Transmission authors and contributors |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
---|
7 | * copy of this software and associated documentation files (the "Software"), |
---|
8 | * to deal in the Software without restriction, including without limitation |
---|
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
10 | * and/or sell copies of the Software, and to permit persons to whom the |
---|
11 | * Software is furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
22 | * DEALINGS IN THE SOFTWARE. |
---|
23 | *****************************************************************************/ |
---|
24 | |
---|
25 | #ifndef TR_TORRENT_H |
---|
26 | #define TR_TORRENT_H 1 |
---|
27 | |
---|
28 | /* 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, |
---|
32 | int do_download ); |
---|
33 | |
---|
34 | int tr_torrentIsPrivate( const tr_torrent * ); |
---|
35 | |
---|
36 | void tr_torrentRecheckCompleteness( tr_torrent * ); |
---|
37 | |
---|
38 | void tr_torrentResetTransferStats( tr_torrent * ); |
---|
39 | |
---|
40 | void tr_torrentSetHasPiece( tr_torrent * tor, |
---|
41 | tr_piece_index_t pieceIndex, |
---|
42 | int has ); |
---|
43 | |
---|
44 | void tr_torrentLock ( const tr_torrent * ); |
---|
45 | void tr_torrentUnlock ( const tr_torrent * ); |
---|
46 | |
---|
47 | int tr_torrentIsSeed ( const tr_torrent * ); |
---|
48 | |
---|
49 | void tr_torrentChangeMyPort ( tr_torrent * ); |
---|
50 | |
---|
51 | int tr_torrentExists( const tr_handle *, const uint8_t * ); |
---|
52 | tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * ); |
---|
53 | tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* ); |
---|
54 | |
---|
55 | void tr_torrentGetRates( const tr_torrent *, float * toClient, float * toPeer ); |
---|
56 | |
---|
57 | int tr_torrentAllowsPex( const tr_torrent * ); |
---|
58 | |
---|
59 | /* get the index of this piece's first block */ |
---|
60 | #define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece ) |
---|
61 | |
---|
62 | /* what piece index is this block in? */ |
---|
63 | #define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece ) |
---|
64 | |
---|
65 | /* how many blocks are in this piece? */ |
---|
66 | #define tr_torPieceCountBlocks(tor,piece) \ |
---|
67 | ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece ) |
---|
68 | |
---|
69 | /* how many bytes are in this piece? */ |
---|
70 | #define tr_torPieceCountBytes(tor,piece) \ |
---|
71 | ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize ) |
---|
72 | |
---|
73 | /* how many bytes are in this block? */ |
---|
74 | #define tr_torBlockCountBytes(tor,block) \ |
---|
75 | ( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize ) |
---|
76 | |
---|
77 | #define tr_block(a,b) _tr_block(tor,a,b) |
---|
78 | tr_block_index_t _tr_block( const tr_torrent * tor, |
---|
79 | tr_piece_index_t index, |
---|
80 | uint32_t offset ); |
---|
81 | |
---|
82 | int tr_torrentReqIsValid( const tr_torrent * tor, |
---|
83 | tr_piece_index_t index, |
---|
84 | uint32_t offset, |
---|
85 | uint32_t length ); |
---|
86 | |
---|
87 | uint64_t tr_pieceOffset( const tr_torrent * tor, |
---|
88 | tr_piece_index_t index, |
---|
89 | uint32_t offset, |
---|
90 | uint32_t length ); |
---|
91 | |
---|
92 | void tr_torrentInitFilePriority( tr_torrent * tor, |
---|
93 | tr_file_index_t fileIndex, |
---|
94 | tr_priority_t priority ); |
---|
95 | |
---|
96 | |
---|
97 | int tr_torrentCountUncheckedPieces( const tr_torrent * ); |
---|
98 | int tr_torrentIsPieceChecked ( const tr_torrent *, tr_piece_index_t piece ); |
---|
99 | int tr_torrentIsFileChecked ( const tr_torrent *, tr_file_index_t file ); |
---|
100 | void tr_torrentSetPieceChecked ( tr_torrent *, tr_piece_index_t piece, int isChecked ); |
---|
101 | void tr_torrentSetFileChecked ( tr_torrent *, tr_file_index_t file, int isChecked ); |
---|
102 | void tr_torrentUncheck ( tr_torrent * ); |
---|
103 | |
---|
104 | int tr_torrentPromoteTracker ( tr_torrent *, int trackerIndex ); |
---|
105 | |
---|
106 | time_t* tr_torrentGetMTimes ( const tr_torrent *, int * setmeCount ); |
---|
107 | |
---|
108 | typedef enum |
---|
109 | { |
---|
110 | TR_VERIFY_NONE, |
---|
111 | TR_VERIFY_WAIT, |
---|
112 | TR_VERIFY_NOW |
---|
113 | } |
---|
114 | tr_verify_state; |
---|
115 | |
---|
116 | struct tr_torrent |
---|
117 | { |
---|
118 | tr_handle * handle; |
---|
119 | tr_info info; |
---|
120 | |
---|
121 | tr_speedlimit uploadLimitMode; |
---|
122 | tr_speedlimit downloadLimitMode; |
---|
123 | struct tr_ratecontrol * upload; |
---|
124 | struct tr_ratecontrol * download; |
---|
125 | struct tr_ratecontrol * swarmspeed; |
---|
126 | |
---|
127 | int error; |
---|
128 | char errorString[128]; |
---|
129 | |
---|
130 | uint8_t obfuscatedHash[SHA_DIGEST_LENGTH]; |
---|
131 | |
---|
132 | /* Where to download */ |
---|
133 | char * destination; |
---|
134 | |
---|
135 | /* How many bytes we ask for per request */ |
---|
136 | uint32_t blockSize; |
---|
137 | tr_block_index_t blockCount; |
---|
138 | |
---|
139 | uint32_t lastBlockSize; |
---|
140 | uint32_t lastPieceSize; |
---|
141 | |
---|
142 | uint32_t blockCountInPiece; |
---|
143 | uint32_t blockCountInLastPiece; |
---|
144 | |
---|
145 | struct tr_completion * completion; |
---|
146 | |
---|
147 | struct tr_bitfield * checkedPieces; |
---|
148 | cp_status_t cpStatus; |
---|
149 | |
---|
150 | struct tr_tracker * tracker; |
---|
151 | struct tr_publisher_tag * trackerSubscription; |
---|
152 | |
---|
153 | uint64_t downloadedCur; |
---|
154 | uint64_t downloadedPrev; |
---|
155 | uint64_t uploadedCur; |
---|
156 | uint64_t uploadedPrev; |
---|
157 | uint64_t corruptCur; |
---|
158 | uint64_t corruptPrev; |
---|
159 | |
---|
160 | uint64_t startDate; |
---|
161 | uint64_t stopDate; |
---|
162 | uint64_t activityDate; |
---|
163 | |
---|
164 | tr_torrent_status_func * status_func; |
---|
165 | void * status_func_user_data; |
---|
166 | |
---|
167 | tr_torrent_active_func * active_func; |
---|
168 | void * active_func_user_data; |
---|
169 | |
---|
170 | unsigned int isRunning : 1; |
---|
171 | unsigned int isDeleting : 1; |
---|
172 | |
---|
173 | uint16_t maxConnectedPeers; |
---|
174 | |
---|
175 | tr_verify_state verifyState; |
---|
176 | |
---|
177 | time_t lastStatTime; |
---|
178 | tr_stat stats; |
---|
179 | |
---|
180 | tr_torrent * next; |
---|
181 | }; |
---|
182 | |
---|
183 | #endif |
---|