1 | /****************************************************************************** |
---|
2 | * $Id: transmission.h 2361 2007-07-15 20:05:32Z charles $ |
---|
3 | * |
---|
4 | * Copyright (c) 2005-2007 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_TRANSMISSION_H |
---|
26 | #define TR_TRANSMISSION_H 1 |
---|
27 | |
---|
28 | #ifdef __cplusplus |
---|
29 | extern "C" { |
---|
30 | #endif |
---|
31 | |
---|
32 | #include "version.h" |
---|
33 | |
---|
34 | #include <inttypes.h> |
---|
35 | #ifndef PRId64 |
---|
36 | # define PRId64 "lld" |
---|
37 | #endif |
---|
38 | #ifndef PRIu64 |
---|
39 | # define PRIu64 "llu" |
---|
40 | #endif |
---|
41 | #include <time.h> |
---|
42 | |
---|
43 | #define SHA_DIGEST_LENGTH 20 |
---|
44 | #ifdef __BEOS__ |
---|
45 | # include <StorageDefs.h> |
---|
46 | # define MAX_PATH_LENGTH B_FILE_NAME_LENGTH |
---|
47 | #else |
---|
48 | # define MAX_PATH_LENGTH 1024 |
---|
49 | #endif |
---|
50 | |
---|
51 | #ifndef INET_ADDRSTRLEN |
---|
52 | #define INET_ADDRSTRLEN 16 |
---|
53 | #endif |
---|
54 | |
---|
55 | #if defined(__MINGW__) |
---|
56 | #define TR_PATH_DELIMITER '\\' |
---|
57 | #define TR_PATH_DELIMITER_STR "\\" |
---|
58 | #else |
---|
59 | #define TR_PATH_DELIMITER '/' |
---|
60 | #define TR_PATH_DELIMITER_STR "/" |
---|
61 | #endif |
---|
62 | |
---|
63 | #define TR_DEFAULT_PORT 9090 |
---|
64 | |
---|
65 | #define TR_PEER_FROM__MAX 4 |
---|
66 | #define TR_PEER_FROM_INCOMING 0 /* connections made to the listening port */ |
---|
67 | #define TR_PEER_FROM_TRACKER 1 /* peers received from a tracker */ |
---|
68 | #define TR_PEER_FROM_CACHE 2 /* peers read from the peer cache */ |
---|
69 | #define TR_PEER_FROM_PEX 3 /* peers discovered via PEX */ |
---|
70 | |
---|
71 | /*********************************************************************** |
---|
72 | * Error codes |
---|
73 | **********************************************************************/ |
---|
74 | /* General errors */ |
---|
75 | #define TR_OK 0x00000000 |
---|
76 | #define TR_ERROR 0x81000000 |
---|
77 | #define TR_ERROR_ASSERT 0x82000000 |
---|
78 | /* I/O errors */ |
---|
79 | #define TR_ERROR_IO_MASK 0x000000FF |
---|
80 | #define TR_ERROR_IO_PARENT ((1<<31) | (1<<0)) |
---|
81 | #define TR_ERROR_IO_PERMISSIONS ((1<<31) | (1<<1)) |
---|
82 | #define TR_ERROR_IO_SPACE ((1<<31) | (1<<2)) |
---|
83 | #define TR_ERROR_IO_FILE_TOO_BIG ((1<<31) | (1<<3)) |
---|
84 | #define TR_ERROR_IO_OPEN_FILES ((1<<31) | (1<<4)) |
---|
85 | #define TR_ERROR_IO_DUP_DOWNLOAD ((1<<31) | (1<<5)) |
---|
86 | #define TR_ERROR_IO_OTHER ((1<<31) | (1<<6)) |
---|
87 | /* Misc */ |
---|
88 | #define TR_ERROR_TC_MASK 0x00000F00 |
---|
89 | #define TR_ERROR_TC_ERROR 0x80000100 |
---|
90 | #define TR_ERROR_TC_WARNING 0x80000200 |
---|
91 | |
---|
92 | #define TR_ERROR_ISSET( num, code ) ( (code) == ( (code) & (num) ) ) |
---|
93 | |
---|
94 | /*********************************************************************** |
---|
95 | * tr_init |
---|
96 | *********************************************************************** |
---|
97 | * Initializes a libtransmission instance. Returns a obscure handle to |
---|
98 | * be passed to all functions below. The tag argument is a short string |
---|
99 | * unique to the program invoking tr_init(), it is currently used as |
---|
100 | * part of saved torrent files' names to prevent one frontend from |
---|
101 | * deleting a torrent used by another. The following tags are used: |
---|
102 | * beos cli daemon gtk macosx |
---|
103 | **********************************************************************/ |
---|
104 | typedef struct tr_handle_s tr_handle_t; |
---|
105 | tr_handle_t * tr_init( const char * tag ); |
---|
106 | |
---|
107 | typedef struct tr_tracker_info_s tr_tracker_info_t; |
---|
108 | |
---|
109 | /*********************************************************************** |
---|
110 | * tr_setMessageLevel |
---|
111 | *********************************************************************** |
---|
112 | * Set the level of messages to be output or queued |
---|
113 | **********************************************************************/ |
---|
114 | #define TR_MSG_ERR 1 |
---|
115 | #define TR_MSG_INF 2 |
---|
116 | #define TR_MSG_DBG 3 |
---|
117 | void tr_setMessageLevel( int ); |
---|
118 | int tr_getMessageLevel( void ); |
---|
119 | |
---|
120 | /*********************************************************************** |
---|
121 | * tr_setMessageQueuing |
---|
122 | *********************************************************************** |
---|
123 | * Enable or disable message queuing |
---|
124 | **********************************************************************/ |
---|
125 | typedef struct tr_msg_list_s tr_msg_list_t; |
---|
126 | void tr_setMessageQueuing( int ); |
---|
127 | |
---|
128 | /*********************************************************************** |
---|
129 | * tr_getQueuedMessages |
---|
130 | *********************************************************************** |
---|
131 | * Return a list of queued messages |
---|
132 | **********************************************************************/ |
---|
133 | tr_msg_list_t * tr_getQueuedMessages( void ); |
---|
134 | void tr_freeMessageList( tr_msg_list_t * list ); |
---|
135 | |
---|
136 | /*********************************************************************** |
---|
137 | * tr_getPrefsDirectory |
---|
138 | *********************************************************************** |
---|
139 | * Returns the full path to a directory which can be used to store |
---|
140 | * preferences. The string belongs to libtransmission, do not free it. |
---|
141 | **********************************************************************/ |
---|
142 | const char * tr_getPrefsDirectory( void ); |
---|
143 | |
---|
144 | /*********************************************************************** |
---|
145 | * tr_setBindPort |
---|
146 | *********************************************************************** |
---|
147 | * Sets the port to listen for incoming peer connections. |
---|
148 | * This can be safely called even with active torrents. |
---|
149 | **********************************************************************/ |
---|
150 | void tr_setBindPort( tr_handle_t *, int ); |
---|
151 | |
---|
152 | /*********************************************************************** |
---|
153 | * tr_natTraversalEnable |
---|
154 | * tr_natTraversalDisable |
---|
155 | *********************************************************************** |
---|
156 | * Enable or disable NAT traversal using NAT-PMP or UPnP IGD. |
---|
157 | **********************************************************************/ |
---|
158 | void tr_natTraversalEnable( tr_handle_t *, int enable ); |
---|
159 | |
---|
160 | /*********************************************************************** |
---|
161 | * tr_handleStatus |
---|
162 | *********************************************************************** |
---|
163 | * Returns some status info for the given handle. |
---|
164 | **********************************************************************/ |
---|
165 | typedef struct tr_handle_status_s tr_handle_status_t; |
---|
166 | tr_handle_status_t * tr_handleStatus( tr_handle_t * ); |
---|
167 | |
---|
168 | /*********************************************************************** |
---|
169 | * tr_setGlobalUploadLimit |
---|
170 | *********************************************************************** |
---|
171 | * Sets the total upload rate limit in KB/s |
---|
172 | **********************************************************************/ |
---|
173 | void tr_setGlobalUploadLimit( tr_handle_t *, int ); |
---|
174 | |
---|
175 | /*********************************************************************** |
---|
176 | * tr_setGlobalDownloadLimit |
---|
177 | *********************************************************************** |
---|
178 | * Sets the total download rate limit in KB/s |
---|
179 | **********************************************************************/ |
---|
180 | void tr_setGlobalDownloadLimit( tr_handle_t *, int ); |
---|
181 | |
---|
182 | /*********************************************************************** |
---|
183 | * tr_torrentCount |
---|
184 | *********************************************************************** |
---|
185 | * Returns the count of open torrents |
---|
186 | **********************************************************************/ |
---|
187 | int tr_torrentCount( tr_handle_t * h ); |
---|
188 | |
---|
189 | |
---|
190 | /*********************************************************************** |
---|
191 | * tr_torrentIterate |
---|
192 | *********************************************************************** |
---|
193 | * Iterates on open torrents |
---|
194 | **********************************************************************/ |
---|
195 | typedef struct tr_torrent_s tr_torrent_t; |
---|
196 | typedef void (*tr_callback_t) ( tr_torrent_t *, void * ); |
---|
197 | void tr_torrentIterate( tr_handle_t *, tr_callback_t, void * ); |
---|
198 | |
---|
199 | void tr_setUseCustomLimit( tr_torrent_t * tor, int limit ); |
---|
200 | void tr_setUploadLimit( tr_torrent_t * tor, int limit ); |
---|
201 | void tr_setDownloadLimit( tr_torrent_t * tor, int limit ); |
---|
202 | |
---|
203 | /*********************************************************************** |
---|
204 | * Torrent Priorities |
---|
205 | **********************************************************************/ |
---|
206 | |
---|
207 | enum |
---|
208 | { |
---|
209 | TR_PRI_LOW = -1, |
---|
210 | TR_PRI_NORMAL = 0, /* since NORMAL is 0, memset initializes nicely */ |
---|
211 | TR_PRI_HIGH = 1 |
---|
212 | }; |
---|
213 | |
---|
214 | typedef int8_t tr_priority_t; |
---|
215 | |
---|
216 | /* set a batch of files to a particular priority. */ |
---|
217 | void tr_torrentSetFilePriorities( tr_torrent_t * tor, |
---|
218 | int * files, |
---|
219 | int fileCount, |
---|
220 | tr_priority_t priority ); |
---|
221 | |
---|
222 | |
---|
223 | /* single-file form of tr_torrentPrioritizeFiles. |
---|
224 | * priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW */ |
---|
225 | void tr_torrentSetFilePriority( tr_torrent_t *, int file, tr_priority_t priority ); |
---|
226 | |
---|
227 | /* returns a malloc()ed array of tor->info.fileCount items, |
---|
228 | * each holding a value of TR_PRI_NORMAL, _HIGH, or _LOW. |
---|
229 | free the array when done. */ |
---|
230 | tr_priority_t* tr_torrentGetFilePriorities( const tr_torrent_t * ); |
---|
231 | |
---|
232 | /* single-file form of tr_torrentGetFilePriorities. |
---|
233 | * returns one of TR_PRI_NORMAL, _HIGH, or _LOW. */ |
---|
234 | tr_priority_t tr_torrentGetFilePriority( const tr_torrent_t *, int file ); |
---|
235 | |
---|
236 | /* returns true if the file's `download' flag is set */ |
---|
237 | int tr_torrentGetFileDL( const tr_torrent_t *, int file ); |
---|
238 | |
---|
239 | /* set a batch of files to be downloaded or not. */ |
---|
240 | void tr_torrentSetFileDLs ( tr_torrent_t * tor, |
---|
241 | int * files, |
---|
242 | int fileCount, |
---|
243 | int do_download ); |
---|
244 | |
---|
245 | /* single-file form of tr_torrentSetFileDLs */ |
---|
246 | void tr_torrentSetFileDL( tr_torrent_t *, int file, int do_download ); |
---|
247 | |
---|
248 | /*********************************************************************** |
---|
249 | * tr_torrentRates |
---|
250 | *********************************************************************** |
---|
251 | * Gets the total download and upload rates |
---|
252 | **********************************************************************/ |
---|
253 | void tr_torrentRates( tr_handle_t *, float *, float * ); |
---|
254 | |
---|
255 | /*********************************************************************** |
---|
256 | * tr_close |
---|
257 | *********************************************************************** |
---|
258 | * Frees memory allocated by tr_init. |
---|
259 | **********************************************************************/ |
---|
260 | void tr_close( tr_handle_t * ); |
---|
261 | |
---|
262 | /*********************************************************************** |
---|
263 | * tr_torrentInit |
---|
264 | *********************************************************************** |
---|
265 | * Opens and parses torrent file at 'path'. If the file exists and is |
---|
266 | * a valid torrent file, returns an handle and adds it to the list of |
---|
267 | * torrents (but doesn't start it). Returns NULL and sets *error |
---|
268 | * otherwise. If hash is not NULL and the torrent is already loaded |
---|
269 | * then it's 20-byte hash will be copied in. If the TR_FLAG_SAVE flag |
---|
270 | * is passed then a copy of the torrent file will be saved. |
---|
271 | **********************************************************************/ |
---|
272 | #define TR_EINVALID 1 |
---|
273 | #define TR_EUNSUPPORTED 2 |
---|
274 | #define TR_EDUPLICATE 3 |
---|
275 | #define TR_EOTHER 666 |
---|
276 | tr_torrent_t * tr_torrentInit( tr_handle_t * handle, |
---|
277 | const char * metainfo_filename, |
---|
278 | const char * destination, |
---|
279 | int flags, |
---|
280 | int * setme_error ); |
---|
281 | |
---|
282 | typedef struct tr_info_s tr_info_t; |
---|
283 | |
---|
284 | /** |
---|
285 | * Parses the specified metainfo file. |
---|
286 | * |
---|
287 | * Returns TR_OK if it parsed and can be added to Transmission. |
---|
288 | * Returns TR_INVALID if it couldn't be parsed. |
---|
289 | * Returns TR_EDUPLICATE if it parsed but can't be added. |
---|
290 | * |
---|
291 | * "destination" can be NULL if you don't need to know whether |
---|
292 | * or not the torrent can be added. |
---|
293 | * |
---|
294 | " "setme_info" can be NULL if you don't need the information. |
---|
295 | * If the metainfo can be parsed and setme_info is non-NULL, |
---|
296 | * it will be filled with the metadata's info. You'll need to |
---|
297 | * call tr_metainfoFree( setme_info ) when done with it. |
---|
298 | */ |
---|
299 | int tr_torrentParse( const tr_handle_t * handle, |
---|
300 | const char * metainfo_filename, |
---|
301 | const char * destination, |
---|
302 | tr_info_t * setme_info ); |
---|
303 | |
---|
304 | /** |
---|
305 | * Parses the cached metainfo file that matches the given hash string. |
---|
306 | * See tr_torrentParse() for a description of the arguments |
---|
307 | */ |
---|
308 | int |
---|
309 | tr_torrentParseHash( const tr_handle_t * h, |
---|
310 | const char * hashStr, |
---|
311 | const char * destination, |
---|
312 | tr_info_t * setme_info ); |
---|
313 | |
---|
314 | |
---|
315 | /*********************************************************************** |
---|
316 | * tr_torrentInitData |
---|
317 | *********************************************************************** |
---|
318 | * Like tr_torrentInit, except the actual torrent data is passed in |
---|
319 | * instead of the filename. |
---|
320 | **********************************************************************/ |
---|
321 | tr_torrent_t * tr_torrentInitData( tr_handle_t *, |
---|
322 | const uint8_t * data, size_t size, |
---|
323 | const char * destination, |
---|
324 | int flags, int * error ); |
---|
325 | |
---|
326 | /*********************************************************************** |
---|
327 | * tr_torrentInitSaved |
---|
328 | *********************************************************************** |
---|
329 | * Opens and parses a torrent file as with tr_torrentInit, only taking |
---|
330 | * the hash string of a saved torrent file instead of a filename. There |
---|
331 | * are currently no valid flags for this function. |
---|
332 | **********************************************************************/ |
---|
333 | tr_torrent_t * tr_torrentInitSaved( tr_handle_t *, |
---|
334 | const char * hashStr, |
---|
335 | const char * destination, |
---|
336 | int flags, int * error ); |
---|
337 | |
---|
338 | /*********************************************************************** |
---|
339 | * tr_torrentDisablePex |
---|
340 | *********************************************************************** |
---|
341 | * Disable or enable peer exchange for this torrent. Peer exchange is |
---|
342 | * enabled by default, except for private torrents where pex is |
---|
343 | * disabled and cannot be enabled. |
---|
344 | **********************************************************************/ |
---|
345 | void tr_torrentDisablePex( tr_torrent_t *, int disable ); |
---|
346 | |
---|
347 | const tr_info_t * tr_torrentInfo( const tr_torrent_t * ); |
---|
348 | |
---|
349 | #if 0 |
---|
350 | /*********************************************************************** |
---|
351 | * tr_torrentScrape |
---|
352 | *********************************************************************** |
---|
353 | * Asks the tracker for the count of seeders and leechers. Returns 0 |
---|
354 | * and fills 's' and 'l' if successful. Otherwise returns 1 if the |
---|
355 | * tracker doesn't support the scrape protocol, is unreachable or |
---|
356 | * replied with some error. tr_torrentScrape may block up to 20 seconds |
---|
357 | * before returning. |
---|
358 | **********************************************************************/ |
---|
359 | int tr_torrentScrape( tr_torrent_t *, int * s, int * l, int * d ); |
---|
360 | #endif |
---|
361 | |
---|
362 | void tr_torrentSetFolder( tr_torrent_t *, const char * ); |
---|
363 | const char * tr_torrentGetFolder( const tr_torrent_t * ); |
---|
364 | |
---|
365 | /*********************************************************************** |
---|
366 | * tr_torrentStart |
---|
367 | *********************************************************************** |
---|
368 | * Starts downloading. The download is launched in a seperate thread, |
---|
369 | * therefore tr_torrentStart returns immediately. |
---|
370 | **********************************************************************/ |
---|
371 | void tr_torrentStart( tr_torrent_t * ); |
---|
372 | |
---|
373 | /*********************************************************************** |
---|
374 | * tr_torrentStop |
---|
375 | *********************************************************************** |
---|
376 | * Stops downloading and notices the tracker that we are leaving. The |
---|
377 | * thread keeps running while doing so. |
---|
378 | * The thread will eventually be joined, either: |
---|
379 | * - by tr_torrentStat when the tracker has been successfully noticed, |
---|
380 | * - by tr_torrentStat if the tracker could not be noticed within 60s, |
---|
381 | * - by tr_torrentClose if you choose to remove the torrent without |
---|
382 | * waiting any further. |
---|
383 | **********************************************************************/ |
---|
384 | void tr_torrentStop( tr_torrent_t * ); |
---|
385 | |
---|
386 | /*********************************************************************** |
---|
387 | * tr_getComplete, tr_getIncomplete and tr_getPartial |
---|
388 | *********************************************************************** |
---|
389 | * The first call after a torrent changed state returns 1. Returns 0 |
---|
390 | * in other cases. |
---|
391 | **********************************************************************/ |
---|
392 | int tr_getIncomplete( tr_torrent_t * tor ); |
---|
393 | int tr_getDone( tr_torrent_t * tor ); |
---|
394 | int tr_getComplete( tr_torrent_t * tor ); |
---|
395 | |
---|
396 | |
---|
397 | /*********************************************************************** |
---|
398 | * tr_manualUpdate |
---|
399 | *********************************************************************** |
---|
400 | * Reannounce to tracker regardless of wait interval |
---|
401 | **********************************************************************/ |
---|
402 | void tr_manualUpdate( tr_torrent_t * ); |
---|
403 | |
---|
404 | /*********************************************************************** |
---|
405 | * tr_torrentStat |
---|
406 | *********************************************************************** |
---|
407 | * Returns a pointer to an tr_stat_t structure with updated information |
---|
408 | * on the torrent. The structure belongs to libtransmission (do not |
---|
409 | * free it) and is guaranteed to be unchanged until the next call to |
---|
410 | * tr_torrentStat. |
---|
411 | * The interface should call this function every second or so in order |
---|
412 | * to update itself. |
---|
413 | **********************************************************************/ |
---|
414 | typedef struct tr_stat_s tr_stat_t; |
---|
415 | const tr_stat_t * tr_torrentStat( tr_torrent_t * ); |
---|
416 | |
---|
417 | /*********************************************************************** |
---|
418 | * tr_torrentPeers |
---|
419 | ***********************************************************************/ |
---|
420 | typedef struct tr_peer_stat_s tr_peer_stat_t; |
---|
421 | tr_peer_stat_t * tr_torrentPeers( const tr_torrent_t *, int * peerCount ); |
---|
422 | void tr_torrentPeersFree( tr_peer_stat_t *, int peerCount ); |
---|
423 | |
---|
424 | typedef struct tr_file_stat_s tr_file_stat_t; |
---|
425 | tr_file_stat_t * tr_torrentFiles( const tr_torrent_t *, int * fileCount ); |
---|
426 | void tr_torrentFilesFree( tr_file_stat_t *, int fileCount ); |
---|
427 | |
---|
428 | |
---|
429 | /*********************************************************************** |
---|
430 | * tr_torrentAvailability |
---|
431 | *********************************************************************** |
---|
432 | * Use this to draw an advanced progress bar which is 'size' pixels |
---|
433 | * wide. Fills 'tab' which you must have allocated: each byte is set |
---|
434 | * to either -1 if we have the piece, otherwise it is set to the number |
---|
435 | * of connected peers who have the piece. |
---|
436 | **********************************************************************/ |
---|
437 | void tr_torrentAvailability( const tr_torrent_t *, int8_t * tab, int size ); |
---|
438 | |
---|
439 | void tr_torrentAmountFinished( const tr_torrent_t * tor, float * tab, int size ); |
---|
440 | |
---|
441 | /*********************************************************************** |
---|
442 | * tr_torrentCompletion |
---|
443 | *********************************************************************** |
---|
444 | * Returns the completion progress for each file in the torrent as an |
---|
445 | * array of floats the same size and order as in tr_info_t. Free the |
---|
446 | * array when done. |
---|
447 | **********************************************************************/ |
---|
448 | float * tr_torrentCompletion( const tr_torrent_t * ); |
---|
449 | |
---|
450 | float tr_torrentFileCompletion( const tr_torrent_t *, int fileIndex ); |
---|
451 | |
---|
452 | uint64_t tr_torrentFileBytesCompleted( const tr_torrent_t *, int fileIndex ); |
---|
453 | |
---|
454 | |
---|
455 | /*********************************************************************** |
---|
456 | * tr_torrentRemoveSaved |
---|
457 | *********************************************************************** |
---|
458 | * Removes the saved copy of a torrent file for torrents which the |
---|
459 | * TR_FLAG_SAVE flag is set. |
---|
460 | **********************************************************************/ |
---|
461 | void tr_torrentRemoveSaved( tr_torrent_t * ); |
---|
462 | |
---|
463 | void tr_torrentRecheck( tr_torrent_t * ); |
---|
464 | |
---|
465 | /*********************************************************************** |
---|
466 | * tr_torrentClose |
---|
467 | *********************************************************************** |
---|
468 | * Frees memory allocated by tr_torrentInit. If the torrent was running, |
---|
469 | * it is stopped first. |
---|
470 | **********************************************************************/ |
---|
471 | void tr_torrentClose( tr_torrent_t * ); |
---|
472 | |
---|
473 | /*********************************************************************** |
---|
474 | * tr_info_s |
---|
475 | **********************************************************************/ |
---|
476 | |
---|
477 | typedef struct tr_file_s |
---|
478 | { |
---|
479 | uint64_t length; /* Length of the file, in bytes */ |
---|
480 | char name[MAX_PATH_LENGTH]; /* Path to the file */ |
---|
481 | int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ |
---|
482 | int8_t dnd; /* nonzero if the file shouldn't be downloaded */ |
---|
483 | int firstPiece; /* We need pieces [firstPiece... */ |
---|
484 | int lastPiece; /* ...lastPiece] to dl this file */ |
---|
485 | uint64_t offset; /* file begins at the torrent's nth byte */ |
---|
486 | } |
---|
487 | tr_file_t; |
---|
488 | |
---|
489 | typedef struct tr_piece_s |
---|
490 | { |
---|
491 | uint8_t hash[SHA_DIGEST_LENGTH]; /* pieces hash */ |
---|
492 | int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ |
---|
493 | int8_t dnd; /* nonzero if the piece shouldn't be downloaded */ |
---|
494 | } |
---|
495 | tr_piece_t; |
---|
496 | |
---|
497 | struct tr_info_s |
---|
498 | { |
---|
499 | /* Path to torrent */ |
---|
500 | char torrent[MAX_PATH_LENGTH]; |
---|
501 | |
---|
502 | /* General info */ |
---|
503 | uint8_t hash[SHA_DIGEST_LENGTH]; |
---|
504 | char hashString[2*SHA_DIGEST_LENGTH+1]; |
---|
505 | char name[MAX_PATH_LENGTH]; |
---|
506 | |
---|
507 | /* Flags */ |
---|
508 | #define TR_FLAG_SAVE 0x01 /* save a copy of the torrent file */ |
---|
509 | #define TR_FLAG_PRIVATE 0x02 /* do not share information for this torrent */ |
---|
510 | #define TR_FLAG_PAUSED 0x04 /* don't start the torrent when adding it */ |
---|
511 | int flags; |
---|
512 | |
---|
513 | /* Tracker info */ |
---|
514 | struct |
---|
515 | { |
---|
516 | tr_tracker_info_t * list; |
---|
517 | int count; |
---|
518 | } * trackerList; |
---|
519 | int trackerTiers; |
---|
520 | |
---|
521 | /* Torrent info */ |
---|
522 | char comment[MAX_PATH_LENGTH]; |
---|
523 | char creator[MAX_PATH_LENGTH]; |
---|
524 | int dateCreated; |
---|
525 | |
---|
526 | /* Pieces info */ |
---|
527 | int pieceSize; |
---|
528 | int pieceCount; |
---|
529 | uint64_t totalSize; |
---|
530 | tr_piece_t * pieces; |
---|
531 | |
---|
532 | /* Files info */ |
---|
533 | int multifile; |
---|
534 | int fileCount; |
---|
535 | tr_file_t * files; |
---|
536 | }; |
---|
537 | |
---|
538 | typedef enum |
---|
539 | { |
---|
540 | TR_STATUS_CHECK_WAIT = (1<<0), /* Waiting in queue to check files */ |
---|
541 | TR_STATUS_CHECK = (1<<1), /* Checking files */ |
---|
542 | TR_STATUS_DOWNLOAD = (1<<2), /* Downloading */ |
---|
543 | TR_STATUS_DONE = (1<<3), /* not at 100% so can't tell the tracker |
---|
544 | we're a seeder, but due to DND files |
---|
545 | there's nothing we want right now */ |
---|
546 | TR_STATUS_SEED = (1<<4), /* Seeding */ |
---|
547 | TR_STATUS_STOPPING = (1<<5), /* Stopping -- closing connections, etc. */ |
---|
548 | TR_STATUS_STOPPED = (1<<6) /* Torrent is stopped */ |
---|
549 | } |
---|
550 | torrent_status_t; |
---|
551 | |
---|
552 | #define TR_STATUS_ACTIVE \ |
---|
553 | (TR_STATUS_CHECK_WAIT|TR_STATUS_CHECK|TR_STATUS_DOWNLOAD|TR_STATUS_DONE|TR_STATUS_SEED) |
---|
554 | #define TR_STATUS_INACTIVE \ |
---|
555 | (TR_STATUS_STOPPING|TR_STATUS_STOPPED) |
---|
556 | |
---|
557 | typedef enum |
---|
558 | { |
---|
559 | TR_CP_INCOMPLETE, /* doesn't have all the desired pieces */ |
---|
560 | TR_CP_DONE, /* has all the pieces but the DND ones */ |
---|
561 | TR_CP_COMPLETE /* has every piece */ |
---|
562 | } |
---|
563 | cp_status_t; |
---|
564 | |
---|
565 | /*********************************************************************** |
---|
566 | * tr_stat_s |
---|
567 | **********************************************************************/ |
---|
568 | struct tr_stat_s |
---|
569 | { |
---|
570 | torrent_status_t status; |
---|
571 | cp_status_t cpStatus; |
---|
572 | |
---|
573 | int error; |
---|
574 | char errorString[128]; |
---|
575 | int cannotConnect; |
---|
576 | |
---|
577 | const tr_tracker_info_t * tracker; |
---|
578 | |
---|
579 | float percentComplete; |
---|
580 | float percentDone; |
---|
581 | float rateDownload; |
---|
582 | float rateUpload; |
---|
583 | int eta; |
---|
584 | int peersTotal; |
---|
585 | int peersConnected; |
---|
586 | int peersFrom[TR_PEER_FROM__MAX]; |
---|
587 | int peersUploading; |
---|
588 | int peersDownloading; |
---|
589 | int seeders; |
---|
590 | int leechers; |
---|
591 | int completedFromTracker; |
---|
592 | |
---|
593 | uint64_t left; |
---|
594 | uint64_t downloaded; |
---|
595 | uint64_t downloadedValid; |
---|
596 | uint64_t uploaded; |
---|
597 | float swarmspeed; |
---|
598 | |
---|
599 | #define TR_RATIO_NA -1 |
---|
600 | float ratio; |
---|
601 | |
---|
602 | uint64_t startDate; |
---|
603 | uint64_t activityDate; |
---|
604 | }; |
---|
605 | |
---|
606 | struct tr_file_stat_s |
---|
607 | { |
---|
608 | uint64_t bytesCompleted; |
---|
609 | float progress; |
---|
610 | cp_status_t completionStatus; |
---|
611 | }; |
---|
612 | |
---|
613 | struct tr_peer_stat_s |
---|
614 | { |
---|
615 | char addr[INET_ADDRSTRLEN]; |
---|
616 | const char * client; |
---|
617 | |
---|
618 | int isConnected; |
---|
619 | int from; |
---|
620 | float progress; |
---|
621 | int port; |
---|
622 | |
---|
623 | int isDownloading; |
---|
624 | int isUploading; |
---|
625 | float downloadFromRate; |
---|
626 | float uploadToRate; |
---|
627 | }; |
---|
628 | |
---|
629 | struct tr_msg_list_s |
---|
630 | { |
---|
631 | int level; |
---|
632 | time_t when; |
---|
633 | char * message; |
---|
634 | struct tr_msg_list_s * next; |
---|
635 | }; |
---|
636 | |
---|
637 | struct tr_tracker_info_s |
---|
638 | { |
---|
639 | char * address; |
---|
640 | int port; |
---|
641 | char * announce; |
---|
642 | char * scrape; |
---|
643 | }; |
---|
644 | |
---|
645 | struct tr_handle_status_s |
---|
646 | { |
---|
647 | #define TR_NAT_TRAVERSAL_MAPPING 1 |
---|
648 | #define TR_NAT_TRAVERSAL_MAPPED 2 |
---|
649 | #define TR_NAT_TRAVERSAL_NOTFOUND 3 |
---|
650 | #define TR_NAT_TRAVERSAL_ERROR 4 |
---|
651 | #define TR_NAT_TRAVERSAL_UNMAPPING 5 |
---|
652 | #define TR_NAT_TRAVERSAL_DISABLED 6 |
---|
653 | #define TR_NAT_TRAVERSAL_IS_DISABLED( st ) \ |
---|
654 | ( TR_NAT_TRAVERSAL_DISABLED == (st) || TR_NAT_TRAVERSAL_UNMAPPING == (st) ) |
---|
655 | int natTraversalStatus; |
---|
656 | int publicPort; |
---|
657 | }; |
---|
658 | |
---|
659 | #ifdef __TRANSMISSION__ |
---|
660 | # include "internal.h" |
---|
661 | #endif |
---|
662 | |
---|
663 | #ifdef __cplusplus |
---|
664 | } |
---|
665 | #endif |
---|
666 | |
---|
667 | #endif |
---|