source: trunk/libtransmission/transmission.h @ 13868

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

make all the log functions/structs/enums use a single 'tr_log' namespace, such as tr_logGetQueue, tr_logAddInfo, tr_logIsLevelActive

  • Property svn:keywords set to Date Rev Author Id
File size: 68.7 KB
Line 
1/******************************************************************************
2 * $Id: transmission.h 13868 2013-01-25 23:34:20Z 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_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/** Instantiate a single torrent.
1065    @return 0 on success,
1066            TR_EINVALID if the torrent couldn't be parsed, or
1067            TR_EDUPLICATE if there's already a matching torrent object. */
1068tr_torrent * tr_torrentNew (const tr_ctor   * ctor,
1069                            int             * setmeError);
1070
1071/** @} */
1072
1073/***********************************************************************
1074 ***
1075 ***  TORRENTS
1076 **/
1077
1078/** @addtogroup tr_torrent Torrents
1079    @{ */
1080
1081typedef int tr_fileFunc (const char * filename);
1082
1083/** @brief Removes our .torrent and .resume files for this torrent */
1084void tr_torrentRemove (tr_torrent  * torrent,
1085                       bool          removeLocalData,
1086                       tr_fileFunc   removeFunc);
1087
1088/** @brief Start a torrent */
1089void tr_torrentStart (tr_torrent * torrent);
1090
1091/** @brief Stop (pause) a torrent */
1092void tr_torrentStop (tr_torrent * torrent);
1093
1094
1095typedef void (tr_torrent_rename_done_func)(tr_torrent  * torrent,
1096                                           const char  * oldpath,
1097                                           const char  * newname,
1098                                           int           error,
1099                                           void        * user_data);
1100
1101/**
1102 * @brief Rename a file or directory in a torrent.
1103 *
1104 * @tor: the torrent whose path will be renamed.
1105 * @oldpath: the path to the file or folder that will be renamed
1106 * @newname: the file or folder's new name
1107 * @callback: the callback invoked when the renaming finishes, or NULL
1108 * @callback_data: the pointer to pass in the callback's user_data arg
1109 *
1110 * As a special case, renaming the root file in a torrent will also
1111 * update tr_info.name.
1112 *
1113 * EXAMPLES
1114 *
1115 *   Consider a tr_torrent where its
1116 *   info.files[0].name is "frobnitz-linux/checksum" and
1117 *   info.files[1].name is "frobnitz-linux/frobnitz.iso".
1118 *
1119 *   1. tr_torrentRenamePath (tor, "frobnitz-linux", "foo") will rename
1120 *      the "frotbnitz-linux" folder as "foo", and update both info.name
1121 *      and info.files[*].name.
1122 *
1123 *   2. tr_torrentRenamePath (tor, "frobnitz-linux/checksum", "foo") will
1124 *      rename the "frobnitz-linux/checksum" file as "foo" and update
1125 *      files[0].name to "frobnitz-linux/foo".
1126 *
1127 * RETURN
1128 *
1129 *   Changing tr_info's contents requires a session lock, so this function
1130 *   returns asynchronously to avoid blocking. If you don't want to be notified
1131 *   when the function has finished, you can pass NULL as the callback arg.
1132 *
1133 *   On success, the callback's error argument will be 0.
1134 *
1135 *   If oldpath can't be found in files[*].name, or if newname is already
1136 *   in files[*].name, or contains a directory separator, or is NULL, "",
1137 *   ".", or "..", the error argument will be EINVAL.
1138 *
1139 *   If the path exists on disk but can't be renamed, the error argument
1140 *   will be the errno set by rename().
1141 */
1142void tr_torrentRenamePath (tr_torrent                  * tor,
1143                           const char                  * oldpath,
1144                           const char                  * newname,
1145                           tr_torrent_rename_done_func   callback,
1146                           void                        * callback_user_data);
1147
1148enum
1149{
1150    TR_LOC_MOVING,
1151    TR_LOC_DONE,
1152    TR_LOC_ERROR
1153};
1154
1155/**
1156 * @brief Tell transmsision where to find this torrent's local data.
1157 *
1158 * if move_from_previous_location is `true', the torrent's incompleteDir
1159 * will be clobberred s.t. additional files being added will be saved
1160 * to the torrent's downloadDir.
1161 */
1162void tr_torrentSetLocation (tr_torrent       * torrent,
1163                            const char       * location,
1164                            bool               move_from_previous_location,
1165                            volatile double  * setme_progress,
1166                            volatile int     * setme_state);
1167
1168uint64_t tr_torrentGetBytesLeftToAllocate (const tr_torrent * torrent);
1169
1170/**
1171 * @brief Returns this torrent's unique ID.
1172 *
1173 * IDs are good as simple lookup keys, but are not persistent
1174 * between sessions. If you need that, use tr_info.hash or
1175 * tr_info.hashString.
1176 */
1177int tr_torrentId (const tr_torrent * torrent);
1178
1179tr_torrent* tr_torrentFindFromId (tr_session * session, int id);
1180
1181tr_torrent* tr_torrentFindFromHash (tr_session     * session,
1182                                    const uint8_t  * hash);
1183
1184/** @brief Convenience function similar to tr_torrentFindFromHash () */
1185tr_torrent* tr_torrentFindFromMagnetLink (tr_session * session,
1186                                          const char * link);
1187
1188/**
1189 * @return this torrent's name.
1190 */
1191const char* tr_torrentName (const tr_torrent *);
1192
1193/**
1194 * @brief find the location of a torrent's file by looking with and without
1195 *        the ".part" suffix, looking in downloadDir and incompleteDir, etc.
1196 * @return a newly-allocated string (that must be tr_freed () by the caller
1197 *         when done) that gives the location of this file on disk,
1198 *         or NULL if no file exists yet.
1199 * @param tor the torrent whose file we're looking for
1200 * @param fileNum the fileIndex, in [0...tr_info.fileCount)
1201 */
1202char* tr_torrentFindFile (const tr_torrent * tor, tr_file_index_t fileNo);
1203
1204
1205/***
1206****  Torrent speed limits
1207****
1208***/
1209
1210void         tr_torrentSetSpeedLimit_KBps (tr_torrent *, tr_direction, unsigned int KBps);
1211unsigned int tr_torrentGetSpeedLimit_KBps (const tr_torrent *, tr_direction);
1212
1213void         tr_torrentUseSpeedLimit      (tr_torrent *, tr_direction, bool);
1214bool         tr_torrentUsesSpeedLimit     (const tr_torrent *, tr_direction);
1215
1216void         tr_torrentUseSessionLimits   (tr_torrent *, bool);
1217bool         tr_torrentUsesSessionLimits  (const tr_torrent *);
1218
1219
1220/****
1221*****  Ratio Limits
1222****/
1223
1224typedef enum
1225{
1226    /* follow the global settings */
1227    TR_RATIOLIMIT_GLOBAL    = 0,
1228
1229    /* override the global settings, seeding until a certain ratio */
1230    TR_RATIOLIMIT_SINGLE    = 1,
1231
1232    /* override the global settings, seeding regardless of ratio */
1233    TR_RATIOLIMIT_UNLIMITED = 2
1234}
1235tr_ratiolimit;
1236
1237void          tr_torrentSetRatioMode (tr_torrent         * tor,
1238                                      tr_ratiolimit        mode);
1239
1240tr_ratiolimit tr_torrentGetRatioMode (const tr_torrent   * tor);
1241
1242void          tr_torrentSetRatioLimit (tr_torrent        * tor,
1243                                       double              ratio);
1244
1245double        tr_torrentGetRatioLimit (const tr_torrent  * tor);
1246
1247
1248bool          tr_torrentGetSeedRatio  (const tr_torrent *, double * ratio);
1249
1250
1251/****
1252*****  Idle Time Limits
1253****/
1254
1255typedef enum
1256{
1257    /* follow the global settings */
1258    TR_IDLELIMIT_GLOBAL    = 0,
1259
1260    /* override the global settings, seeding until a certain idle time */
1261    TR_IDLELIMIT_SINGLE    = 1,
1262
1263    /* override the global settings, seeding regardless of activity */
1264    TR_IDLELIMIT_UNLIMITED = 2
1265}
1266tr_idlelimit;
1267
1268void          tr_torrentSetIdleMode (tr_torrent         * tor,
1269                                      tr_idlelimit         mode);
1270
1271tr_idlelimit  tr_torrentGetIdleMode (const tr_torrent   * tor);
1272
1273void          tr_torrentSetIdleLimit (tr_torrent         * tor,
1274                                      uint16_t             idleMinutes);
1275
1276uint16_t      tr_torrentGetIdleLimit (const tr_torrent   * tor);
1277
1278
1279bool          tr_torrentGetSeedIdle (const tr_torrent *, uint16_t * minutes);
1280
1281/****
1282*****  Peer Limits
1283****/
1284
1285void          tr_torrentSetPeerLimit (tr_torrent * tor, uint16_t peerLimit);
1286
1287uint16_t      tr_torrentGetPeerLimit (const tr_torrent * tor);
1288
1289/****
1290*****  File Priorities
1291****/
1292
1293enum
1294{
1295    TR_PRI_LOW    = -1,
1296    TR_PRI_NORMAL =  0, /* since NORMAL is 0, memset initializes nicely */
1297    TR_PRI_HIGH   =  1
1298};
1299
1300/**
1301 * @brief Set a batch of files to a particular priority.
1302 *
1303 * @param priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW
1304 */
1305void tr_torrentSetFilePriorities (tr_torrent             * torrent,
1306                                  const tr_file_index_t  * files,
1307                                  tr_file_index_t          fileCount,
1308                                  tr_priority_t            priority);
1309
1310/**
1311 * @brief Get this torrent's file priorities.
1312 *
1313 * @return A malloc ()ed array of tor->info.fileCount items,
1314 *         each holding a TR_PRI_NORMAL, TR_PRI_HIGH, or TR_PRI_LOW.
1315 *         It's the caller's responsibility to free () this.
1316 */
1317tr_priority_t*  tr_torrentGetFilePriorities (const tr_torrent * torrent);
1318
1319/** @brief Set a batch of files to be downloaded or not. */
1320void tr_torrentSetFileDLs (tr_torrent             * torrent,
1321                           const tr_file_index_t  * files,
1322                           tr_file_index_t          fileCount,
1323                           bool                     do_download);
1324
1325
1326const tr_info * tr_torrentInfo (const tr_torrent * torrent);
1327
1328/* Raw function to change the torrent's downloadDir field.
1329   This should only be used by libtransmission or to bootstrap
1330   a newly-instantiated tr_torrent object. */
1331void tr_torrentSetDownloadDir (tr_torrent  * torrent, const char * path);
1332
1333const char * tr_torrentGetDownloadDir (const tr_torrent * torrent);
1334
1335/**
1336 * Returns the root directory of where the torrent is.
1337 *
1338 * This will usually be the downloadDir. However if the torrent
1339 * has an incompleteDir enabled and hasn't finished downloading
1340 * yet, that will be returned instead.
1341 */
1342const char * tr_torrentGetCurrentDir (const tr_torrent * tor);
1343
1344
1345char* tr_torrentInfoGetMagnetLink (const tr_info * inf);
1346
1347/**
1348 * Returns a newly-allocated string with a magnet link of the torrent.
1349 * Use tr_free () to free the string when done.
1350 */
1351static inline
1352char* tr_torrentGetMagnetLink (const tr_torrent * tor)
1353{
1354    return tr_torrentInfoGetMagnetLink (tr_torrentInfo (tor));
1355}
1356
1357/**
1358***
1359**/
1360
1361
1362/** @brief a part of tr_info that represents a single tracker */
1363typedef struct tr_tracker_info
1364{
1365    int      tier;
1366    char *   announce;
1367    char *   scrape;
1368    uint32_t id; /* unique identifier used to match to a tr_tracker_stat */
1369}
1370tr_tracker_info;
1371
1372/**
1373 * @brief Modify a torrent's tracker list.
1374 *
1375 * This updates both the `torrent' object's tracker list
1376 * and the metainfo file in tr_sessionGetConfigDir ()'s torrent subdirectory.
1377 *
1378 * @param torrent The torrent whose tracker list is to be modified
1379 * @param trackers An array of trackers, sorted by tier from first to last.
1380 *                 NOTE: only the `tier' and `announce' fields are used.
1381 *                 libtransmission derives `scrape' from `announce'
1382 *                 and reassigns 'id'.
1383 * @param trackerCount size of the `trackers' array
1384 */
1385bool
1386tr_torrentSetAnnounceList (tr_torrent             * torrent,
1387                           const tr_tracker_info  * trackers,
1388                           int                      trackerCount);
1389
1390
1391/**
1392***
1393**/
1394
1395typedef enum
1396{
1397    TR_LEECH,        /* doesn't have all the desired pieces */
1398    TR_SEED,         /* has the entire torrent */
1399    TR_PARTIAL_SEED  /* has the desired pieces, but not the entire torrent */
1400}
1401tr_completeness;
1402
1403/**
1404 * @param wasRunning whether or not the torrent was running when
1405 *                   it changed its completeness state
1406 */
1407typedef void (tr_torrent_completeness_func)(tr_torrent       * torrent,
1408                                            tr_completeness    completeness,
1409                                            bool               wasRunning,
1410                                            void             * user_data);
1411
1412typedef void (tr_torrent_ratio_limit_hit_func)(tr_torrent   * torrent,
1413                                               void         * user_data);
1414
1415typedef void (tr_torrent_idle_limit_hit_func)(tr_torrent   * torrent,
1416                                              void         * user_data);
1417
1418
1419/**
1420 * Register to be notified whenever a torrent's "completeness"
1421 * changes. This will be called, for example, when a torrent
1422 * finishes downloading and changes from TR_LEECH to
1423 * either TR_SEED or TR_PARTIAL_SEED.
1424 *
1425 * func is invoked FROM LIBTRANSMISSION'S THREAD!
1426 * This means func must be fast (to avoid blocking peers),
1427 * shouldn't call libtransmission functions (to avoid deadlock),
1428 * and shouldn't modify client-level memory without using a mutex!
1429 *
1430 * @see tr_completeness
1431 */
1432void tr_torrentSetCompletenessCallback (
1433         tr_torrent                    * torrent,
1434         tr_torrent_completeness_func    func,
1435         void                          * user_data);
1436
1437void tr_torrentClearCompletenessCallback (tr_torrent * torrent);
1438
1439
1440
1441typedef void (tr_torrent_metadata_func)(tr_torrent  * torrent,
1442                                           void        * user_data);
1443/**
1444 * Register to be notified whenever a torrent changes from
1445 * having incomplete metadata to having complete metadata.
1446 * This happens when a magnet link finishes downloading
1447 * metadata from its peers.
1448 */
1449void tr_torrentSetMetadataCallback (
1450         tr_torrent                * tor,
1451         tr_torrent_metadata_func     func,
1452         void                      * user_data);
1453
1454/**
1455 * Register to be notified whenever a torrent's ratio limit
1456 * has been hit. This will be called when the torrent's
1457 * ul/dl ratio has met or exceeded the designated ratio limit.
1458 *
1459 * Has the same restrictions as tr_torrentSetCompletenessCallback
1460 */
1461void tr_torrentSetRatioLimitHitCallback (
1462     tr_torrent                     * torrent,
1463     tr_torrent_ratio_limit_hit_func  func,
1464     void                           * user_data);
1465
1466void tr_torrentClearRatioLimitHitCallback (tr_torrent * torrent);
1467
1468/**
1469 * Register to be notified whenever a torrent's idle limit
1470 * has been hit. This will be called when the seeding torrent's
1471 * idle time has met or exceeded the designated idle limit.
1472 *
1473 * Has the same restrictions as tr_torrentSetCompletenessCallback
1474 */
1475void tr_torrentSetIdleLimitHitCallback (
1476     tr_torrent                          * torrent,
1477     tr_torrent_idle_limit_hit_func        func,
1478     void                                * user_data);
1479
1480void tr_torrentClearIdleLimitHitCallback (tr_torrent * torrent);
1481
1482
1483/**
1484 * MANUAL ANNOUNCE
1485 *
1486 * Trackers usually set an announce interval of 15 or 30 minutes.
1487 * Users can send one-time announce requests that override this
1488 * interval by calling tr_torrentManualUpdate ().
1489 *
1490 * The wait interval for tr_torrentManualUpdate () is much smaller.
1491 * You can test whether or not a manual update is possible
1492 * (for example, to desensitize the button) by calling
1493 * tr_torrentCanManualUpdate ().
1494 */
1495
1496void tr_torrentManualUpdate (tr_torrent * torrent);
1497
1498bool tr_torrentCanManualUpdate (const tr_torrent * torrent);
1499
1500/***
1501****  tr_peer_stat
1502***/
1503
1504typedef struct tr_peer_stat
1505{
1506    bool  isUTP;
1507
1508    bool  isEncrypted;
1509    bool  isDownloadingFrom;
1510    bool  isUploadingTo;
1511    bool  isSeed;
1512
1513    bool  peerIsChoked;
1514    bool  peerIsInterested;
1515    bool  clientIsChoked;
1516    bool  clientIsInterested;
1517    bool  isIncoming;
1518
1519    uint8_t  from;
1520    tr_port  port;
1521
1522    char     addr[TR_INET6_ADDRSTRLEN];
1523    char     client[80];
1524    char     flagStr[32];
1525
1526    float    progress;
1527    double   rateToPeer_KBps;
1528    double   rateToClient_KBps;
1529
1530
1531/***
1532****  THESE NEXT FOUR FIELDS ARE EXPERIMENTAL.
1533****  Don't rely on them; they'll probably go away
1534***/
1535    /* how many blocks we've sent to this peer in the last 120 seconds */
1536    uint32_t  blocksToPeer;
1537    /* how many blocks this client's sent to us in the last 120 seconds */
1538    uint32_t  blocksToClient;
1539    /* how many requests to this peer that we've cancelled in the last 120 seconds */
1540    uint32_t  cancelsToPeer;
1541    /* how many requests this peer made of us, then cancelled, in the last 120 seconds */
1542    uint32_t  cancelsToClient;
1543
1544    /* how many requests the peer has made that we haven't responded to yet */
1545    int      pendingReqsToClient;
1546
1547    /* how many requests we've made and are currently awaiting a response for */
1548    int      pendingReqsToPeer;
1549}
1550tr_peer_stat;
1551
1552tr_peer_stat * tr_torrentPeers (const tr_torrent * torrent,
1553                                int              * peerCount);
1554
1555void           tr_torrentPeersFree (tr_peer_stat * peerStats,
1556                                    int            peerCount);
1557
1558/***
1559****  tr_tracker_stat
1560***/
1561
1562typedef enum
1563{
1564    /* we won't (announce,scrape) this torrent to this tracker because
1565     * the torrent is stopped, or because of an error, or whatever */
1566    TR_TRACKER_INACTIVE = 0,
1567
1568    /* we will (announce,scrape) this torrent to this tracker, and are
1569     * waiting for enough time to pass to satisfy the tracker's interval */
1570    TR_TRACKER_WAITING = 1,
1571
1572    /* it's time to (announce,scrape) this torrent, and we're waiting on a
1573     * a free slot to open up in the announce manager */
1574    TR_TRACKER_QUEUED = 2,
1575
1576    /* we're (announcing,scraping) this torrent right now */
1577    TR_TRACKER_ACTIVE = 3
1578}
1579tr_tracker_state;
1580
1581typedef struct
1582{
1583    /* how many downloads this tracker knows of (-1 means it does not know) */
1584    int downloadCount;
1585
1586    /* whether or not we've ever sent this tracker an announcement */
1587    bool hasAnnounced;
1588
1589    /* whether or not we've ever scraped to this tracker */
1590    bool hasScraped;
1591
1592    /* human-readable string identifying the tracker */
1593    char host[1024];
1594
1595    /* the full announce URL */
1596    char announce[1024];
1597
1598    /* the full scrape URL */
1599    char scrape[1024];
1600
1601    /* Transmission uses one tracker per tier,
1602     * and the others are kept as backups */
1603    bool isBackup;
1604
1605    /* is the tracker announcing, waiting, queued, etc */
1606    tr_tracker_state announceState;
1607
1608    /* is the tracker scraping, waiting, queued, etc */
1609    tr_tracker_state scrapeState;
1610
1611    /* number of peers the tracker told us about last time.
1612     * if "lastAnnounceSucceeded" is false, this field is undefined */
1613    int lastAnnouncePeerCount;
1614
1615    /* human-readable string with the result of the last announce.
1616       if "hasAnnounced" is false, this field is undefined */
1617    char lastAnnounceResult[128];
1618
1619    /* when the last announce was sent to the tracker.
1620     * if "hasAnnounced" is false, this field is undefined */
1621    time_t lastAnnounceStartTime;
1622
1623    /* whether or not the last announce was a success.
1624       if "hasAnnounced" is false, this field is undefined */
1625    bool lastAnnounceSucceeded;
1626
1627    /* whether or not the last announce timed out. */
1628    bool lastAnnounceTimedOut;
1629
1630    /* when the last announce was completed.
1631       if "hasAnnounced" is false, this field is undefined */
1632    time_t lastAnnounceTime;
1633
1634    /* human-readable string with the result of the last scrape.
1635     * if "hasScraped" is false, this field is undefined */
1636    char lastScrapeResult[128];
1637
1638    /* when the last scrape was sent to the tracker.
1639     * if "hasScraped" is false, this field is undefined */
1640    time_t lastScrapeStartTime;
1641
1642    /* whether or not the last scrape was a success.
1643       if "hasAnnounced" is false, this field is undefined */
1644    bool lastScrapeSucceeded;
1645
1646    /* whether or not the last scrape timed out. */
1647    bool lastScrapeTimedOut;
1648
1649    /* when the last scrape was completed.
1650       if "hasScraped" is false, this field is undefined */
1651    time_t lastScrapeTime;
1652
1653    /* number of leechers this tracker knows of (-1 means it does not know) */
1654    int leecherCount;
1655
1656    /* when the next periodic announce message will be sent out.
1657       if announceState isn't TR_TRACKER_WAITING, this field is undefined */
1658    time_t nextAnnounceTime;
1659
1660    /* when the next periodic scrape message will be sent out.
1661       if scrapeState isn't TR_TRACKER_WAITING, this field is undefined */
1662    time_t nextScrapeTime;
1663
1664    /* number of seeders this tracker knows of (-1 means it does not know) */
1665    int seederCount;
1666
1667    /* which tier this tracker is in */
1668    int tier;
1669
1670    /* used to match to a tr_tracker_info */
1671    uint32_t id;
1672}
1673tr_tracker_stat;
1674
1675tr_tracker_stat * tr_torrentTrackers (const tr_torrent * torrent,
1676                                      int              * setmeTrackerCount);
1677
1678void tr_torrentTrackersFree (tr_tracker_stat * trackerStats,
1679                             int               trackerCount);
1680
1681
1682
1683/**
1684 * @brief get the download speeds for each of this torrent's webseed sources.
1685 *
1686 * @return an array of tor->info.webseedCount floats giving download speeds.
1687 *         Each speed in the array corresponds to the webseed at the same
1688 *         array index in tor->info.webseeds.
1689 *         To differentiate "idle" and "stalled" status, idle webseeds will
1690 *         return -1 instead of 0 KiB/s.
1691 *         NOTE: always free this array with tr_free () when you're done with it.
1692 */
1693double*  tr_torrentWebSpeeds_KBps (const tr_torrent * torrent);
1694
1695typedef struct tr_file_stat
1696{
1697    uint64_t    bytesCompleted;
1698    float       progress;
1699}
1700tr_file_stat;
1701
1702tr_file_stat * tr_torrentFiles (const tr_torrent  * torrent,
1703                                tr_file_index_t   * fileCount);
1704
1705void tr_torrentFilesFree (tr_file_stat     * files,
1706                          tr_file_index_t    fileCount);
1707
1708
1709/***********************************************************************
1710 * tr_torrentAvailability
1711 ***********************************************************************
1712 * Use this to draw an advanced progress bar which is 'size' pixels
1713 * wide. Fills 'tab' which you must have allocated: each byte is set
1714 * to either -1 if we have the piece, otherwise it is set to the number
1715 * of connected peers who have the piece.
1716 **********************************************************************/
1717void tr_torrentAvailability (const tr_torrent  * torrent,
1718                             int8_t            * tab,
1719                             int                 size);
1720
1721void tr_torrentAmountFinished (const tr_torrent  * torrent,
1722                               float             * tab,
1723                               int                 size);
1724
1725void tr_torrentVerify (tr_torrent * torrent);
1726
1727/***********************************************************************
1728 * tr_info
1729 **********************************************************************/
1730
1731/** @brief a part of tr_info that represents a single file of the torrent's content */
1732typedef struct tr_file
1733{
1734    uint64_t          length;      /* Length of the file, in bytes */
1735    char *            name;        /* Path to the file */
1736    int8_t            priority;    /* TR_PRI_HIGH, _NORMAL, or _LOW */
1737    int8_t            dnd;         /* "do not download" flag */
1738    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 */
1739    tr_piece_index_t  firstPiece;  /* We need pieces [firstPiece... */
1740    tr_piece_index_t  lastPiece;   /* ...lastPiece] to dl this file */
1741    uint64_t          offset;      /* file begins at the torrent's nth byte */
1742}
1743tr_file;
1744
1745/** @brief a part of tr_info that represents a single piece of the torrent's content */
1746typedef struct tr_piece
1747{
1748    time_t   timeChecked;              /* the last time we tested this piece */
1749    uint8_t  hash[SHA_DIGEST_LENGTH];  /* pieces hash */
1750    int8_t   priority;                 /* TR_PRI_HIGH, _NORMAL, or _LOW */
1751    int8_t   dnd;                      /* "do not download" flag */
1752}
1753tr_piece;
1754
1755/** @brief information about a torrent that comes from its metainfo file */
1756struct tr_info
1757{
1758    /* total size of the torrent, in bytes */
1759    uint64_t           totalSize;
1760
1761    /* The original name that came in this torrent's metainfo.
1762     * CLIENT CODE: NOT USE THIS FIELD. */
1763    char             * originalName;
1764
1765    /* The torrent's name. */
1766    char             * name;
1767
1768    /* Path to torrent Transmission's internal copy of the .torrent file. */
1769    char             * torrent;
1770
1771    char            ** webseeds;
1772
1773    char             * comment;
1774    char             * creator;
1775    tr_file          * files;
1776    tr_piece         * pieces;
1777
1778    /* these trackers are sorted by tier */
1779    tr_tracker_info  * trackers;
1780
1781    /* Torrent info */
1782    time_t             dateCreated;
1783
1784    unsigned int       trackerCount;
1785    unsigned int       webseedCount;
1786    tr_file_index_t    fileCount;
1787    uint32_t           pieceSize;
1788    tr_piece_index_t   pieceCount;
1789
1790    /* General info */
1791    uint8_t            hash[SHA_DIGEST_LENGTH];
1792    char               hashString[2 * SHA_DIGEST_LENGTH + 1];
1793
1794    /* Flags */
1795    bool               isPrivate;
1796    bool               isMultifile;
1797};
1798
1799static inline bool tr_torrentHasMetadata (const tr_torrent * tor)
1800{
1801    return tr_torrentInfo (tor)->fileCount > 0;
1802}
1803
1804/**
1805 * What the torrent is doing right now.
1806 *
1807 * Note: these values will become a straight enum at some point in the future.
1808 * Do not rely on their current `bitfield' implementation
1809 */
1810typedef enum
1811{
1812    TR_STATUS_STOPPED        = 0, /* Torrent is stopped */
1813    TR_STATUS_CHECK_WAIT     = 1, /* Queued to check files */
1814    TR_STATUS_CHECK          = 2, /* Checking files */
1815    TR_STATUS_DOWNLOAD_WAIT  = 3, /* Queued to download */
1816    TR_STATUS_DOWNLOAD       = 4, /* Downloading */
1817    TR_STATUS_SEED_WAIT      = 5, /* Queued to seed */
1818    TR_STATUS_SEED           = 6  /* Seeding */
1819}
1820tr_torrent_activity;
1821
1822enum
1823{
1824    TR_PEER_FROM_INCOMING  = 0, /* connections made to the listening port */
1825    TR_PEER_FROM_LPD,           /* peers found by local announcements */
1826    TR_PEER_FROM_TRACKER,       /* peers found from a tracker */
1827    TR_PEER_FROM_DHT,           /* peers found from the DHT */
1828    TR_PEER_FROM_PEX,           /* peers found from PEX */
1829    TR_PEER_FROM_RESUME,        /* peers found in the .resume file */
1830    TR_PEER_FROM_LTEP,          /* peer address provided in an LTEP handshake */
1831    TR_PEER_FROM__MAX
1832};
1833
1834typedef enum
1835{
1836    /* everything's fine */
1837    TR_STAT_OK               = 0,
1838
1839    /* when we anounced to the tracker, we got a warning in the response */
1840    TR_STAT_TRACKER_WARNING  = 1,
1841
1842    /* when we anounced to the tracker, we got an error in the response */
1843    TR_STAT_TRACKER_ERROR    = 2,
1844
1845    /* local trouble, such as disk full or permissions error */
1846    TR_STAT_LOCAL_ERROR      = 3
1847}
1848tr_stat_errtype;
1849
1850/** @brief Used by tr_torrentStat () to tell clients about a torrent's state and statistics */
1851typedef struct tr_stat
1852{
1853    /** The torrent's unique Id.
1854        @see tr_torrentId () */
1855    int    id;
1856
1857    /** What is this torrent doing right now? */
1858    tr_torrent_activity activity;
1859
1860    /** Defines what kind of text is in errorString.
1861        @see errorString */
1862    tr_stat_errtype error;
1863
1864    /** A warning or error message regarding the torrent.
1865        @see error */
1866    char errorString[512];
1867
1868    /** When tr_stat.activity is TR_STATUS_CHECK or TR_STATUS_CHECK_WAIT,
1869        this is the percentage of how much of the files has been
1870        verified. When it gets to 1, the verify process is done.
1871        Range is [0..1]
1872        @see tr_stat.activity */
1873    float recheckProgress;
1874
1875    /** How much has been downloaded of the entire torrent.
1876        Range is [0..1] */
1877    float percentComplete;
1878
1879    /** How much of the metadata the torrent has.
1880        For torrents added from a .torrent this will always be 1.
1881        For magnet links, this number will from from 0 to 1 as the metadata is downloaded.
1882        Range is [0..1] */
1883    float metadataPercentComplete;
1884
1885    /** How much has been downloaded of the files the user wants. This differs
1886        from percentComplete if the user wants only some of the torrent's files.
1887        Range is [0..1]
1888        @see tr_stat.leftUntilDone */
1889    float percentDone;
1890
1891    /** How much has been uploaded to satisfy the seed ratio.
1892        This is 1 if the ratio is reached or the torrent is set to seed forever.
1893        Range is [0..1] */
1894    float seedRatioPercentDone;
1895
1896    /** Speed all data being sent for this torrent.
1897        This includes piece data, protocol messages, and TCP overhead */
1898    float rawUploadSpeed_KBps;
1899
1900    /** Speed all data being received for this torrent.
1901        This includes piece data, protocol messages, and TCP overhead */
1902    float rawDownloadSpeed_KBps;
1903
1904    /** Speed all piece being sent for this torrent.
1905        This ONLY counts piece data. */
1906    float pieceUploadSpeed_KBps;
1907
1908    /** Speed all piece being received for this torrent.
1909        This ONLY counts piece data. */
1910    float pieceDownloadSpeed_KBps;
1911
1912#define TR_ETA_NOT_AVAIL -1
1913#define TR_ETA_UNKNOWN -2
1914    /** If downloading, estimated number of seconds left until the torrent is done.
1915        If seeding, estimated number of seconds left until seed ratio is reached. */
1916    int    eta;
1917    /** If seeding, number of seconds left until the idle time limit is reached. */
1918    int    etaIdle;
1919
1920    /** Number of peers that we're connected to */
1921    int    peersConnected;
1922
1923    /** How many peers we found out about from the tracker, or from pex,
1924        or from incoming connections, or from our resume file. */
1925    int    peersFrom[TR_PEER_FROM__MAX];
1926
1927    /** Number of peers that are sending data to us. */
1928    int    peersSendingToUs;
1929
1930    /** Number of peers that we're sending data to */
1931    int    peersGettingFromUs;
1932
1933    /** Number of webseeds that are sending data to us. */
1934    int    webseedsSendingToUs;
1935
1936    /** Byte count of all the piece data we'll have downloaded when we're done,
1937        whether or not we have it yet. This may be less than tr_info.totalSize
1938        if only some of the torrent's files are wanted.
1939        [0...tr_info.totalSize] */
1940    uint64_t    sizeWhenDone;
1941
1942    /** Byte count of how much data is left to be downloaded until we've got
1943        all the pieces that we want. [0...tr_info.sizeWhenDone] */
1944    uint64_t    leftUntilDone;
1945
1946    /** Byte count of all the piece data we want and don't have yet,
1947        but that a connected peer does have. [0...leftUntilDone] */
1948    uint64_t    desiredAvailable;
1949
1950    /** Byte count of all the corrupt data you've ever downloaded for
1951        this torrent. If you're on a poisoned torrent, this number can
1952        grow very large. */
1953    uint64_t    corruptEver;
1954
1955    /** Byte count of all data you've ever uploaded for this torrent. */
1956    uint64_t    uploadedEver;
1957
1958    /** Byte count of all the non-corrupt data you've ever downloaded
1959        for this torrent. If you deleted the files and downloaded a second
1960        time, this will be 2*totalSize.. */
1961    uint64_t    downloadedEver;
1962
1963    /** Byte count of all the checksum-verified data we have for this torrent.
1964      */
1965    uint64_t    haveValid;
1966
1967    /** Byte count of all the partial piece data we have for this torrent.
1968        As pieces become complete, this value may decrease as portions of it
1969        are moved to `corrupt' or `haveValid'. */
1970    uint64_t    haveUnchecked;
1971
1972    /** time when one or more of the torrent's trackers will
1973        allow you to manually ask for more peers,
1974        or 0 if you can't */
1975    time_t manualAnnounceTime;
1976
1977#define TR_RATIO_NA  -1
1978#define TR_RATIO_INF -2
1979    /** TR_RATIO_INF, TR_RATIO_NA, or a regular ratio */
1980    float    ratio;
1981
1982    /** When the torrent was first added. */
1983    time_t    addedDate;
1984
1985    /** When the torrent finished downloading. */
1986    time_t    doneDate;
1987
1988    /** When the torrent was last started. */
1989    time_t    startDate;
1990
1991    /** The last time we uploaded or downloaded piece data on this torrent. */
1992    time_t    activityDate;
1993
1994    /** Number of seconds since the last activity (or since started).
1995        -1 if activity is not seeding or downloading. */
1996    int    idleSecs;
1997
1998    /** Cumulative seconds the torrent's ever spent downloading */
1999    int    secondsDownloading;
2000
2001    /** Cumulative seconds the torrent's ever spent seeding */
2002    int    secondsSeeding;
2003
2004    /** A torrent is considered finished if it has met its seed ratio.
2005        As a result, only paused torrents can be finished. */
2006    bool   finished;
2007
2008    /** This torrent's queue position.
2009        All torrents have a queue position, even if it's not queued. */
2010    int queuePosition;
2011
2012    /** True if the torrent is running, but has been idle for long enough
2013        to be considered stalled.  @see tr_sessionGetQueueStalledMinutes () */
2014    bool isStalled;
2015}
2016tr_stat;
2017
2018/** Return a pointer to an tr_stat structure with updated information
2019    on the torrent. This is typically called by the GUI clients every
2020    second or so to get a new snapshot of the torrent's status. */
2021const tr_stat * tr_torrentStat (tr_torrent * torrent);
2022
2023/** Like tr_torrentStat (), but only recalculates the statistics if it's
2024    been longer than a second since they were last calculated. This can
2025    reduce the CPU load if you're calling tr_torrentStat () frequently. */
2026const tr_stat * tr_torrentStatCached (tr_torrent * torrent);
2027
2028/** @deprecated */
2029void tr_torrentSetAddedDate (tr_torrent * torrent,
2030                             time_t       addedDate);
2031
2032/** @deprecated */
2033void tr_torrentSetActivityDate (tr_torrent * torrent,
2034                                time_t       activityDate);
2035
2036/** @deprecated */
2037void tr_torrentSetDoneDate (tr_torrent * torrent, time_t doneDate);
2038
2039/** @} */
2040
2041/** @brief Sanity checker to test that the direction is TR_UP or TR_DOWN */
2042static inline bool tr_isDirection (tr_direction d) { return d==TR_UP || d==TR_DOWN; }
2043
2044/** @brief Sanity checker to test that a bool is true or false */
2045static inline bool tr_isBool (bool b) { return b==1 || b==0; }
2046
2047#ifdef __cplusplus
2048}
2049#endif
2050
2051#endif
Note: See TracBrowser for help on using the repository browser.