1 | /****************************************************************************** |
---|
2 | * $Id: transmission.h 3486 2007-10-20 22:07:21Z 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(WIN32) |
---|
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 | enum |
---|
66 | { |
---|
67 | TR_PEER_FROM_INCOMING = 0, /* connections made to the listening port */ |
---|
68 | TR_PEER_FROM_TRACKER = 1, /* peers received from a tracker */ |
---|
69 | TR_PEER_FROM_CACHE = 2, /* peers read from the peer cache */ |
---|
70 | TR_PEER_FROM_PEX = 3, /* peers discovered via PEX */ |
---|
71 | TR_PEER_FROM__MAX |
---|
72 | }; |
---|
73 | |
---|
74 | /*********************************************************************** |
---|
75 | * Error codes |
---|
76 | **********************************************************************/ |
---|
77 | /* General errors */ |
---|
78 | #define TR_OK 0x00000000 |
---|
79 | #define TR_ERROR 0x81000000 |
---|
80 | #define TR_ERROR_ASSERT 0x82000000 |
---|
81 | /* I/O errors */ |
---|
82 | #define TR_ERROR_IO_MASK 0x000000FF |
---|
83 | #define TR_ERROR_IO_PARENT 0x80000001 |
---|
84 | #define TR_ERROR_IO_PERMISSIONS 0x80000002 |
---|
85 | #define TR_ERROR_IO_SPACE 0x80000004 |
---|
86 | #define TR_ERROR_IO_FILE_TOO_BIG 0x80000008 |
---|
87 | #define TR_ERROR_IO_OPEN_FILES 0x80000010 |
---|
88 | #define TR_ERROR_IO_DUP_DOWNLOAD 0x80000020 |
---|
89 | #define TR_ERROR_IO_OTHER 0x80000040 |
---|
90 | /* Misc */ |
---|
91 | #define TR_ERROR_TC_MASK 0x00000F00 |
---|
92 | #define TR_ERROR_TC_ERROR 0x80000100 |
---|
93 | #define TR_ERROR_TC_WARNING 0x80000200 |
---|
94 | |
---|
95 | #define TR_ERROR_ISSET( num, code ) ( (code) == ( (code) & (num) ) ) |
---|
96 | |
---|
97 | /*********************************************************************** |
---|
98 | * tr_init |
---|
99 | *********************************************************************** |
---|
100 | * Initializes a libtransmission instance. Returns a obscure handle to |
---|
101 | * be passed to all functions below. The tag argument is a short string |
---|
102 | * unique to the program invoking tr_init(), it is currently used as |
---|
103 | * part of saved torrent files' names to prevent one frontend from |
---|
104 | * deleting a torrent used by another. The following tags are used: |
---|
105 | * beos cli daemon gtk macosx |
---|
106 | **********************************************************************/ |
---|
107 | |
---|
108 | typedef struct tr_handle tr_handle; |
---|
109 | |
---|
110 | tr_handle * tr_init( const char * tag ); |
---|
111 | |
---|
112 | typedef struct tr_tracker_info tr_tracker_info; |
---|
113 | |
---|
114 | /** |
---|
115 | *** |
---|
116 | **/ |
---|
117 | |
---|
118 | typedef enum |
---|
119 | { |
---|
120 | TR_ENCRYPTION_PREFERRED, |
---|
121 | TR_ENCRYPTION_REQUIRED |
---|
122 | } |
---|
123 | tr_encryption_mode; |
---|
124 | |
---|
125 | tr_encryption_mode tr_getEncryptionMode( tr_handle * handle ); |
---|
126 | |
---|
127 | void tr_setEncryptionMode( tr_handle * handle, tr_encryption_mode mode ); |
---|
128 | |
---|
129 | /*********************************************************************** |
---|
130 | * tr_setMessageLevel |
---|
131 | *********************************************************************** |
---|
132 | * Set the level of messages to be output or queued |
---|
133 | **********************************************************************/ |
---|
134 | #define TR_MSG_ERR 1 |
---|
135 | #define TR_MSG_INF 2 |
---|
136 | #define TR_MSG_DBG 3 |
---|
137 | void tr_setMessageLevel( int ); |
---|
138 | int tr_getMessageLevel( void ); |
---|
139 | |
---|
140 | /*********************************************************************** |
---|
141 | * tr_setMessageQueuing |
---|
142 | *********************************************************************** |
---|
143 | * Enable or disable message queuing |
---|
144 | **********************************************************************/ |
---|
145 | typedef struct tr_msg_list tr_msg_list; |
---|
146 | void tr_setMessageQueuing( int ); |
---|
147 | |
---|
148 | /*********************************************************************** |
---|
149 | * tr_getQueuedMessages |
---|
150 | *********************************************************************** |
---|
151 | * Return a list of queued messages |
---|
152 | **********************************************************************/ |
---|
153 | tr_msg_list * tr_getQueuedMessages( void ); |
---|
154 | void tr_freeMessageList( tr_msg_list * list ); |
---|
155 | |
---|
156 | /*********************************************************************** |
---|
157 | * tr_getPrefsDirectory |
---|
158 | *********************************************************************** |
---|
159 | * Returns the full path to a directory which can be used to store |
---|
160 | * preferences. The string belongs to libtransmission, do not free it. |
---|
161 | **********************************************************************/ |
---|
162 | const char * tr_getPrefsDirectory( void ); |
---|
163 | |
---|
164 | /*********************************************************************** |
---|
165 | * tr_setBindPort |
---|
166 | *********************************************************************** |
---|
167 | * Sets the port to listen for incoming peer connections. |
---|
168 | * This can be safely called even with active torrents. |
---|
169 | **********************************************************************/ |
---|
170 | void tr_setBindPort( tr_handle *, int ); |
---|
171 | |
---|
172 | int tr_getPublicPort( const tr_handle * ); |
---|
173 | |
---|
174 | /*********************************************************************** |
---|
175 | * tr_natTraversalEnable |
---|
176 | * tr_natTraversalDisable |
---|
177 | *********************************************************************** |
---|
178 | * Enable or disable NAT traversal using NAT-PMP or UPnP IGD. |
---|
179 | **********************************************************************/ |
---|
180 | void tr_natTraversalEnable( tr_handle *, int enable ); |
---|
181 | |
---|
182 | /*********************************************************************** |
---|
183 | * tr_handleStatus |
---|
184 | *********************************************************************** |
---|
185 | * Returns some status info for the given handle. |
---|
186 | **********************************************************************/ |
---|
187 | typedef struct tr_handle_status tr_handle_status; |
---|
188 | tr_handle_status * tr_handleStatus( tr_handle * ); |
---|
189 | |
---|
190 | |
---|
191 | /*********************************************************************** |
---|
192 | * tr_torrentCount |
---|
193 | *********************************************************************** |
---|
194 | * Returns the count of open torrents |
---|
195 | **********************************************************************/ |
---|
196 | int tr_torrentCount( tr_handle * h ); |
---|
197 | |
---|
198 | |
---|
199 | /*********************************************************************** |
---|
200 | * tr_torrentIterate |
---|
201 | *********************************************************************** |
---|
202 | * Iterates on open torrents |
---|
203 | **********************************************************************/ |
---|
204 | typedef struct tr_torrent tr_torrent; |
---|
205 | typedef void (*tr_callback_t) ( tr_torrent *, void * ); |
---|
206 | void tr_torrentIterate( tr_handle *, tr_callback_t, void * ); |
---|
207 | |
---|
208 | |
---|
209 | /*********************************************************************** |
---|
210 | *** Speed Limits |
---|
211 | **/ |
---|
212 | |
---|
213 | enum { TR_UP, TR_DOWN }; |
---|
214 | |
---|
215 | typedef enum |
---|
216 | { |
---|
217 | TR_SPEEDLIMIT_GLOBAL, /* only follow the overall speed limit */ |
---|
218 | TR_SPEEDLIMIT_SINGLE, /* only follow the per-torrent limit */ |
---|
219 | TR_SPEEDLIMIT_UNLIMITED /* no limits at all */ |
---|
220 | } |
---|
221 | tr_speedlimit; |
---|
222 | |
---|
223 | void tr_torrentSetSpeedMode( tr_torrent * tor, |
---|
224 | int up_or_down, |
---|
225 | tr_speedlimit mode ); |
---|
226 | |
---|
227 | tr_speedlimit tr_torrentGetSpeedMode( const tr_torrent * tor, |
---|
228 | int up_or_down); |
---|
229 | |
---|
230 | void tr_torrentSetSpeedLimit( tr_torrent * tor, |
---|
231 | int up_or_down, |
---|
232 | int single_KiB_sec ); |
---|
233 | |
---|
234 | int tr_torrentGetSpeedLimit( const tr_torrent * tor, |
---|
235 | int up_or_down ); |
---|
236 | |
---|
237 | void tr_setUseGlobalSpeedLimit( tr_handle * handle, |
---|
238 | int up_or_down, |
---|
239 | int use_flag ); |
---|
240 | |
---|
241 | void tr_setGlobalSpeedLimit( tr_handle * handle, |
---|
242 | int up_or_down, |
---|
243 | int global_KiB_sec ); |
---|
244 | |
---|
245 | void tr_getGlobalSpeedLimit( tr_handle * handle, |
---|
246 | int up_or_down, |
---|
247 | int * setme_is_enabled, |
---|
248 | int * setme_KiBsec ); |
---|
249 | |
---|
250 | /*********************************************************************** |
---|
251 | * Torrent Priorities |
---|
252 | **********************************************************************/ |
---|
253 | |
---|
254 | enum |
---|
255 | { |
---|
256 | TR_PRI_LOW = -1, |
---|
257 | TR_PRI_NORMAL = 0, /* since NORMAL is 0, memset initializes nicely */ |
---|
258 | TR_PRI_HIGH = 1 |
---|
259 | }; |
---|
260 | |
---|
261 | typedef int8_t tr_priority_t; |
---|
262 | |
---|
263 | /* set a batch of files to a particular priority. |
---|
264 | * priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW */ |
---|
265 | void tr_torrentSetFilePriorities( tr_torrent * tor, |
---|
266 | int * files, |
---|
267 | int fileCount, |
---|
268 | tr_priority_t priority ); |
---|
269 | |
---|
270 | /* returns a malloc()ed array of tor->info.fileCount items, |
---|
271 | * each holding a value of TR_PRI_NORMAL, _HIGH, or _LOW. |
---|
272 | free the array when done. */ |
---|
273 | tr_priority_t* tr_torrentGetFilePriorities( const tr_torrent * ); |
---|
274 | |
---|
275 | /* single-file form of tr_torrentGetFilePriorities. |
---|
276 | * returns one of TR_PRI_NORMAL, _HIGH, or _LOW. */ |
---|
277 | tr_priority_t tr_torrentGetFilePriority( const tr_torrent *, int file ); |
---|
278 | |
---|
279 | /* returns true if the file's `download' flag is set */ |
---|
280 | int tr_torrentGetFileDL( const tr_torrent *, int file ); |
---|
281 | |
---|
282 | /* set a batch of files to be downloaded or not. */ |
---|
283 | void tr_torrentSetFileDLs ( tr_torrent * tor, |
---|
284 | int * files, |
---|
285 | int fileCount, |
---|
286 | int do_download ); |
---|
287 | |
---|
288 | /*********************************************************************** |
---|
289 | * tr_torrentRates |
---|
290 | *********************************************************************** |
---|
291 | * Gets the total download and upload rates |
---|
292 | **********************************************************************/ |
---|
293 | void tr_torrentRates( tr_handle *, float *, float * ); |
---|
294 | |
---|
295 | /*********************************************************************** |
---|
296 | * tr_close |
---|
297 | *********************************************************************** |
---|
298 | * Frees memory allocated by tr_init. |
---|
299 | **********************************************************************/ |
---|
300 | void tr_close( tr_handle * ); |
---|
301 | |
---|
302 | |
---|
303 | |
---|
304 | /** |
---|
305 | * Load all the torrents in tr_getTorrentsDirectory(). |
---|
306 | * This can be used at startup to kickstart all the torrents |
---|
307 | * from the previous session. |
---|
308 | */ |
---|
309 | tr_torrent ** tr_loadTorrents ( tr_handle * h, |
---|
310 | const char * destination, |
---|
311 | int isPaused, |
---|
312 | int * setmeCount ); |
---|
313 | |
---|
314 | |
---|
315 | /*********************************************************************** |
---|
316 | * tr_torrentInit |
---|
317 | *********************************************************************** |
---|
318 | * Opens and parses torrent file at 'path'. If the file exists and is |
---|
319 | * a valid torrent file, returns an handle and adds it to the list of |
---|
320 | * torrents (but doesn't start it). Returns NULL and sets *error |
---|
321 | * otherwise. If hash is not NULL and the torrent is already loaded |
---|
322 | * then it's 20-byte hash will be copied in. If the TR_FLAG_SAVE flag |
---|
323 | * is passed then a copy of the torrent file will be saved. |
---|
324 | **********************************************************************/ |
---|
325 | #define TR_EINVALID 1 |
---|
326 | #define TR_EUNSUPPORTED 2 |
---|
327 | #define TR_EDUPLICATE 3 |
---|
328 | #define TR_EOTHER 666 |
---|
329 | tr_torrent * tr_torrentInit( tr_handle * handle, |
---|
330 | const char * metainfo_filename, |
---|
331 | const char * destination, |
---|
332 | int isPaused, |
---|
333 | int * setme_error ); |
---|
334 | |
---|
335 | typedef struct tr_info tr_info; |
---|
336 | |
---|
337 | /** |
---|
338 | * Parses the specified metainfo file. |
---|
339 | * |
---|
340 | * Returns TR_OK if it parsed and can be added to Transmission. |
---|
341 | * Returns TR_INVALID if it couldn't be parsed. |
---|
342 | * Returns TR_EDUPLICATE if it parsed but can't be added. |
---|
343 | * |
---|
344 | * "destination" can be NULL if you don't need to know whether |
---|
345 | * or not the torrent can be added. |
---|
346 | * |
---|
347 | " "setme_info" can be NULL if you don't need the information. |
---|
348 | * If the metainfo can be parsed and setme_info is non-NULL, |
---|
349 | * it will be filled with the metadata's info. You'll need to |
---|
350 | * call tr_metainfoFree( setme_info ) when done with it. |
---|
351 | */ |
---|
352 | int tr_torrentParse( const tr_handle * handle, |
---|
353 | const char * metainfo_filename, |
---|
354 | const char * destination, |
---|
355 | tr_info * setme_info ); |
---|
356 | |
---|
357 | /** |
---|
358 | * Parses the cached metainfo file that matches the given hash string. |
---|
359 | * See tr_torrentParse() for a description of the arguments |
---|
360 | */ |
---|
361 | int |
---|
362 | tr_torrentParseHash( const tr_handle * h, |
---|
363 | const char * hashStr, |
---|
364 | const char * destination, |
---|
365 | tr_info * setme_info ); |
---|
366 | |
---|
367 | |
---|
368 | /*********************************************************************** |
---|
369 | * tr_torrentInitData |
---|
370 | *********************************************************************** |
---|
371 | * Like tr_torrentInit, except the actual torrent data is passed in |
---|
372 | * instead of the filename. |
---|
373 | **********************************************************************/ |
---|
374 | tr_torrent * tr_torrentInitData( tr_handle *, |
---|
375 | const uint8_t * data, size_t size, |
---|
376 | const char * destination, |
---|
377 | int isPaused, |
---|
378 | int * error ); |
---|
379 | |
---|
380 | /*********************************************************************** |
---|
381 | * tr_torrentInitSaved |
---|
382 | *********************************************************************** |
---|
383 | * Opens and parses a torrent file as with tr_torrentInit, only taking |
---|
384 | * the hash string of a saved torrent file instead of a filename. There |
---|
385 | * are currently no valid flags for this function. |
---|
386 | **********************************************************************/ |
---|
387 | tr_torrent * tr_torrentInitSaved( tr_handle *, |
---|
388 | const char * hashStr, |
---|
389 | const char * destination, |
---|
390 | int isPaused, |
---|
391 | int * error ); |
---|
392 | |
---|
393 | /*********************************************************************** |
---|
394 | * tr_torrentDisablePex |
---|
395 | *********************************************************************** |
---|
396 | * Disable or enable peer exchange for this torrent. Peer exchange is |
---|
397 | * enabled by default, except for private torrents where pex is |
---|
398 | * disabled and cannot be enabled. |
---|
399 | **********************************************************************/ |
---|
400 | void tr_torrentDisablePex( tr_torrent *, int disable ); |
---|
401 | int tr_torrentIsPexEnabled( const tr_torrent * ); |
---|
402 | |
---|
403 | const tr_info * tr_torrentInfo( const tr_torrent * ); |
---|
404 | |
---|
405 | #if 0 |
---|
406 | /*********************************************************************** |
---|
407 | * tr_torrentScrape |
---|
408 | *********************************************************************** |
---|
409 | * Asks the tracker for the count of seeders and leechers. Returns 0 |
---|
410 | * and fills 's' and 'l' if successful. Otherwise returns 1 if the |
---|
411 | * tracker doesn't support the scrape protocol, is unreachable or |
---|
412 | * replied with some error. tr_torrentScrape may block up to 20 seconds |
---|
413 | * before returning. |
---|
414 | **********************************************************************/ |
---|
415 | int tr_torrentScrape( tr_torrent *, int * s, int * l, int * d ); |
---|
416 | #endif |
---|
417 | |
---|
418 | void tr_torrentSetFolder( tr_torrent *, const char * ); |
---|
419 | const char * tr_torrentGetFolder( const tr_torrent * ); |
---|
420 | |
---|
421 | /*********************************************************************** |
---|
422 | * tr_torrentStart |
---|
423 | *********************************************************************** |
---|
424 | * Starts downloading. The download is launched in a seperate thread, |
---|
425 | * therefore tr_torrentStart returns immediately. |
---|
426 | **********************************************************************/ |
---|
427 | void tr_torrentStart( tr_torrent * ); |
---|
428 | |
---|
429 | /*********************************************************************** |
---|
430 | * tr_torrentStop |
---|
431 | *********************************************************************** |
---|
432 | * Stops downloading and notices the tracker that we are leaving. The |
---|
433 | * thread keeps running while doing so. |
---|
434 | * The thread will eventually be joined, either: |
---|
435 | * - by tr_torrentStat when the tracker has been successfully noticed, |
---|
436 | * - by tr_torrentStat if the tracker could not be noticed within 60s, |
---|
437 | * - by tr_torrentClose if you choose to remove the torrent without |
---|
438 | * waiting any further. |
---|
439 | **********************************************************************/ |
---|
440 | void tr_torrentStop( tr_torrent * ); |
---|
441 | |
---|
442 | |
---|
443 | /** |
---|
444 | *** Register to be notified whenever a torrent's state changes. |
---|
445 | **/ |
---|
446 | |
---|
447 | typedef enum |
---|
448 | { |
---|
449 | TR_CP_INCOMPLETE, /* doesn't have all the desired pieces */ |
---|
450 | TR_CP_DONE, /* has all the pieces but the DND ones */ |
---|
451 | TR_CP_COMPLETE /* has every piece */ |
---|
452 | } |
---|
453 | cp_status_t; |
---|
454 | |
---|
455 | typedef void (tr_torrent_status_func)(tr_torrent * torrent, |
---|
456 | cp_status_t status, |
---|
457 | void * user_data ); |
---|
458 | |
---|
459 | void tr_torrentSetStatusCallback( tr_torrent * torrent, |
---|
460 | tr_torrent_status_func func, |
---|
461 | void * user_data ); |
---|
462 | |
---|
463 | void tr_torrentClearStatusCallback( tr_torrent * torrent ); |
---|
464 | |
---|
465 | /** |
---|
466 | * MANUAL ANNOUNCE |
---|
467 | * |
---|
468 | * Trackers usually set an announce interval of 15 or 30 minutes. |
---|
469 | * Users can send one-time announce requests that override this |
---|
470 | * interval by calling tr_manualUpdate(). |
---|
471 | * |
---|
472 | * The wait interval for tr_manualUpdate() is much smaller. |
---|
473 | * You can test whether or not a manual update is possible |
---|
474 | * (for example, to desensitize the button) by calling |
---|
475 | * tr_torrentCanManualUpdate(). |
---|
476 | */ |
---|
477 | |
---|
478 | void tr_manualUpdate( tr_torrent * ); |
---|
479 | |
---|
480 | int tr_torrentCanManualUpdate( const tr_torrent * ); |
---|
481 | |
---|
482 | /*********************************************************************** |
---|
483 | * tr_torrentStat |
---|
484 | *********************************************************************** |
---|
485 | * Returns a pointer to an tr_stat structure with updated information |
---|
486 | * on the torrent. The structure belongs to libtransmission (do not |
---|
487 | * free it) and is guaranteed to be unchanged until the next call to |
---|
488 | * tr_torrentStat. |
---|
489 | * The interface should call this function every second or so in order |
---|
490 | * to update itself. |
---|
491 | **********************************************************************/ |
---|
492 | typedef struct tr_stat tr_stat; |
---|
493 | const tr_stat * tr_torrentStat( tr_torrent * ); |
---|
494 | |
---|
495 | /*********************************************************************** |
---|
496 | * tr_torrentPeers |
---|
497 | ***********************************************************************/ |
---|
498 | typedef struct tr_peer_stat tr_peer_stat; |
---|
499 | tr_peer_stat * tr_torrentPeers( const tr_torrent *, int * peerCount ); |
---|
500 | void tr_torrentPeersFree( tr_peer_stat *, int peerCount ); |
---|
501 | |
---|
502 | typedef struct tr_file_stat tr_file_stat; |
---|
503 | tr_file_stat * tr_torrentFiles( const tr_torrent *, int * fileCount ); |
---|
504 | void tr_torrentFilesFree( tr_file_stat *, int fileCount ); |
---|
505 | |
---|
506 | |
---|
507 | /*********************************************************************** |
---|
508 | * tr_torrentAvailability |
---|
509 | *********************************************************************** |
---|
510 | * Use this to draw an advanced progress bar which is 'size' pixels |
---|
511 | * wide. Fills 'tab' which you must have allocated: each byte is set |
---|
512 | * to either -1 if we have the piece, otherwise it is set to the number |
---|
513 | * of connected peers who have the piece. |
---|
514 | **********************************************************************/ |
---|
515 | void tr_torrentAvailability( const tr_torrent *, int8_t * tab, int size ); |
---|
516 | |
---|
517 | void tr_torrentAmountFinished( const tr_torrent * tor, float * tab, int size ); |
---|
518 | |
---|
519 | /*********************************************************************** |
---|
520 | * tr_torrentRemoveSaved |
---|
521 | *********************************************************************** |
---|
522 | * Removes the saved copy of a torrent file for torrents which the |
---|
523 | * TR_FLAG_SAVE flag is set. |
---|
524 | **********************************************************************/ |
---|
525 | void tr_torrentRemoveSaved( tr_torrent * ); |
---|
526 | |
---|
527 | void tr_torrentRecheck( tr_torrent * ); |
---|
528 | |
---|
529 | /*********************************************************************** |
---|
530 | * tr_torrentClose |
---|
531 | *********************************************************************** |
---|
532 | * Frees memory allocated by tr_torrentInit. If the torrent was running, |
---|
533 | * it is stopped first. |
---|
534 | **********************************************************************/ |
---|
535 | void tr_torrentClose( tr_torrent * ); |
---|
536 | |
---|
537 | /*********************************************************************** |
---|
538 | * tr_info |
---|
539 | **********************************************************************/ |
---|
540 | |
---|
541 | typedef struct tr_file |
---|
542 | { |
---|
543 | uint64_t length; /* Length of the file, in bytes */ |
---|
544 | char name[MAX_PATH_LENGTH]; /* Path to the file */ |
---|
545 | int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ |
---|
546 | int8_t dnd; /* nonzero if the file shouldn't be downloaded */ |
---|
547 | int firstPiece; /* We need pieces [firstPiece... */ |
---|
548 | int lastPiece; /* ...lastPiece] to dl this file */ |
---|
549 | uint64_t offset; /* file begins at the torrent's nth byte */ |
---|
550 | } |
---|
551 | tr_file; |
---|
552 | |
---|
553 | typedef struct tr_piece |
---|
554 | { |
---|
555 | uint8_t hash[SHA_DIGEST_LENGTH]; /* pieces hash */ |
---|
556 | int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ |
---|
557 | int8_t dnd; /* nonzero if the piece shouldn't be downloaded */ |
---|
558 | } |
---|
559 | tr_piece; |
---|
560 | |
---|
561 | struct tr_info |
---|
562 | { |
---|
563 | /* Path to torrent */ |
---|
564 | char torrent[MAX_PATH_LENGTH]; |
---|
565 | |
---|
566 | /* General info */ |
---|
567 | uint8_t hash[SHA_DIGEST_LENGTH]; |
---|
568 | char hashString[2*SHA_DIGEST_LENGTH+1]; |
---|
569 | char name[MAX_PATH_LENGTH]; |
---|
570 | |
---|
571 | /* Flags */ |
---|
572 | unsigned int isPrivate : 1; |
---|
573 | unsigned int isMultifile : 1; |
---|
574 | |
---|
575 | /* Tracker info */ |
---|
576 | struct |
---|
577 | { |
---|
578 | tr_tracker_info * list; |
---|
579 | int count; |
---|
580 | } * trackerList; |
---|
581 | int trackerTiers; |
---|
582 | char * primaryAddress; |
---|
583 | |
---|
584 | /* Torrent info */ |
---|
585 | char comment[MAX_PATH_LENGTH]; |
---|
586 | char creator[MAX_PATH_LENGTH]; |
---|
587 | int dateCreated; |
---|
588 | |
---|
589 | /* Pieces info */ |
---|
590 | int pieceSize; |
---|
591 | int pieceCount; |
---|
592 | uint64_t totalSize; |
---|
593 | tr_piece * pieces; |
---|
594 | |
---|
595 | /* Files info */ |
---|
596 | int fileCount; |
---|
597 | tr_file * files; |
---|
598 | }; |
---|
599 | |
---|
600 | typedef enum |
---|
601 | { |
---|
602 | TR_STATUS_CHECK_WAIT = (1<<0), /* Waiting in queue to check files */ |
---|
603 | TR_STATUS_CHECK = (1<<1), /* Checking files */ |
---|
604 | TR_STATUS_DOWNLOAD = (1<<2), /* Downloading */ |
---|
605 | TR_STATUS_DONE = (1<<3), /* not at 100% so can't tell the tracker |
---|
606 | we're a seeder, but due to DND files |
---|
607 | there's nothing we want right now */ |
---|
608 | TR_STATUS_SEED = (1<<4), /* Seeding */ |
---|
609 | TR_STATUS_STOPPED = (1<<5) /* Torrent is stopped */ |
---|
610 | } |
---|
611 | tr_torrent_status; |
---|
612 | |
---|
613 | #define TR_STATUS_IS_ACTIVE(s) ((s) != TR_STATUS_STOPPED) |
---|
614 | |
---|
615 | /*********************************************************************** |
---|
616 | * tr_stat |
---|
617 | **********************************************************************/ |
---|
618 | struct tr_stat |
---|
619 | { |
---|
620 | tr_torrent_status status; |
---|
621 | |
---|
622 | int error; |
---|
623 | char errorString[128]; |
---|
624 | |
---|
625 | const tr_tracker_info * tracker; |
---|
626 | |
---|
627 | float recheckProgress; |
---|
628 | float percentComplete; |
---|
629 | float percentDone; |
---|
630 | float rateDownload; |
---|
631 | float rateUpload; |
---|
632 | int eta; |
---|
633 | int peersKnown; |
---|
634 | int peersConnected; |
---|
635 | int peersFrom[TR_PEER_FROM__MAX]; |
---|
636 | int peersSendingToUs; |
---|
637 | int peersGettingFromUs; |
---|
638 | int seeders; |
---|
639 | int leechers; |
---|
640 | int completedFromTracker; |
---|
641 | |
---|
642 | /* Byte count of how much data is left to be downloaded until |
---|
643 | * we're done -- that is, until we've got all the pieces we wanted. */ |
---|
644 | uint64_t leftUntilDone; |
---|
645 | |
---|
646 | /* Byte count of all the corrupt data you've ever downloaded for |
---|
647 | * this torrent. If you're on a poisoned torrent, this number can |
---|
648 | * grow very large. */ |
---|
649 | uint64_t corruptEver; |
---|
650 | |
---|
651 | /* Byte count of all data you've ever uploaded for this torrent. */ |
---|
652 | uint64_t uploadedEver; |
---|
653 | |
---|
654 | /* Byte count of all the non-corrupt data you've ever downloaded |
---|
655 | * for this torrent. If you deleted the files and downloaded a second time, |
---|
656 | * this will be 2*totalSize.. */ |
---|
657 | uint64_t downloadedEver; |
---|
658 | |
---|
659 | /* Byte count of all the checksum-verified data we have for this torrent. */ |
---|
660 | uint64_t haveValid; |
---|
661 | |
---|
662 | /* Byte count of all the partial piece data we have for this torrent. |
---|
663 | * As pieces become complete, this value may decrease as portions of it are |
---|
664 | * moved to `corrupt' or `haveValid'. */ |
---|
665 | uint64_t haveUnchecked; |
---|
666 | |
---|
667 | /* Byte count of all the non-DND piece data that either we already have, |
---|
668 | * or that a peer we're connected to has. [0...desiredSize] */ |
---|
669 | uint64_t desiredAvailable; |
---|
670 | |
---|
671 | /* Byte count of all the piece data we want, whether we currently |
---|
672 | * have it nor not. [0...tr_info.totalSize] */ |
---|
673 | uint64_t desiredSize; |
---|
674 | |
---|
675 | float swarmspeed; |
---|
676 | |
---|
677 | #define TR_RATIO_NA -1 |
---|
678 | float ratio; |
---|
679 | |
---|
680 | uint64_t startDate; |
---|
681 | uint64_t activityDate; |
---|
682 | }; |
---|
683 | |
---|
684 | struct tr_file_stat |
---|
685 | { |
---|
686 | uint64_t bytesCompleted; |
---|
687 | float progress; |
---|
688 | }; |
---|
689 | |
---|
690 | struct tr_peer_stat |
---|
691 | { |
---|
692 | char addr[INET_ADDRSTRLEN]; |
---|
693 | const char * client; |
---|
694 | |
---|
695 | unsigned int isEncrypted : 1; |
---|
696 | unsigned int isDownloading : 1; |
---|
697 | unsigned int isUploading : 1; |
---|
698 | |
---|
699 | uint8_t from; |
---|
700 | uint16_t port; |
---|
701 | |
---|
702 | float progress; |
---|
703 | float downloadFromRate; |
---|
704 | float uploadToRate; |
---|
705 | }; |
---|
706 | |
---|
707 | struct tr_msg_list |
---|
708 | { |
---|
709 | uint8_t level; |
---|
710 | time_t when; |
---|
711 | char * message; |
---|
712 | struct tr_msg_list * next; |
---|
713 | }; |
---|
714 | |
---|
715 | struct tr_tracker_info |
---|
716 | { |
---|
717 | char * address; |
---|
718 | int port; |
---|
719 | char * announce; |
---|
720 | char * scrape; |
---|
721 | }; |
---|
722 | |
---|
723 | struct tr_handle_status |
---|
724 | { |
---|
725 | #define TR_NAT_TRAVERSAL_MAPPING 1 |
---|
726 | #define TR_NAT_TRAVERSAL_MAPPED 2 |
---|
727 | #define TR_NAT_TRAVERSAL_NOTFOUND 3 |
---|
728 | #define TR_NAT_TRAVERSAL_ERROR 4 |
---|
729 | #define TR_NAT_TRAVERSAL_UNMAPPING 5 |
---|
730 | #define TR_NAT_TRAVERSAL_DISABLED 6 |
---|
731 | #define TR_NAT_TRAVERSAL_IS_DISABLED( st ) \ |
---|
732 | ( TR_NAT_TRAVERSAL_DISABLED == (st) || TR_NAT_TRAVERSAL_UNMAPPING == (st) ) |
---|
733 | int natTraversalStatus; |
---|
734 | int publicPort; |
---|
735 | }; |
---|
736 | |
---|
737 | #ifdef __TRANSMISSION__ |
---|
738 | # include "internal.h" |
---|
739 | #endif |
---|
740 | |
---|
741 | #ifdef __cplusplus |
---|
742 | } |
---|
743 | #endif |
---|
744 | |
---|
745 | #endif |
---|