source: trunk/libtransmission/transmission.h @ 11086

Last change on this file since 11086 was 11086, checked in by Longinus00, 12 years ago

(trunk) #3471:Add 'finished' to filterbar

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