source: trunk/libtransmission/transmission.h @ 14383

Last change on this file since 14383 was 14383, checked in by mikedld, 8 years ago

Don't mess with MinGW printf support for now (tricky)

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