1 | /* |
---|
2 | * This file Copyright (C) Transmission authors and contributors |
---|
3 | * |
---|
4 | * It may be used under the 3-Clause BSD License, the GNU Public License v2, |
---|
5 | * or v3, or any future license endorsed by Mnemosyne LLC. |
---|
6 | * |
---|
7 | * $Id: transmission.h 14384 2014-12-13 17:04:14Z mikedld $ |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * This file defines the public API for the libtransmission library. |
---|
12 | * The other public API headers are variant.h and utils.h; |
---|
13 | * most of the remaining headers in libtransmission are private. |
---|
14 | */ |
---|
15 | |
---|
16 | #ifndef TR_TRANSMISSION_H |
---|
17 | #define TR_TRANSMISSION_H 1 |
---|
18 | |
---|
19 | #ifdef __cplusplus |
---|
20 | extern "C" { |
---|
21 | #endif |
---|
22 | |
---|
23 | /*** |
---|
24 | **** |
---|
25 | **** Basic Types |
---|
26 | **** |
---|
27 | ***/ |
---|
28 | |
---|
29 | #include <inttypes.h> /* uintN_t */ |
---|
30 | #include <time.h> /* time_t */ |
---|
31 | |
---|
32 | #ifdef _MSC_VER |
---|
33 | typedef intptr_t ssize_t; |
---|
34 | #endif |
---|
35 | |
---|
36 | #if !defined (__cplusplus) |
---|
37 | #ifdef HAVE_STDBOOL_H |
---|
38 | #include <stdbool.h> |
---|
39 | #elif !defined (__bool_true_false_are_defined) |
---|
40 | #define bool uint8_t |
---|
41 | #define true 1 |
---|
42 | #define false 0 |
---|
43 | #endif |
---|
44 | #endif |
---|
45 | |
---|
46 | #ifndef PRId64 |
---|
47 | #ifdef _WIN32 |
---|
48 | #define PRId64 "I64" |
---|
49 | #else |
---|
50 | #define PRId64 "lld" |
---|
51 | #endif |
---|
52 | #endif |
---|
53 | |
---|
54 | #ifndef PRIu64 |
---|
55 | #ifdef _WIN32 |
---|
56 | #define PRIu64 "I64u" |
---|
57 | #else |
---|
58 | #define PRIu64 "llu" |
---|
59 | #endif |
---|
60 | #endif |
---|
61 | |
---|
62 | #ifndef PRIu32 |
---|
63 | #ifdef _WIN32 |
---|
64 | #define PRIu32 "u" |
---|
65 | #else |
---|
66 | #define PRIu32 "lu" |
---|
67 | #endif |
---|
68 | #endif |
---|
69 | |
---|
70 | #ifndef PRIdMAX |
---|
71 | #ifdef _WIN32 |
---|
72 | #define PRIdMAX "I64" |
---|
73 | #else |
---|
74 | #define PRIdMAX "jd" |
---|
75 | #endif |
---|
76 | #endif |
---|
77 | |
---|
78 | #ifndef TR_PRIuSIZE |
---|
79 | #ifdef _WIN32 |
---|
80 | #define TR_PRIuSIZE "Iu" |
---|
81 | #else |
---|
82 | #define TR_PRIuSIZE "zu" |
---|
83 | #endif |
---|
84 | #endif |
---|
85 | |
---|
86 | #if defined (_MSC_VER) && !defined (__cplusplus) |
---|
87 | #define inline __inline |
---|
88 | #endif |
---|
89 | |
---|
90 | #define SHA_DIGEST_LENGTH 20 |
---|
91 | #define TR_INET6_ADDRSTRLEN 46 |
---|
92 | |
---|
93 | typedef uint32_t tr_file_index_t; |
---|
94 | typedef uint32_t tr_piece_index_t; |
---|
95 | /* assuming a 16 KiB block, a 32-bit block index gives us a maximum torrent size of 63 TiB. |
---|
96 | * if we ever need to grow past that, change this to uint64_t ;) */ |
---|
97 | typedef uint32_t tr_block_index_t; |
---|
98 | typedef uint16_t tr_port; |
---|
99 | |
---|
100 | typedef struct tr_ctor tr_ctor; |
---|
101 | typedef struct tr_info tr_info; |
---|
102 | typedef struct tr_torrent tr_torrent; |
---|
103 | typedef struct tr_session tr_session; |
---|
104 | |
---|
105 | struct tr_variant; |
---|
106 | |
---|
107 | typedef int8_t tr_priority_t; |
---|
108 | |
---|
109 | #define TR_RPC_SESSION_ID_HEADER "X-Transmission-Session-Id" |
---|
110 | |
---|
111 | typedef enum |
---|
112 | { |
---|
113 | TR_PREALLOCATE_NONE = 0, |
---|
114 | TR_PREALLOCATE_SPARSE = 1, |
---|
115 | TR_PREALLOCATE_FULL = 2 |
---|
116 | } |
---|
117 | tr_preallocation_mode; |
---|
118 | |
---|
119 | typedef enum |
---|
120 | { |
---|
121 | TR_CLEAR_PREFERRED, |
---|
122 | TR_ENCRYPTION_PREFERRED, |
---|
123 | TR_ENCRYPTION_REQUIRED |
---|
124 | } |
---|
125 | tr_encryption_mode; |
---|
126 | |
---|
127 | |
---|
128 | /*** |
---|
129 | **** |
---|
130 | **** Startup & Shutdown |
---|
131 | **** |
---|
132 | ***/ |
---|
133 | |
---|
134 | /** |
---|
135 | * @addtogroup tr_session Session |
---|
136 | * |
---|
137 | * A libtransmission session is created by calling tr_sessionInit (). |
---|
138 | * libtransmission creates a thread for itself so that it can operate |
---|
139 | * independently of the caller's event loop. The session will continue |
---|
140 | * until tr_sessionClose () is called. |
---|
141 | * |
---|
142 | * @{ |
---|
143 | */ |
---|
144 | |
---|
145 | /** |
---|
146 | * @brief returns Transmission's default configuration file directory. |
---|
147 | * |
---|
148 | * The default configuration directory is determined this way: |
---|
149 | * -# If the TRANSMISSION_HOME environment variable is set, its value is used. |
---|
150 | * -# On Darwin, "${HOME}/Library/Application Support/${appname}" is used. |
---|
151 | * -# On Windows, "${CSIDL_APPDATA}/${appname}" is used. |
---|
152 | * -# If XDG_CONFIG_HOME is set, "${XDG_CONFIG_HOME}/${appname}" is used. |
---|
153 | * -# ${HOME}/.config/${appname}" is used as a last resort. |
---|
154 | */ |
---|
155 | const char* tr_getDefaultConfigDir (const char * appname); |
---|
156 | |
---|
157 | /** |
---|
158 | * @brief returns Transmisson's default download directory. |
---|
159 | * |
---|
160 | * The default download directory is determined this way: |
---|
161 | * -# If the HOME environment variable is set, "${HOME}/Downloads" is used. |
---|
162 | * -# On Windows, "${CSIDL_MYDOCUMENTS}/Downloads" is used. |
---|
163 | * -# Otherwise, getpwuid (getuid ())->pw_dir + "/Downloads" is used. |
---|
164 | */ |
---|
165 | const char* tr_getDefaultDownloadDir (void); |
---|
166 | |
---|
167 | |
---|
168 | #define TR_DEFAULT_BIND_ADDRESS_IPV4 "0.0.0.0" |
---|
169 | #define TR_DEFAULT_BIND_ADDRESS_IPV6 "::" |
---|
170 | #define TR_DEFAULT_RPC_WHITELIST "127.0.0.1" |
---|
171 | #define TR_DEFAULT_RPC_PORT_STR "9091" |
---|
172 | #define TR_DEFAULT_RPC_URL_STR "/transmission/" |
---|
173 | #define TR_DEFAULT_PEER_PORT_STR "51413" |
---|
174 | #define TR_DEFAULT_PEER_SOCKET_TOS_STR "default" |
---|
175 | #define TR_DEFAULT_PEER_LIMIT_GLOBAL_STR "200" |
---|
176 | #define TR_DEFAULT_PEER_LIMIT_TORRENT_STR "50" |
---|
177 | |
---|
178 | /** |
---|
179 | * Add libtransmission's default settings to the benc dictionary. |
---|
180 | * |
---|
181 | * Example: |
---|
182 | * @code |
---|
183 | * tr_variant settings; |
---|
184 | * int64_t i; |
---|
185 | * |
---|
186 | * tr_variantInitDict (&settings, 0); |
---|
187 | * tr_sessionGetDefaultSettings (&settings); |
---|
188 | * if (tr_variantDictFindInt (&settings, TR_PREFS_KEY_PEER_PORT, &i)) |
---|
189 | * fprintf (stderr, "the default peer port is %d\n", (int)i); |
---|
190 | * tr_variantFree (&settings); |
---|
191 | * @endcode |
---|
192 | * |
---|
193 | * @param initme pointer to a tr_variant dictionary |
---|
194 | * @see tr_sessionLoadSettings () |
---|
195 | * @see tr_sessionInit () |
---|
196 | * @see tr_getDefaultConfigDir () |
---|
197 | */ |
---|
198 | void tr_sessionGetDefaultSettings (struct tr_variant * dictionary); |
---|
199 | |
---|
200 | /** |
---|
201 | * Add the session's current configuration settings to the benc dictionary. |
---|
202 | * |
---|
203 | * FIXME: this probably belongs in libtransmissionapp |
---|
204 | * |
---|
205 | * @param session |
---|
206 | * @param dictionary |
---|
207 | * @see tr_sessionGetDefaultSettings () |
---|
208 | */ |
---|
209 | void tr_sessionGetSettings (tr_session *, struct tr_variant * dictionary); |
---|
210 | |
---|
211 | /** |
---|
212 | * Load settings from the configuration directory's settings.json file, |
---|
213 | * using libtransmission's default settings as fallbacks for missing keys. |
---|
214 | * |
---|
215 | * FIXME: this belongs in libtransmissionapp |
---|
216 | * |
---|
217 | * @param dictionary pointer to an uninitialized tr_variant |
---|
218 | * @param configDir the configuration directory to find settings.json |
---|
219 | * @param appName if configDir is empty, appName is used to find the default dir. |
---|
220 | * @return success true if the settings were loaded, false otherwise |
---|
221 | * @see tr_sessionGetDefaultSettings () |
---|
222 | * @see tr_sessionInit () |
---|
223 | * @see tr_sessionSaveSettings () |
---|
224 | */ |
---|
225 | bool tr_sessionLoadSettings (struct tr_variant * dictionary, |
---|
226 | const char * configDir, |
---|
227 | const char * appName); |
---|
228 | |
---|
229 | /** |
---|
230 | * Add the session's configuration settings to the benc dictionary |
---|
231 | * and save it to the configuration directory's settings.json file. |
---|
232 | * |
---|
233 | * FIXME: this belongs in libtransmissionapp |
---|
234 | * |
---|
235 | * @param session |
---|
236 | * @param dictionary |
---|
237 | * @see tr_sessionLoadSettings () |
---|
238 | */ |
---|
239 | void tr_sessionSaveSettings (tr_session * session, |
---|
240 | const char * configDir, |
---|
241 | const struct tr_variant * dictonary); |
---|
242 | |
---|
243 | /** |
---|
244 | * @brief Initialize a libtransmission session. |
---|
245 | * |
---|
246 | * For example, this will instantiate a session with all the default values: |
---|
247 | * @code |
---|
248 | * tr_variant settings; |
---|
249 | * tr_session * session; |
---|
250 | * const char * configDir; |
---|
251 | * |
---|
252 | * tr_variantInitDict (&settings, 0); |
---|
253 | * tr_sessionGetDefaultSettings (&settings); |
---|
254 | * configDir = tr_getDefaultConfigDir ("Transmission"); |
---|
255 | * session = tr_sessionInit ("mac", configDir, true, &settings); |
---|
256 | * |
---|
257 | * tr_variantFree (&settings); |
---|
258 | * @endcode |
---|
259 | * |
---|
260 | * @param tag "gtk", "macosx", "daemon", etc... this is only for pre-1.30 resume files |
---|
261 | * @param configDir where Transmission will look for resume files, blocklists, etc. |
---|
262 | * @param messageQueueingEnabled if false, messages will be dumped to stderr |
---|
263 | * @param settings libtransmission settings |
---|
264 | * @see tr_sessionGetDefaultSettings () |
---|
265 | * @see tr_sessionLoadSettings () |
---|
266 | * @see tr_getDefaultConfigDir () |
---|
267 | */ |
---|
268 | tr_session * tr_sessionInit (const char * tag, |
---|
269 | const char * configDir, |
---|
270 | bool messageQueueingEnabled, |
---|
271 | struct tr_variant * settings); |
---|
272 | |
---|
273 | /** @brief Update a session's settings from a benc dictionary |
---|
274 | like to the one used in tr_sessionInit () */ |
---|
275 | void tr_sessionSet (tr_session * session, |
---|
276 | struct tr_variant * settings); |
---|
277 | |
---|
278 | /** @brief Rescan the blocklists directory and |
---|
279 | reload whatever blocklist files are found there */ |
---|
280 | void tr_sessionReloadBlocklists (tr_session * session); |
---|
281 | |
---|
282 | |
---|
283 | /** @brief End a libtransmission session |
---|
284 | @see tr_sessionInit () */ |
---|
285 | void tr_sessionClose (tr_session *); |
---|
286 | |
---|
287 | /** |
---|
288 | * @brief Return the session's configuration directory. |
---|
289 | * |
---|
290 | * This is where transmission stores its .torrent files, .resume files, |
---|
291 | * blocklists, etc. It's set in tr_transmissionInit () and is immutable |
---|
292 | * during the session. |
---|
293 | */ |
---|
294 | const char * tr_sessionGetConfigDir (const tr_session *); |
---|
295 | |
---|
296 | /** |
---|
297 | * @brief Set the per-session default download folder for new torrents. |
---|
298 | * @see tr_sessionInit () |
---|
299 | * @see tr_sessionGetDownloadDir () |
---|
300 | * @see tr_ctorSetDownloadDir () |
---|
301 | */ |
---|
302 | void tr_sessionSetDownloadDir (tr_session * session, const char * downloadDir); |
---|
303 | |
---|
304 | /** |
---|
305 | * @brief Get the default download folder for new torrents. |
---|
306 | * |
---|
307 | * This is set by tr_sessionInit () or tr_sessionSetDownloadDir (), |
---|
308 | * and can be overridden on a per-torrent basis by tr_ctorSetDownloadDir (). |
---|
309 | */ |
---|
310 | const char * tr_sessionGetDownloadDir (const tr_session * session); |
---|
311 | |
---|
312 | /** |
---|
313 | * @brief Get available disk space (in bytes) for the specified directory. |
---|
314 | * @return zero or positive integer on success, -1 in case of error. |
---|
315 | */ |
---|
316 | int64_t tr_sessionGetDirFreeSpace (tr_session * session, const char * dir); |
---|
317 | |
---|
318 | /** |
---|
319 | * @brief Set the torrent's bandwidth priority. |
---|
320 | */ |
---|
321 | void tr_ctorSetBandwidthPriority (tr_ctor * ctor, tr_priority_t priority); |
---|
322 | |
---|
323 | /** |
---|
324 | * @brief Get the torrent's bandwidth priority. |
---|
325 | */ |
---|
326 | tr_priority_t tr_ctorGetBandwidthPriority (const tr_ctor * ctor); |
---|
327 | |
---|
328 | |
---|
329 | /** |
---|
330 | * @brief set the per-session incomplete download folder. |
---|
331 | * |
---|
332 | * When you add a new torrent and the session's incomplete directory is enabled, |
---|
333 | * the new torrent will start downloading into that directory, and then be moved |
---|
334 | * to tr_torrent.downloadDir when the torrent is finished downloading. |
---|
335 | * |
---|
336 | * Torrents aren't moved as a result of changing the session's incomplete dir -- |
---|
337 | * it's applied to new torrents, not existing ones. |
---|
338 | * |
---|
339 | * tr_torrentSetLocation () overrules the incomplete dir: when a user specifies |
---|
340 | * a new location, that becomes the torrent's new downloadDir and the torrent |
---|
341 | * is moved there immediately regardless of whether or not it's complete. |
---|
342 | * |
---|
343 | * @see tr_sessionInit () |
---|
344 | * @see tr_sessionGetIncompleteDir () |
---|
345 | * @see tr_sessionSetIncompleteDirEnabled () |
---|
346 | * @see tr_sessionGetIncompleteDirEnabled () |
---|
347 | */ |
---|
348 | void tr_sessionSetIncompleteDir (tr_session * session, const char * dir); |
---|
349 | |
---|
350 | /** @brief get the per-session incomplete download folder */ |
---|
351 | const char* tr_sessionGetIncompleteDir (const tr_session * session); |
---|
352 | |
---|
353 | /** @brief enable or disable use of the incomplete download folder */ |
---|
354 | void tr_sessionSetIncompleteDirEnabled (tr_session * session, bool); |
---|
355 | |
---|
356 | /** @brief get whether or not the incomplete download folder is enabled */ |
---|
357 | bool tr_sessionIsIncompleteDirEnabled (const tr_session * session); |
---|
358 | |
---|
359 | |
---|
360 | /** |
---|
361 | * @brief When enabled, newly-created files will have ".part" appended |
---|
362 | * to their filename until the file is fully downloaded |
---|
363 | * |
---|
364 | * This is not retroactive -- toggling this will not rename existing files. |
---|
365 | * It only applies to new files created by Transmission after this API call. |
---|
366 | * |
---|
367 | * @see tr_sessionIsIncompleteFileNamingEnabled () |
---|
368 | */ |
---|
369 | void tr_sessionSetIncompleteFileNamingEnabled (tr_session * session, bool); |
---|
370 | |
---|
371 | /** @brief return true if files will end in ".part" until they're complete */ |
---|
372 | bool tr_sessionIsIncompleteFileNamingEnabled (const tr_session * session); |
---|
373 | |
---|
374 | /** |
---|
375 | * @brief Set whether or not RPC calls are allowed in this session. |
---|
376 | * |
---|
377 | * @details If true, libtransmission will open a server socket to listen |
---|
378 | * for incoming http RPC requests as described in docs/rpc-spec.txt. |
---|
379 | * |
---|
380 | * This is intially set by tr_sessionInit () and can be |
---|
381 | * queried by tr_sessionIsRPCEnabled (). |
---|
382 | */ |
---|
383 | void tr_sessionSetRPCEnabled (tr_session * session, |
---|
384 | bool isEnabled); |
---|
385 | |
---|
386 | /** @brief Get whether or not RPC calls are allowed in this session. |
---|
387 | @see tr_sessionInit () |
---|
388 | @see tr_sessionSetRPCEnabled () */ |
---|
389 | bool tr_sessionIsRPCEnabled (const tr_session * session); |
---|
390 | |
---|
391 | /** @brief Specify which port to listen for RPC requests on. |
---|
392 | @see tr_sessionInit () |
---|
393 | @see tr_sessionGetRPCPort */ |
---|
394 | void tr_sessionSetRPCPort (tr_session * session, |
---|
395 | tr_port port); |
---|
396 | |
---|
397 | /** @brief Get which port to listen for RPC requests on. |
---|
398 | @see tr_sessionInit () |
---|
399 | @see tr_sessionSetRPCPort */ |
---|
400 | tr_port tr_sessionGetRPCPort (const tr_session * session); |
---|
401 | |
---|
402 | /** |
---|
403 | * @brief Specify which base URL to use. |
---|
404 | * |
---|
405 | * @detail The RPC API is accessible under <url>/rpc, the web interface under |
---|
406 | * <url>/web. |
---|
407 | * |
---|
408 | * @see tr_sessionGetRPCUrl |
---|
409 | */ |
---|
410 | void tr_sessionSetRPCUrl (tr_session * session, |
---|
411 | const char * url); |
---|
412 | |
---|
413 | /** |
---|
414 | * @brief Get the base URL. |
---|
415 | * @see tr_sessionInit () |
---|
416 | * @see tr_sessionSetRPCUrl |
---|
417 | */ |
---|
418 | const char* tr_sessionGetRPCUrl (const tr_session * session); |
---|
419 | |
---|
420 | /** |
---|
421 | * @brief Specify a whitelist for remote RPC access |
---|
422 | * |
---|
423 | * The whitelist is a comma-separated list of dotted-quad IP addresses |
---|
424 | * to be allowed. Wildmat notation is supported, meaning that |
---|
425 | * '?' is interpreted as a single-character wildcard and |
---|
426 | * '*' is interprted as a multi-character wildcard. |
---|
427 | */ |
---|
428 | void tr_sessionSetRPCWhitelist (tr_session * session, |
---|
429 | const char * whitelist); |
---|
430 | |
---|
431 | /** @brief get the Access Control List for allowing/denying RPC requests. |
---|
432 | @return a comma-separated string of whitelist domains. |
---|
433 | @see tr_sessionInit |
---|
434 | @see tr_sessionSetRPCWhitelist */ |
---|
435 | const char* tr_sessionGetRPCWhitelist (const tr_session *); |
---|
436 | |
---|
437 | void tr_sessionSetRPCWhitelistEnabled (tr_session * session, |
---|
438 | bool isEnabled); |
---|
439 | |
---|
440 | bool tr_sessionGetRPCWhitelistEnabled (const tr_session * session); |
---|
441 | |
---|
442 | void tr_sessionSetRPCPassword (tr_session * session, |
---|
443 | const char * password); |
---|
444 | |
---|
445 | void tr_sessionSetRPCUsername (tr_session * session, |
---|
446 | const char * username); |
---|
447 | |
---|
448 | /** @brief get the password used to restrict RPC requests. |
---|
449 | @return the password string. |
---|
450 | @see tr_sessionInit () |
---|
451 | @see tr_sessionSetRPCPassword () */ |
---|
452 | const char* tr_sessionGetRPCPassword (const tr_session * session); |
---|
453 | |
---|
454 | const char* tr_sessionGetRPCUsername (const tr_session * session); |
---|
455 | |
---|
456 | void tr_sessionSetRPCPasswordEnabled (tr_session * session, |
---|
457 | bool isEnabled); |
---|
458 | |
---|
459 | bool tr_sessionIsRPCPasswordEnabled (const tr_session * session); |
---|
460 | |
---|
461 | const char* tr_sessionGetRPCBindAddress (const tr_session * session); |
---|
462 | |
---|
463 | |
---|
464 | typedef enum |
---|
465 | { |
---|
466 | TR_RPC_TORRENT_ADDED, |
---|
467 | TR_RPC_TORRENT_STARTED, |
---|
468 | TR_RPC_TORRENT_STOPPED, |
---|
469 | TR_RPC_TORRENT_REMOVING, |
---|
470 | TR_RPC_TORRENT_TRASHING, /* _REMOVING + delete local data */ |
---|
471 | TR_RPC_TORRENT_CHANGED, /* catch-all for the "torrent-set" rpc method */ |
---|
472 | TR_RPC_TORRENT_MOVED, |
---|
473 | TR_RPC_SESSION_CHANGED, |
---|
474 | TR_RPC_SESSION_QUEUE_POSITIONS_CHANGED, /* catch potentially multiple torrents being moved in the queue */ |
---|
475 | TR_RPC_SESSION_CLOSE |
---|
476 | } |
---|
477 | tr_rpc_callback_type; |
---|
478 | |
---|
479 | typedef enum |
---|
480 | { |
---|
481 | /* no special handling is needed by the caller */ |
---|
482 | TR_RPC_OK = 0, |
---|
483 | |
---|
484 | /* indicates to the caller that the client will take care of |
---|
485 | * removing the torrent itself. For example the client may |
---|
486 | * need to keep the torrent alive long enough to cleanly close |
---|
487 | * some resources in another thread. */ |
---|
488 | TR_RPC_NOREMOVE = (1 << 1) |
---|
489 | } |
---|
490 | tr_rpc_callback_status; |
---|
491 | |
---|
492 | typedef tr_rpc_callback_status (*tr_rpc_func)(tr_session * session, |
---|
493 | tr_rpc_callback_type type, |
---|
494 | struct tr_torrent * tor_or_null, |
---|
495 | void * user_data); |
---|
496 | |
---|
497 | /** |
---|
498 | * Register to be notified whenever something is changed via RPC, |
---|
499 | * such as a torrent being added, removed, started, stopped, etc. |
---|
500 | * |
---|
501 | * func is invoked FROM LIBTRANSMISSION'S THREAD! |
---|
502 | * This means func must be fast (to avoid blocking peers), |
---|
503 | * shouldn't call libtransmission functions (to avoid deadlock), |
---|
504 | * and shouldn't modify client-level memory without using a mutex! |
---|
505 | */ |
---|
506 | void tr_sessionSetRPCCallback (tr_session * session, |
---|
507 | tr_rpc_func func, |
---|
508 | void * user_data); |
---|
509 | |
---|
510 | /** |
---|
511 | *** |
---|
512 | **/ |
---|
513 | |
---|
514 | /** @brief Used by tr_sessionGetStats () and tr_sessionGetCumulativeStats () */ |
---|
515 | typedef struct tr_session_stats |
---|
516 | { |
---|
517 | float ratio; /* TR_RATIO_INF, TR_RATIO_NA, or total up/down */ |
---|
518 | uint64_t uploadedBytes; /* total up */ |
---|
519 | uint64_t downloadedBytes; /* total down */ |
---|
520 | uint64_t filesAdded; /* number of files added */ |
---|
521 | uint64_t sessionCount; /* program started N times */ |
---|
522 | uint64_t secondsActive; /* how long Transmisson's been running */ |
---|
523 | } |
---|
524 | tr_session_stats; |
---|
525 | |
---|
526 | /** @brief Get bandwidth use statistics for the current session */ |
---|
527 | void tr_sessionGetStats (const tr_session * session, |
---|
528 | tr_session_stats * setme); |
---|
529 | |
---|
530 | /** @brief Get cumulative bandwidth statistics for current and past sessions */ |
---|
531 | void tr_sessionGetCumulativeStats (const tr_session * session, |
---|
532 | tr_session_stats * setme); |
---|
533 | |
---|
534 | void tr_sessionClearStats (tr_session * session); |
---|
535 | |
---|
536 | /** |
---|
537 | * @brief Set whether or not torrents are allowed to do peer exchanges. |
---|
538 | * |
---|
539 | * PEX is always disabled in private torrents regardless of this. |
---|
540 | * In public torrents, PEX is enabled by default. |
---|
541 | */ |
---|
542 | void tr_sessionSetPexEnabled (tr_session * session, bool isEnabled); |
---|
543 | bool tr_sessionIsPexEnabled (const tr_session * session); |
---|
544 | |
---|
545 | bool tr_sessionIsDHTEnabled (const tr_session * session); |
---|
546 | void tr_sessionSetDHTEnabled (tr_session * session, bool); |
---|
547 | |
---|
548 | bool tr_sessionIsUTPEnabled (const tr_session * session); |
---|
549 | void tr_sessionSetUTPEnabled (tr_session * session, bool); |
---|
550 | |
---|
551 | bool tr_sessionIsLPDEnabled (const tr_session * session); |
---|
552 | void tr_sessionSetLPDEnabled (tr_session * session, bool enabled); |
---|
553 | |
---|
554 | void tr_sessionSetCacheLimit_MB (tr_session * session, int mb); |
---|
555 | int tr_sessionGetCacheLimit_MB (const tr_session * session); |
---|
556 | |
---|
557 | tr_encryption_mode tr_sessionGetEncryption (tr_session * session); |
---|
558 | void tr_sessionSetEncryption (tr_session * session, |
---|
559 | tr_encryption_mode mode); |
---|
560 | |
---|
561 | |
---|
562 | /*********************************************************************** |
---|
563 | ** Incoming Peer Connections Port |
---|
564 | */ |
---|
565 | |
---|
566 | void tr_sessionSetPortForwardingEnabled (tr_session * session, |
---|
567 | bool enabled); |
---|
568 | |
---|
569 | bool tr_sessionIsPortForwardingEnabled (const tr_session * session); |
---|
570 | |
---|
571 | void tr_sessionSetPeerPort (tr_session * session, |
---|
572 | tr_port port); |
---|
573 | |
---|
574 | tr_port tr_sessionGetPeerPort (const tr_session * session); |
---|
575 | |
---|
576 | tr_port tr_sessionSetPeerPortRandom (tr_session * session); |
---|
577 | |
---|
578 | void tr_sessionSetPeerPortRandomOnStart (tr_session * session, bool random); |
---|
579 | |
---|
580 | bool tr_sessionGetPeerPortRandomOnStart (tr_session * session); |
---|
581 | |
---|
582 | typedef enum |
---|
583 | { |
---|
584 | TR_PORT_ERROR, |
---|
585 | TR_PORT_UNMAPPED, |
---|
586 | TR_PORT_UNMAPPING, |
---|
587 | TR_PORT_MAPPING, |
---|
588 | TR_PORT_MAPPED |
---|
589 | } |
---|
590 | tr_port_forwarding; |
---|
591 | |
---|
592 | tr_port_forwarding tr_sessionGetPortForwarding (const tr_session * session); |
---|
593 | |
---|
594 | typedef enum |
---|
595 | { |
---|
596 | TR_CLIENT_TO_PEER = 0, TR_UP = 0, |
---|
597 | TR_PEER_TO_CLIENT = 1, TR_DOWN = 1 |
---|
598 | } |
---|
599 | tr_direction; |
---|
600 | |
---|
601 | /*** |
---|
602 | **** |
---|
603 | ***/ |
---|
604 | |
---|
605 | /*** |
---|
606 | **** Primary session speed limits |
---|
607 | ***/ |
---|
608 | |
---|
609 | void tr_sessionSetSpeedLimit_KBps (tr_session *, tr_direction, unsigned int KBps); |
---|
610 | unsigned int tr_sessionGetSpeedLimit_KBps (const tr_session *, tr_direction); |
---|
611 | |
---|
612 | void tr_sessionLimitSpeed (tr_session *, tr_direction, bool); |
---|
613 | bool tr_sessionIsSpeedLimited (const tr_session *, tr_direction); |
---|
614 | |
---|
615 | |
---|
616 | /*** |
---|
617 | **** Alternative speed limits that are used during scheduled times |
---|
618 | ***/ |
---|
619 | |
---|
620 | void tr_sessionSetAltSpeed_KBps (tr_session *, tr_direction, unsigned int Bps); |
---|
621 | unsigned int tr_sessionGetAltSpeed_KBps (const tr_session *, tr_direction); |
---|
622 | |
---|
623 | void tr_sessionUseAltSpeed (tr_session *, bool); |
---|
624 | bool tr_sessionUsesAltSpeed (const tr_session *); |
---|
625 | |
---|
626 | void tr_sessionUseAltSpeedTime (tr_session *, bool); |
---|
627 | bool tr_sessionUsesAltSpeedTime (const tr_session *); |
---|
628 | |
---|
629 | void tr_sessionSetAltSpeedBegin (tr_session *, int minsSinceMidnight); |
---|
630 | int tr_sessionGetAltSpeedBegin (const tr_session *); |
---|
631 | |
---|
632 | void tr_sessionSetAltSpeedEnd (tr_session *, int minsSinceMidnight); |
---|
633 | int tr_sessionGetAltSpeedEnd (const tr_session *); |
---|
634 | |
---|
635 | typedef enum |
---|
636 | { |
---|
637 | TR_SCHED_SUN = (1<<0), |
---|
638 | TR_SCHED_MON = (1<<1), |
---|
639 | TR_SCHED_TUES = (1<<2), |
---|
640 | TR_SCHED_WED = (1<<3), |
---|
641 | TR_SCHED_THURS = (1<<4), |
---|
642 | TR_SCHED_FRI = (1<<5), |
---|
643 | TR_SCHED_SAT = (1<<6), |
---|
644 | TR_SCHED_WEEKDAY = (TR_SCHED_MON|TR_SCHED_TUES|TR_SCHED_WED| |
---|
645 | TR_SCHED_THURS|TR_SCHED_FRI), |
---|
646 | TR_SCHED_WEEKEND = (TR_SCHED_SUN|TR_SCHED_SAT), |
---|
647 | TR_SCHED_ALL = (TR_SCHED_WEEKDAY|TR_SCHED_WEEKEND) |
---|
648 | } |
---|
649 | tr_sched_day; |
---|
650 | |
---|
651 | void tr_sessionSetAltSpeedDay (tr_session *, tr_sched_day day); |
---|
652 | tr_sched_day tr_sessionGetAltSpeedDay (const tr_session *); |
---|
653 | |
---|
654 | typedef void (*tr_altSpeedFunc)(tr_session *, |
---|
655 | bool active, |
---|
656 | bool userDriven, |
---|
657 | void *); |
---|
658 | |
---|
659 | void tr_sessionClearAltSpeedFunc (tr_session *); |
---|
660 | void tr_sessionSetAltSpeedFunc (tr_session *, tr_altSpeedFunc, void *); |
---|
661 | |
---|
662 | |
---|
663 | bool tr_sessionGetActiveSpeedLimit_KBps (const tr_session * session, |
---|
664 | tr_direction dir, |
---|
665 | double * setme); |
---|
666 | |
---|
667 | /*** |
---|
668 | **** |
---|
669 | ***/ |
---|
670 | |
---|
671 | double tr_sessionGetRawSpeed_KBps (const tr_session *, tr_direction); |
---|
672 | |
---|
673 | void tr_sessionSetRatioLimited (tr_session *, bool isLimited); |
---|
674 | bool tr_sessionIsRatioLimited (const tr_session *); |
---|
675 | |
---|
676 | void tr_sessionSetRatioLimit (tr_session *, double desiredRatio); |
---|
677 | double tr_sessionGetRatioLimit (const tr_session *); |
---|
678 | |
---|
679 | void tr_sessionSetIdleLimited (tr_session *, bool isLimited); |
---|
680 | bool tr_sessionIsIdleLimited (const tr_session *); |
---|
681 | |
---|
682 | void tr_sessionSetIdleLimit (tr_session *, uint16_t idleMinutes); |
---|
683 | uint16_t tr_sessionGetIdleLimit (const tr_session *); |
---|
684 | |
---|
685 | void tr_sessionSetPeerLimit (tr_session *, uint16_t maxGlobalPeers); |
---|
686 | uint16_t tr_sessionGetPeerLimit (const tr_session *); |
---|
687 | |
---|
688 | void tr_sessionSetPeerLimitPerTorrent (tr_session *, uint16_t maxPeers); |
---|
689 | uint16_t tr_sessionGetPeerLimitPerTorrent (const tr_session *); |
---|
690 | |
---|
691 | void tr_sessionSetPaused (tr_session *, bool isPaused); |
---|
692 | bool tr_sessionGetPaused (const tr_session *); |
---|
693 | |
---|
694 | void tr_sessionSetDeleteSource (tr_session *, bool deleteSource); |
---|
695 | bool tr_sessionGetDeleteSource (const tr_session *); |
---|
696 | |
---|
697 | tr_priority_t tr_torrentGetPriority (const tr_torrent *); |
---|
698 | void tr_torrentSetPriority (tr_torrent *, tr_priority_t); |
---|
699 | |
---|
700 | /*** |
---|
701 | **** |
---|
702 | **** Torrent Queueing |
---|
703 | **** |
---|
704 | **** There are independent queues for seeding (TR_UP) and leeching (TR_DOWN). |
---|
705 | **** |
---|
706 | **** If the session already has enough non-stalled seeds/leeches when |
---|
707 | **** tr_torrentStart () is called, the torrent will be moved into the |
---|
708 | **** appropriate queue and its state will be TR_STATUS_{DOWNLOAD,SEED}_WAIT. |
---|
709 | **** |
---|
710 | **** To bypass the queue and unconditionally start the torrent use |
---|
711 | **** tr_torrentStartNow (). |
---|
712 | **** |
---|
713 | **** Torrents can be moved in the queue using the simple functions |
---|
714 | **** tr_torrentQueueMove{Top,Up,Down,Bottom}. They can be moved to |
---|
715 | **** arbitrary points in the queue with tr_torrentSetQueuePosition (). |
---|
716 | **** |
---|
717 | ***/ |
---|
718 | |
---|
719 | |
---|
720 | /** @brief Like tr_torrentStart (), but resumes right away regardless of the queues. */ |
---|
721 | void tr_torrentStartNow (tr_torrent *); |
---|
722 | |
---|
723 | /** @brief Return the queued torrent's position in the queue it's in. [0...n) */ |
---|
724 | int tr_torrentGetQueuePosition (const tr_torrent *); |
---|
725 | |
---|
726 | /** @brief Set the queued torrent's position in the queue it's in. |
---|
727 | * Special cases: pos <= 0 moves to the front; pos >= queue length moves to the back */ |
---|
728 | void tr_torrentSetQueuePosition (tr_torrent *, int queuePosition); |
---|
729 | |
---|
730 | /** |
---|
731 | **/ |
---|
732 | |
---|
733 | /** @brief Convenience function for moving a batch of torrents to the front of their queue (s) */ |
---|
734 | void tr_torrentsQueueMoveTop (tr_torrent ** torrents, int torrentCount); |
---|
735 | |
---|
736 | /** @brief Convenience function for moving a batch of torrents ahead one step in their queue (s) */ |
---|
737 | void tr_torrentsQueueMoveUp (tr_torrent ** torrents, int torrentCount); |
---|
738 | |
---|
739 | /** @brief Convenience function for moving a batch of torrents back one step in their queue (s) */ |
---|
740 | void tr_torrentsQueueMoveDown (tr_torrent ** torrents, int torrentCount); |
---|
741 | |
---|
742 | /** @brief Convenience function for moving a batch of torrents to the back of their queue (s) */ |
---|
743 | void tr_torrentsQueueMoveBottom (tr_torrent ** torrents, int torrentCount); |
---|
744 | |
---|
745 | /** |
---|
746 | **/ |
---|
747 | |
---|
748 | /** @brief Set the number of torrents allowed to download (if direction is TR_DOWN) or seed (if direction is TR_UP) at the same time */ |
---|
749 | void tr_sessionSetQueueSize (tr_session *, tr_direction, int max_simultaneous_seed_torrents); |
---|
750 | |
---|
751 | /** @brief Return the number of torrents allowed to download (if direction is TR_DOWN) or seed (if direction is TR_UP) at the same time */ |
---|
752 | int tr_sessionGetQueueSize (const tr_session *, tr_direction); |
---|
753 | |
---|
754 | /** @brief Set whether or not to limit how many torrents can download (TR_DOWN) or seed (TR_UP) at the same time */ |
---|
755 | void tr_sessionSetQueueEnabled (tr_session *, tr_direction, bool do_limit_simultaneous_seed_torrents); |
---|
756 | |
---|
757 | /** @brief Return true if we're limiting how many torrents can concurrently download (TR_DOWN) or seed (TR_UP) at the same time */ |
---|
758 | bool tr_sessionGetQueueEnabled (const tr_session *, tr_direction); |
---|
759 | |
---|
760 | /** |
---|
761 | **/ |
---|
762 | |
---|
763 | /** @brief Consider torrent as 'stalled' when it's been inactive for N minutes. |
---|
764 | Stalled torrents are left running but are not counted by tr_sessionGetQueueSize (). */ |
---|
765 | void tr_sessionSetQueueStalledMinutes (tr_session *, int minutes); |
---|
766 | |
---|
767 | /** @return the number of minutes a torrent can be idle before being considered as stalled */ |
---|
768 | int tr_sessionGetQueueStalledMinutes (const tr_session *); |
---|
769 | |
---|
770 | /** @brief Set whether or not to count torrents idle for over N minutes as 'stalled' */ |
---|
771 | void tr_sessionSetQueueStalledEnabled (tr_session *, bool); |
---|
772 | |
---|
773 | /** @return true if we're torrents idle for over N minutes will be flagged as 'stalled' */ |
---|
774 | bool tr_sessionGetQueueStalledEnabled (const tr_session *); |
---|
775 | |
---|
776 | /** |
---|
777 | **/ |
---|
778 | |
---|
779 | /** @brief Set a callback that is invoked when the queue starts a torrent */ |
---|
780 | void tr_torrentSetQueueStartCallback (tr_torrent * torrent, void (*callback)(tr_torrent *, void *), void * user_data); |
---|
781 | |
---|
782 | |
---|
783 | /*** |
---|
784 | **** |
---|
785 | **** |
---|
786 | ***/ |
---|
787 | |
---|
788 | /** |
---|
789 | * Load all the torrents in tr_getTorrentDir (). |
---|
790 | * This can be used at startup to kickstart all the torrents |
---|
791 | * from the previous session. |
---|
792 | */ |
---|
793 | tr_torrent ** tr_sessionLoadTorrents (tr_session * session, |
---|
794 | tr_ctor * ctor, |
---|
795 | int * setmeCount); |
---|
796 | |
---|
797 | /** |
---|
798 | *** |
---|
799 | **/ |
---|
800 | |
---|
801 | bool tr_sessionIsTorrentDoneScriptEnabled (const tr_session *); |
---|
802 | |
---|
803 | void tr_sessionSetTorrentDoneScriptEnabled (tr_session *, bool isEnabled); |
---|
804 | |
---|
805 | const char * tr_sessionGetTorrentDoneScript (const tr_session *); |
---|
806 | |
---|
807 | void tr_sessionSetTorrentDoneScript (tr_session *, const char * scriptFilename); |
---|
808 | |
---|
809 | |
---|
810 | /** @} */ |
---|
811 | |
---|
812 | /** |
---|
813 | *** |
---|
814 | **/ |
---|
815 | |
---|
816 | |
---|
817 | /*********************************************************************** |
---|
818 | ** Message Logging |
---|
819 | */ |
---|
820 | |
---|
821 | typedef enum |
---|
822 | { |
---|
823 | TR_LOG_ERROR = 1, |
---|
824 | TR_LOG_INFO = 2, |
---|
825 | TR_LOG_DEBUG = 3, |
---|
826 | TR_LOG_FIREHOSE = 4 |
---|
827 | } |
---|
828 | tr_log_level; |
---|
829 | |
---|
830 | void tr_logSetLevel (tr_log_level); |
---|
831 | |
---|
832 | typedef struct tr_log_message |
---|
833 | { |
---|
834 | /* TR_LOG_ERROR, TR_LOG_INFO, or TR_LOG_DEBUG */ |
---|
835 | tr_log_level level; |
---|
836 | |
---|
837 | /* The line number in the source file where this message originated */ |
---|
838 | int line; |
---|
839 | |
---|
840 | /* Time the message was generated */ |
---|
841 | time_t when; |
---|
842 | |
---|
843 | /* The torrent associated with this message, |
---|
844 | * or a module name such as "Port Forwarding" for non-torrent messages, |
---|
845 | * or NULL. */ |
---|
846 | char * name; |
---|
847 | |
---|
848 | /* The message */ |
---|
849 | char * message; |
---|
850 | |
---|
851 | /* The source file where this message originated */ |
---|
852 | const char * file; |
---|
853 | |
---|
854 | /* linked list of messages */ |
---|
855 | struct tr_log_message * next; |
---|
856 | } |
---|
857 | tr_log_message; |
---|
858 | |
---|
859 | tr_log_message * tr_logGetQueue (void); |
---|
860 | bool tr_logGetQueueEnabled (void); |
---|
861 | void tr_logSetQueueEnabled (bool isEnabled); |
---|
862 | void tr_logFreeQueue (tr_log_message * freeme); |
---|
863 | |
---|
864 | /** @addtogroup Blocklists |
---|
865 | @{ */ |
---|
866 | |
---|
867 | /** |
---|
868 | * Specify a range of IPs for Transmission to block. |
---|
869 | * |
---|
870 | * Filename must be an uncompressed ascii file. |
---|
871 | * |
---|
872 | * libtransmission does not keep a handle to `filename' |
---|
873 | * after this call returns, so the caller is free to |
---|
874 | * keep or delete `filename' as it wishes. |
---|
875 | * libtransmission makes its own copy of the file |
---|
876 | * massaged into a binary format easier to search. |
---|
877 | * |
---|
878 | * The caller only needs to invoke this when the blocklist |
---|
879 | * has changed. |
---|
880 | * |
---|
881 | * Passing NULL for a filename will clear the blocklist. |
---|
882 | */ |
---|
883 | int tr_blocklistSetContent (tr_session * session, |
---|
884 | const char * filename); |
---|
885 | |
---|
886 | int tr_blocklistGetRuleCount (const tr_session * session); |
---|
887 | |
---|
888 | bool tr_blocklistExists (const tr_session * session); |
---|
889 | |
---|
890 | bool tr_blocklistIsEnabled (const tr_session * session); |
---|
891 | |
---|
892 | void tr_blocklistSetEnabled (tr_session * session, |
---|
893 | bool isEnabled); |
---|
894 | |
---|
895 | /** @brief The blocklist that ges updated when an RPC client |
---|
896 | invokes the "blocklist-update" method */ |
---|
897 | void tr_blocklistSetURL (tr_session *, const char * url); |
---|
898 | |
---|
899 | const char * tr_blocklistGetURL (const tr_session *); |
---|
900 | |
---|
901 | /** @brief the file in the $config/blocklists/ directory that's |
---|
902 | used by tr_blocklistSetContent () and "blocklist-update" */ |
---|
903 | #define DEFAULT_BLOCKLIST_FILENAME "blocklist.bin" |
---|
904 | |
---|
905 | /** @} */ |
---|
906 | |
---|
907 | |
---|
908 | /** @addtogroup tr_ctor Torrent Constructors |
---|
909 | @{ |
---|
910 | |
---|
911 | Instantiating a tr_torrent had gotten more complicated as features were |
---|
912 | added. At one point there were four functions to check metainfo and five |
---|
913 | to create a tr_torrent object. |
---|
914 | |
---|
915 | To remedy this, a Torrent Constructor (struct tr_ctor) has been introduced: |
---|
916 | - Simplifies the API to two functions: tr_torrentParse () and tr_torrentNew () |
---|
917 | - You can set the fields you want; the system sets defaults for the rest. |
---|
918 | - You can specify whether or not your fields should supercede resume's. |
---|
919 | - We can add new features to tr_ctor without breaking tr_torrentNew ()'s API. |
---|
920 | |
---|
921 | All the tr_ctor{Get,Set}* () functions with a return value return |
---|
922 | an error number, or zero if no error occurred. |
---|
923 | |
---|
924 | You must call one of the SetMetainfo () functions before creating |
---|
925 | a torrent with a tr_ctor. The other functions are optional. |
---|
926 | |
---|
927 | You can reuse a single tr_ctor to create a batch of torrents -- |
---|
928 | just call one of the SetMetainfo () functions between each |
---|
929 | tr_torrentNew () call. |
---|
930 | |
---|
931 | Every call to tr_ctorSetMetainfo* () frees the previous metainfo. |
---|
932 | */ |
---|
933 | |
---|
934 | typedef enum |
---|
935 | { |
---|
936 | TR_FALLBACK, /* indicates the ctor value should be used only |
---|
937 | in case of missing resume settings */ |
---|
938 | |
---|
939 | TR_FORCE, /* indicates the ctor value should be used |
---|
940 | regardless of what's in the resume settings */ |
---|
941 | } |
---|
942 | tr_ctorMode; |
---|
943 | |
---|
944 | /** @brief Create a torrent constructor object used to instantiate a tr_torrent |
---|
945 | @param session the tr_session. This is required if you're going to call |
---|
946 | tr_torrentNew (), but you can use NULL for tr_torrentParse (). |
---|
947 | @see tr_torrentNew (), tr_torrentParse () */ |
---|
948 | tr_ctor* tr_ctorNew (const tr_session * session_or_NULL); |
---|
949 | |
---|
950 | /** @brief Free a torrent constructor object */ |
---|
951 | void tr_ctorFree (tr_ctor * ctor); |
---|
952 | |
---|
953 | /** @brief Set whether or not to delete the source .torrent file |
---|
954 | when the torrent is added. (Default: False) */ |
---|
955 | void tr_ctorSetDeleteSource (tr_ctor * ctor, bool doDelete); |
---|
956 | |
---|
957 | /** @brief Set the constructor's metainfo from a magnet link */ |
---|
958 | int tr_ctorSetMetainfoFromMagnetLink (tr_ctor * ctor, const char * magnet); |
---|
959 | |
---|
960 | /** @brief Set the constructor's metainfo from a raw benc already in memory */ |
---|
961 | int tr_ctorSetMetainfo (tr_ctor * ctor, const uint8_t * metainfo, size_t len); |
---|
962 | |
---|
963 | /** @brief Set the constructor's metainfo from a local .torrent file */ |
---|
964 | int tr_ctorSetMetainfoFromFile (tr_ctor * ctor, const char * filename); |
---|
965 | |
---|
966 | /** |
---|
967 | * @brief Set the metainfo from an existing file in tr_getTorrentDir (). |
---|
968 | * |
---|
969 | * This is used by the Mac client on startup to pick and choose which |
---|
970 | * torrents to load |
---|
971 | */ |
---|
972 | int tr_ctorSetMetainfoFromHash (tr_ctor * ctor, const char * hashString); |
---|
973 | |
---|
974 | /** @brief Set how many peers this torrent can connect to. (Default: 50) */ |
---|
975 | void tr_ctorSetPeerLimit (tr_ctor * ctor, tr_ctorMode mode, uint16_t limit); |
---|
976 | |
---|
977 | /** @brief Set the download folder for the torrent being added with this ctor. |
---|
978 | @see tr_ctorSetDownloadDir () |
---|
979 | @see tr_sessionInit () */ |
---|
980 | void tr_ctorSetDownloadDir (tr_ctor * ctor, |
---|
981 | tr_ctorMode mode, |
---|
982 | const char * directory); |
---|
983 | |
---|
984 | /** |
---|
985 | * @brief Set the incompleteDir for this torrent. |
---|
986 | * |
---|
987 | * This is not a supported API call. |
---|
988 | * It only exists so the mac client can migrate |
---|
989 | * its older incompleteDir settings, and that's |
---|
990 | * the only place where it should be used. |
---|
991 | */ |
---|
992 | void tr_ctorSetIncompleteDir (tr_ctor * ctor, const char * directory); |
---|
993 | |
---|
994 | /** Set whether or not the torrent begins downloading/seeding when created. |
---|
995 | (Default: not paused) */ |
---|
996 | void tr_ctorSetPaused (tr_ctor * ctor, |
---|
997 | tr_ctorMode mode, |
---|
998 | bool isPaused); |
---|
999 | |
---|
1000 | /** @brief Set the priorities for files in a torrent */ |
---|
1001 | void tr_ctorSetFilePriorities (tr_ctor * ctor, |
---|
1002 | const tr_file_index_t * files, |
---|
1003 | tr_file_index_t fileCount, |
---|
1004 | tr_priority_t priority); |
---|
1005 | |
---|
1006 | /** @brief Set the download flag for files in a torrent */ |
---|
1007 | void tr_ctorSetFilesWanted (tr_ctor * ctor, |
---|
1008 | const tr_file_index_t * fileIndices, |
---|
1009 | tr_file_index_t fileCount, |
---|
1010 | bool wanted); |
---|
1011 | |
---|
1012 | |
---|
1013 | /** @brief Get this peer constructor's peer limit */ |
---|
1014 | int tr_ctorGetPeerLimit (const tr_ctor * ctor, |
---|
1015 | tr_ctorMode mode, |
---|
1016 | uint16_t * setmeCount); |
---|
1017 | |
---|
1018 | /** @brief Get the "isPaused" flag from this peer constructor */ |
---|
1019 | int tr_ctorGetPaused (const tr_ctor * ctor, |
---|
1020 | tr_ctorMode mode, |
---|
1021 | bool * setmeIsPaused); |
---|
1022 | |
---|
1023 | /** @brief Get the download path from this peer constructor */ |
---|
1024 | int tr_ctorGetDownloadDir (const tr_ctor * ctor, |
---|
1025 | tr_ctorMode mode, |
---|
1026 | const char ** setmeDownloadDir); |
---|
1027 | |
---|
1028 | /** @brief Get the incomplete directory from this peer constructor */ |
---|
1029 | int tr_ctorGetIncompleteDir (const tr_ctor * ctor, |
---|
1030 | const char ** setmeIncompleteDir); |
---|
1031 | |
---|
1032 | /** @brief Get the metainfo from this peer constructor */ |
---|
1033 | int tr_ctorGetMetainfo (const tr_ctor * ctor, |
---|
1034 | const struct tr_variant ** setme); |
---|
1035 | |
---|
1036 | /** @brief Get the "delete .torrent file" flag from this peer constructor */ |
---|
1037 | int tr_ctorGetDeleteSource (const tr_ctor * ctor, |
---|
1038 | bool * setmeDoDelete); |
---|
1039 | |
---|
1040 | /** @brief Get the tr_session poiner from this peer constructor */ |
---|
1041 | tr_session* tr_ctorGetSession (const tr_ctor * ctor); |
---|
1042 | |
---|
1043 | /** @brief Get the .torrent file that this ctor's metainfo came from, |
---|
1044 | or NULL if tr_ctorSetMetainfoFromFile () wasn't used */ |
---|
1045 | const char* tr_ctorGetSourceFile (const tr_ctor * ctor); |
---|
1046 | |
---|
1047 | typedef enum |
---|
1048 | { |
---|
1049 | TR_PARSE_OK, |
---|
1050 | TR_PARSE_ERR, |
---|
1051 | TR_PARSE_DUPLICATE |
---|
1052 | } |
---|
1053 | tr_parse_result; |
---|
1054 | |
---|
1055 | /** |
---|
1056 | * @brief Parses the specified metainfo |
---|
1057 | * |
---|
1058 | * @return TR_PARSE_ERR if parsing failed; |
---|
1059 | * TR_PARSE_OK if parsing succeeded and it's not a duplicate; |
---|
1060 | * TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate. |
---|
1061 | * |
---|
1062 | * @param setme_info If parsing is successful and setme_info is non-NULL, |
---|
1063 | * the parsed metainfo is stored there and sould be freed |
---|
1064 | * by calling tr_metainfoFree () when no longer needed. |
---|
1065 | * |
---|
1066 | * Notes: |
---|
1067 | * |
---|
1068 | * 1. tr_torrentParse () won't be able to check for duplicates -- and therefore |
---|
1069 | * won't return TR_PARSE_DUPLICATE -- unless ctor's "download-dir" and |
---|
1070 | * session variable is set. |
---|
1071 | * |
---|
1072 | * 2. setme_info->torrent's value can't be set unless ctor's session variable |
---|
1073 | * is set. |
---|
1074 | */ |
---|
1075 | tr_parse_result tr_torrentParse (const tr_ctor * ctor, |
---|
1076 | tr_info * setme_info_or_NULL); |
---|
1077 | |
---|
1078 | /** @brief free a metainfo |
---|
1079 | @see tr_torrentParse */ |
---|
1080 | void tr_metainfoFree (tr_info * inf); |
---|
1081 | |
---|
1082 | |
---|
1083 | /** |
---|
1084 | * Instantiate a single torrent. |
---|
1085 | * |
---|
1086 | * Returns a pointer to the torrent on success, or NULL on failure. |
---|
1087 | * |
---|
1088 | * @param setme_error: TR_PARSE_ERR if the parsing failed; |
---|
1089 | * TR_PARSE_OK if parsing succeeded and it's not a duplicate; |
---|
1090 | * TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate. |
---|
1091 | * |
---|
1092 | * @param setme_duplicate_id: when setmeError is TR_PARSE_DUPLICATE, |
---|
1093 | * this field is set to the duplicate torrent's id. |
---|
1094 | */ |
---|
1095 | tr_torrent * tr_torrentNew (const tr_ctor * ctor, |
---|
1096 | int * setme_error, |
---|
1097 | int * setme_duplicate_id); |
---|
1098 | |
---|
1099 | /** @} */ |
---|
1100 | |
---|
1101 | /*********************************************************************** |
---|
1102 | *** |
---|
1103 | *** TORRENTS |
---|
1104 | **/ |
---|
1105 | |
---|
1106 | /** @addtogroup tr_torrent Torrents |
---|
1107 | @{ */ |
---|
1108 | |
---|
1109 | typedef int (*tr_fileFunc) (const char * filename); |
---|
1110 | |
---|
1111 | /** @brief Removes our .torrent and .resume files for this torrent */ |
---|
1112 | void tr_torrentRemove (tr_torrent * torrent, |
---|
1113 | bool removeLocalData, |
---|
1114 | tr_fileFunc removeFunc); |
---|
1115 | |
---|
1116 | /** @brief Start a torrent */ |
---|
1117 | void tr_torrentStart (tr_torrent * torrent); |
---|
1118 | |
---|
1119 | /** @brief Stop (pause) a torrent */ |
---|
1120 | void tr_torrentStop (tr_torrent * torrent); |
---|
1121 | |
---|
1122 | |
---|
1123 | typedef void (*tr_torrent_rename_done_func)(tr_torrent * torrent, |
---|
1124 | const char * oldpath, |
---|
1125 | const char * newname, |
---|
1126 | int error, |
---|
1127 | void * user_data); |
---|
1128 | |
---|
1129 | /** |
---|
1130 | * @brief Rename a file or directory in a torrent. |
---|
1131 | * |
---|
1132 | * @tor: the torrent whose path will be renamed. |
---|
1133 | * @oldpath: the path to the file or folder that will be renamed |
---|
1134 | * @newname: the file or folder's new name |
---|
1135 | * @callback: the callback invoked when the renaming finishes, or NULL |
---|
1136 | * @callback_data: the pointer to pass in the callback's user_data arg |
---|
1137 | * |
---|
1138 | * As a special case, renaming the root file in a torrent will also |
---|
1139 | * update tr_info.name. |
---|
1140 | * |
---|
1141 | * EXAMPLES |
---|
1142 | * |
---|
1143 | * Consider a tr_torrent where its |
---|
1144 | * info.files[0].name is "frobnitz-linux/checksum" and |
---|
1145 | * info.files[1].name is "frobnitz-linux/frobnitz.iso". |
---|
1146 | * |
---|
1147 | * 1. tr_torrentRenamePath (tor, "frobnitz-linux", "foo") will rename |
---|
1148 | * the "frotbnitz-linux" folder as "foo", and update both info.name |
---|
1149 | * and info.files[*].name. |
---|
1150 | * |
---|
1151 | * 2. tr_torrentRenamePath (tor, "frobnitz-linux/checksum", "foo") will |
---|
1152 | * rename the "frobnitz-linux/checksum" file as "foo" and update |
---|
1153 | * files[0].name to "frobnitz-linux/foo". |
---|
1154 | * |
---|
1155 | * RETURN |
---|
1156 | * |
---|
1157 | * Changing tr_info's contents requires a session lock, so this function |
---|
1158 | * returns asynchronously to avoid blocking. If you don't want to be notified |
---|
1159 | * when the function has finished, you can pass NULL as the callback arg. |
---|
1160 | * |
---|
1161 | * On success, the callback's error argument will be 0. |
---|
1162 | * |
---|
1163 | * If oldpath can't be found in files[*].name, or if newname is already |
---|
1164 | * in files[*].name, or contains a directory separator, or is NULL, "", |
---|
1165 | * ".", or "..", the error argument will be EINVAL. |
---|
1166 | * |
---|
1167 | * If the path exists on disk but can't be renamed, the error argument |
---|
1168 | * will be the errno set by rename(). |
---|
1169 | */ |
---|
1170 | void tr_torrentRenamePath (tr_torrent * tor, |
---|
1171 | const char * oldpath, |
---|
1172 | const char * newname, |
---|
1173 | tr_torrent_rename_done_func callback, |
---|
1174 | void * callback_user_data); |
---|
1175 | |
---|
1176 | enum |
---|
1177 | { |
---|
1178 | TR_LOC_MOVING, |
---|
1179 | TR_LOC_DONE, |
---|
1180 | TR_LOC_ERROR |
---|
1181 | }; |
---|
1182 | |
---|
1183 | /** |
---|
1184 | * @brief Tell transmsision where to find this torrent's local data. |
---|
1185 | * |
---|
1186 | * if move_from_previous_location is `true', the torrent's incompleteDir |
---|
1187 | * will be clobberred s.t. additional files being added will be saved |
---|
1188 | * to the torrent's downloadDir. |
---|
1189 | */ |
---|
1190 | void tr_torrentSetLocation (tr_torrent * torrent, |
---|
1191 | const char * location, |
---|
1192 | bool move_from_previous_location, |
---|
1193 | volatile double * setme_progress, |
---|
1194 | volatile int * setme_state); |
---|
1195 | |
---|
1196 | uint64_t tr_torrentGetBytesLeftToAllocate (const tr_torrent * torrent); |
---|
1197 | |
---|
1198 | /** |
---|
1199 | * @brief Returns this torrent's unique ID. |
---|
1200 | * |
---|
1201 | * IDs are good as simple lookup keys, but are not persistent |
---|
1202 | * between sessions. If you need that, use tr_info.hash or |
---|
1203 | * tr_info.hashString. |
---|
1204 | */ |
---|
1205 | int tr_torrentId (const tr_torrent * torrent); |
---|
1206 | |
---|
1207 | tr_torrent* tr_torrentFindFromId (tr_session * session, int id); |
---|
1208 | |
---|
1209 | tr_torrent* tr_torrentFindFromHash (tr_session * session, |
---|
1210 | const uint8_t * hash); |
---|
1211 | |
---|
1212 | /** @brief Convenience function similar to tr_torrentFindFromHash () */ |
---|
1213 | tr_torrent* tr_torrentFindFromMagnetLink (tr_session * session, |
---|
1214 | const char * link); |
---|
1215 | |
---|
1216 | /** |
---|
1217 | * @return this torrent's name. |
---|
1218 | */ |
---|
1219 | const char* tr_torrentName (const tr_torrent *); |
---|
1220 | |
---|
1221 | /** |
---|
1222 | * @brief find the location of a torrent's file by looking with and without |
---|
1223 | * the ".part" suffix, looking in downloadDir and incompleteDir, etc. |
---|
1224 | * @return a newly-allocated string (that must be tr_freed () by the caller |
---|
1225 | * when done) that gives the location of this file on disk, |
---|
1226 | * or NULL if no file exists yet. |
---|
1227 | * @param tor the torrent whose file we're looking for |
---|
1228 | * @param fileNum the fileIndex, in [0...tr_info.fileCount) |
---|
1229 | */ |
---|
1230 | char* tr_torrentFindFile (const tr_torrent * tor, tr_file_index_t fileNo); |
---|
1231 | |
---|
1232 | |
---|
1233 | /*** |
---|
1234 | **** Torrent speed limits |
---|
1235 | **** |
---|
1236 | ***/ |
---|
1237 | |
---|
1238 | void tr_torrentSetSpeedLimit_KBps (tr_torrent *, tr_direction, unsigned int KBps); |
---|
1239 | unsigned int tr_torrentGetSpeedLimit_KBps (const tr_torrent *, tr_direction); |
---|
1240 | |
---|
1241 | void tr_torrentUseSpeedLimit (tr_torrent *, tr_direction, bool); |
---|
1242 | bool tr_torrentUsesSpeedLimit (const tr_torrent *, tr_direction); |
---|
1243 | |
---|
1244 | void tr_torrentUseSessionLimits (tr_torrent *, bool); |
---|
1245 | bool tr_torrentUsesSessionLimits (const tr_torrent *); |
---|
1246 | |
---|
1247 | |
---|
1248 | /**** |
---|
1249 | ***** Ratio Limits |
---|
1250 | ****/ |
---|
1251 | |
---|
1252 | typedef enum |
---|
1253 | { |
---|
1254 | /* follow the global settings */ |
---|
1255 | TR_RATIOLIMIT_GLOBAL = 0, |
---|
1256 | |
---|
1257 | /* override the global settings, seeding until a certain ratio */ |
---|
1258 | TR_RATIOLIMIT_SINGLE = 1, |
---|
1259 | |
---|
1260 | /* override the global settings, seeding regardless of ratio */ |
---|
1261 | TR_RATIOLIMIT_UNLIMITED = 2 |
---|
1262 | } |
---|
1263 | tr_ratiolimit; |
---|
1264 | |
---|
1265 | void tr_torrentSetRatioMode (tr_torrent * tor, |
---|
1266 | tr_ratiolimit mode); |
---|
1267 | |
---|
1268 | tr_ratiolimit tr_torrentGetRatioMode (const tr_torrent * tor); |
---|
1269 | |
---|
1270 | void tr_torrentSetRatioLimit (tr_torrent * tor, |
---|
1271 | double ratio); |
---|
1272 | |
---|
1273 | double tr_torrentGetRatioLimit (const tr_torrent * tor); |
---|
1274 | |
---|
1275 | |
---|
1276 | bool tr_torrentGetSeedRatio (const tr_torrent *, double * ratio); |
---|
1277 | |
---|
1278 | |
---|
1279 | /**** |
---|
1280 | ***** Idle Time Limits |
---|
1281 | ****/ |
---|
1282 | |
---|
1283 | typedef enum |
---|
1284 | { |
---|
1285 | /* follow the global settings */ |
---|
1286 | TR_IDLELIMIT_GLOBAL = 0, |
---|
1287 | |
---|
1288 | /* override the global settings, seeding until a certain idle time */ |
---|
1289 | TR_IDLELIMIT_SINGLE = 1, |
---|
1290 | |
---|
1291 | /* override the global settings, seeding regardless of activity */ |
---|
1292 | TR_IDLELIMIT_UNLIMITED = 2 |
---|
1293 | } |
---|
1294 | tr_idlelimit; |
---|
1295 | |
---|
1296 | void tr_torrentSetIdleMode (tr_torrent * tor, |
---|
1297 | tr_idlelimit mode); |
---|
1298 | |
---|
1299 | tr_idlelimit tr_torrentGetIdleMode (const tr_torrent * tor); |
---|
1300 | |
---|
1301 | void tr_torrentSetIdleLimit (tr_torrent * tor, |
---|
1302 | uint16_t idleMinutes); |
---|
1303 | |
---|
1304 | uint16_t tr_torrentGetIdleLimit (const tr_torrent * tor); |
---|
1305 | |
---|
1306 | |
---|
1307 | bool tr_torrentGetSeedIdle (const tr_torrent *, uint16_t * minutes); |
---|
1308 | |
---|
1309 | /**** |
---|
1310 | ***** Peer Limits |
---|
1311 | ****/ |
---|
1312 | |
---|
1313 | void tr_torrentSetPeerLimit (tr_torrent * tor, uint16_t peerLimit); |
---|
1314 | |
---|
1315 | uint16_t tr_torrentGetPeerLimit (const tr_torrent * tor); |
---|
1316 | |
---|
1317 | /**** |
---|
1318 | ***** File Priorities |
---|
1319 | ****/ |
---|
1320 | |
---|
1321 | enum |
---|
1322 | { |
---|
1323 | TR_PRI_LOW = -1, |
---|
1324 | TR_PRI_NORMAL = 0, /* since NORMAL is 0, memset initializes nicely */ |
---|
1325 | TR_PRI_HIGH = 1 |
---|
1326 | }; |
---|
1327 | |
---|
1328 | /** |
---|
1329 | * @brief Set a batch of files to a particular priority. |
---|
1330 | * |
---|
1331 | * @param priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW |
---|
1332 | */ |
---|
1333 | void tr_torrentSetFilePriorities (tr_torrent * torrent, |
---|
1334 | const tr_file_index_t * files, |
---|
1335 | tr_file_index_t fileCount, |
---|
1336 | tr_priority_t priority); |
---|
1337 | |
---|
1338 | /** |
---|
1339 | * @brief Get this torrent's file priorities. |
---|
1340 | * |
---|
1341 | * @return A malloc ()ed array of tor->info.fileCount items, |
---|
1342 | * each holding a TR_PRI_NORMAL, TR_PRI_HIGH, or TR_PRI_LOW. |
---|
1343 | * It's the caller's responsibility to free () this. |
---|
1344 | */ |
---|
1345 | tr_priority_t* tr_torrentGetFilePriorities (const tr_torrent * torrent); |
---|
1346 | |
---|
1347 | /** @brief Set a batch of files to be downloaded or not. */ |
---|
1348 | void tr_torrentSetFileDLs (tr_torrent * torrent, |
---|
1349 | const tr_file_index_t * files, |
---|
1350 | tr_file_index_t fileCount, |
---|
1351 | bool do_download); |
---|
1352 | |
---|
1353 | |
---|
1354 | const tr_info * tr_torrentInfo (const tr_torrent * torrent); |
---|
1355 | |
---|
1356 | /* Raw function to change the torrent's downloadDir field. |
---|
1357 | This should only be used by libtransmission or to bootstrap |
---|
1358 | a newly-instantiated tr_torrent object. */ |
---|
1359 | void tr_torrentSetDownloadDir (tr_torrent * torrent, const char * path); |
---|
1360 | |
---|
1361 | const char * tr_torrentGetDownloadDir (const tr_torrent * torrent); |
---|
1362 | |
---|
1363 | /** |
---|
1364 | * Returns the root directory of where the torrent is. |
---|
1365 | * |
---|
1366 | * This will usually be the downloadDir. However if the torrent |
---|
1367 | * has an incompleteDir enabled and hasn't finished downloading |
---|
1368 | * yet, that will be returned instead. |
---|
1369 | */ |
---|
1370 | const char * tr_torrentGetCurrentDir (const tr_torrent * tor); |
---|
1371 | |
---|
1372 | |
---|
1373 | char* tr_torrentInfoGetMagnetLink (const tr_info * inf); |
---|
1374 | |
---|
1375 | /** |
---|
1376 | * Returns a newly-allocated string with a magnet link of the torrent. |
---|
1377 | * Use tr_free () to free the string when done. |
---|
1378 | */ |
---|
1379 | static inline |
---|
1380 | char* tr_torrentGetMagnetLink (const tr_torrent * tor) |
---|
1381 | { |
---|
1382 | return tr_torrentInfoGetMagnetLink (tr_torrentInfo (tor)); |
---|
1383 | } |
---|
1384 | |
---|
1385 | /** |
---|
1386 | *** |
---|
1387 | **/ |
---|
1388 | |
---|
1389 | |
---|
1390 | /** @brief a part of tr_info that represents a single tracker */ |
---|
1391 | typedef struct tr_tracker_info |
---|
1392 | { |
---|
1393 | int tier; |
---|
1394 | char * announce; |
---|
1395 | char * scrape; |
---|
1396 | uint32_t id; /* unique identifier used to match to a tr_tracker_stat */ |
---|
1397 | } |
---|
1398 | tr_tracker_info; |
---|
1399 | |
---|
1400 | /** |
---|
1401 | * @brief Modify a torrent's tracker list. |
---|
1402 | * |
---|
1403 | * This updates both the `torrent' object's tracker list |
---|
1404 | * and the metainfo file in tr_sessionGetConfigDir ()'s torrent subdirectory. |
---|
1405 | * |
---|
1406 | * @param torrent The torrent whose tracker list is to be modified |
---|
1407 | * @param trackers An array of trackers, sorted by tier from first to last. |
---|
1408 | * NOTE: only the `tier' and `announce' fields are used. |
---|
1409 | * libtransmission derives `scrape' from `announce' |
---|
1410 | * and reassigns 'id'. |
---|
1411 | * @param trackerCount size of the `trackers' array |
---|
1412 | */ |
---|
1413 | bool |
---|
1414 | tr_torrentSetAnnounceList (tr_torrent * torrent, |
---|
1415 | const tr_tracker_info * trackers, |
---|
1416 | int trackerCount); |
---|
1417 | |
---|
1418 | |
---|
1419 | /** |
---|
1420 | *** |
---|
1421 | **/ |
---|
1422 | |
---|
1423 | typedef enum |
---|
1424 | { |
---|
1425 | TR_LEECH, /* doesn't have all the desired pieces */ |
---|
1426 | TR_SEED, /* has the entire torrent */ |
---|
1427 | TR_PARTIAL_SEED /* has the desired pieces, but not the entire torrent */ |
---|
1428 | } |
---|
1429 | tr_completeness; |
---|
1430 | |
---|
1431 | /** |
---|
1432 | * @param wasRunning whether or not the torrent was running when |
---|
1433 | * it changed its completeness state |
---|
1434 | */ |
---|
1435 | typedef void (*tr_torrent_completeness_func)(tr_torrent * torrent, |
---|
1436 | tr_completeness completeness, |
---|
1437 | bool wasRunning, |
---|
1438 | void * user_data); |
---|
1439 | |
---|
1440 | typedef void (*tr_torrent_ratio_limit_hit_func)(tr_torrent * torrent, |
---|
1441 | void * user_data); |
---|
1442 | |
---|
1443 | typedef void (*tr_torrent_idle_limit_hit_func)(tr_torrent * torrent, |
---|
1444 | void * user_data); |
---|
1445 | |
---|
1446 | |
---|
1447 | /** |
---|
1448 | * Register to be notified whenever a torrent's "completeness" |
---|
1449 | * changes. This will be called, for example, when a torrent |
---|
1450 | * finishes downloading and changes from TR_LEECH to |
---|
1451 | * either TR_SEED or TR_PARTIAL_SEED. |
---|
1452 | * |
---|
1453 | * func is invoked FROM LIBTRANSMISSION'S THREAD! |
---|
1454 | * This means func must be fast (to avoid blocking peers), |
---|
1455 | * shouldn't call libtransmission functions (to avoid deadlock), |
---|
1456 | * and shouldn't modify client-level memory without using a mutex! |
---|
1457 | * |
---|
1458 | * @see tr_completeness |
---|
1459 | */ |
---|
1460 | void tr_torrentSetCompletenessCallback ( |
---|
1461 | tr_torrent * torrent, |
---|
1462 | tr_torrent_completeness_func func, |
---|
1463 | void * user_data); |
---|
1464 | |
---|
1465 | void tr_torrentClearCompletenessCallback (tr_torrent * torrent); |
---|
1466 | |
---|
1467 | |
---|
1468 | |
---|
1469 | typedef void (*tr_torrent_metadata_func)(tr_torrent * torrent, |
---|
1470 | void * user_data); |
---|
1471 | /** |
---|
1472 | * Register to be notified whenever a torrent changes from |
---|
1473 | * having incomplete metadata to having complete metadata. |
---|
1474 | * This happens when a magnet link finishes downloading |
---|
1475 | * metadata from its peers. |
---|
1476 | */ |
---|
1477 | void tr_torrentSetMetadataCallback ( |
---|
1478 | tr_torrent * tor, |
---|
1479 | tr_torrent_metadata_func func, |
---|
1480 | void * user_data); |
---|
1481 | |
---|
1482 | /** |
---|
1483 | * Register to be notified whenever a torrent's ratio limit |
---|
1484 | * has been hit. This will be called when the torrent's |
---|
1485 | * ul/dl ratio has met or exceeded the designated ratio limit. |
---|
1486 | * |
---|
1487 | * Has the same restrictions as tr_torrentSetCompletenessCallback |
---|
1488 | */ |
---|
1489 | void tr_torrentSetRatioLimitHitCallback ( |
---|
1490 | tr_torrent * torrent, |
---|
1491 | tr_torrent_ratio_limit_hit_func func, |
---|
1492 | void * user_data); |
---|
1493 | |
---|
1494 | void tr_torrentClearRatioLimitHitCallback (tr_torrent * torrent); |
---|
1495 | |
---|
1496 | /** |
---|
1497 | * Register to be notified whenever a torrent's idle limit |
---|
1498 | * has been hit. This will be called when the seeding torrent's |
---|
1499 | * idle time has met or exceeded the designated idle limit. |
---|
1500 | * |
---|
1501 | * Has the same restrictions as tr_torrentSetCompletenessCallback |
---|
1502 | */ |
---|
1503 | void tr_torrentSetIdleLimitHitCallback ( |
---|
1504 | tr_torrent * torrent, |
---|
1505 | tr_torrent_idle_limit_hit_func func, |
---|
1506 | void * user_data); |
---|
1507 | |
---|
1508 | void tr_torrentClearIdleLimitHitCallback (tr_torrent * torrent); |
---|
1509 | |
---|
1510 | |
---|
1511 | /** |
---|
1512 | * MANUAL ANNOUNCE |
---|
1513 | * |
---|
1514 | * Trackers usually set an announce interval of 15 or 30 minutes. |
---|
1515 | * Users can send one-time announce requests that override this |
---|
1516 | * interval by calling tr_torrentManualUpdate (). |
---|
1517 | * |
---|
1518 | * The wait interval for tr_torrentManualUpdate () is much smaller. |
---|
1519 | * You can test whether or not a manual update is possible |
---|
1520 | * (for example, to desensitize the button) by calling |
---|
1521 | * tr_torrentCanManualUpdate (). |
---|
1522 | */ |
---|
1523 | |
---|
1524 | void tr_torrentManualUpdate (tr_torrent * torrent); |
---|
1525 | |
---|
1526 | bool tr_torrentCanManualUpdate (const tr_torrent * torrent); |
---|
1527 | |
---|
1528 | /*** |
---|
1529 | **** tr_peer_stat |
---|
1530 | ***/ |
---|
1531 | |
---|
1532 | typedef struct tr_peer_stat |
---|
1533 | { |
---|
1534 | bool isUTP; |
---|
1535 | |
---|
1536 | bool isEncrypted; |
---|
1537 | bool isDownloadingFrom; |
---|
1538 | bool isUploadingTo; |
---|
1539 | bool isSeed; |
---|
1540 | |
---|
1541 | bool peerIsChoked; |
---|
1542 | bool peerIsInterested; |
---|
1543 | bool clientIsChoked; |
---|
1544 | bool clientIsInterested; |
---|
1545 | bool isIncoming; |
---|
1546 | |
---|
1547 | uint8_t from; |
---|
1548 | tr_port port; |
---|
1549 | |
---|
1550 | char addr[TR_INET6_ADDRSTRLEN]; |
---|
1551 | char client[80]; |
---|
1552 | char flagStr[32]; |
---|
1553 | |
---|
1554 | float progress; |
---|
1555 | double rateToPeer_KBps; |
---|
1556 | double rateToClient_KBps; |
---|
1557 | |
---|
1558 | |
---|
1559 | /*** |
---|
1560 | **** THESE NEXT FOUR FIELDS ARE EXPERIMENTAL. |
---|
1561 | **** Don't rely on them; they'll probably go away |
---|
1562 | ***/ |
---|
1563 | /* how many blocks we've sent to this peer in the last 120 seconds */ |
---|
1564 | uint32_t blocksToPeer; |
---|
1565 | /* how many blocks this client's sent to us in the last 120 seconds */ |
---|
1566 | uint32_t blocksToClient; |
---|
1567 | /* how many requests to this peer that we've cancelled in the last 120 seconds */ |
---|
1568 | uint32_t cancelsToPeer; |
---|
1569 | /* how many requests this peer made of us, then cancelled, in the last 120 seconds */ |
---|
1570 | uint32_t cancelsToClient; |
---|
1571 | |
---|
1572 | /* how many requests the peer has made that we haven't responded to yet */ |
---|
1573 | int pendingReqsToClient; |
---|
1574 | |
---|
1575 | /* how many requests we've made and are currently awaiting a response for */ |
---|
1576 | int pendingReqsToPeer; |
---|
1577 | } |
---|
1578 | tr_peer_stat; |
---|
1579 | |
---|
1580 | tr_peer_stat * tr_torrentPeers (const tr_torrent * torrent, |
---|
1581 | int * peerCount); |
---|
1582 | |
---|
1583 | void tr_torrentPeersFree (tr_peer_stat * peerStats, |
---|
1584 | int peerCount); |
---|
1585 | |
---|
1586 | /*** |
---|
1587 | **** tr_tracker_stat |
---|
1588 | ***/ |
---|
1589 | |
---|
1590 | typedef enum |
---|
1591 | { |
---|
1592 | /* we won't (announce,scrape) this torrent to this tracker because |
---|
1593 | * the torrent is stopped, or because of an error, or whatever */ |
---|
1594 | TR_TRACKER_INACTIVE = 0, |
---|
1595 | |
---|
1596 | /* we will (announce,scrape) this torrent to this tracker, and are |
---|
1597 | * waiting for enough time to pass to satisfy the tracker's interval */ |
---|
1598 | TR_TRACKER_WAITING = 1, |
---|
1599 | |
---|
1600 | /* it's time to (announce,scrape) this torrent, and we're waiting on a |
---|
1601 | * a free slot to open up in the announce manager */ |
---|
1602 | TR_TRACKER_QUEUED = 2, |
---|
1603 | |
---|
1604 | /* we're (announcing,scraping) this torrent right now */ |
---|
1605 | TR_TRACKER_ACTIVE = 3 |
---|
1606 | } |
---|
1607 | tr_tracker_state; |
---|
1608 | |
---|
1609 | typedef struct |
---|
1610 | { |
---|
1611 | /* how many downloads this tracker knows of (-1 means it does not know) */ |
---|
1612 | int downloadCount; |
---|
1613 | |
---|
1614 | /* whether or not we've ever sent this tracker an announcement */ |
---|
1615 | bool hasAnnounced; |
---|
1616 | |
---|
1617 | /* whether or not we've ever scraped to this tracker */ |
---|
1618 | bool hasScraped; |
---|
1619 | |
---|
1620 | /* human-readable string identifying the tracker */ |
---|
1621 | char host[1024]; |
---|
1622 | |
---|
1623 | /* the full announce URL */ |
---|
1624 | char announce[1024]; |
---|
1625 | |
---|
1626 | /* the full scrape URL */ |
---|
1627 | char scrape[1024]; |
---|
1628 | |
---|
1629 | /* Transmission uses one tracker per tier, |
---|
1630 | * and the others are kept as backups */ |
---|
1631 | bool isBackup; |
---|
1632 | |
---|
1633 | /* is the tracker announcing, waiting, queued, etc */ |
---|
1634 | tr_tracker_state announceState; |
---|
1635 | |
---|
1636 | /* is the tracker scraping, waiting, queued, etc */ |
---|
1637 | tr_tracker_state scrapeState; |
---|
1638 | |
---|
1639 | /* number of peers the tracker told us about last time. |
---|
1640 | * if "lastAnnounceSucceeded" is false, this field is undefined */ |
---|
1641 | int lastAnnouncePeerCount; |
---|
1642 | |
---|
1643 | /* human-readable string with the result of the last announce. |
---|
1644 | if "hasAnnounced" is false, this field is undefined */ |
---|
1645 | char lastAnnounceResult[128]; |
---|
1646 | |
---|
1647 | /* when the last announce was sent to the tracker. |
---|
1648 | * if "hasAnnounced" is false, this field is undefined */ |
---|
1649 | time_t lastAnnounceStartTime; |
---|
1650 | |
---|
1651 | /* whether or not the last announce was a success. |
---|
1652 | if "hasAnnounced" is false, this field is undefined */ |
---|
1653 | bool lastAnnounceSucceeded; |
---|
1654 | |
---|
1655 | /* whether or not the last announce timed out. */ |
---|
1656 | bool lastAnnounceTimedOut; |
---|
1657 | |
---|
1658 | /* when the last announce was completed. |
---|
1659 | if "hasAnnounced" is false, this field is undefined */ |
---|
1660 | time_t lastAnnounceTime; |
---|
1661 | |
---|
1662 | /* human-readable string with the result of the last scrape. |
---|
1663 | * if "hasScraped" is false, this field is undefined */ |
---|
1664 | char lastScrapeResult[128]; |
---|
1665 | |
---|
1666 | /* when the last scrape was sent to the tracker. |
---|
1667 | * if "hasScraped" is false, this field is undefined */ |
---|
1668 | time_t lastScrapeStartTime; |
---|
1669 | |
---|
1670 | /* whether or not the last scrape was a success. |
---|
1671 | if "hasAnnounced" is false, this field is undefined */ |
---|
1672 | bool lastScrapeSucceeded; |
---|
1673 | |
---|
1674 | /* whether or not the last scrape timed out. */ |
---|
1675 | bool lastScrapeTimedOut; |
---|
1676 | |
---|
1677 | /* when the last scrape was completed. |
---|
1678 | if "hasScraped" is false, this field is undefined */ |
---|
1679 | time_t lastScrapeTime; |
---|
1680 | |
---|
1681 | /* number of leechers this tracker knows of (-1 means it does not know) */ |
---|
1682 | int leecherCount; |
---|
1683 | |
---|
1684 | /* when the next periodic announce message will be sent out. |
---|
1685 | if announceState isn't TR_TRACKER_WAITING, this field is undefined */ |
---|
1686 | time_t nextAnnounceTime; |
---|
1687 | |
---|
1688 | /* when the next periodic scrape message will be sent out. |
---|
1689 | if scrapeState isn't TR_TRACKER_WAITING, this field is undefined */ |
---|
1690 | time_t nextScrapeTime; |
---|
1691 | |
---|
1692 | /* number of seeders this tracker knows of (-1 means it does not know) */ |
---|
1693 | int seederCount; |
---|
1694 | |
---|
1695 | /* which tier this tracker is in */ |
---|
1696 | int tier; |
---|
1697 | |
---|
1698 | /* used to match to a tr_tracker_info */ |
---|
1699 | uint32_t id; |
---|
1700 | } |
---|
1701 | tr_tracker_stat; |
---|
1702 | |
---|
1703 | tr_tracker_stat * tr_torrentTrackers (const tr_torrent * torrent, |
---|
1704 | int * setmeTrackerCount); |
---|
1705 | |
---|
1706 | void tr_torrentTrackersFree (tr_tracker_stat * trackerStats, |
---|
1707 | int trackerCount); |
---|
1708 | |
---|
1709 | |
---|
1710 | |
---|
1711 | /** |
---|
1712 | * @brief get the download speeds for each of this torrent's webseed sources. |
---|
1713 | * |
---|
1714 | * @return an array of tor->info.webseedCount floats giving download speeds. |
---|
1715 | * Each speed in the array corresponds to the webseed at the same |
---|
1716 | * array index in tor->info.webseeds. |
---|
1717 | * To differentiate "idle" and "stalled" status, idle webseeds will |
---|
1718 | * return -1 instead of 0 KiB/s. |
---|
1719 | * NOTE: always free this array with tr_free () when you're done with it. |
---|
1720 | */ |
---|
1721 | double* tr_torrentWebSpeeds_KBps (const tr_torrent * torrent); |
---|
1722 | |
---|
1723 | typedef struct tr_file_stat |
---|
1724 | { |
---|
1725 | uint64_t bytesCompleted; |
---|
1726 | float progress; |
---|
1727 | } |
---|
1728 | tr_file_stat; |
---|
1729 | |
---|
1730 | tr_file_stat * tr_torrentFiles (const tr_torrent * torrent, |
---|
1731 | tr_file_index_t * fileCount); |
---|
1732 | |
---|
1733 | void tr_torrentFilesFree (tr_file_stat * files, |
---|
1734 | tr_file_index_t fileCount); |
---|
1735 | |
---|
1736 | |
---|
1737 | /*********************************************************************** |
---|
1738 | * tr_torrentAvailability |
---|
1739 | *********************************************************************** |
---|
1740 | * Use this to draw an advanced progress bar which is 'size' pixels |
---|
1741 | * wide. Fills 'tab' which you must have allocated: each byte is set |
---|
1742 | * to either -1 if we have the piece, otherwise it is set to the number |
---|
1743 | * of connected peers who have the piece. |
---|
1744 | **********************************************************************/ |
---|
1745 | void tr_torrentAvailability (const tr_torrent * torrent, |
---|
1746 | int8_t * tab, |
---|
1747 | int size); |
---|
1748 | |
---|
1749 | void tr_torrentAmountFinished (const tr_torrent * torrent, |
---|
1750 | float * tab, |
---|
1751 | int size); |
---|
1752 | |
---|
1753 | /** |
---|
1754 | * Callback function invoked when a torrent finishes being verified. |
---|
1755 | * |
---|
1756 | * @param torrent the torrent that was verified |
---|
1757 | * @param aborted true if the verify ended prematurely for some reason, |
---|
1758 | * such as tr_torrentStop() or tr_torrentSetLocation() |
---|
1759 | * being called during verification. |
---|
1760 | * @param callback_data the user-defined pointer from tr_torrentVerify() |
---|
1761 | */ |
---|
1762 | typedef void (*tr_verify_done_func)(tr_torrent * torrent, |
---|
1763 | bool aborted, |
---|
1764 | void * user_data); |
---|
1765 | |
---|
1766 | /** |
---|
1767 | * Queue a torrent for verification. |
---|
1768 | * |
---|
1769 | * If callback_func is non-NULL, it will be called from the libtransmission |
---|
1770 | * thread after the torrent's completness state is updated after the |
---|
1771 | * file verification pass. |
---|
1772 | */ |
---|
1773 | void tr_torrentVerify (tr_torrent * torrent, |
---|
1774 | tr_verify_done_func callback_func_or_NULL, |
---|
1775 | void * callback_data_or_NULL); |
---|
1776 | |
---|
1777 | /*********************************************************************** |
---|
1778 | * tr_info |
---|
1779 | **********************************************************************/ |
---|
1780 | |
---|
1781 | /** @brief a part of tr_info that represents a single file of the torrent's content */ |
---|
1782 | typedef struct tr_file |
---|
1783 | { |
---|
1784 | uint64_t length; /* Length of the file, in bytes */ |
---|
1785 | char * name; /* Path to the file */ |
---|
1786 | int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ |
---|
1787 | int8_t dnd; /* "do not download" flag */ |
---|
1788 | int8_t is_renamed; /* true if we're using a different path from the one in the metainfo; ie, if the user has renamed it */ |
---|
1789 | tr_piece_index_t firstPiece; /* We need pieces [firstPiece... */ |
---|
1790 | tr_piece_index_t lastPiece; /* ...lastPiece] to dl this file */ |
---|
1791 | uint64_t offset; /* file begins at the torrent's nth byte */ |
---|
1792 | } |
---|
1793 | tr_file; |
---|
1794 | |
---|
1795 | /** @brief a part of tr_info that represents a single piece of the torrent's content */ |
---|
1796 | typedef struct tr_piece |
---|
1797 | { |
---|
1798 | time_t timeChecked; /* the last time we tested this piece */ |
---|
1799 | uint8_t hash[SHA_DIGEST_LENGTH]; /* pieces hash */ |
---|
1800 | int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ |
---|
1801 | int8_t dnd; /* "do not download" flag */ |
---|
1802 | } |
---|
1803 | tr_piece; |
---|
1804 | |
---|
1805 | /** @brief information about a torrent that comes from its metainfo file */ |
---|
1806 | struct tr_info |
---|
1807 | { |
---|
1808 | /* total size of the torrent, in bytes */ |
---|
1809 | uint64_t totalSize; |
---|
1810 | |
---|
1811 | /* The original name that came in this torrent's metainfo. |
---|
1812 | * CLIENT CODE: NOT USE THIS FIELD. */ |
---|
1813 | char * originalName; |
---|
1814 | |
---|
1815 | /* The torrent's name. */ |
---|
1816 | char * name; |
---|
1817 | |
---|
1818 | /* Path to torrent Transmission's internal copy of the .torrent file. */ |
---|
1819 | char * torrent; |
---|
1820 | |
---|
1821 | char ** webseeds; |
---|
1822 | |
---|
1823 | char * comment; |
---|
1824 | char * creator; |
---|
1825 | tr_file * files; |
---|
1826 | tr_piece * pieces; |
---|
1827 | |
---|
1828 | /* these trackers are sorted by tier */ |
---|
1829 | tr_tracker_info * trackers; |
---|
1830 | |
---|
1831 | /* Torrent info */ |
---|
1832 | time_t dateCreated; |
---|
1833 | |
---|
1834 | unsigned int trackerCount; |
---|
1835 | unsigned int webseedCount; |
---|
1836 | tr_file_index_t fileCount; |
---|
1837 | uint32_t pieceSize; |
---|
1838 | tr_piece_index_t pieceCount; |
---|
1839 | |
---|
1840 | /* General info */ |
---|
1841 | uint8_t hash[SHA_DIGEST_LENGTH]; |
---|
1842 | char hashString[2 * SHA_DIGEST_LENGTH + 1]; |
---|
1843 | |
---|
1844 | /* Flags */ |
---|
1845 | bool isPrivate; |
---|
1846 | bool isFolder; |
---|
1847 | }; |
---|
1848 | |
---|
1849 | static inline bool tr_torrentHasMetadata (const tr_torrent * tor) |
---|
1850 | { |
---|
1851 | return tr_torrentInfo (tor)->fileCount > 0; |
---|
1852 | } |
---|
1853 | |
---|
1854 | /** |
---|
1855 | * What the torrent is doing right now. |
---|
1856 | * |
---|
1857 | * Note: these values will become a straight enum at some point in the future. |
---|
1858 | * Do not rely on their current `bitfield' implementation |
---|
1859 | */ |
---|
1860 | typedef enum |
---|
1861 | { |
---|
1862 | TR_STATUS_STOPPED = 0, /* Torrent is stopped */ |
---|
1863 | TR_STATUS_CHECK_WAIT = 1, /* Queued to check files */ |
---|
1864 | TR_STATUS_CHECK = 2, /* Checking files */ |
---|
1865 | TR_STATUS_DOWNLOAD_WAIT = 3, /* Queued to download */ |
---|
1866 | TR_STATUS_DOWNLOAD = 4, /* Downloading */ |
---|
1867 | TR_STATUS_SEED_WAIT = 5, /* Queued to seed */ |
---|
1868 | TR_STATUS_SEED = 6 /* Seeding */ |
---|
1869 | } |
---|
1870 | tr_torrent_activity; |
---|
1871 | |
---|
1872 | enum |
---|
1873 | { |
---|
1874 | TR_PEER_FROM_INCOMING = 0, /* connections made to the listening port */ |
---|
1875 | TR_PEER_FROM_LPD, /* peers found by local announcements */ |
---|
1876 | TR_PEER_FROM_TRACKER, /* peers found from a tracker */ |
---|
1877 | TR_PEER_FROM_DHT, /* peers found from the DHT */ |
---|
1878 | TR_PEER_FROM_PEX, /* peers found from PEX */ |
---|
1879 | TR_PEER_FROM_RESUME, /* peers found in the .resume file */ |
---|
1880 | TR_PEER_FROM_LTEP, /* peer address provided in an LTEP handshake */ |
---|
1881 | TR_PEER_FROM__MAX |
---|
1882 | }; |
---|
1883 | |
---|
1884 | typedef enum |
---|
1885 | { |
---|
1886 | /* everything's fine */ |
---|
1887 | TR_STAT_OK = 0, |
---|
1888 | |
---|
1889 | /* when we anounced to the tracker, we got a warning in the response */ |
---|
1890 | TR_STAT_TRACKER_WARNING = 1, |
---|
1891 | |
---|
1892 | /* when we anounced to the tracker, we got an error in the response */ |
---|
1893 | TR_STAT_TRACKER_ERROR = 2, |
---|
1894 | |
---|
1895 | /* local trouble, such as disk full or permissions error */ |
---|
1896 | TR_STAT_LOCAL_ERROR = 3 |
---|
1897 | } |
---|
1898 | tr_stat_errtype; |
---|
1899 | |
---|
1900 | /** @brief Used by tr_torrentStat () to tell clients about a torrent's state and statistics */ |
---|
1901 | typedef struct tr_stat |
---|
1902 | { |
---|
1903 | /** The torrent's unique Id. |
---|
1904 | @see tr_torrentId () */ |
---|
1905 | int id; |
---|
1906 | |
---|
1907 | /** What is this torrent doing right now? */ |
---|
1908 | tr_torrent_activity activity; |
---|
1909 | |
---|
1910 | /** Defines what kind of text is in errorString. |
---|
1911 | @see errorString */ |
---|
1912 | tr_stat_errtype error; |
---|
1913 | |
---|
1914 | /** A warning or error message regarding the torrent. |
---|
1915 | @see error */ |
---|
1916 | char errorString[512]; |
---|
1917 | |
---|
1918 | /** When tr_stat.activity is TR_STATUS_CHECK or TR_STATUS_CHECK_WAIT, |
---|
1919 | this is the percentage of how much of the files has been |
---|
1920 | verified. When it gets to 1, the verify process is done. |
---|
1921 | Range is [0..1] |
---|
1922 | @see tr_stat.activity */ |
---|
1923 | float recheckProgress; |
---|
1924 | |
---|
1925 | /** How much has been downloaded of the entire torrent. |
---|
1926 | Range is [0..1] */ |
---|
1927 | float percentComplete; |
---|
1928 | |
---|
1929 | /** How much of the metadata the torrent has. |
---|
1930 | For torrents added from a .torrent this will always be 1. |
---|
1931 | For magnet links, this number will from from 0 to 1 as the metadata is downloaded. |
---|
1932 | Range is [0..1] */ |
---|
1933 | float metadataPercentComplete; |
---|
1934 | |
---|
1935 | /** How much has been downloaded of the files the user wants. This differs |
---|
1936 | from percentComplete if the user wants only some of the torrent's files. |
---|
1937 | Range is [0..1] |
---|
1938 | @see tr_stat.leftUntilDone */ |
---|
1939 | float percentDone; |
---|
1940 | |
---|
1941 | /** How much has been uploaded to satisfy the seed ratio. |
---|
1942 | This is 1 if the ratio is reached or the torrent is set to seed forever. |
---|
1943 | Range is [0..1] */ |
---|
1944 | float seedRatioPercentDone; |
---|
1945 | |
---|
1946 | /** Speed all data being sent for this torrent. |
---|
1947 | This includes piece data, protocol messages, and TCP overhead */ |
---|
1948 | float rawUploadSpeed_KBps; |
---|
1949 | |
---|
1950 | /** Speed all data being received for this torrent. |
---|
1951 | This includes piece data, protocol messages, and TCP overhead */ |
---|
1952 | float rawDownloadSpeed_KBps; |
---|
1953 | |
---|
1954 | /** Speed all piece being sent for this torrent. |
---|
1955 | This ONLY counts piece data. */ |
---|
1956 | float pieceUploadSpeed_KBps; |
---|
1957 | |
---|
1958 | /** Speed all piece being received for this torrent. |
---|
1959 | This ONLY counts piece data. */ |
---|
1960 | float pieceDownloadSpeed_KBps; |
---|
1961 | |
---|
1962 | #define TR_ETA_NOT_AVAIL -1 |
---|
1963 | #define TR_ETA_UNKNOWN -2 |
---|
1964 | /** If downloading, estimated number of seconds left until the torrent is done. |
---|
1965 | If seeding, estimated number of seconds left until seed ratio is reached. */ |
---|
1966 | int eta; |
---|
1967 | /** If seeding, number of seconds left until the idle time limit is reached. */ |
---|
1968 | int etaIdle; |
---|
1969 | |
---|
1970 | /** Number of peers that we're connected to */ |
---|
1971 | int peersConnected; |
---|
1972 | |
---|
1973 | /** How many peers we found out about from the tracker, or from pex, |
---|
1974 | or from incoming connections, or from our resume file. */ |
---|
1975 | int peersFrom[TR_PEER_FROM__MAX]; |
---|
1976 | |
---|
1977 | /** Number of peers that are sending data to us. */ |
---|
1978 | int peersSendingToUs; |
---|
1979 | |
---|
1980 | /** Number of peers that we're sending data to */ |
---|
1981 | int peersGettingFromUs; |
---|
1982 | |
---|
1983 | /** Number of webseeds that are sending data to us. */ |
---|
1984 | int webseedsSendingToUs; |
---|
1985 | |
---|
1986 | /** Byte count of all the piece data we'll have downloaded when we're done, |
---|
1987 | whether or not we have it yet. This may be less than tr_info.totalSize |
---|
1988 | if only some of the torrent's files are wanted. |
---|
1989 | [0...tr_info.totalSize] */ |
---|
1990 | uint64_t sizeWhenDone; |
---|
1991 | |
---|
1992 | /** Byte count of how much data is left to be downloaded until we've got |
---|
1993 | all the pieces that we want. [0...tr_info.sizeWhenDone] */ |
---|
1994 | uint64_t leftUntilDone; |
---|
1995 | |
---|
1996 | /** Byte count of all the piece data we want and don't have yet, |
---|
1997 | but that a connected peer does have. [0...leftUntilDone] */ |
---|
1998 | uint64_t desiredAvailable; |
---|
1999 | |
---|
2000 | /** Byte count of all the corrupt data you've ever downloaded for |
---|
2001 | this torrent. If you're on a poisoned torrent, this number can |
---|
2002 | grow very large. */ |
---|
2003 | uint64_t corruptEver; |
---|
2004 | |
---|
2005 | /** Byte count of all data you've ever uploaded for this torrent. */ |
---|
2006 | uint64_t uploadedEver; |
---|
2007 | |
---|
2008 | /** Byte count of all the non-corrupt data you've ever downloaded |
---|
2009 | for this torrent. If you deleted the files and downloaded a second |
---|
2010 | time, this will be 2*totalSize.. */ |
---|
2011 | uint64_t downloadedEver; |
---|
2012 | |
---|
2013 | /** Byte count of all the checksum-verified data we have for this torrent. |
---|
2014 | */ |
---|
2015 | uint64_t haveValid; |
---|
2016 | |
---|
2017 | /** Byte count of all the partial piece data we have for this torrent. |
---|
2018 | As pieces become complete, this value may decrease as portions of it |
---|
2019 | are moved to `corrupt' or `haveValid'. */ |
---|
2020 | uint64_t haveUnchecked; |
---|
2021 | |
---|
2022 | /** time when one or more of the torrent's trackers will |
---|
2023 | allow you to manually ask for more peers, |
---|
2024 | or 0 if you can't */ |
---|
2025 | time_t manualAnnounceTime; |
---|
2026 | |
---|
2027 | #define TR_RATIO_NA -1 |
---|
2028 | #define TR_RATIO_INF -2 |
---|
2029 | /** TR_RATIO_INF, TR_RATIO_NA, or a regular ratio */ |
---|
2030 | float ratio; |
---|
2031 | |
---|
2032 | /** When the torrent was first added. */ |
---|
2033 | time_t addedDate; |
---|
2034 | |
---|
2035 | /** When the torrent finished downloading. */ |
---|
2036 | time_t doneDate; |
---|
2037 | |
---|
2038 | /** When the torrent was last started. */ |
---|
2039 | time_t startDate; |
---|
2040 | |
---|
2041 | /** The last time we uploaded or downloaded piece data on this torrent. */ |
---|
2042 | time_t activityDate; |
---|
2043 | |
---|
2044 | /** Number of seconds since the last activity (or since started). |
---|
2045 | -1 if activity is not seeding or downloading. */ |
---|
2046 | int idleSecs; |
---|
2047 | |
---|
2048 | /** Cumulative seconds the torrent's ever spent downloading */ |
---|
2049 | int secondsDownloading; |
---|
2050 | |
---|
2051 | /** Cumulative seconds the torrent's ever spent seeding */ |
---|
2052 | int secondsSeeding; |
---|
2053 | |
---|
2054 | /** A torrent is considered finished if it has met its seed ratio. |
---|
2055 | As a result, only paused torrents can be finished. */ |
---|
2056 | bool finished; |
---|
2057 | |
---|
2058 | /** This torrent's queue position. |
---|
2059 | All torrents have a queue position, even if it's not queued. */ |
---|
2060 | int queuePosition; |
---|
2061 | |
---|
2062 | /** True if the torrent is running, but has been idle for long enough |
---|
2063 | to be considered stalled. @see tr_sessionGetQueueStalledMinutes () */ |
---|
2064 | bool isStalled; |
---|
2065 | } |
---|
2066 | tr_stat; |
---|
2067 | |
---|
2068 | /** Return a pointer to an tr_stat structure with updated information |
---|
2069 | on the torrent. This is typically called by the GUI clients every |
---|
2070 | second or so to get a new snapshot of the torrent's status. */ |
---|
2071 | const tr_stat * tr_torrentStat (tr_torrent * torrent); |
---|
2072 | |
---|
2073 | /** Like tr_torrentStat (), but only recalculates the statistics if it's |
---|
2074 | been longer than a second since they were last calculated. This can |
---|
2075 | reduce the CPU load if you're calling tr_torrentStat () frequently. */ |
---|
2076 | const tr_stat * tr_torrentStatCached (tr_torrent * torrent); |
---|
2077 | |
---|
2078 | /** @deprecated */ |
---|
2079 | void tr_torrentSetAddedDate (tr_torrent * torrent, |
---|
2080 | time_t addedDate); |
---|
2081 | |
---|
2082 | /** @deprecated */ |
---|
2083 | void tr_torrentSetActivityDate (tr_torrent * torrent, |
---|
2084 | time_t activityDate); |
---|
2085 | |
---|
2086 | /** @deprecated */ |
---|
2087 | void tr_torrentSetDoneDate (tr_torrent * torrent, time_t doneDate); |
---|
2088 | |
---|
2089 | /** @} */ |
---|
2090 | |
---|
2091 | /** @brief Sanity checker to test that the direction is TR_UP or TR_DOWN */ |
---|
2092 | static inline bool tr_isDirection (tr_direction d) { return d==TR_UP || d==TR_DOWN; } |
---|
2093 | |
---|
2094 | /** @brief Sanity checker to test that a bool is true or false */ |
---|
2095 | static inline bool tr_isBool (bool b) { return b==1 || b==0; } |
---|
2096 | |
---|
2097 | #ifdef __cplusplus |
---|
2098 | } |
---|
2099 | #endif |
---|
2100 | |
---|
2101 | #endif |
---|