source: trunk/libtransmission/transmission.h @ 11969

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

(trunk libT) add a bool to tr_peer_stat and the RPC peer list to denote whether or not a peer's connected via µTP

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