1 | /****************************************************************************** |
---|
2 | * $Id: transmission.h 5034 2008-02-14 01:12:00Z charles $ |
---|
3 | * |
---|
4 | * Copyright (c) 2005-2008 Transmission authors and contributors |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
---|
7 | * copy of this software and associated documentation files (the "Software"), |
---|
8 | * to deal in the Software without restriction, including without limitation |
---|
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
10 | * and/or sell copies of the Software, and to permit persons to whom the |
---|
11 | * Software is furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
22 | * DEALINGS IN THE SOFTWARE. |
---|
23 | *****************************************************************************/ |
---|
24 | |
---|
25 | #ifndef TR_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> /* uintN_t */ |
---|
35 | #ifndef PRId64 |
---|
36 | # define PRId64 "lld" |
---|
37 | #endif |
---|
38 | #ifndef PRIu64 |
---|
39 | # define PRIu64 "llu" |
---|
40 | #endif |
---|
41 | #include <time.h> /* time_t */ |
---|
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 | #define TR_DEFAULT_PORT 51413 |
---|
52 | |
---|
53 | enum |
---|
54 | { |
---|
55 | TR_PEER_FROM_INCOMING = 0, /* connections made to the listening port */ |
---|
56 | TR_PEER_FROM_TRACKER = 1, /* peers received from a tracker */ |
---|
57 | TR_PEER_FROM_CACHE = 2, /* peers read from the peer cache */ |
---|
58 | TR_PEER_FROM_PEX = 3, /* peers discovered via PEX */ |
---|
59 | TR_PEER_FROM__MAX |
---|
60 | }; |
---|
61 | |
---|
62 | /*********************************************************************** |
---|
63 | * tr_init |
---|
64 | *********************************************************************** |
---|
65 | * Initializes and returns an opaque libtransmission handle |
---|
66 | * to be passed to functions below. The tag argument is a short string |
---|
67 | * unique to the program invoking tr_init(), it is currently used as |
---|
68 | * part of saved torrent files' names to prevent one frontend from |
---|
69 | * deleting a torrent used by another. The following tags are used: |
---|
70 | * beos cli daemon gtk macosx wx |
---|
71 | **********************************************************************/ |
---|
72 | |
---|
73 | typedef struct tr_handle tr_handle; |
---|
74 | |
---|
75 | tr_handle * tr_initFull( const char * tag, |
---|
76 | int isPexEnabled, |
---|
77 | int isNatEnabled, |
---|
78 | int publicPort, |
---|
79 | int encryptionMode, |
---|
80 | int isUploadLimitEnabled, |
---|
81 | int uploadLimit, |
---|
82 | int isDownloadLimitEnabled, |
---|
83 | int downloadLimit, |
---|
84 | int globalPeerLimit, |
---|
85 | int messageLevel, |
---|
86 | int isMessageQueueingEnabled ); |
---|
87 | |
---|
88 | /** |
---|
89 | * Like tr_initFull() but with default values supplied. |
---|
90 | */ |
---|
91 | tr_handle * tr_init( const char * tag ); |
---|
92 | |
---|
93 | /** |
---|
94 | * Shut down a libtransmission instance created by tr_init*() |
---|
95 | */ |
---|
96 | void tr_close( tr_handle * ); |
---|
97 | |
---|
98 | |
---|
99 | /** |
---|
100 | *** |
---|
101 | **/ |
---|
102 | |
---|
103 | typedef struct tr_session_stats |
---|
104 | { |
---|
105 | uint64_t uploadedBytes; /* total up */ |
---|
106 | uint64_t downloadedBytes; /* total down */ |
---|
107 | double ratio; /* TR_RATIO_INF, TR_RATIO_NA, or total up/down */ |
---|
108 | uint64_t filesAdded; /* number of files added */ |
---|
109 | uint64_t sessionCount; /* program started N times */ |
---|
110 | uint64_t secondsActive; /* how long Transmisson's been running */ |
---|
111 | } |
---|
112 | tr_session_stats; |
---|
113 | |
---|
114 | /* stats from the current session. */ |
---|
115 | void tr_getSessionStats( const tr_handle * handle, |
---|
116 | tr_session_stats * setme ); |
---|
117 | |
---|
118 | /* stats from the current and past sessions. */ |
---|
119 | void tr_getCumulativeSessionStats( const tr_handle * handle, |
---|
120 | tr_session_stats * setme ); |
---|
121 | |
---|
122 | |
---|
123 | /** |
---|
124 | *** |
---|
125 | **/ |
---|
126 | |
---|
127 | typedef enum |
---|
128 | { |
---|
129 | TR_PLAINTEXT_PREFERRED, |
---|
130 | TR_ENCRYPTION_PREFERRED, |
---|
131 | TR_ENCRYPTION_REQUIRED |
---|
132 | } |
---|
133 | tr_encryption_mode; |
---|
134 | |
---|
135 | tr_encryption_mode tr_getEncryptionMode( tr_handle * handle ); |
---|
136 | |
---|
137 | void tr_setEncryptionMode( tr_handle * handle, tr_encryption_mode mode ); |
---|
138 | |
---|
139 | /*********************************************************************** |
---|
140 | * tr_getPrefsDirectory |
---|
141 | *********************************************************************** |
---|
142 | * Returns the full path to a directory which can be used to store |
---|
143 | * preferences. The string belongs to libtransmission, do not free it. |
---|
144 | **********************************************************************/ |
---|
145 | const char * tr_getPrefsDirectory( void ); |
---|
146 | |
---|
147 | |
---|
148 | |
---|
149 | |
---|
150 | /*********************************************************************** |
---|
151 | ** Message Logging |
---|
152 | */ |
---|
153 | |
---|
154 | #define TR_MSG_ERR 1 |
---|
155 | #define TR_MSG_INF 2 |
---|
156 | #define TR_MSG_DBG 3 |
---|
157 | void tr_setMessageLevel( int ); |
---|
158 | int tr_getMessageLevel( void ); |
---|
159 | |
---|
160 | void tr_setMessageQueuing( int enable ); |
---|
161 | |
---|
162 | typedef struct tr_msg_list tr_msg_list; |
---|
163 | tr_msg_list * tr_getQueuedMessages( void ); |
---|
164 | void tr_freeMessageList( tr_msg_list * freeme ); |
---|
165 | |
---|
166 | /*********************************************************************** |
---|
167 | ** Incoming Peer Connections Port |
---|
168 | */ |
---|
169 | |
---|
170 | void tr_setBindPort( tr_handle *, int ); |
---|
171 | |
---|
172 | void tr_natTraversalEnable( tr_handle *, int enable ); |
---|
173 | |
---|
174 | int tr_getPublicPort( const tr_handle * ); |
---|
175 | |
---|
176 | typedef enum |
---|
177 | { |
---|
178 | TR_NAT_TRAVERSAL_MAPPING, |
---|
179 | TR_NAT_TRAVERSAL_MAPPED, |
---|
180 | TR_NAT_TRAVERSAL_UNMAPPING, |
---|
181 | TR_NAT_TRAVERSAL_UNMAPPED, |
---|
182 | TR_NAT_TRAVERSAL_ERROR, |
---|
183 | } |
---|
184 | tr_nat_traversal_status; |
---|
185 | |
---|
186 | typedef struct tr_handle_status |
---|
187 | { |
---|
188 | tr_nat_traversal_status natTraversalStatus; |
---|
189 | int publicPort; |
---|
190 | } |
---|
191 | tr_handle_status; |
---|
192 | |
---|
193 | const tr_handle_status * tr_handleStatus( tr_handle * ); |
---|
194 | |
---|
195 | |
---|
196 | /*********************************************************************** |
---|
197 | *** |
---|
198 | *** TORRENTS |
---|
199 | **/ |
---|
200 | |
---|
201 | typedef struct tr_torrent tr_torrent; |
---|
202 | |
---|
203 | int tr_torrentCount( const tr_handle * h ); |
---|
204 | |
---|
205 | /*********************************************************************** |
---|
206 | *** Speed Limits |
---|
207 | **/ |
---|
208 | |
---|
209 | enum { TR_UP, TR_DOWN }; |
---|
210 | |
---|
211 | typedef enum |
---|
212 | { |
---|
213 | TR_SPEEDLIMIT_GLOBAL, /* only follow the overall speed limit */ |
---|
214 | TR_SPEEDLIMIT_SINGLE, /* only follow the per-torrent limit */ |
---|
215 | TR_SPEEDLIMIT_UNLIMITED /* no limits at all */ |
---|
216 | } |
---|
217 | tr_speedlimit; |
---|
218 | |
---|
219 | void tr_torrentSetSpeedMode( tr_torrent * tor, |
---|
220 | int up_or_down, |
---|
221 | tr_speedlimit mode ); |
---|
222 | |
---|
223 | tr_speedlimit tr_torrentGetSpeedMode( const tr_torrent * tor, |
---|
224 | int up_or_down); |
---|
225 | |
---|
226 | void tr_torrentSetSpeedLimit( tr_torrent * tor, |
---|
227 | int up_or_down, |
---|
228 | int single_KiB_sec ); |
---|
229 | |
---|
230 | int tr_torrentGetSpeedLimit( const tr_torrent * tor, |
---|
231 | int up_or_down ); |
---|
232 | |
---|
233 | void tr_setUseGlobalSpeedLimit( tr_handle * handle, |
---|
234 | int up_or_down, |
---|
235 | int use_flag ); |
---|
236 | |
---|
237 | void tr_setGlobalSpeedLimit( tr_handle * handle, |
---|
238 | int up_or_down, |
---|
239 | int global_KiB_sec ); |
---|
240 | |
---|
241 | void tr_getGlobalSpeedLimit( tr_handle * handle, |
---|
242 | int up_or_down, |
---|
243 | int * setme_is_enabled, |
---|
244 | int * setme_KiBsec ); |
---|
245 | |
---|
246 | |
---|
247 | /*********************************************************************** |
---|
248 | *** Peer Limits |
---|
249 | **/ |
---|
250 | |
---|
251 | void tr_torrentSetMaxConnectedPeers( tr_torrent * tor, |
---|
252 | uint16_t maxConnectedPeers); |
---|
253 | |
---|
254 | uint16_t tr_torrentGetMaxConnectedPeers( const tr_torrent * tor ); |
---|
255 | |
---|
256 | void tr_setGlobalPeerLimit( tr_handle * handle, |
---|
257 | uint16_t maxGlobalPeers ); |
---|
258 | |
---|
259 | uint16_t tr_getGlobalPeerLimit( const tr_handle * handle ); |
---|
260 | |
---|
261 | |
---|
262 | |
---|
263 | |
---|
264 | /*********************************************************************** |
---|
265 | * Torrent Priorities |
---|
266 | **********************************************************************/ |
---|
267 | |
---|
268 | enum |
---|
269 | { |
---|
270 | TR_PRI_LOW = -1, |
---|
271 | TR_PRI_NORMAL = 0, /* since NORMAL is 0, memset initializes nicely */ |
---|
272 | TR_PRI_HIGH = 1 |
---|
273 | }; |
---|
274 | |
---|
275 | typedef int8_t tr_priority_t; |
---|
276 | |
---|
277 | /* set a batch of files to a particular priority. |
---|
278 | * priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW */ |
---|
279 | void tr_torrentSetFilePriorities( tr_torrent * tor, |
---|
280 | int * files, |
---|
281 | int fileCount, |
---|
282 | tr_priority_t priority ); |
---|
283 | |
---|
284 | /* returns a malloc()ed array of tor->info.fileCount items, |
---|
285 | * each holding a value of TR_PRI_NORMAL, _HIGH, or _LOW. |
---|
286 | free the array when done. */ |
---|
287 | tr_priority_t* tr_torrentGetFilePriorities( const tr_torrent * ); |
---|
288 | |
---|
289 | /* single-file form of tr_torrentGetFilePriorities. |
---|
290 | * returns one of TR_PRI_NORMAL, _HIGH, or _LOW. */ |
---|
291 | tr_priority_t tr_torrentGetFilePriority( const tr_torrent *, int file ); |
---|
292 | |
---|
293 | /* returns true if the file's `download' flag is set */ |
---|
294 | int tr_torrentGetFileDL( const tr_torrent *, int file ); |
---|
295 | |
---|
296 | /* set a batch of files to be downloaded or not. */ |
---|
297 | void tr_torrentSetFileDLs ( tr_torrent * tor, |
---|
298 | int * files, |
---|
299 | int fileCount, |
---|
300 | int do_download ); |
---|
301 | |
---|
302 | /*********************************************************************** |
---|
303 | * tr_torrentRates |
---|
304 | *********************************************************************** |
---|
305 | * Gets the total download and upload rates |
---|
306 | **********************************************************************/ |
---|
307 | void tr_torrentRates( tr_handle *, float *, float * ); |
---|
308 | |
---|
309 | |
---|
310 | |
---|
311 | /** |
---|
312 | * Torrent Instantiation |
---|
313 | * |
---|
314 | * Instantiating a tr_torrent had gotten more complicated as features were |
---|
315 | * added. At one point there were four functions to check metainfo and five |
---|
316 | * to create tr_torrent. |
---|
317 | * |
---|
318 | * To remedy this, a Torrent Constructor (struct tr_ctor) has been introduced: |
---|
319 | * + Simplifies the API down to two (non-deprecated) functions. |
---|
320 | * + You can set the fields you want; the system sets defaults for the rest. |
---|
321 | * + You can specify whether or not your fields should supercede fastresume's. |
---|
322 | * + We can add new features to tr_ctor without breaking tr_torrentNew()'s API. |
---|
323 | * |
---|
324 | * All the tr_ctor{Get,Set}*() functions with a return value return |
---|
325 | * an error number, or zero if no error occurred. |
---|
326 | * |
---|
327 | * You must call one of the SetMetainfo() functions before creating |
---|
328 | * a torrent with a tr_ctor. The other functions are optional. |
---|
329 | * |
---|
330 | * You can reuse a single tr_ctor to create a batch of torrents -- |
---|
331 | * just call one of the SetMetainfo() functions between each |
---|
332 | * tr_torrentNew() call. |
---|
333 | * |
---|
334 | * Every call to tr_ctorSetMetainfo*() frees the previous metainfo. |
---|
335 | */ |
---|
336 | |
---|
337 | typedef enum |
---|
338 | { |
---|
339 | TR_FALLBACK, /* indicates the ctor value should be used only |
---|
340 | in case of missing fastresume settings */ |
---|
341 | |
---|
342 | TR_FORCE, /* indicates the ctor value should be used |
---|
343 | regardless of what's in the fastresume settings */ |
---|
344 | } |
---|
345 | tr_ctorMode; |
---|
346 | |
---|
347 | typedef struct tr_ctor tr_ctor; |
---|
348 | struct benc_val_s; |
---|
349 | |
---|
350 | tr_ctor* tr_ctorNew ( const tr_handle * handle); |
---|
351 | |
---|
352 | void tr_ctorFree ( tr_ctor * ctor ); |
---|
353 | |
---|
354 | void tr_ctorSetSave ( tr_ctor * ctor, |
---|
355 | int saveMetadataInOurTorrentsDir ); |
---|
356 | |
---|
357 | void tr_ctorSetDeleteSource ( tr_ctor * ctor, |
---|
358 | uint8_t doDelete ); |
---|
359 | |
---|
360 | int tr_ctorSetMetainfo ( tr_ctor * ctor, |
---|
361 | const uint8_t * metainfo, |
---|
362 | size_t len ); |
---|
363 | |
---|
364 | int tr_ctorSetMetainfoFromFile ( tr_ctor * ctor, |
---|
365 | const char * filename ); |
---|
366 | |
---|
367 | int tr_ctorSetMetainfoFromHash ( tr_ctor * ctor, |
---|
368 | const char * hashString ); |
---|
369 | |
---|
370 | void tr_ctorSetMaxConnectedPeers ( tr_ctor * ctor, |
---|
371 | tr_ctorMode mode, |
---|
372 | uint16_t maxConnectedPeers ); |
---|
373 | |
---|
374 | void tr_ctorSetDestination ( tr_ctor * ctor, |
---|
375 | tr_ctorMode mode, |
---|
376 | const char * directory ); |
---|
377 | |
---|
378 | void tr_ctorSetPaused ( tr_ctor * ctor, |
---|
379 | tr_ctorMode mode, |
---|
380 | uint8_t isPaused ); |
---|
381 | |
---|
382 | int tr_ctorGetMaxConnectedPeers ( const tr_ctor * ctor, |
---|
383 | tr_ctorMode mode, |
---|
384 | uint16_t * setmeCount ); |
---|
385 | |
---|
386 | int tr_ctorGetPaused ( const tr_ctor * ctor, |
---|
387 | tr_ctorMode mode, |
---|
388 | uint8_t * setmeIsPaused ); |
---|
389 | |
---|
390 | int tr_ctorGetDestination ( const tr_ctor * ctor, |
---|
391 | tr_ctorMode mode, |
---|
392 | const char ** setmeDestination ); |
---|
393 | |
---|
394 | int tr_ctorGetMetainfo ( const tr_ctor * ctor, |
---|
395 | const struct benc_val_s ** setme ); |
---|
396 | |
---|
397 | int tr_ctorGetSave ( const tr_ctor * ctor ); |
---|
398 | |
---|
399 | int tr_ctorGetDeleteSource ( const tr_ctor * ctor, |
---|
400 | uint8_t * setmeDoDelete ); |
---|
401 | |
---|
402 | /* returns NULL if tr_ctorSetMetainfoFromFile() wasn't used */ |
---|
403 | const char* tr_ctorGetSourceFile ( const tr_ctor * ctor ); |
---|
404 | |
---|
405 | |
---|
406 | typedef struct tr_info tr_info; |
---|
407 | |
---|
408 | /** |
---|
409 | * Parses the specified metainfo. |
---|
410 | * Returns TR_OK if it parsed and can be added to Transmission. |
---|
411 | * Returns TR_INVALID if it couldn't be parsed. |
---|
412 | * Returns TR_EDUPLICATE if it parsed but can't be added. |
---|
413 | * "destination" must be set to test for TR_EDUPLICATE. |
---|
414 | * |
---|
415 | * If "setme_info" is non-NULL, the parsed metainfo is stored there |
---|
416 | * and will need to be freed by the caller via tr_metainfoFree(). |
---|
417 | */ |
---|
418 | int tr_torrentParse( const tr_handle * handle, |
---|
419 | const tr_ctor * ctor, |
---|
420 | tr_info * setme_info_or_NULL ); |
---|
421 | |
---|
422 | /** |
---|
423 | * Instantiate a single torrent. |
---|
424 | */ |
---|
425 | #define TR_EINVALID 1 |
---|
426 | #define TR_EUNSUPPORTED 2 |
---|
427 | #define TR_EDUPLICATE 3 |
---|
428 | #define TR_EOTHER 666 |
---|
429 | tr_torrent * tr_torrentNew( tr_handle * handle, |
---|
430 | const tr_ctor * ctor, |
---|
431 | int * setmeError ); |
---|
432 | |
---|
433 | |
---|
434 | /** |
---|
435 | * Load all the torrents in tr_getTorrentsDirectory(). |
---|
436 | * This can be used at startup to kickstart all the torrents |
---|
437 | * from the previous session. |
---|
438 | */ |
---|
439 | tr_torrent ** tr_loadTorrents ( tr_handle * h, |
---|
440 | tr_ctor * ctor, |
---|
441 | int * setmeCount ); |
---|
442 | |
---|
443 | |
---|
444 | |
---|
445 | /** |
---|
446 | * Set whether or not torrents are allowed to do peer exchanges. |
---|
447 | * PEX is always disabled in private torrents regardless of this. |
---|
448 | * In public torrents, PEX is enabled by default. |
---|
449 | */ |
---|
450 | void tr_setPexEnabled( tr_handle *, int isEnabled ); |
---|
451 | |
---|
452 | int tr_isPexEnabled( const tr_handle * ); |
---|
453 | |
---|
454 | const tr_info * tr_torrentInfo( const tr_torrent * ); |
---|
455 | |
---|
456 | void tr_torrentSetFolder( tr_torrent *, const char * ); |
---|
457 | |
---|
458 | const char * tr_torrentGetFolder( const tr_torrent * ); |
---|
459 | |
---|
460 | void tr_torrentStart( tr_torrent * ); |
---|
461 | |
---|
462 | void tr_torrentStop( tr_torrent * ); |
---|
463 | |
---|
464 | |
---|
465 | /** |
---|
466 | *** |
---|
467 | **/ |
---|
468 | |
---|
469 | typedef enum |
---|
470 | { |
---|
471 | TR_CP_INCOMPLETE, /* doesn't have all the desired pieces */ |
---|
472 | TR_CP_DONE, /* has all the pieces but the DND ones */ |
---|
473 | TR_CP_COMPLETE /* has every piece */ |
---|
474 | } |
---|
475 | cp_status_t; |
---|
476 | |
---|
477 | typedef void (tr_torrent_status_func)(tr_torrent * torrent, |
---|
478 | cp_status_t status, |
---|
479 | void * user_data ); |
---|
480 | |
---|
481 | /** |
---|
482 | * Register to be notified whenever a torrent's state changes. |
---|
483 | * |
---|
484 | * func is invoked FROM LIBTRANSMISSION'S THREAD! |
---|
485 | * This means func must be fast (to avoid blocking peers), |
---|
486 | * shouldn't call libtransmission functions (to avoid deadlock), |
---|
487 | * and shouldn't modify client-level memory without using a mutex! |
---|
488 | */ |
---|
489 | void tr_torrentSetStatusCallback( tr_torrent * torrent, |
---|
490 | tr_torrent_status_func func, |
---|
491 | void * user_data ); |
---|
492 | |
---|
493 | void tr_torrentClearStatusCallback( tr_torrent * torrent ); |
---|
494 | |
---|
495 | |
---|
496 | |
---|
497 | /** |
---|
498 | *** |
---|
499 | **/ |
---|
500 | |
---|
501 | typedef void (tr_torrent_active_func)(tr_torrent * torrent, |
---|
502 | int isRunning, |
---|
503 | void * user_data ); |
---|
504 | |
---|
505 | /** |
---|
506 | * Register to be notified whenever a torrent starts or stops. |
---|
507 | * |
---|
508 | * func is invoked FROM LIBTRANSMISSION'S THREAD! |
---|
509 | * This means func must be fast (to avoid blocking peers), |
---|
510 | * shouldn't call libtransmission functions (to avoid deadlock), |
---|
511 | * and shouldn't modify client-level memory without using a mutex! |
---|
512 | */ |
---|
513 | void tr_torrentSetActiveCallback( tr_torrent * torrent, |
---|
514 | tr_torrent_active_func func, |
---|
515 | void * user_data ); |
---|
516 | |
---|
517 | void tr_torrentClearActiveCallback( tr_torrent * torrent ); |
---|
518 | |
---|
519 | |
---|
520 | /** |
---|
521 | * MANUAL ANNOUNCE |
---|
522 | * |
---|
523 | * Trackers usually set an announce interval of 15 or 30 minutes. |
---|
524 | * Users can send one-time announce requests that override this |
---|
525 | * interval by calling tr_manualUpdate(). |
---|
526 | * |
---|
527 | * The wait interval for tr_manualUpdate() is much smaller. |
---|
528 | * You can test whether or not a manual update is possible |
---|
529 | * (for example, to desensitize the button) by calling |
---|
530 | * tr_torrentCanManualUpdate(). |
---|
531 | */ |
---|
532 | |
---|
533 | void tr_manualUpdate( tr_torrent * ); |
---|
534 | |
---|
535 | int tr_torrentCanManualUpdate( const tr_torrent * ); |
---|
536 | |
---|
537 | /*********************************************************************** |
---|
538 | * tr_torrentStat |
---|
539 | *********************************************************************** |
---|
540 | * Returns a pointer to an tr_stat structure with updated information |
---|
541 | * on the torrent. The structure belongs to libtransmission (do not |
---|
542 | * free it) and is guaranteed to be unchanged until the next call to |
---|
543 | * tr_torrentStat. |
---|
544 | * The interface should call this function every second or so in order |
---|
545 | * to update itself. |
---|
546 | **********************************************************************/ |
---|
547 | typedef struct tr_stat tr_stat; |
---|
548 | const tr_stat * tr_torrentStat( tr_torrent * ); |
---|
549 | const tr_stat * tr_torrentStatCached( tr_torrent * ); |
---|
550 | |
---|
551 | /*********************************************************************** |
---|
552 | * tr_torrentPeers |
---|
553 | ***********************************************************************/ |
---|
554 | typedef struct tr_peer_stat tr_peer_stat; |
---|
555 | tr_peer_stat * tr_torrentPeers( const tr_torrent *, int * peerCount ); |
---|
556 | void tr_torrentPeersFree( tr_peer_stat *, int peerCount ); |
---|
557 | |
---|
558 | typedef struct tr_file_stat tr_file_stat; |
---|
559 | tr_file_stat * tr_torrentFiles( const tr_torrent *, int * fileCount ); |
---|
560 | void tr_torrentFilesFree( tr_file_stat *, int fileCount ); |
---|
561 | |
---|
562 | |
---|
563 | /*********************************************************************** |
---|
564 | * tr_torrentAvailability |
---|
565 | *********************************************************************** |
---|
566 | * Use this to draw an advanced progress bar which is 'size' pixels |
---|
567 | * wide. Fills 'tab' which you must have allocated: each byte is set |
---|
568 | * to either -1 if we have the piece, otherwise it is set to the number |
---|
569 | * of connected peers who have the piece. |
---|
570 | **********************************************************************/ |
---|
571 | void tr_torrentAvailability( const tr_torrent *, int8_t * tab, int size ); |
---|
572 | |
---|
573 | void tr_torrentAmountFinished( const tr_torrent * tor, float * tab, int size ); |
---|
574 | |
---|
575 | /*********************************************************************** |
---|
576 | * tr_torrentRemoveSaved |
---|
577 | *********************************************************************** |
---|
578 | * delete's Transmission's copy of the torrent's metadata from |
---|
579 | * tr_getTorrentsDirectory(). |
---|
580 | **********************************************************************/ |
---|
581 | void tr_torrentRemoveSaved( tr_torrent * ); |
---|
582 | |
---|
583 | void tr_torrentRecheck( tr_torrent * ); |
---|
584 | |
---|
585 | /** |
---|
586 | * Frees memory allocated by tr_torrentNew(). |
---|
587 | * Running torrents are stopped first. |
---|
588 | */ |
---|
589 | void tr_torrentClose( tr_torrent * ); |
---|
590 | |
---|
591 | /*********************************************************************** |
---|
592 | * tr_info |
---|
593 | **********************************************************************/ |
---|
594 | |
---|
595 | typedef struct tr_file |
---|
596 | { |
---|
597 | uint64_t length; /* Length of the file, in bytes */ |
---|
598 | char * name; /* Path to the file */ |
---|
599 | int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ |
---|
600 | int8_t dnd; /* nonzero if the file shouldn't be downloaded */ |
---|
601 | int firstPiece; /* We need pieces [firstPiece... */ |
---|
602 | int lastPiece; /* ...lastPiece] to dl this file */ |
---|
603 | uint64_t offset; /* file begins at the torrent's nth byte */ |
---|
604 | } |
---|
605 | tr_file; |
---|
606 | |
---|
607 | typedef struct tr_piece |
---|
608 | { |
---|
609 | uint8_t hash[SHA_DIGEST_LENGTH]; /* pieces hash */ |
---|
610 | int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ |
---|
611 | int8_t dnd; /* nonzero if the piece shouldn't be downloaded */ |
---|
612 | } |
---|
613 | tr_piece; |
---|
614 | |
---|
615 | typedef struct tr_tracker_info |
---|
616 | { |
---|
617 | char * address; |
---|
618 | int port; |
---|
619 | char * announce; |
---|
620 | char * scrape; |
---|
621 | } |
---|
622 | tr_tracker_info; |
---|
623 | |
---|
624 | struct tr_info |
---|
625 | { |
---|
626 | /* Path to torrent */ |
---|
627 | char torrent[MAX_PATH_LENGTH]; |
---|
628 | |
---|
629 | /* General info */ |
---|
630 | uint8_t hash[SHA_DIGEST_LENGTH]; |
---|
631 | char hashString[2*SHA_DIGEST_LENGTH+1]; |
---|
632 | char name[MAX_PATH_LENGTH]; |
---|
633 | |
---|
634 | /* Flags */ |
---|
635 | unsigned int isPrivate : 1; |
---|
636 | unsigned int isMultifile : 1; |
---|
637 | |
---|
638 | /* Tracker info */ |
---|
639 | struct |
---|
640 | { |
---|
641 | tr_tracker_info * list; |
---|
642 | int count; |
---|
643 | } * trackerList; |
---|
644 | int trackerTiers; |
---|
645 | char * primaryAddress; |
---|
646 | |
---|
647 | /* Torrent info */ |
---|
648 | char * comment; |
---|
649 | char * creator; |
---|
650 | int dateCreated; |
---|
651 | |
---|
652 | /* Pieces info */ |
---|
653 | int pieceSize; |
---|
654 | int pieceCount; |
---|
655 | uint64_t totalSize; |
---|
656 | tr_piece * pieces; |
---|
657 | |
---|
658 | /* Files info */ |
---|
659 | int fileCount; |
---|
660 | tr_file * files; |
---|
661 | }; |
---|
662 | |
---|
663 | typedef enum |
---|
664 | { |
---|
665 | TR_STATUS_CHECK_WAIT = (1<<0), /* Waiting in queue to check files */ |
---|
666 | TR_STATUS_CHECK = (1<<1), /* Checking files */ |
---|
667 | TR_STATUS_DOWNLOAD = (1<<2), /* Downloading */ |
---|
668 | TR_STATUS_DONE = (1<<3), /* not at 100% so can't tell the tracker |
---|
669 | we're a seeder, but due to DND files |
---|
670 | there's nothing we want right now */ |
---|
671 | TR_STATUS_SEED = (1<<4), /* Seeding */ |
---|
672 | TR_STATUS_STOPPED = (1<<5) /* Torrent is stopped */ |
---|
673 | } |
---|
674 | tr_torrent_status; |
---|
675 | |
---|
676 | #define TR_STATUS_IS_ACTIVE(s) ((s) != TR_STATUS_STOPPED) |
---|
677 | |
---|
678 | /** |
---|
679 | * Transmission error codes |
---|
680 | * errors are always negative, and 0 refers to no error. |
---|
681 | */ |
---|
682 | typedef enum tr_errno |
---|
683 | { |
---|
684 | TR_OK = 0, |
---|
685 | |
---|
686 | /* general errors */ |
---|
687 | TR_ERROR = -100, |
---|
688 | TR_ERROR_ASSERT, |
---|
689 | |
---|
690 | /* io errors */ |
---|
691 | TR_ERROR_IO_PARENT = -200, |
---|
692 | TR_ERROR_IO_PERMISSIONS, |
---|
693 | TR_ERROR_IO_SPACE, |
---|
694 | TR_ERROR_IO_FILE_TOO_BIG, |
---|
695 | TR_ERROR_IO_OPEN_FILES, |
---|
696 | TR_ERROR_IO_DUP_DOWNLOAD, |
---|
697 | TR_ERROR_IO_OTHER, |
---|
698 | |
---|
699 | /* tracker errors */ |
---|
700 | TR_ERROR_TC_ERROR = -300, |
---|
701 | TR_ERROR_TC_WARNING |
---|
702 | } |
---|
703 | tr_errno; |
---|
704 | |
---|
705 | #define TR_ERROR_IS_IO(e) (TR_ERROR_IO_PARENT<=(e) && (e)<=TR_ERROR_IO_OTHER) |
---|
706 | #define TR_ERROR_IS_TC(e) (TR_ERROR_TC_ERROR<=(e) && (e)<=TR_ERROR_TC_WARNING) |
---|
707 | |
---|
708 | struct tr_stat |
---|
709 | { |
---|
710 | tr_torrent_status status; |
---|
711 | |
---|
712 | tr_errno error; |
---|
713 | char errorString[128]; |
---|
714 | |
---|
715 | const tr_tracker_info * tracker; |
---|
716 | |
---|
717 | float recheckProgress; |
---|
718 | float percentComplete; |
---|
719 | float percentDone; |
---|
720 | float rateDownload; |
---|
721 | float rateUpload; |
---|
722 | int eta; |
---|
723 | int peersKnown; |
---|
724 | int peersConnected; |
---|
725 | int peersFrom[TR_PEER_FROM__MAX]; |
---|
726 | int peersSendingToUs; |
---|
727 | int peersGettingFromUs; |
---|
728 | int seeders; |
---|
729 | int leechers; |
---|
730 | int completedFromTracker; |
---|
731 | |
---|
732 | /* if the torrent is running, this is the time at which |
---|
733 | * the client can manually ask the torrent's tracker |
---|
734 | * for more peers. otherwise, the value is zero. */ |
---|
735 | time_t manualAnnounceTime; |
---|
736 | |
---|
737 | /* Byte count of how much data is left to be downloaded until |
---|
738 | * we're done -- that is, until we've got all the pieces we wanted. */ |
---|
739 | uint64_t leftUntilDone; |
---|
740 | |
---|
741 | /* Byte count of all the corrupt data you've ever downloaded for |
---|
742 | * this torrent. If you're on a poisoned torrent, this number can |
---|
743 | * grow very large. */ |
---|
744 | uint64_t corruptEver; |
---|
745 | |
---|
746 | /* Byte count of all data you've ever uploaded for this torrent. */ |
---|
747 | uint64_t uploadedEver; |
---|
748 | |
---|
749 | /* Byte count of all the non-corrupt data you've ever downloaded |
---|
750 | * for this torrent. If you deleted the files and downloaded a second time, |
---|
751 | * this will be 2*totalSize.. */ |
---|
752 | uint64_t downloadedEver; |
---|
753 | |
---|
754 | /* Byte count of all the checksum-verified data we have for this torrent. */ |
---|
755 | uint64_t haveValid; |
---|
756 | |
---|
757 | /* Byte count of all the partial piece data we have for this torrent. |
---|
758 | * As pieces become complete, this value may decrease as portions of it are |
---|
759 | * moved to `corrupt' or `haveValid'. */ |
---|
760 | uint64_t haveUnchecked; |
---|
761 | |
---|
762 | /* Byte count of all the non-DND piece data that either we already have, |
---|
763 | * or that a peer we're connected to has. [0...desiredSize] */ |
---|
764 | uint64_t desiredAvailable; |
---|
765 | |
---|
766 | /* Byte count of all the piece data we want, whether we currently |
---|
767 | * have it nor not. [0...tr_info.totalSize] */ |
---|
768 | uint64_t desiredSize; |
---|
769 | |
---|
770 | float swarmspeed; |
---|
771 | |
---|
772 | #define TR_RATIO_NA -1 |
---|
773 | #define TR_RATIO_INF -2 |
---|
774 | /* TR_RATIO_INF, TR_RATIO_NA, or a regular ratio */ |
---|
775 | float ratio; |
---|
776 | |
---|
777 | uint64_t startDate; |
---|
778 | uint64_t activityDate; |
---|
779 | }; |
---|
780 | |
---|
781 | struct tr_file_stat |
---|
782 | { |
---|
783 | uint64_t bytesCompleted; |
---|
784 | float progress; |
---|
785 | }; |
---|
786 | |
---|
787 | struct tr_peer_stat |
---|
788 | { |
---|
789 | char addr[16]; |
---|
790 | char client[80]; |
---|
791 | |
---|
792 | unsigned int isEncrypted : 1; |
---|
793 | unsigned int isDownloadingFrom : 1; |
---|
794 | unsigned int isUploadingTo : 1; |
---|
795 | |
---|
796 | unsigned int peerIsChoked : 1; |
---|
797 | unsigned int peerIsInterested : 1; |
---|
798 | unsigned int clientIsChoked : 1; |
---|
799 | unsigned int clientIsInterested : 1; |
---|
800 | unsigned int isIncoming : 1; |
---|
801 | |
---|
802 | char flagStr[32]; |
---|
803 | |
---|
804 | uint8_t from; |
---|
805 | uint16_t port; |
---|
806 | |
---|
807 | float progress; |
---|
808 | float downloadFromRate; |
---|
809 | float uploadToRate; |
---|
810 | }; |
---|
811 | |
---|
812 | struct tr_msg_list |
---|
813 | { |
---|
814 | uint8_t level; |
---|
815 | time_t when; |
---|
816 | char * message; |
---|
817 | const char * file; |
---|
818 | int line; |
---|
819 | struct tr_msg_list * next; |
---|
820 | }; |
---|
821 | |
---|
822 | |
---|
823 | #ifdef __TRANSMISSION__ |
---|
824 | # include "internal.h" |
---|
825 | #endif |
---|
826 | |
---|
827 | #ifdef __cplusplus |
---|
828 | } |
---|
829 | #endif |
---|
830 | |
---|
831 | #endif |
---|