1 | /****************************************************************************** |
---|
2 | * $Id: torrent.h 7154 2008-11-25 21:35:17Z 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 __TRANSMISSION__ |
---|
26 | #error only libtransmission should #include this header. |
---|
27 | #endif |
---|
28 | |
---|
29 | #ifndef TR_TORRENT_H |
---|
30 | #define TR_TORRENT_H 1 |
---|
31 | |
---|
32 | struct tr_bandwidth; |
---|
33 | struct tr_ratecontrol; |
---|
34 | |
---|
35 | /** |
---|
36 | *** Package-visible ctor API |
---|
37 | **/ |
---|
38 | |
---|
39 | void tr_ctorSetSave( tr_ctor * ctor, |
---|
40 | int saveMetadataInOurTorrentsDir ); |
---|
41 | |
---|
42 | int tr_ctorGetSave( const tr_ctor * ctor ); |
---|
43 | |
---|
44 | /** |
---|
45 | *** |
---|
46 | **/ |
---|
47 | |
---|
48 | /* just like tr_torrentSetFileDLs but doesn't trigger a fastresume save */ |
---|
49 | void tr_torrentInitFileDLs( tr_torrent * tor, |
---|
50 | tr_file_index_t * files, |
---|
51 | tr_file_index_t fileCount, |
---|
52 | int do_download ); |
---|
53 | |
---|
54 | int tr_torrentIsPrivate( const tr_torrent * ); |
---|
55 | |
---|
56 | void tr_torrentRecheckCompleteness( tr_torrent * ); |
---|
57 | |
---|
58 | void tr_torrentResetTransferStats( tr_torrent * ); |
---|
59 | |
---|
60 | void tr_torrentSetHasPiece( tr_torrent * tor, |
---|
61 | tr_piece_index_t pieceIndex, |
---|
62 | int has ); |
---|
63 | |
---|
64 | void tr_torrentLock( const tr_torrent * session ); |
---|
65 | |
---|
66 | void tr_torrentUnlock( const tr_torrent * session ); |
---|
67 | |
---|
68 | int tr_torrentIsSeed( const tr_torrent * session ); |
---|
69 | |
---|
70 | void tr_torrentChangeMyPort( tr_torrent * session ); |
---|
71 | |
---|
72 | int tr_torrentExists( const tr_session * session, |
---|
73 | const uint8_t * hash ); |
---|
74 | |
---|
75 | tr_torrent* tr_torrentFindFromId( tr_session * session, |
---|
76 | int id ); |
---|
77 | |
---|
78 | tr_torrent* tr_torrentFindFromHash( tr_session * session, |
---|
79 | const uint8_t * hash ); |
---|
80 | |
---|
81 | tr_torrent* tr_torrentFindFromHashString( tr_session * session, |
---|
82 | const char * hashString ); |
---|
83 | |
---|
84 | tr_torrent* tr_torrentFindFromObfuscatedHash( tr_session * session, |
---|
85 | const uint8_t * hash ); |
---|
86 | |
---|
87 | int tr_torrentAllowsPex( const tr_torrent * ); |
---|
88 | |
---|
89 | int tr_torrentIsPieceTransferAllowed( const tr_torrent * torrent, |
---|
90 | tr_direction direction ); |
---|
91 | |
---|
92 | /* get the index of this piece's first block */ |
---|
93 | #define tr_torPieceFirstBlock( tor, piece ) ( ( piece ) *\ |
---|
94 | ( tor )->blockCountInPiece ) |
---|
95 | |
---|
96 | /* what piece index is this block in? */ |
---|
97 | #define tr_torBlockPiece( tor, block ) ( ( block ) /\ |
---|
98 | ( tor )->blockCountInPiece ) |
---|
99 | |
---|
100 | /* how many blocks are in this piece? */ |
---|
101 | #define tr_torPieceCountBlocks( tor, piece ) \ |
---|
102 | ( ( ( piece ) ==\ |
---|
103 | ( ( tor )->info.pieceCount - \ |
---|
104 | 1 ) ) ? ( tor )->blockCountInLastPiece : ( tor )->blockCountInPiece ) |
---|
105 | |
---|
106 | /* how many bytes are in this piece? */ |
---|
107 | #define tr_torPieceCountBytes( tor, piece ) \ |
---|
108 | ( ( ( piece ) ==\ |
---|
109 | ( ( tor )->info.pieceCount - \ |
---|
110 | 1 ) ) ? ( tor )->lastPieceSize : ( tor )->info.pieceSize ) |
---|
111 | |
---|
112 | /* how many bytes are in this block? */ |
---|
113 | #define tr_torBlockCountBytes( tor, block ) \ |
---|
114 | ( ( ( block ) ==\ |
---|
115 | ( ( tor )->blockCount - \ |
---|
116 | 1 ) ) ? ( tor )->lastBlockSize : ( tor )->blockSize ) |
---|
117 | |
---|
118 | #define tr_block( a, b ) _tr_block( tor, a, b ) |
---|
119 | tr_block_index_t _tr_block( const tr_torrent * tor, |
---|
120 | tr_piece_index_t index, |
---|
121 | uint32_t offset ); |
---|
122 | |
---|
123 | int tr_torrentReqIsValid( const tr_torrent * tor, |
---|
124 | tr_piece_index_t index, |
---|
125 | uint32_t offset, |
---|
126 | uint32_t length ); |
---|
127 | |
---|
128 | uint64_t tr_pieceOffset( const tr_torrent * tor, |
---|
129 | tr_piece_index_t index, |
---|
130 | uint32_t offset, |
---|
131 | uint32_t length ); |
---|
132 | |
---|
133 | void tr_torrentInitFilePriority( tr_torrent * tor, |
---|
134 | tr_file_index_t fileIndex, |
---|
135 | tr_priority_t priority ); |
---|
136 | |
---|
137 | |
---|
138 | int tr_torrentCountUncheckedPieces( const tr_torrent * ); |
---|
139 | |
---|
140 | int tr_torrentIsPieceChecked( const tr_torrent * tor, |
---|
141 | tr_piece_index_t piece ); |
---|
142 | |
---|
143 | int tr_torrentIsFileChecked( const tr_torrent * tor, |
---|
144 | tr_file_index_t file ); |
---|
145 | |
---|
146 | void tr_torrentSetPieceChecked( tr_torrent * tor, |
---|
147 | tr_piece_index_t piece, |
---|
148 | int isChecked ); |
---|
149 | |
---|
150 | void tr_torrentSetFileChecked( tr_torrent * tor, |
---|
151 | tr_file_index_t file, |
---|
152 | int isChecked ); |
---|
153 | |
---|
154 | void tr_torrentUncheck( tr_torrent * tor ); |
---|
155 | |
---|
156 | int tr_torrentPromoteTracker( tr_torrent * tor, |
---|
157 | int trackerIndex ); |
---|
158 | |
---|
159 | time_t* tr_torrentGetMTimes( const tr_torrent * tor, |
---|
160 | size_t * setmeCount ); |
---|
161 | |
---|
162 | typedef enum |
---|
163 | { |
---|
164 | TR_VERIFY_NONE, |
---|
165 | TR_VERIFY_WAIT, |
---|
166 | TR_VERIFY_NOW |
---|
167 | } |
---|
168 | tr_verify_state; |
---|
169 | |
---|
170 | struct tr_torrent |
---|
171 | { |
---|
172 | tr_session * session; |
---|
173 | tr_info info; |
---|
174 | |
---|
175 | tr_speedlimit speedLimitMode[2]; |
---|
176 | |
---|
177 | struct tr_ratecontrol * swarmSpeed; |
---|
178 | |
---|
179 | int error; |
---|
180 | char errorString[128]; |
---|
181 | |
---|
182 | uint8_t obfuscatedHash[SHA_DIGEST_LENGTH]; |
---|
183 | |
---|
184 | /* Where to download */ |
---|
185 | char * downloadDir; |
---|
186 | |
---|
187 | /* How many bytes we ask for per request */ |
---|
188 | uint32_t blockSize; |
---|
189 | tr_block_index_t blockCount; |
---|
190 | |
---|
191 | uint32_t lastBlockSize; |
---|
192 | uint32_t lastPieceSize; |
---|
193 | |
---|
194 | uint32_t blockCountInPiece; |
---|
195 | uint32_t blockCountInLastPiece; |
---|
196 | |
---|
197 | struct tr_completion * completion; |
---|
198 | |
---|
199 | struct tr_bitfield * checkedPieces; |
---|
200 | tr_completeness completeness; |
---|
201 | |
---|
202 | struct tr_tracker * tracker; |
---|
203 | struct tr_publisher_tag * trackerSubscription; |
---|
204 | |
---|
205 | uint64_t downloadedCur; |
---|
206 | uint64_t downloadedPrev; |
---|
207 | uint64_t uploadedCur; |
---|
208 | uint64_t uploadedPrev; |
---|
209 | uint64_t corruptCur; |
---|
210 | uint64_t corruptPrev; |
---|
211 | |
---|
212 | time_t addedDate; |
---|
213 | time_t activityDate; |
---|
214 | time_t doneDate; |
---|
215 | time_t startDate; |
---|
216 | |
---|
217 | tr_torrent_completeness_func * completeness_func; |
---|
218 | void * completeness_func_user_data; |
---|
219 | |
---|
220 | unsigned int isRunning : 1; |
---|
221 | unsigned int isDeleting : 1; |
---|
222 | |
---|
223 | uint16_t maxConnectedPeers; |
---|
224 | |
---|
225 | tr_verify_state verifyState; |
---|
226 | |
---|
227 | time_t lastStatTime; |
---|
228 | tr_stat stats; |
---|
229 | |
---|
230 | tr_torrent * next; |
---|
231 | |
---|
232 | int uniqueId; |
---|
233 | |
---|
234 | struct tr_bandwidth * bandwidth; |
---|
235 | }; |
---|
236 | |
---|
237 | #endif |
---|