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