source: trunk/libtransmission/transmission.h @ 13807

Last change on this file since 13807 was 13807, checked in by jordan, 8 years ago

(trunk) #1220 'change top folder names' -- added support for this in libtransmission's C and RPC APIs.

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