source: trunk/libtransmission/transmission.h @ 11599

Last change on this file since 11599 was 11599, checked in by charles, 11 years ago

(trunk) Join the 21st century and use only 1 space at the end sentences. This commit is nearly as important as the semi-annual ones that remove trailing spaces from the ends of lines of code... :)

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