source: trunk/libtransmission/transmission.h @ 12281

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

(trunk libT) save 48 bytes per tr_torrent object. whoo!

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