source: trunk/libtransmission/transmission.h @ 12640

Last change on this file since 12640 was 12640, checked in by jordan, 10 years ago

Add a mechanism for enabling/disabling the stalled minutes feature. This is a pre-existing feature in the Mac client.

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