source: trunk/libtransmission/transmission.h @ 11812

Last change on this file since 11812 was 11812, checked in by jordan, 11 years ago

(trunk libT) tweak the documentation on a couple of structs

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