source: trunk/libtransmission/transmission.h @ 14077

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

(trunk, libT) #4682 'Add return id from duplicate torrent torrent-add rpc' -- added.

  • Property svn:keywords set to Date Rev Author Id
File size: 70.0 KB
Line 
1/******************************************************************************
2 * $Id: transmission.h 14077 2013-05-22 20:35:38Z 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 specified directory.
295 * @return zero or positive integer on success, -1 in case of error.
296 */
297int64_t tr_sessionGetDirFreeSpace (tr_session * session, const char * dir);
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_LOG_ERROR    = 1,
805  TR_LOG_INFO     = 2,
806  TR_LOG_DEBUG    = 3,
807  TR_LOG_FIREHOSE = 4
808}
809tr_log_level;
810
811void tr_logSetLevel (tr_log_level);
812
813typedef struct tr_log_message
814{
815  /* TR_LOG_ERROR, TR_LOG_INFO, or TR_LOG_DEBUG */
816  tr_log_level level;
817
818  /* The line number in the source file where this message originated */
819  int line;
820
821  /* Time the message was generated */
822  time_t when;
823
824  /* The torrent associated with this message,
825   * or a module name such as "Port Forwarding" for non-torrent messages,
826   * or NULL. */
827  char * name;
828
829  /* The message */
830  char *  message;
831
832  /* The source file where this message originated */
833  const char * file;
834
835  /* linked list of messages */
836  struct tr_log_message * next;
837}
838tr_log_message;
839
840tr_log_message * tr_logGetQueue        (void);
841bool             tr_logGetQueueEnabled (void);
842void             tr_logSetQueueEnabled (bool isEnabled);
843void             tr_logFreeQueue       (tr_log_message * freeme);
844
845/** @addtogroup Blocklists
846    @{ */
847
848/**
849 * Specify a range of IPs for Transmission to block.
850 *
851 * Filename must be an uncompressed ascii file.
852 *
853 * libtransmission does not keep a handle to `filename'
854 * after this call returns, so the caller is free to
855 * keep or delete `filename' as it wishes.
856 * libtransmission makes its own copy of the file
857 * massaged into a binary format easier to search.
858 *
859 * The caller only needs to invoke this when the blocklist
860 * has changed.
861 *
862 * Passing NULL for a filename will clear the blocklist.
863 */
864int     tr_blocklistSetContent (tr_session       * session,
865                                   const char       * filename);
866
867int     tr_blocklistGetRuleCount (const tr_session * session);
868
869bool    tr_blocklistExists     (const tr_session * session);
870
871bool    tr_blocklistIsEnabled  (const tr_session * session);
872
873void    tr_blocklistSetEnabled (tr_session       * session,
874                                   bool               isEnabled);
875
876/** @brief The blocklist that ges updated when an RPC client
877           invokes the "blocklist-update" method */
878void tr_blocklistSetURL       (tr_session *, const char * url);
879
880const char * tr_blocklistGetURL (const tr_session *);
881
882/** @brief the file in the $config/blocklists/ directory that's
883           used by tr_blocklistSetContent () and "blocklist-update" */
884#define DEFAULT_BLOCKLIST_FILENAME "blocklist.bin"
885
886/** @} */
887
888
889/** @addtogroup tr_ctor Torrent Constructors
890    @{
891
892    Instantiating a tr_torrent had gotten more complicated as features were
893    added. At one point there were four functions to check metainfo and five
894    to create a tr_torrent object.
895
896    To remedy this, a Torrent Constructor (struct tr_ctor) has been introduced:
897    - Simplifies the API to two functions: tr_torrentParse () and tr_torrentNew ()
898    - You can set the fields you want; the system sets defaults for the rest.
899    - You can specify whether or not your fields should supercede resume's.
900    - We can add new features to tr_ctor without breaking tr_torrentNew ()'s API.
901
902    All the tr_ctor{Get,Set}* () functions with a return value return
903    an error number, or zero if no error occurred.
904
905    You must call one of the SetMetainfo () functions before creating
906    a torrent with a tr_ctor. The other functions are optional.
907
908    You can reuse a single tr_ctor to create a batch of torrents --
909    just call one of the SetMetainfo () functions between each
910    tr_torrentNew () call.
911
912    Every call to tr_ctorSetMetainfo* () frees the previous metainfo.
913 */
914
915typedef enum
916{
917    TR_FALLBACK, /* indicates the ctor value should be used only
918                    in case of missing resume settings */
919
920    TR_FORCE, /* indicates the ctor value should be used
921                 regardless of what's in the resume settings */
922}
923tr_ctorMode;
924
925/** @brief Create a torrent constructor object used to instantiate a tr_torrent
926    @param session the tr_session. This is required if you're going to call
927                   tr_torrentNew (), but you can use NULL for tr_torrentParse ().
928    @see tr_torrentNew (), tr_torrentParse () */
929tr_ctor* tr_ctorNew (const tr_session * session_or_NULL);
930
931/** @brief Free a torrent constructor object */
932void  tr_ctorFree (tr_ctor * ctor);
933
934/** @brief Set whether or not to delete the source .torrent file
935           when the torrent is added. (Default: False) */
936void  tr_ctorSetDeleteSource (tr_ctor * ctor, bool doDelete);
937
938/** @brief Set the constructor's metainfo from a magnet link */
939int tr_ctorSetMetainfoFromMagnetLink (tr_ctor * ctor, const char * magnet);
940
941/** @brief Set the constructor's metainfo from a raw benc already in memory */
942int tr_ctorSetMetainfo (tr_ctor * ctor, const uint8_t * metainfo, size_t len);
943
944/** @brief Set the constructor's metainfo from a local .torrent file */
945int tr_ctorSetMetainfoFromFile (tr_ctor * ctor, const char * filename);
946
947/**
948 * @brief Set the metainfo from an existing file in tr_getTorrentDir ().
949 *
950 * This is used by the Mac client on startup to pick and choose which
951 * torrents to load
952 */
953int tr_ctorSetMetainfoFromHash (tr_ctor * ctor, const char * hashString);
954
955/** @brief Set how many peers this torrent can connect to. (Default: 50) */
956void tr_ctorSetPeerLimit (tr_ctor * ctor, tr_ctorMode mode, uint16_t limit);
957
958/** @brief Set the download folder for the torrent being added with this ctor.
959    @see tr_ctorSetDownloadDir ()
960    @see tr_sessionInit () */
961void  tr_ctorSetDownloadDir (tr_ctor      * ctor,
962                             tr_ctorMode    mode,
963                             const char   * directory);
964
965/**
966 * @brief Set the incompleteDir for this torrent.
967 *
968 * This is not a supported API call.
969 * It only exists so the mac client can migrate
970 * its older incompleteDir settings, and that's
971 * the only place where it should be used.
972 */
973void tr_ctorSetIncompleteDir (tr_ctor * ctor, const char * directory);
974
975/** Set whether or not the torrent begins downloading/seeding when created.
976  (Default: not paused) */
977void        tr_ctorSetPaused (tr_ctor      * ctor,
978                              tr_ctorMode    mode,
979                              bool           isPaused);
980
981/** @brief Set the priorities for files in a torrent */
982void        tr_ctorSetFilePriorities (tr_ctor                * ctor,
983                                      const tr_file_index_t  * files,
984                                      tr_file_index_t          fileCount,
985                                      tr_priority_t            priority);
986
987/** @brief Set the download flag for files in a torrent */
988void        tr_ctorSetFilesWanted (tr_ctor                * ctor,
989                                   const tr_file_index_t  * fileIndices,
990                                   tr_file_index_t          fileCount,
991                                   bool                     wanted);
992
993
994/** @brief Get this peer constructor's peer limit */
995int         tr_ctorGetPeerLimit (const tr_ctor * ctor,
996                                 tr_ctorMode     mode,
997                                 uint16_t *      setmeCount);
998
999/** @brief Get the "isPaused" flag from this peer constructor */
1000int         tr_ctorGetPaused (const tr_ctor * ctor,
1001                              tr_ctorMode     mode,
1002                              bool          * setmeIsPaused);
1003
1004/** @brief Get the download path from this peer constructor */
1005int         tr_ctorGetDownloadDir (const tr_ctor  * ctor,
1006                                   tr_ctorMode      mode,
1007                                   const char    ** setmeDownloadDir);
1008
1009/** @brief Get the incomplete directory from this peer constructor */
1010int         tr_ctorGetIncompleteDir (const tr_ctor  * ctor,
1011                                     const char    ** setmeIncompleteDir);
1012
1013/** @brief Get the metainfo from this peer constructor */
1014int         tr_ctorGetMetainfo (const tr_ctor            * ctor,
1015                                const struct tr_variant ** setme);
1016
1017/** @brief Get the "delete .torrent file" flag from this peer constructor */
1018int         tr_ctorGetDeleteSource (const tr_ctor  * ctor,
1019                                    bool           * setmeDoDelete);
1020
1021/** @brief Get the tr_session poiner from this peer constructor */
1022tr_session* tr_ctorGetSession (const tr_ctor * ctor);
1023
1024/** @brief Get the .torrent file that this ctor's metainfo came from,
1025           or NULL if tr_ctorSetMetainfoFromFile () wasn't used */
1026const char* tr_ctorGetSourceFile (const tr_ctor * ctor);
1027
1028typedef enum
1029{
1030    TR_PARSE_OK,
1031    TR_PARSE_ERR,
1032    TR_PARSE_DUPLICATE
1033}
1034tr_parse_result;
1035
1036/**
1037 * @brief Parses the specified metainfo
1038 *
1039 * @return TR_PARSE_ERR if parsing failed;
1040 *         TR_PARSE_OK if parsing succeeded and it's not a duplicate;
1041 *         TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate.
1042 *
1043 * @param setme_info If parsing is successful and setme_info is non-NULL,
1044 *                   the parsed metainfo is stored there and sould be freed
1045 *                   by calling tr_metainfoFree () when no longer needed.
1046 *
1047 * Notes:
1048 *
1049 * 1. tr_torrentParse () won't be able to check for duplicates -- and therefore
1050 *    won't return TR_PARSE_DUPLICATE -- unless ctor's "download-dir" and
1051 *    session variable is set.
1052 *
1053 * 2. setme_info->torrent's value can't be set unless ctor's session variable
1054 *    is set.
1055 */
1056tr_parse_result  tr_torrentParse (const tr_ctor  * ctor,
1057                                  tr_info        * setme_info_or_NULL);
1058
1059/** @brief free a metainfo
1060    @see tr_torrentParse */
1061void tr_metainfoFree (tr_info * inf);
1062
1063
1064/**
1065 * Instantiate a single torrent.
1066 *
1067 * Returns a pointer to the torrent on success, or NULL on failure.
1068 *
1069 * @param setme_error: TR_PARSE_ERR if the parsing failed;
1070 *                     TR_PARSE_OK if parsing succeeded and it's not a duplicate;
1071 *                     TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate.
1072 *
1073 * @param setme_duplicate_id: when setmeError is TR_PARSE_DUPLICATE,
1074 *                            this field is set to the duplicate torrent's id.
1075 */
1076tr_torrent * tr_torrentNew (const tr_ctor   * ctor,
1077                            int             * setme_error,
1078                            int             * setme_duplicate_id);
1079
1080/** @} */
1081
1082/***********************************************************************
1083 ***
1084 ***  TORRENTS
1085 **/
1086
1087/** @addtogroup tr_torrent Torrents
1088    @{ */
1089
1090typedef int tr_fileFunc (const char * filename);
1091
1092/** @brief Removes our .torrent and .resume files for this torrent */
1093void tr_torrentRemove (tr_torrent  * torrent,
1094                       bool          removeLocalData,
1095                       tr_fileFunc   removeFunc);
1096
1097/** @brief Start a torrent */
1098void tr_torrentStart (tr_torrent * torrent);
1099
1100/** @brief Stop (pause) a torrent */
1101void tr_torrentStop (tr_torrent * torrent);
1102
1103
1104typedef void (tr_torrent_rename_done_func)(tr_torrent  * torrent,
1105                                           const char  * oldpath,
1106                                           const char  * newname,
1107                                           int           error,
1108                                           void        * user_data);
1109
1110/**
1111 * @brief Rename a file or directory in a torrent.
1112 *
1113 * @tor: the torrent whose path will be renamed.
1114 * @oldpath: the path to the file or folder that will be renamed
1115 * @newname: the file or folder's new name
1116 * @callback: the callback invoked when the renaming finishes, or NULL
1117 * @callback_data: the pointer to pass in the callback's user_data arg
1118 *
1119 * As a special case, renaming the root file in a torrent will also
1120 * update tr_info.name.
1121 *
1122 * EXAMPLES
1123 *
1124 *   Consider a tr_torrent where its
1125 *   info.files[0].name is "frobnitz-linux/checksum" and
1126 *   info.files[1].name is "frobnitz-linux/frobnitz.iso".
1127 *
1128 *   1. tr_torrentRenamePath (tor, "frobnitz-linux", "foo") will rename
1129 *      the "frotbnitz-linux" folder as "foo", and update both info.name
1130 *      and info.files[*].name.
1131 *
1132 *   2. tr_torrentRenamePath (tor, "frobnitz-linux/checksum", "foo") will
1133 *      rename the "frobnitz-linux/checksum" file as "foo" and update
1134 *      files[0].name to "frobnitz-linux/foo".
1135 *
1136 * RETURN
1137 *
1138 *   Changing tr_info's contents requires a session lock, so this function
1139 *   returns asynchronously to avoid blocking. If you don't want to be notified
1140 *   when the function has finished, you can pass NULL as the callback arg.
1141 *
1142 *   On success, the callback's error argument will be 0.
1143 *
1144 *   If oldpath can't be found in files[*].name, or if newname is already
1145 *   in files[*].name, or contains a directory separator, or is NULL, "",
1146 *   ".", or "..", the error argument will be EINVAL.
1147 *
1148 *   If the path exists on disk but can't be renamed, the error argument
1149 *   will be the errno set by rename().
1150 */
1151void tr_torrentRenamePath (tr_torrent                  * tor,
1152                           const char                  * oldpath,
1153                           const char                  * newname,
1154                           tr_torrent_rename_done_func   callback,
1155                           void                        * callback_user_data);
1156
1157enum
1158{
1159    TR_LOC_MOVING,
1160    TR_LOC_DONE,
1161    TR_LOC_ERROR
1162};
1163
1164/**
1165 * @brief Tell transmsision where to find this torrent's local data.
1166 *
1167 * if move_from_previous_location is `true', the torrent's incompleteDir
1168 * will be clobberred s.t. additional files being added will be saved
1169 * to the torrent's downloadDir.
1170 */
1171void tr_torrentSetLocation (tr_torrent       * torrent,
1172                            const char       * location,
1173                            bool               move_from_previous_location,
1174                            volatile double  * setme_progress,
1175                            volatile int     * setme_state);
1176
1177uint64_t tr_torrentGetBytesLeftToAllocate (const tr_torrent * torrent);
1178
1179/**
1180 * @brief Returns this torrent's unique ID.
1181 *
1182 * IDs are good as simple lookup keys, but are not persistent
1183 * between sessions. If you need that, use tr_info.hash or
1184 * tr_info.hashString.
1185 */
1186int tr_torrentId (const tr_torrent * torrent);
1187
1188tr_torrent* tr_torrentFindFromId (tr_session * session, int id);
1189
1190tr_torrent* tr_torrentFindFromHash (tr_session     * session,
1191                                    const uint8_t  * hash);
1192
1193/** @brief Convenience function similar to tr_torrentFindFromHash () */
1194tr_torrent* tr_torrentFindFromMagnetLink (tr_session * session,
1195                                          const char * link);
1196
1197/**
1198 * @return this torrent's name.
1199 */
1200const char* tr_torrentName (const tr_torrent *);
1201
1202/**
1203 * @brief find the location of a torrent's file by looking with and without
1204 *        the ".part" suffix, looking in downloadDir and incompleteDir, etc.
1205 * @return a newly-allocated string (that must be tr_freed () by the caller
1206 *         when done) that gives the location of this file on disk,
1207 *         or NULL if no file exists yet.
1208 * @param tor the torrent whose file we're looking for
1209 * @param fileNum the fileIndex, in [0...tr_info.fileCount)
1210 */
1211char* tr_torrentFindFile (const tr_torrent * tor, tr_file_index_t fileNo);
1212
1213
1214/***
1215****  Torrent speed limits
1216****
1217***/
1218
1219void         tr_torrentSetSpeedLimit_KBps (tr_torrent *, tr_direction, unsigned int KBps);
1220unsigned int tr_torrentGetSpeedLimit_KBps (const tr_torrent *, tr_direction);
1221
1222void         tr_torrentUseSpeedLimit      (tr_torrent *, tr_direction, bool);
1223bool         tr_torrentUsesSpeedLimit     (const tr_torrent *, tr_direction);
1224
1225void         tr_torrentUseSessionLimits   (tr_torrent *, bool);
1226bool         tr_torrentUsesSessionLimits  (const tr_torrent *);
1227
1228
1229/****
1230*****  Ratio Limits
1231****/
1232
1233typedef enum
1234{
1235    /* follow the global settings */
1236    TR_RATIOLIMIT_GLOBAL    = 0,
1237
1238    /* override the global settings, seeding until a certain ratio */
1239    TR_RATIOLIMIT_SINGLE    = 1,
1240
1241    /* override the global settings, seeding regardless of ratio */
1242    TR_RATIOLIMIT_UNLIMITED = 2
1243}
1244tr_ratiolimit;
1245
1246void          tr_torrentSetRatioMode (tr_torrent         * tor,
1247                                      tr_ratiolimit        mode);
1248
1249tr_ratiolimit tr_torrentGetRatioMode (const tr_torrent   * tor);
1250
1251void          tr_torrentSetRatioLimit (tr_torrent        * tor,
1252                                       double              ratio);
1253
1254double        tr_torrentGetRatioLimit (const tr_torrent  * tor);
1255
1256
1257bool          tr_torrentGetSeedRatio  (const tr_torrent *, double * ratio);
1258
1259
1260/****
1261*****  Idle Time Limits
1262****/
1263
1264typedef enum
1265{
1266    /* follow the global settings */
1267    TR_IDLELIMIT_GLOBAL    = 0,
1268
1269    /* override the global settings, seeding until a certain idle time */
1270    TR_IDLELIMIT_SINGLE    = 1,
1271
1272    /* override the global settings, seeding regardless of activity */
1273    TR_IDLELIMIT_UNLIMITED = 2
1274}
1275tr_idlelimit;
1276
1277void          tr_torrentSetIdleMode (tr_torrent         * tor,
1278                                      tr_idlelimit         mode);
1279
1280tr_idlelimit  tr_torrentGetIdleMode (const tr_torrent   * tor);
1281
1282void          tr_torrentSetIdleLimit (tr_torrent         * tor,
1283                                      uint16_t             idleMinutes);
1284
1285uint16_t      tr_torrentGetIdleLimit (const tr_torrent   * tor);
1286
1287
1288bool          tr_torrentGetSeedIdle (const tr_torrent *, uint16_t * minutes);
1289
1290/****
1291*****  Peer Limits
1292****/
1293
1294void          tr_torrentSetPeerLimit (tr_torrent * tor, uint16_t peerLimit);
1295
1296uint16_t      tr_torrentGetPeerLimit (const tr_torrent * tor);
1297
1298/****
1299*****  File Priorities
1300****/
1301
1302enum
1303{
1304    TR_PRI_LOW    = -1,
1305    TR_PRI_NORMAL =  0, /* since NORMAL is 0, memset initializes nicely */
1306    TR_PRI_HIGH   =  1
1307};
1308
1309/**
1310 * @brief Set a batch of files to a particular priority.
1311 *
1312 * @param priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW
1313 */
1314void tr_torrentSetFilePriorities (tr_torrent             * torrent,
1315                                  const tr_file_index_t  * files,
1316                                  tr_file_index_t          fileCount,
1317                                  tr_priority_t            priority);
1318
1319/**
1320 * @brief Get this torrent's file priorities.
1321 *
1322 * @return A malloc ()ed array of tor->info.fileCount items,
1323 *         each holding a TR_PRI_NORMAL, TR_PRI_HIGH, or TR_PRI_LOW.
1324 *         It's the caller's responsibility to free () this.
1325 */
1326tr_priority_t*  tr_torrentGetFilePriorities (const tr_torrent * torrent);
1327
1328/** @brief Set a batch of files to be downloaded or not. */
1329void tr_torrentSetFileDLs (tr_torrent             * torrent,
1330                           const tr_file_index_t  * files,
1331                           tr_file_index_t          fileCount,
1332                           bool                     do_download);
1333
1334
1335const tr_info * tr_torrentInfo (const tr_torrent * torrent);
1336
1337/* Raw function to change the torrent's downloadDir field.
1338   This should only be used by libtransmission or to bootstrap
1339   a newly-instantiated tr_torrent object. */
1340void tr_torrentSetDownloadDir (tr_torrent  * torrent, const char * path);
1341
1342const char * tr_torrentGetDownloadDir (const tr_torrent * torrent);
1343
1344/**
1345 * Returns the root directory of where the torrent is.
1346 *
1347 * This will usually be the downloadDir. However if the torrent
1348 * has an incompleteDir enabled and hasn't finished downloading
1349 * yet, that will be returned instead.
1350 */
1351const char * tr_torrentGetCurrentDir (const tr_torrent * tor);
1352
1353
1354char* tr_torrentInfoGetMagnetLink (const tr_info * inf);
1355
1356/**
1357 * Returns a newly-allocated string with a magnet link of the torrent.
1358 * Use tr_free () to free the string when done.
1359 */
1360static inline
1361char* tr_torrentGetMagnetLink (const tr_torrent * tor)
1362{
1363    return tr_torrentInfoGetMagnetLink (tr_torrentInfo (tor));
1364}
1365
1366/**
1367***
1368**/
1369
1370
1371/** @brief a part of tr_info that represents a single tracker */
1372typedef struct tr_tracker_info
1373{
1374    int      tier;
1375    char *   announce;
1376    char *   scrape;
1377    uint32_t id; /* unique identifier used to match to a tr_tracker_stat */
1378}
1379tr_tracker_info;
1380
1381/**
1382 * @brief Modify a torrent's tracker list.
1383 *
1384 * This updates both the `torrent' object's tracker list
1385 * and the metainfo file in tr_sessionGetConfigDir ()'s torrent subdirectory.
1386 *
1387 * @param torrent The torrent whose tracker list is to be modified
1388 * @param trackers An array of trackers, sorted by tier from first to last.
1389 *                 NOTE: only the `tier' and `announce' fields are used.
1390 *                 libtransmission derives `scrape' from `announce'
1391 *                 and reassigns 'id'.
1392 * @param trackerCount size of the `trackers' array
1393 */
1394bool
1395tr_torrentSetAnnounceList (tr_torrent             * torrent,
1396                           const tr_tracker_info  * trackers,
1397                           int                      trackerCount);
1398
1399
1400/**
1401***
1402**/
1403
1404typedef enum
1405{
1406    TR_LEECH,        /* doesn't have all the desired pieces */
1407    TR_SEED,         /* has the entire torrent */
1408    TR_PARTIAL_SEED  /* has the desired pieces, but not the entire torrent */
1409}
1410tr_completeness;
1411
1412/**
1413 * @param wasRunning whether or not the torrent was running when
1414 *                   it changed its completeness state
1415 */
1416typedef void (tr_torrent_completeness_func)(tr_torrent       * torrent,
1417                                            tr_completeness    completeness,
1418                                            bool               wasRunning,
1419                                            void             * user_data);
1420
1421typedef void (tr_torrent_ratio_limit_hit_func)(tr_torrent   * torrent,
1422                                               void         * user_data);
1423
1424typedef void (tr_torrent_idle_limit_hit_func)(tr_torrent   * torrent,
1425                                              void         * user_data);
1426
1427
1428/**
1429 * Register to be notified whenever a torrent's "completeness"
1430 * changes. This will be called, for example, when a torrent
1431 * finishes downloading and changes from TR_LEECH to
1432 * either TR_SEED or TR_PARTIAL_SEED.
1433 *
1434 * func is invoked FROM LIBTRANSMISSION'S THREAD!
1435 * This means func must be fast (to avoid blocking peers),
1436 * shouldn't call libtransmission functions (to avoid deadlock),
1437 * and shouldn't modify client-level memory without using a mutex!
1438 *
1439 * @see tr_completeness
1440 */
1441void tr_torrentSetCompletenessCallback (
1442         tr_torrent                    * torrent,
1443         tr_torrent_completeness_func    func,
1444         void                          * user_data);
1445
1446void tr_torrentClearCompletenessCallback (tr_torrent * torrent);
1447
1448
1449
1450typedef void (tr_torrent_metadata_func)(tr_torrent  * torrent,
1451                                        void        * user_data);
1452/**
1453 * Register to be notified whenever a torrent changes from
1454 * having incomplete metadata to having complete metadata.
1455 * This happens when a magnet link finishes downloading
1456 * metadata from its peers.
1457 */
1458void tr_torrentSetMetadataCallback (
1459         tr_torrent                * tor,
1460         tr_torrent_metadata_func     func,
1461         void                      * user_data);
1462
1463/**
1464 * Register to be notified whenever a torrent's ratio limit
1465 * has been hit. This will be called when the torrent's
1466 * ul/dl ratio has met or exceeded the designated ratio limit.
1467 *
1468 * Has the same restrictions as tr_torrentSetCompletenessCallback
1469 */
1470void tr_torrentSetRatioLimitHitCallback (
1471     tr_torrent                     * torrent,
1472     tr_torrent_ratio_limit_hit_func  func,
1473     void                           * user_data);
1474
1475void tr_torrentClearRatioLimitHitCallback (tr_torrent * torrent);
1476
1477/**
1478 * Register to be notified whenever a torrent's idle limit
1479 * has been hit. This will be called when the seeding torrent's
1480 * idle time has met or exceeded the designated idle limit.
1481 *
1482 * Has the same restrictions as tr_torrentSetCompletenessCallback
1483 */
1484void tr_torrentSetIdleLimitHitCallback (
1485     tr_torrent                          * torrent,
1486     tr_torrent_idle_limit_hit_func        func,
1487     void                                * user_data);
1488
1489void tr_torrentClearIdleLimitHitCallback (tr_torrent * torrent);
1490
1491
1492/**
1493 * MANUAL ANNOUNCE
1494 *
1495 * Trackers usually set an announce interval of 15 or 30 minutes.
1496 * Users can send one-time announce requests that override this
1497 * interval by calling tr_torrentManualUpdate ().
1498 *
1499 * The wait interval for tr_torrentManualUpdate () is much smaller.
1500 * You can test whether or not a manual update is possible
1501 * (for example, to desensitize the button) by calling
1502 * tr_torrentCanManualUpdate ().
1503 */
1504
1505void tr_torrentManualUpdate (tr_torrent * torrent);
1506
1507bool tr_torrentCanManualUpdate (const tr_torrent * torrent);
1508
1509/***
1510****  tr_peer_stat
1511***/
1512
1513typedef struct tr_peer_stat
1514{
1515    bool  isUTP;
1516
1517    bool  isEncrypted;
1518    bool  isDownloadingFrom;
1519    bool  isUploadingTo;
1520    bool  isSeed;
1521
1522    bool  peerIsChoked;
1523    bool  peerIsInterested;
1524    bool  clientIsChoked;
1525    bool  clientIsInterested;
1526    bool  isIncoming;
1527
1528    uint8_t  from;
1529    tr_port  port;
1530
1531    char     addr[TR_INET6_ADDRSTRLEN];
1532    char     client[80];
1533    char     flagStr[32];
1534
1535    float    progress;
1536    double   rateToPeer_KBps;
1537    double   rateToClient_KBps;
1538
1539
1540/***
1541****  THESE NEXT FOUR FIELDS ARE EXPERIMENTAL.
1542****  Don't rely on them; they'll probably go away
1543***/
1544    /* how many blocks we've sent to this peer in the last 120 seconds */
1545    uint32_t  blocksToPeer;
1546    /* how many blocks this client's sent to us in the last 120 seconds */
1547    uint32_t  blocksToClient;
1548    /* how many requests to this peer that we've cancelled in the last 120 seconds */
1549    uint32_t  cancelsToPeer;
1550    /* how many requests this peer made of us, then cancelled, in the last 120 seconds */
1551    uint32_t  cancelsToClient;
1552
1553    /* how many requests the peer has made that we haven't responded to yet */
1554    int      pendingReqsToClient;
1555
1556    /* how many requests we've made and are currently awaiting a response for */
1557    int      pendingReqsToPeer;
1558}
1559tr_peer_stat;
1560
1561tr_peer_stat * tr_torrentPeers (const tr_torrent * torrent,
1562                                int              * peerCount);
1563
1564void           tr_torrentPeersFree (tr_peer_stat * peerStats,
1565                                    int            peerCount);
1566
1567/***
1568****  tr_tracker_stat
1569***/
1570
1571typedef enum
1572{
1573    /* we won't (announce,scrape) this torrent to this tracker because
1574     * the torrent is stopped, or because of an error, or whatever */
1575    TR_TRACKER_INACTIVE = 0,
1576
1577    /* we will (announce,scrape) this torrent to this tracker, and are
1578     * waiting for enough time to pass to satisfy the tracker's interval */
1579    TR_TRACKER_WAITING = 1,
1580
1581    /* it's time to (announce,scrape) this torrent, and we're waiting on a
1582     * a free slot to open up in the announce manager */
1583    TR_TRACKER_QUEUED = 2,
1584
1585    /* we're (announcing,scraping) this torrent right now */
1586    TR_TRACKER_ACTIVE = 3
1587}
1588tr_tracker_state;
1589
1590typedef struct
1591{
1592    /* how many downloads this tracker knows of (-1 means it does not know) */
1593    int downloadCount;
1594
1595    /* whether or not we've ever sent this tracker an announcement */
1596    bool hasAnnounced;
1597
1598    /* whether or not we've ever scraped to this tracker */
1599    bool hasScraped;
1600
1601    /* human-readable string identifying the tracker */
1602    char host[1024];
1603
1604    /* the full announce URL */
1605    char announce[1024];
1606
1607    /* the full scrape URL */
1608    char scrape[1024];
1609
1610    /* Transmission uses one tracker per tier,
1611     * and the others are kept as backups */
1612    bool isBackup;
1613
1614    /* is the tracker announcing, waiting, queued, etc */
1615    tr_tracker_state announceState;
1616
1617    /* is the tracker scraping, waiting, queued, etc */
1618    tr_tracker_state scrapeState;
1619
1620    /* number of peers the tracker told us about last time.
1621     * if "lastAnnounceSucceeded" is false, this field is undefined */
1622    int lastAnnouncePeerCount;
1623
1624    /* human-readable string with the result of the last announce.
1625       if "hasAnnounced" is false, this field is undefined */
1626    char lastAnnounceResult[128];
1627
1628    /* when the last announce was sent to the tracker.
1629     * if "hasAnnounced" is false, this field is undefined */
1630    time_t lastAnnounceStartTime;
1631
1632    /* whether or not the last announce was a success.
1633       if "hasAnnounced" is false, this field is undefined */
1634    bool lastAnnounceSucceeded;
1635
1636    /* whether or not the last announce timed out. */
1637    bool lastAnnounceTimedOut;
1638
1639    /* when the last announce was completed.
1640       if "hasAnnounced" is false, this field is undefined */
1641    time_t lastAnnounceTime;
1642
1643    /* human-readable string with the result of the last scrape.
1644     * if "hasScraped" is false, this field is undefined */
1645    char lastScrapeResult[128];
1646
1647    /* when the last scrape was sent to the tracker.
1648     * if "hasScraped" is false, this field is undefined */
1649    time_t lastScrapeStartTime;
1650
1651    /* whether or not the last scrape was a success.
1652       if "hasAnnounced" is false, this field is undefined */
1653    bool lastScrapeSucceeded;
1654
1655    /* whether or not the last scrape timed out. */
1656    bool lastScrapeTimedOut;
1657
1658    /* when the last scrape was completed.
1659       if "hasScraped" is false, this field is undefined */
1660    time_t lastScrapeTime;
1661
1662    /* number of leechers this tracker knows of (-1 means it does not know) */
1663    int leecherCount;
1664
1665    /* when the next periodic announce message will be sent out.
1666       if announceState isn't TR_TRACKER_WAITING, this field is undefined */
1667    time_t nextAnnounceTime;
1668
1669    /* when the next periodic scrape message will be sent out.
1670       if scrapeState isn't TR_TRACKER_WAITING, this field is undefined */
1671    time_t nextScrapeTime;
1672
1673    /* number of seeders this tracker knows of (-1 means it does not know) */
1674    int seederCount;
1675
1676    /* which tier this tracker is in */
1677    int tier;
1678
1679    /* used to match to a tr_tracker_info */
1680    uint32_t id;
1681}
1682tr_tracker_stat;
1683
1684tr_tracker_stat * tr_torrentTrackers (const tr_torrent * torrent,
1685                                      int              * setmeTrackerCount);
1686
1687void tr_torrentTrackersFree (tr_tracker_stat * trackerStats,
1688                             int               trackerCount);
1689
1690
1691
1692/**
1693 * @brief get the download speeds for each of this torrent's webseed sources.
1694 *
1695 * @return an array of tor->info.webseedCount floats giving download speeds.
1696 *         Each speed in the array corresponds to the webseed at the same
1697 *         array index in tor->info.webseeds.
1698 *         To differentiate "idle" and "stalled" status, idle webseeds will
1699 *         return -1 instead of 0 KiB/s.
1700 *         NOTE: always free this array with tr_free () when you're done with it.
1701 */
1702double*  tr_torrentWebSpeeds_KBps (const tr_torrent * torrent);
1703
1704typedef struct tr_file_stat
1705{
1706    uint64_t    bytesCompleted;
1707    float       progress;
1708}
1709tr_file_stat;
1710
1711tr_file_stat * tr_torrentFiles (const tr_torrent  * torrent,
1712                                tr_file_index_t   * fileCount);
1713
1714void tr_torrentFilesFree (tr_file_stat     * files,
1715                          tr_file_index_t    fileCount);
1716
1717
1718/***********************************************************************
1719 * tr_torrentAvailability
1720 ***********************************************************************
1721 * Use this to draw an advanced progress bar which is 'size' pixels
1722 * wide. Fills 'tab' which you must have allocated: each byte is set
1723 * to either -1 if we have the piece, otherwise it is set to the number
1724 * of connected peers who have the piece.
1725 **********************************************************************/
1726void tr_torrentAvailability (const tr_torrent  * torrent,
1727                             int8_t            * tab,
1728                             int                 size);
1729
1730void tr_torrentAmountFinished (const tr_torrent  * torrent,
1731                               float             * tab,
1732                               int                 size);
1733
1734/**
1735 * Callback function invoked when a torrent finishes being verified.
1736 *
1737 * @param torrent the torrent that was verified
1738 * @param aborted true if the verify ended prematurely for some reason,
1739 *                such as tr_torrentStop() or tr_torrentSetLocation()
1740 *                being called during verification.
1741 * @param callback_data the user-defined pointer from tr_torrentVerify()
1742 */
1743typedef void (*tr_verify_done_func)(tr_torrent  * torrent,
1744                                    bool          aborted,
1745                                    void        * user_data);
1746
1747/**
1748 * Queue a torrent for verification.
1749 *
1750 * If callback_func is non-NULL, it will be called from the libtransmission
1751 * thread after the torrent's completness state is updated after the
1752 * file verification pass.
1753 */
1754void tr_torrentVerify (tr_torrent           * torrent,
1755                       tr_verify_done_func    callback_func_or_NULL,
1756                       void                 * callback_data_or_NULL);
1757
1758/***********************************************************************
1759 * tr_info
1760 **********************************************************************/
1761
1762/** @brief a part of tr_info that represents a single file of the torrent's content */
1763typedef struct tr_file
1764{
1765    uint64_t          length;      /* Length of the file, in bytes */
1766    char *            name;        /* Path to the file */
1767    int8_t            priority;    /* TR_PRI_HIGH, _NORMAL, or _LOW */
1768    int8_t            dnd;         /* "do not download" flag */
1769    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 */
1770    tr_piece_index_t  firstPiece;  /* We need pieces [firstPiece... */
1771    tr_piece_index_t  lastPiece;   /* ...lastPiece] to dl this file */
1772    uint64_t          offset;      /* file begins at the torrent's nth byte */
1773}
1774tr_file;
1775
1776/** @brief a part of tr_info that represents a single piece of the torrent's content */
1777typedef struct tr_piece
1778{
1779    time_t   timeChecked;              /* the last time we tested this piece */
1780    uint8_t  hash[SHA_DIGEST_LENGTH];  /* pieces hash */
1781    int8_t   priority;                 /* TR_PRI_HIGH, _NORMAL, or _LOW */
1782    int8_t   dnd;                      /* "do not download" flag */
1783}
1784tr_piece;
1785
1786/** @brief information about a torrent that comes from its metainfo file */
1787struct tr_info
1788{
1789    /* total size of the torrent, in bytes */
1790    uint64_t           totalSize;
1791
1792    /* The original name that came in this torrent's metainfo.
1793     * CLIENT CODE: NOT USE THIS FIELD. */
1794    char             * originalName;
1795
1796    /* The torrent's name. */
1797    char             * name;
1798
1799    /* Path to torrent Transmission's internal copy of the .torrent file. */
1800    char             * torrent;
1801
1802    char            ** webseeds;
1803
1804    char             * comment;
1805    char             * creator;
1806    tr_file          * files;
1807    tr_piece         * pieces;
1808
1809    /* these trackers are sorted by tier */
1810    tr_tracker_info  * trackers;
1811
1812    /* Torrent info */
1813    time_t             dateCreated;
1814
1815    unsigned int       trackerCount;
1816    unsigned int       webseedCount;
1817    tr_file_index_t    fileCount;
1818    uint32_t           pieceSize;
1819    tr_piece_index_t   pieceCount;
1820
1821    /* General info */
1822    uint8_t            hash[SHA_DIGEST_LENGTH];
1823    char               hashString[2 * SHA_DIGEST_LENGTH + 1];
1824
1825    /* Flags */
1826    bool               isPrivate;
1827    bool               isMultifile;
1828};
1829
1830static inline bool tr_torrentHasMetadata (const tr_torrent * tor)
1831{
1832    return tr_torrentInfo (tor)->fileCount > 0;
1833}
1834
1835/**
1836 * What the torrent is doing right now.
1837 *
1838 * Note: these values will become a straight enum at some point in the future.
1839 * Do not rely on their current `bitfield' implementation
1840 */
1841typedef enum
1842{
1843    TR_STATUS_STOPPED        = 0, /* Torrent is stopped */
1844    TR_STATUS_CHECK_WAIT     = 1, /* Queued to check files */
1845    TR_STATUS_CHECK          = 2, /* Checking files */
1846    TR_STATUS_DOWNLOAD_WAIT  = 3, /* Queued to download */
1847    TR_STATUS_DOWNLOAD       = 4, /* Downloading */
1848    TR_STATUS_SEED_WAIT      = 5, /* Queued to seed */
1849    TR_STATUS_SEED           = 6  /* Seeding */
1850}
1851tr_torrent_activity;
1852
1853enum
1854{
1855    TR_PEER_FROM_INCOMING  = 0, /* connections made to the listening port */
1856    TR_PEER_FROM_LPD,           /* peers found by local announcements */
1857    TR_PEER_FROM_TRACKER,       /* peers found from a tracker */
1858    TR_PEER_FROM_DHT,           /* peers found from the DHT */
1859    TR_PEER_FROM_PEX,           /* peers found from PEX */
1860    TR_PEER_FROM_RESUME,        /* peers found in the .resume file */
1861    TR_PEER_FROM_LTEP,          /* peer address provided in an LTEP handshake */
1862    TR_PEER_FROM__MAX
1863};
1864
1865typedef enum
1866{
1867    /* everything's fine */
1868    TR_STAT_OK               = 0,
1869
1870    /* when we anounced to the tracker, we got a warning in the response */
1871    TR_STAT_TRACKER_WARNING  = 1,
1872
1873    /* when we anounced to the tracker, we got an error in the response */
1874    TR_STAT_TRACKER_ERROR    = 2,
1875
1876    /* local trouble, such as disk full or permissions error */
1877    TR_STAT_LOCAL_ERROR      = 3
1878}
1879tr_stat_errtype;
1880
1881/** @brief Used by tr_torrentStat () to tell clients about a torrent's state and statistics */
1882typedef struct tr_stat
1883{
1884    /** The torrent's unique Id.
1885        @see tr_torrentId () */
1886    int    id;
1887
1888    /** What is this torrent doing right now? */
1889    tr_torrent_activity activity;
1890
1891    /** Defines what kind of text is in errorString.
1892        @see errorString */
1893    tr_stat_errtype error;
1894
1895    /** A warning or error message regarding the torrent.
1896        @see error */
1897    char errorString[512];
1898
1899    /** When tr_stat.activity is TR_STATUS_CHECK or TR_STATUS_CHECK_WAIT,
1900        this is the percentage of how much of the files has been
1901        verified. When it gets to 1, the verify process is done.
1902        Range is [0..1]
1903        @see tr_stat.activity */
1904    float recheckProgress;
1905
1906    /** How much has been downloaded of the entire torrent.
1907        Range is [0..1] */
1908    float percentComplete;
1909
1910    /** How much of the metadata the torrent has.
1911        For torrents added from a .torrent this will always be 1.
1912        For magnet links, this number will from from 0 to 1 as the metadata is downloaded.
1913        Range is [0..1] */
1914    float metadataPercentComplete;
1915
1916    /** How much has been downloaded of the files the user wants. This differs
1917        from percentComplete if the user wants only some of the torrent's files.
1918        Range is [0..1]
1919        @see tr_stat.leftUntilDone */
1920    float percentDone;
1921
1922    /** How much has been uploaded to satisfy the seed ratio.
1923        This is 1 if the ratio is reached or the torrent is set to seed forever.
1924        Range is [0..1] */
1925    float seedRatioPercentDone;
1926
1927    /** Speed all data being sent for this torrent.
1928        This includes piece data, protocol messages, and TCP overhead */
1929    float rawUploadSpeed_KBps;
1930
1931    /** Speed all data being received for this torrent.
1932        This includes piece data, protocol messages, and TCP overhead */
1933    float rawDownloadSpeed_KBps;
1934
1935    /** Speed all piece being sent for this torrent.
1936        This ONLY counts piece data. */
1937    float pieceUploadSpeed_KBps;
1938
1939    /** Speed all piece being received for this torrent.
1940        This ONLY counts piece data. */
1941    float pieceDownloadSpeed_KBps;
1942
1943#define TR_ETA_NOT_AVAIL -1
1944#define TR_ETA_UNKNOWN -2
1945    /** If downloading, estimated number of seconds left until the torrent is done.
1946        If seeding, estimated number of seconds left until seed ratio is reached. */
1947    int    eta;
1948    /** If seeding, number of seconds left until the idle time limit is reached. */
1949    int    etaIdle;
1950
1951    /** Number of peers that we're connected to */
1952    int    peersConnected;
1953
1954    /** How many peers we found out about from the tracker, or from pex,
1955        or from incoming connections, or from our resume file. */
1956    int    peersFrom[TR_PEER_FROM__MAX];
1957
1958    /** Number of peers that are sending data to us. */
1959    int    peersSendingToUs;
1960
1961    /** Number of peers that we're sending data to */
1962    int    peersGettingFromUs;
1963
1964    /** Number of webseeds that are sending data to us. */
1965    int    webseedsSendingToUs;
1966
1967    /** Byte count of all the piece data we'll have downloaded when we're done,
1968        whether or not we have it yet. This may be less than tr_info.totalSize
1969        if only some of the torrent's files are wanted.
1970        [0...tr_info.totalSize] */
1971    uint64_t    sizeWhenDone;
1972
1973    /** Byte count of how much data is left to be downloaded until we've got
1974        all the pieces that we want. [0...tr_info.sizeWhenDone] */
1975    uint64_t    leftUntilDone;
1976
1977    /** Byte count of all the piece data we want and don't have yet,
1978        but that a connected peer does have. [0...leftUntilDone] */
1979    uint64_t    desiredAvailable;
1980
1981    /** Byte count of all the corrupt data you've ever downloaded for
1982        this torrent. If you're on a poisoned torrent, this number can
1983        grow very large. */
1984    uint64_t    corruptEver;
1985
1986    /** Byte count of all data you've ever uploaded for this torrent. */
1987    uint64_t    uploadedEver;
1988
1989    /** Byte count of all the non-corrupt data you've ever downloaded
1990        for this torrent. If you deleted the files and downloaded a second
1991        time, this will be 2*totalSize.. */
1992    uint64_t    downloadedEver;
1993
1994    /** Byte count of all the checksum-verified data we have for this torrent.
1995      */
1996    uint64_t    haveValid;
1997
1998    /** Byte count of all the partial piece data we have for this torrent.
1999        As pieces become complete, this value may decrease as portions of it
2000        are moved to `corrupt' or `haveValid'. */
2001    uint64_t    haveUnchecked;
2002
2003    /** time when one or more of the torrent's trackers will
2004        allow you to manually ask for more peers,
2005        or 0 if you can't */
2006    time_t manualAnnounceTime;
2007
2008#define TR_RATIO_NA  -1
2009#define TR_RATIO_INF -2
2010    /** TR_RATIO_INF, TR_RATIO_NA, or a regular ratio */
2011    float    ratio;
2012
2013    /** When the torrent was first added. */
2014    time_t    addedDate;
2015
2016    /** When the torrent finished downloading. */
2017    time_t    doneDate;
2018
2019    /** When the torrent was last started. */
2020    time_t    startDate;
2021
2022    /** The last time we uploaded or downloaded piece data on this torrent. */
2023    time_t    activityDate;
2024
2025    /** Number of seconds since the last activity (or since started).
2026        -1 if activity is not seeding or downloading. */
2027    int    idleSecs;
2028
2029    /** Cumulative seconds the torrent's ever spent downloading */
2030    int    secondsDownloading;
2031
2032    /** Cumulative seconds the torrent's ever spent seeding */
2033    int    secondsSeeding;
2034
2035    /** A torrent is considered finished if it has met its seed ratio.
2036        As a result, only paused torrents can be finished. */
2037    bool   finished;
2038
2039    /** This torrent's queue position.
2040        All torrents have a queue position, even if it's not queued. */
2041    int queuePosition;
2042
2043    /** True if the torrent is running, but has been idle for long enough
2044        to be considered stalled.  @see tr_sessionGetQueueStalledMinutes () */
2045    bool isStalled;
2046}
2047tr_stat;
2048
2049/** Return a pointer to an tr_stat structure with updated information
2050    on the torrent. This is typically called by the GUI clients every
2051    second or so to get a new snapshot of the torrent's status. */
2052const tr_stat * tr_torrentStat (tr_torrent * torrent);
2053
2054/** Like tr_torrentStat (), but only recalculates the statistics if it's
2055    been longer than a second since they were last calculated. This can
2056    reduce the CPU load if you're calling tr_torrentStat () frequently. */
2057const tr_stat * tr_torrentStatCached (tr_torrent * torrent);
2058
2059/** @deprecated */
2060void tr_torrentSetAddedDate (tr_torrent * torrent,
2061                             time_t       addedDate);
2062
2063/** @deprecated */
2064void tr_torrentSetActivityDate (tr_torrent * torrent,
2065                                time_t       activityDate);
2066
2067/** @deprecated */
2068void tr_torrentSetDoneDate (tr_torrent * torrent, time_t doneDate);
2069
2070/** @} */
2071
2072/** @brief Sanity checker to test that the direction is TR_UP or TR_DOWN */
2073static inline bool tr_isDirection (tr_direction d) { return d==TR_UP || d==TR_DOWN; }
2074
2075/** @brief Sanity checker to test that a bool is true or false */
2076static inline bool tr_isBool (bool b) { return b==1 || b==0; }
2077
2078#ifdef __cplusplus
2079}
2080#endif
2081
2082#endif
Note: See TracBrowser for help on using the repository browser.