source: trunk/libtransmission/transmission.h @ 14587

Last change on this file since 14587 was 14587, checked in by mikedld, 7 years ago

Use tr_sys_path_remove instead of remove

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