1 /******************************************************************************
2 * $Id: transmission.h 11373 2010-11-01 00:12:30Z charles $
4 * Copyright (c) 2005-2008 Transmission authors and contributors
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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 *****************************************************************************/
26 * This file defines the public API for the libtransmission library.
28 * Other headers with a public API are bencode.h and utils.h.
29 * Most of the remaining headers in libtransmission are private.
31 #ifndef TR_TRANSMISSION_H
32 #define TR_TRANSMISSION_H 1
44 #include <inttypes.h> /* uintN_t */
45 #include <time.h> /* time_t */
57 #if defined(WIN32) && defined(_MSC_VER)
58 #define inline __inline
61 #define SHA_DIGEST_LENGTH 20
62 #define TR_INET6_ADDRSTRLEN 46
64 typedef uint32_t tr_file_index_t
;
65 typedef 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 ;) */
68 typedef uint32_t tr_block_index_t
;
69 typedef uint16_t tr_port
;
70 typedef uint8_t tr_bool
;
72 typedef struct tr_ctor tr_ctor
;
73 typedef struct tr_info tr_info
;
74 typedef struct tr_torrent tr_torrent
;
75 typedef struct tr_session tr_session
;
79 typedef int8_t tr_priority_t
;
81 #define TR_RPC_SESSION_ID_HEADER "X-Transmission-Session-Id"
85 TR_PREALLOCATE_NONE
= 0,
86 TR_PREALLOCATE_SPARSE
= 1,
87 TR_PREALLOCATE_FULL
= 2
89 tr_preallocation_mode
;
94 TR_ENCRYPTION_PREFERRED
,
95 TR_ENCRYPTION_REQUIRED
102 **** Startup & Shutdown
107 * @addtogroup tr_session Session
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.
118 * @brief returns Transmission's default configuration file directory.
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.
127 const char* tr_getDefaultConfigDir( const char * appname
);
130 * @brief returns Transmisson's default download directory.
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.
137 const char* tr_getDefaultDownloadDir( void );
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_PEER_PORT_STR "51413"
146 #define TR_DEFAULT_PEER_SOCKET_TOS_STR "0"
147 #define TR_DEFAULT_PEER_LIMIT_GLOBAL_STR "240"
148 #define TR_DEFAULT_PEER_LIMIT_TORRENT_STR "60"
150 #define TR_PREFS_KEY_ALT_SPEED_ENABLED "alt-speed-enabled"
151 #define TR_PREFS_KEY_ALT_SPEED_UP_KBps "alt-speed-up"
152 #define TR_PREFS_KEY_ALT_SPEED_DOWN_KBps "alt-speed-down"
153 #define TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN "alt-speed-time-begin"
154 #define TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED "alt-speed-time-enabled"
155 #define TR_PREFS_KEY_ALT_SPEED_TIME_END "alt-speed-time-end"
156 #define TR_PREFS_KEY_ALT_SPEED_TIME_DAY "alt-speed-time-day"
157 #define TR_PREFS_KEY_BIND_ADDRESS_IPV4 "bind-address-ipv4"
158 #define TR_PREFS_KEY_BIND_ADDRESS_IPV6 "bind-address-ipv6"
159 #define TR_PREFS_KEY_BLOCKLIST_ENABLED "blocklist-enabled"
160 #define TR_PREFS_KEY_BLOCKLIST_URL "blocklist-url"
161 #define TR_PREFS_KEY_MAX_CACHE_SIZE_MB "cache-size-mb"
162 #define TR_PREFS_KEY_DHT_ENABLED "dht-enabled"
163 #define TR_PREFS_KEY_LPD_ENABLED "lpd-enabled"
164 #define TR_PREFS_KEY_DOWNLOAD_DIR "download-dir"
165 #define TR_PREFS_KEY_ENCRYPTION "encryption"
166 #define TR_PREFS_KEY_IDLE_LIMIT "idle-seeding-limit"
167 #define TR_PREFS_KEY_IDLE_LIMIT_ENABLED "idle-seeding-limit-enabled"
168 #define TR_PREFS_KEY_INCOMPLETE_DIR "incomplete-dir"
169 #define TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED "incomplete-dir-enabled"
170 #define TR_PREFS_KEY_LAZY_BITFIELD "lazy-bitfield-enabled"
171 #define TR_PREFS_KEY_MSGLEVEL "message-level"
172 #define TR_PREFS_KEY_OPEN_FILE_LIMIT "open-file-limit"
173 #define TR_PREFS_KEY_PEER_LIMIT_GLOBAL "peer-limit-global"
174 #define TR_PREFS_KEY_PEER_LIMIT_TORRENT "peer-limit-per-torrent"
175 #define TR_PREFS_KEY_PEER_PORT "peer-port"
176 #define TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START "peer-port-random-on-start"
177 #define TR_PREFS_KEY_PEER_PORT_RANDOM_LOW "peer-port-random-low"
178 #define TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH "peer-port-random-high"
179 #define TR_PREFS_KEY_PEER_SOCKET_TOS "peer-socket-tos"
180 #define TR_PREFS_KEY_PEER_CONGESTION_ALGORITHM "peer-congestion-algorithm"
181 #define TR_PREFS_KEY_PEX_ENABLED "pex-enabled"
182 #define TR_PREFS_KEY_PORT_FORWARDING "port-forwarding-enabled"
183 #define TR_PREFS_KEY_PREALLOCATION "preallocation"
184 #define TR_PREFS_KEY_RATIO "ratio-limit"
185 #define TR_PREFS_KEY_RATIO_ENABLED "ratio-limit-enabled"
186 #define TR_PREFS_KEY_RENAME_PARTIAL_FILES "rename-partial-files"
187 #define TR_PREFS_KEY_RPC_AUTH_REQUIRED "rpc-authentication-required"
188 #define TR_PREFS_KEY_RPC_BIND_ADDRESS "rpc-bind-address"
189 #define TR_PREFS_KEY_RPC_ENABLED "rpc-enabled"
190 #define TR_PREFS_KEY_RPC_PASSWORD "rpc-password"
191 #define TR_PREFS_KEY_RPC_PORT "rpc-port"
192 #define TR_PREFS_KEY_RPC_USERNAME "rpc-username"
193 #define TR_PREFS_KEY_RPC_WHITELIST_ENABLED "rpc-whitelist-enabled"
194 #define TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME "script-torrent-done-filename"
195 #define TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED "script-torrent-done-enabled"
196 #define TR_PREFS_KEY_RPC_WHITELIST "rpc-whitelist"
197 #define TR_PREFS_KEY_DSPEED_KBps "speed-limit-down"
198 #define TR_PREFS_KEY_DSPEED_ENABLED "speed-limit-down-enabled"
199 #define TR_PREFS_KEY_USPEED_KBps "speed-limit-up"
200 #define TR_PREFS_KEY_USPEED_ENABLED "speed-limit-up-enabled"
201 #define TR_PREFS_KEY_UMASK "umask"
202 #define TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT "upload-slots-per-torrent"
203 #define TR_PREFS_KEY_START "start-added-torrents"
204 #define TR_PREFS_KEY_TRASH_ORIGINAL "trash-original-torrent-files"
208 * Add libtransmission's default settings to the benc dictionary.
215 * tr_bencInitDict( &settings, 0 );
216 * tr_sessionGetDefaultSettings( &settings );
217 * if( tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT, &i ) )
218 * fprintf( stderr, "the default peer port is %d\n", (int)i );
219 * tr_bencFree( &settings );
222 * @param initme pointer to a tr_benc dictionary
223 * @see tr_sessionLoadSettings()
224 * @see tr_sessionInit()
225 * @see tr_getDefaultConfigDir()
227 void tr_sessionGetDefaultSettings( const char * configDir
, struct tr_benc
* dictionary
);
230 * Add the session's current configuration settings to the benc dictionary.
232 * FIXME: this probably belongs in libtransmissionapp
236 * @see tr_sessionGetDefaultSettings()
238 void tr_sessionGetSettings( tr_session
*, struct tr_benc
* dictionary
);
241 * Load settings from the configuration directory's settings.json file,
242 * using libtransmission's default settings as fallbacks for missing keys.
244 * FIXME: this belongs in libtransmissionapp
246 * @param dictionary pointer to an uninitialized tr_benc
247 * @param configDir the configuration directory to find settings.json
248 * @param appName if configDir is empty, appName is used to find the default dir.
249 * @return success TRUE if the settings were loaded, FALSE otherwise
250 * @see tr_sessionGetDefaultSettings()
251 * @see tr_sessionInit()
252 * @see tr_sessionSaveSettings()
254 tr_bool
tr_sessionLoadSettings( struct tr_benc
* dictionary
,
255 const char * configDir
,
256 const char * appName
);
259 * Add the session's configuration settings to the benc dictionary
260 * and save it to the configuration directory's settings.json file.
262 * FIXME: this belongs in libtransmissionapp
266 * @see tr_sessionLoadSettings()
268 void tr_sessionSaveSettings( tr_session
* session
,
269 const char * configDir
,
270 const struct tr_benc
* dictonary
);
273 * @brief Initialize a libtransmission session.
275 * For example, this will instantiate a session with all the default values:
278 * tr_session * session;
279 * const char * configDir;
281 * tr_bencInitDict( &settings, 0 );
282 * tr_sessionGetDefaultSettings( &settings );
283 * configDir = tr_getDefaultConfigDir( "Transmission" );
284 * session = tr_sessionInit( "mac", configDir, true, &settings );
286 * tr_bencFree( &settings );
289 * @param tag "gtk", "macosx", "daemon", etc... this is only for pre-1.30 resume files
290 * @param configDir where Transmission will look for resume files, blocklists, etc.
291 * @param messageQueueingEnabled if false, messages will be dumped to stderr
292 * @param settings libtransmission settings
293 * @see tr_sessionGetDefaultSettings()
294 * @see tr_sessionLoadSettings()
295 * @see tr_getDefaultConfigDir()
297 tr_session
* tr_sessionInit( const char * tag
,
298 const char * configDir
,
299 tr_bool messageQueueingEnabled
,
300 struct tr_benc
* settings
);
302 /** @brief Update a session's settings from a benc dictionary like to the one used in tr_sessionInit() */
303 void tr_sessionSet( tr_session
* session
,
304 struct tr_benc
* settings
);
306 /** @brief Rescan the blocklists directory and reload whatever blocklist files are found there */
307 void tr_sessionReloadBlocklists( tr_session
* session
);
310 /** @brief End a libtransmission session
311 @see tr_sessionInit() */
312 void tr_sessionClose( tr_session
* );
315 * @brief Return the session's configuration directory.
317 * This is where transmission stores its .torrent files, .resume files,
318 * blocklists, etc. It's set in tr_transmissionInit() and is immutable
319 * during the session.
321 const char * tr_sessionGetConfigDir( const tr_session
* );
324 * @brief Set the per-session default download folder for new torrents.
325 * @see tr_sessionInit()
326 * @see tr_sessionGetDownloadDir()
327 * @see tr_ctorSetDownloadDir()
329 void tr_sessionSetDownloadDir( tr_session
* session
, const char * downloadDir
);
332 * @brief Get the default download folder for new torrents.
334 * This is set by tr_sessionInit() or tr_sessionSetDownloadDir(),
335 * and can be overridden on a per-torrent basis by tr_ctorSetDownloadDir().
337 const char * tr_sessionGetDownloadDir( const tr_session
* session
);
341 * @brief Set the torrent's bandwidth priority.
343 void tr_ctorSetBandwidthPriority( tr_ctor
* ctor
, tr_priority_t priority
);
346 * @brief Get the torrent's bandwidth priority.
348 tr_priority_t
tr_ctorGetBandwidthPriority( const tr_ctor
* ctor
);
352 * @brief set the per-session incomplete download folder.
354 * When you add a new torrent and the session's incomplete directory is enabled,
355 * the new torrent will start downloading into that directory, and then be moved
356 * to tr_torrent.downloadDir when the torrent is finished downloading.
358 * Torrents are not moved as a result of changing the session's incomplete dir --
359 * it's applied to new torrents, not existing ones.
361 * tr_torrentSetLocation() overrules the incomplete dir: when a user specifies
362 * a new location, that becomes the torrent's new downloadDir and the torrent
363 * is moved there immediately regardless of whether or not it's complete.
365 * @see tr_sessionInit()
366 * @see tr_sessionGetIncompleteDir()
367 * @see tr_sessionSetIncompleteDirEnabled()
368 * @see tr_sessionGetIncompleteDirEnabled()
370 void tr_sessionSetIncompleteDir( tr_session
* session
, const char * dir
);
372 /** @brief get the per-session incomplete download folder */
373 const char* tr_sessionGetIncompleteDir( const tr_session
* session
);
375 /** @brief enable or disable use of the incomplete download folder */
376 void tr_sessionSetIncompleteDirEnabled( tr_session
* session
, tr_bool
);
378 /** @brief get whether or not the incomplete download folder is enabled */
379 tr_bool
tr_sessionIsIncompleteDirEnabled( const tr_session
* session
);
383 * @brief When enabled, newly-created files will have ".part" appended
384 * to their filename until the file is fully downloaded
386 * This is not retroactive -- toggling this will not rename existing files.
387 * It only applies to new files created by Transmission after this API call.
389 * @see tr_sessionIsIncompleteFileNamingEnabled()
391 void tr_sessionSetIncompleteFileNamingEnabled( tr_session
* session
, tr_bool
);
393 /** @brief return whether or filenames will have ".part" at the end until they're complete */
394 tr_bool
tr_sessionIsIncompleteFileNamingEnabled( const tr_session
* session
);
397 * @brief Set whether or not RPC calls are allowed in this session.
399 * @details If true, libtransmission will open a server socket to listen
400 * for incoming http RPC requests as described in docs/rpc-spec.txt.
402 * This is intially set by tr_sessionInit() and can be
403 * queried by tr_sessionIsRPCEnabled().
405 void tr_sessionSetRPCEnabled( tr_session
* session
,
408 /** @brief Get whether or not RPC calls are allowed in this session.
409 @see tr_sessionInit()
410 @see tr_sessionSetRPCEnabled() */
411 tr_bool
tr_sessionIsRPCEnabled( const tr_session
* session
);
413 /** @brief Specify which port to listen for RPC requests on.
414 @see tr_sessionInit()
415 @see tr_sessionGetRPCPort */
416 void tr_sessionSetRPCPort( tr_session
* session
,
419 /** @brief Get which port to listen for RPC requests on.
420 @see tr_sessionInit()
421 @see tr_sessionSetRPCPort */
422 tr_port
tr_sessionGetRPCPort( const tr_session
* session
);
425 * @brief Specify a whitelist for remote RPC access
427 * The whitelist is a comma-separated list of dotted-quad IP addresses
428 * to be allowed. Wildmat notation is supported, meaning that
429 * '?' is interpreted as a single-character wildcard and
430 * '*' is interprted as a multi-character wildcard.
432 void tr_sessionSetRPCWhitelist( tr_session
* session
,
433 const char * whitelist
);
435 /** @brief get the Access Control List for allowing/denying RPC requests.
436 @return a comma-separated string of whitelist domains.
438 @see tr_sessionSetRPCWhitelist */
439 const char* tr_sessionGetRPCWhitelist( const tr_session
* );
441 void tr_sessionSetRPCWhitelistEnabled( tr_session
* session
,
444 tr_bool
tr_sessionGetRPCWhitelistEnabled( const tr_session
* session
);
446 void tr_sessionSetRPCPassword( tr_session
* session
,
447 const char * password
);
449 void tr_sessionSetRPCUsername( tr_session
* session
,
450 const char * username
);
452 /** @brief get the password used to restrict RPC requests.
453 @return the password string.
454 @see tr_sessionInit()
455 @see tr_sessionSetRPCPassword() */
456 const char* tr_sessionGetRPCPassword( const tr_session
* session
);
458 const char* tr_sessionGetRPCUsername( const tr_session
* session
);
460 void tr_sessionSetRPCPasswordEnabled( tr_session
* session
,
463 tr_bool
tr_sessionIsRPCPasswordEnabled( const tr_session
* session
);
465 const char* tr_sessionGetRPCBindAddress( const tr_session
* session
);
470 TR_RPC_TORRENT_ADDED
,
471 TR_RPC_TORRENT_STARTED
,
472 TR_RPC_TORRENT_STOPPED
,
473 TR_RPC_TORRENT_REMOVING
,
474 TR_RPC_TORRENT_CHANGED
, /* catch-all for the "torrent-set" rpc method */
475 TR_RPC_TORRENT_MOVED
,
476 TR_RPC_SESSION_CHANGED
478 tr_rpc_callback_type
;
482 /* no special handling is needed by the caller */
485 /* indicates to the caller that the client will take care of
486 * removing the torrent itself. For example the client may
487 * need to keep the torrent alive long enough to cleanly close
488 * some resources in another thread. */
489 TR_RPC_NOREMOVE
= ( 1 << 1 )
491 tr_rpc_callback_status
;
493 typedef tr_rpc_callback_status (*tr_rpc_func
)(tr_session
* session
,
494 tr_rpc_callback_type type
,
495 struct tr_torrent
* tor_or_null
,
499 * Register to be notified whenever something is changed via RPC,
500 * such as a torrent being added, removed, started, stopped, etc.
502 * func is invoked FROM LIBTRANSMISSION'S THREAD!
503 * This means func must be fast (to avoid blocking peers),
504 * shouldn't call libtransmission functions (to avoid deadlock),
505 * and shouldn't modify client-level memory without using a mutex!
507 void tr_sessionSetRPCCallback( tr_session
* session
,
515 /** @brief Used by tr_sessionGetStats() and tr_sessionGetCumulativeStats() to give bandwidth statistics */
516 typedef struct tr_session_stats
518 float ratio
; /* TR_RATIO_INF, TR_RATIO_NA, or total up/down */
519 uint64_t uploadedBytes
; /* total up */
520 uint64_t downloadedBytes
; /* total down */
521 uint64_t filesAdded
; /* number of files added */
522 uint64_t sessionCount
; /* program started N times */
523 uint64_t secondsActive
; /* how long Transmisson's been running */
527 /** @brief Get bandwidth use statistics about the current session */
528 void tr_sessionGetStats( const tr_session
* session
, tr_session_stats
* setme
);
530 /** @brief Get cumulative bandwidth use statistics for the current and past sessions */
531 void tr_sessionGetCumulativeStats( const tr_session
* session
, tr_session_stats
* setme
);
533 void tr_sessionClearStats( tr_session
* session
);
536 * @brief Set whether or not torrents are allowed to do peer exchanges.
538 * PEX is always disabled in private torrents regardless of this.
539 * In public torrents, PEX is enabled by default.
541 void tr_sessionSetPexEnabled( tr_session
* session
, tr_bool isEnabled
);
542 tr_bool
tr_sessionIsPexEnabled( const tr_session
* session
);
544 tr_bool
tr_sessionIsDHTEnabled( const tr_session
* session
);
545 void tr_sessionSetDHTEnabled( tr_session
* session
, tr_bool
);
547 tr_bool
tr_sessionIsLPDEnabled( const tr_session
* session
);
548 void tr_sessionSetLPDEnabled( tr_session
* session
, tr_bool enabled
);
550 void tr_sessionSetCacheLimit_MB( tr_session
* session
, int mb
);
551 int tr_sessionGetCacheLimit_MB( const tr_session
* session
);
553 void tr_sessionSetLazyBitfieldEnabled( tr_session
* session
, tr_bool enabled
);
554 tr_bool
tr_sessionIsLazyBitfieldEnabled( const tr_session
* session
);
556 tr_encryption_mode
tr_sessionGetEncryption( tr_session
* session
);
557 void tr_sessionSetEncryption( tr_session
* session
,
558 tr_encryption_mode mode
);
561 /***********************************************************************
562 ** Incoming Peer Connections Port
565 void tr_sessionSetPortForwardingEnabled( tr_session
* session
,
568 tr_bool
tr_sessionIsPortForwardingEnabled( const tr_session
* session
);
570 void tr_sessionSetPeerPort( tr_session
* session
,
573 tr_port
tr_sessionGetPeerPort( const tr_session
* session
);
575 tr_port
tr_sessionSetPeerPortRandom( tr_session
* session
);
577 void tr_sessionSetPeerPortRandomOnStart( tr_session
* session
,
580 tr_bool
tr_sessionGetPeerPortRandomOnStart( tr_session
* session
);
592 tr_port_forwarding
tr_sessionGetPortForwarding( const tr_session
* session
);
596 TR_CLIENT_TO_PEER
= 0, TR_UP
= 0,
597 TR_PEER_TO_CLIENT
= 1, TR_DOWN
= 1
606 **** Primary session speed limits
609 void tr_sessionSetSpeedLimit_KBps( tr_session
*, tr_direction
, int KBps
);
610 int tr_sessionGetSpeedLimit_KBps( const tr_session
*, tr_direction
);
612 void tr_sessionLimitSpeed ( tr_session
*, tr_direction
, tr_bool
);
613 tr_bool
tr_sessionIsSpeedLimited ( const tr_session
*, tr_direction
);
617 **** Alternative speed limits that are used during scheduled times
620 void tr_sessionSetAltSpeed_KBps( tr_session
*, tr_direction
, int Bps
);
621 int tr_sessionGetAltSpeed_KBps( const tr_session
*, tr_direction
);
623 void tr_sessionUseAltSpeed ( tr_session
*, tr_bool
);
624 tr_bool
tr_sessionUsesAltSpeed ( const tr_session
* );
626 void tr_sessionUseAltSpeedTime ( tr_session
*, tr_bool
);
627 tr_bool
tr_sessionUsesAltSpeedTime ( const tr_session
* );
629 void tr_sessionSetAltSpeedBegin ( tr_session
*, int minsSinceMidnight
);
630 int tr_sessionGetAltSpeedBegin ( const tr_session
* );
632 void tr_sessionSetAltSpeedEnd ( tr_session
*, int minsSinceMidnight
);
633 int tr_sessionGetAltSpeedEnd ( const tr_session
* );
637 TR_SCHED_SUN
= (1<<0),
638 TR_SCHED_MON
= (1<<1),
639 TR_SCHED_TUES
= (1<<2),
640 TR_SCHED_WED
= (1<<3),
641 TR_SCHED_THURS
= (1<<4),
642 TR_SCHED_FRI
= (1<<5),
643 TR_SCHED_SAT
= (1<<6),
644 TR_SCHED_WEEKDAY
= (TR_SCHED_MON
|TR_SCHED_TUES
|TR_SCHED_WED
|TR_SCHED_THURS
|TR_SCHED_FRI
),
645 TR_SCHED_WEEKEND
= (TR_SCHED_SUN
|TR_SCHED_SAT
),
646 TR_SCHED_ALL
= (TR_SCHED_WEEKDAY
|TR_SCHED_WEEKEND
)
650 void tr_sessionSetAltSpeedDay ( tr_session
*, tr_sched_day day
);
651 tr_sched_day
tr_sessionGetAltSpeedDay ( const tr_session
* );
653 typedef void ( tr_altSpeedFunc
) ( tr_session
*, tr_bool active
, tr_bool userDriven
, void * );
654 void tr_sessionClearAltSpeedFunc ( tr_session
* );
655 void tr_sessionSetAltSpeedFunc ( tr_session
*, tr_altSpeedFunc
*, void * );
658 tr_bool
tr_sessionGetActiveSpeedLimit_KBps( const tr_session
* session
,
666 double tr_sessionGetRawSpeed_KBps ( const tr_session
*, tr_direction
);
667 double tr_sessionGetPieceSpeed_KBps( const tr_session
*, tr_direction
);
669 void tr_sessionSetRatioLimited ( tr_session
*, tr_bool isLimited
);
670 tr_bool
tr_sessionIsRatioLimited ( const tr_session
* );
672 void tr_sessionSetRatioLimit ( tr_session
*, double desiredRatio
);
673 double tr_sessionGetRatioLimit ( const tr_session
* );
675 void tr_sessionSetIdleLimited ( tr_session
*, tr_bool isLimited
);
676 tr_bool
tr_sessionIsIdleLimited ( const tr_session
* );
678 void tr_sessionSetIdleLimit ( tr_session
*, uint16_t idleMinutes
);
679 uint16_t tr_sessionGetIdleLimit ( const tr_session
* );
681 void tr_sessionSetPeerLimit( tr_session
*, uint16_t maxGlobalPeers
);
682 uint16_t tr_sessionGetPeerLimit( const tr_session
* );
684 void tr_sessionSetPeerLimitPerTorrent( tr_session
*, uint16_t maxGlobalPeers
);
685 uint16_t tr_sessionGetPeerLimitPerTorrent( const tr_session
* );
687 tr_priority_t
tr_torrentGetPriority( const tr_torrent
* );
688 void tr_torrentSetPriority( tr_torrent
*, tr_priority_t
);
690 void tr_sessionSetPaused ( tr_session
*, tr_bool isPaused
);
691 tr_bool
tr_sessionGetPaused ( const tr_session
* );
693 void tr_sessionSetDeleteSource ( tr_session
*, tr_bool deleteSource
);
694 tr_bool
tr_sessionGetDeleteSource ( const tr_session
* );
697 * Load all the torrents in tr_getTorrentDir().
698 * This can be used at startup to kickstart all the torrents
699 * from the previous session.
701 tr_torrent
** tr_sessionLoadTorrents( tr_session
* session
,
709 tr_bool
tr_sessionIsTorrentDoneScriptEnabled( const tr_session
* );
711 void tr_sessionSetTorrentDoneScriptEnabled( tr_session
*, tr_bool isEnabled
);
713 const char * tr_sessionGetTorrentDoneScript( const tr_session
* );
715 void tr_sessionSetTorrentDoneScript( tr_session
*, const char * scriptFilename
);
725 /***********************************************************************
737 void tr_setMessageLevel( tr_msg_level
);
739 tr_msg_level
tr_getMessageLevel( void );
741 typedef struct tr_msg_list
743 /* TR_MSG_ERR, TR_MSG_INF, or TR_MSG_DBG */
746 /* The line number in the source file where this message originated */
749 /* Time the message was generated */
752 /* The torrent associated with this message,
753 * or a module name such as "Port Forwarding" for non-torrent messages,
760 /* The source file where this message originated */
763 /* linked list of messages */
764 struct tr_msg_list
* next
;
768 void tr_setMessageQueuing( tr_bool isEnabled
);
770 tr_bool
tr_getMessageQueuing( void );
772 tr_msg_list
* tr_getQueuedMessages( void );
774 void tr_freeMessageList( tr_msg_list
* freeme
);
776 /** @addtogroup Blocklists
780 * Specify a range of IPs for Transmission to block.
782 * Filename must be an uncompressed ascii file.
784 * libtransmission does not keep a handle to `filename'
785 * after this call returns, so the caller is free to
786 * keep or delete `filename' as it wishes.
787 * libtransmission makes its own copy of the file
788 * massaged into a binary format easier to search.
790 * The caller only needs to invoke this when the blocklist
793 * Passing NULL for a filename will clear the blocklist.
795 int tr_blocklistSetContent ( tr_session
* session
,
796 const char * filename
);
798 int tr_blocklistGetRuleCount ( const tr_session
* session
);
800 tr_bool
tr_blocklistExists ( const tr_session
* session
);
802 tr_bool
tr_blocklistIsEnabled ( const tr_session
* session
);
804 void tr_blocklistSetEnabled ( tr_session
* session
,
807 /** @brief The blocklist that ges updated when an RPC client
808 invokes the "blocklist-update" method */
809 void tr_blocklistSetURL ( tr_session
*, const char * url
);
811 const char * tr_blocklistGetURL ( const tr_session
* );
813 /** @brief the file in the $config/blocklists/ directory that's
814 used by tr_blocklistSetContent() and "blocklist-update" */
815 #define DEFAULT_BLOCKLIST_FILENAME "blocklist.bin"
820 /** @addtogroup tr_ctor Torrent Constructors
823 Instantiating a tr_torrent had gotten more complicated as features were
824 added. At one point there were four functions to check metainfo and five
825 to create tr_torrent.
827 To remedy this, a Torrent Constructor (struct tr_ctor) has been introduced:
828 - Simplifies the API to two functions: tr_torrentParse() and tr_torrentNew()
829 - You can set the fields you want; the system sets defaults for the rest.
830 - You can specify whether or not your fields should supercede resume's.
831 - We can add new features to tr_ctor without breaking tr_torrentNew()'s API.
833 All the tr_ctor{Get,Set}*() functions with a return value return
834 an error number, or zero if no error occurred.
836 You must call one of the SetMetainfo() functions before creating
837 a torrent with a tr_ctor. The other functions are optional.
839 You can reuse a single tr_ctor to create a batch of torrents --
840 just call one of the SetMetainfo() functions between each
841 tr_torrentNew() call.
843 Every call to tr_ctorSetMetainfo*() frees the previous metainfo.
848 TR_FALLBACK
, /* indicates the ctor value should be used only
849 in case of missing resume settings */
851 TR_FORCE
, /* indicates the ctor value should be used
852 regardless of what's in the resume settings */
858 /** @brief Create a new torrent constructor object used to instantiate a tr_torrent
859 @param session the tr_session. NULL is allowed if you're only calling tr_torrentParse() rather than tr_torrentNew()
860 @see tr_torrentNew(), tr_torrentParse() */
861 tr_ctor
* tr_ctorNew( const tr_session
* session_or_NULL
);
863 /** @brief Free a torrent constructor object */
864 void tr_ctorFree( tr_ctor
* ctor
);
866 /** @brief Set whether or not to delete the source .torrent file when a torrent is added. (Default: False) */
867 void tr_ctorSetDeleteSource( tr_ctor
* ctor
, tr_bool doDelete
);
869 /** @brief Set the constructor's metainfo from a magnet link */
870 int tr_ctorSetMetainfoFromMagnetLink( tr_ctor
* ctor
, const char * magnet_link
);
872 /** @brief Set the constructor's metainfo from a raw benc already in memory */
873 int tr_ctorSetMetainfo( tr_ctor
* ctor
, const uint8_t * metainfo
, size_t len
);
875 /** @brief Set the constructor's metainfo from a local .torrent file */
876 int tr_ctorSetMetainfoFromFile( tr_ctor
* ctor
, const char * filename
);
879 * @brief Set the constructor's metainfo from an already-existing file in tr_getTorrentDir().
881 * This is used by the mac client on startup to pick and choose which existing torrents to load
883 int tr_ctorSetMetainfoFromHash( tr_ctor
* ctor
, const char * hashString
);
885 /** @brief Set the maximum number of peers this torrent can connect to. (Default: 50) */
886 void tr_ctorSetPeerLimit( tr_ctor
* ctor
, tr_ctorMode mode
, uint16_t peerLimit
);
888 /** @brief Set the download folder for the torrent being added with this ctor.
889 @see tr_ctorSetDownloadDir()
890 @see tr_sessionInit() */
891 void tr_ctorSetDownloadDir( tr_ctor
* ctor
,
893 const char * directory
);
896 * @brief Set the incompleteDir for this torrent.
898 * This is not a supported API call.
899 * It only exists so the mac client can migrate
900 * its older incompleteDir settings, and that's
901 * the only place where it should be used.
903 void tr_ctorSetIncompleteDir( tr_ctor
* ctor
, const char * directory
);
905 /** Set whether or not the torrent begins downloading/seeding when created.
906 (Default: not paused) */
907 void tr_ctorSetPaused( tr_ctor
* ctor
,
911 /** @brief Set the priorities for files in a torrent */
912 void tr_ctorSetFilePriorities( tr_ctor
* ctor
,
913 const tr_file_index_t
* files
,
914 tr_file_index_t fileCount
,
915 tr_priority_t priority
);
917 /** @brief Set the download flag for files in a torrent */
918 void tr_ctorSetFilesWanted( tr_ctor
* ctor
,
919 const tr_file_index_t
* fileIndices
,
920 tr_file_index_t fileCount
,
924 /** @brief Get this peer constructor's peer limit */
925 int tr_ctorGetPeerLimit( const tr_ctor
* ctor
,
927 uint16_t * setmeCount
);
929 /** @brief Get the "isPaused" flag from this peer constructor */
930 int tr_ctorGetPaused( const tr_ctor
* ctor
,
932 tr_bool
* setmeIsPaused
);
934 /** @brief Get the download path from this peer constructor */
935 int tr_ctorGetDownloadDir( const tr_ctor
* ctor
,
937 const char ** setmeDownloadDir
);
939 /** @brief Get the incomplete directory from this peer constructor */
940 int tr_ctorGetIncompleteDir( const tr_ctor
* ctor
,
941 const char ** setmeIncompleteDir
);
943 /** @brief Get the metainfo from this peer constructor */
944 int tr_ctorGetMetainfo( const tr_ctor
* ctor
,
945 const struct tr_benc
** setme
);
947 /** @brief Get the "delete .torrent file" flag from this peer constructor */
948 int tr_ctorGetDeleteSource( const tr_ctor
* ctor
,
949 tr_bool
* setmeDoDelete
);
951 /** @brief Get the tr_session poiner from this peer constructor */
952 tr_session
* tr_ctorGetSession( const tr_ctor
* ctor
);
954 /** @brief Get the .torrent file that this ctor's metainfo came from, or NULL if tr_ctorSetMetainfoFromFile() wasn't used */
955 const char* tr_ctorGetSourceFile( const tr_ctor
* ctor
);
966 * @brief Parses the specified metainfo
968 * @return TR_PARSE_ERR if parsing failed;
969 * TR_PARSE_OK if parsing succeeded and it's not a duplicate;
970 * TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate.
972 * @param setme_info If parsing is successful and setme_info is non-NULL,
973 * the parsed metainfo is stored there and sould be freed
974 * by calling tr_metainfoFree() when no longer needed.
978 * 1. tr_torrentParse() won't be able to check for duplicates -- and therefore
979 * won't return TR_PARSE_DUPLICATE -- unless ctor's "download-dir" and
980 * session variable is set.
982 * 2. setme_info->torrent's value can't be set unless ctor's session variable
985 tr_parse_result
tr_torrentParse( const tr_ctor
* ctor
,
986 tr_info
* setme_info_or_NULL
);
988 /** @brief free a metainfo
989 @see tr_torrentParse */
990 void tr_metainfoFree( tr_info
* inf
);
993 /** Instantiate a single torrent.
994 @return 0 on success,
995 TR_EINVALID if the torrent couldn't be parsed, or
996 TR_EDUPLICATE if there's already a matching torrent object. */
997 tr_torrent
* tr_torrentNew( const tr_ctor
* ctor
,
1002 /***********************************************************************
1007 /** @addtogroup tr_torrent Torrents
1010 /** @brief Frees memory allocated by tr_torrentNew().
1011 Running torrents are stopped first. */
1012 void tr_torrentFree( tr_torrent
* torrent
);
1014 /** @brief Removes our .torrent and .resume files for
1015 this torrent, then calls tr_torrentFree(). */
1016 void tr_torrentRemove( tr_torrent
* torrent
);
1018 /** @brief Start a torrent */
1019 void tr_torrentStart( tr_torrent
* torrent
);
1021 /** @brief Stop (pause) a torrent */
1022 void tr_torrentStop( tr_torrent
* torrent
);
1032 * @brief Tell transmsision where to find this torrent's local data.
1034 * if move_from_previous_location is `true', the torrent's incompleteDir
1035 * will be clobberred s.t. additional files being added will be saved
1036 * to the torrent's downloadDir.
1038 void tr_torrentSetLocation( tr_torrent
* torrent
,
1039 const char * location
,
1040 tr_bool move_from_previous_location
,
1041 double * setme_progress
,
1042 int * setme_state
);
1044 typedef int tr_fileFunc( const char * filename
);
1047 * @brief Deletes the torrent's local data.
1049 * @param fileFunc Pass in "unlink" to destroy the files or, on platforms with
1050 * recycle bins, pass in a function that uses it instead.
1051 * tr_torrentDeleteLocalData() ignores fileFunc's return value.
1053 void tr_torrentDeleteLocalData( tr_torrent
* torrent
, tr_fileFunc fileFunc
);
1055 uint64_t tr_torrentGetBytesLeftToAllocate( const tr_torrent
* torrent
);
1058 * @brief Returns this torrent's unique ID.
1060 * IDs are good as simple lookup keys, but are not persistent
1061 * between sessions. If you need that, use tr_info.hash or
1062 * tr_info.hashString.
1064 int tr_torrentId( const tr_torrent
* torrent
);
1066 tr_torrent
* tr_torrentFindFromId( tr_session
* session
, int id
);
1068 tr_torrent
* tr_torrentFindFromHash( tr_session
* session
, const uint8_t * hash
);
1070 /** @brief Convenience function similar to tr_torrentFindFromHash() */
1071 tr_torrent
* tr_torrentFindFromMagnetLink( tr_session
* session
, const char * link
);
1075 * @brief find the location of a torrent's file by looking with and without
1076 * the ".part" suffix, looking in downloadDir and incompleteDir, etc.
1077 * @return a newly-allocated string (that must be tr_freed() by the caller when done)
1078 * that gives the location of this file on disk, or NULL if no file exists yet.
1079 * @param tor the torrent whose file we're looking for
1080 * @param fileNum the fileIndex, in [0...tr_info.fileCount)
1082 char* tr_torrentFindFile( const tr_torrent
* tor
, tr_file_index_t fileNo
);
1086 **** Torrent speed limits
1090 void tr_torrentSetSpeedLimit_KBps ( tr_torrent
*, tr_direction
, int KBps
);
1091 int tr_torrentGetSpeedLimit_KBps ( const tr_torrent
*, tr_direction
);
1093 void tr_torrentUseSpeedLimit ( tr_torrent
*, tr_direction
, tr_bool
);
1094 tr_bool
tr_torrentUsesSpeedLimit ( const tr_torrent
*, tr_direction
);
1096 void tr_torrentUseSessionLimits ( tr_torrent
*, tr_bool
);
1097 tr_bool
tr_torrentUsesSessionLimits ( const tr_torrent
* );
1106 TR_RATIOLIMIT_GLOBAL
= 0, /* follow the global settings */
1107 TR_RATIOLIMIT_SINGLE
= 1, /* override the global settings, seeding until a certain ratio */
1108 TR_RATIOLIMIT_UNLIMITED
= 2 /* override the global settings, seeding regardless of ratio */
1112 void tr_torrentSetRatioMode( tr_torrent
* tor
,
1113 tr_ratiolimit mode
);
1115 tr_ratiolimit
tr_torrentGetRatioMode( const tr_torrent
* tor
);
1117 void tr_torrentSetRatioLimit( tr_torrent
* tor
,
1120 double tr_torrentGetRatioLimit( const tr_torrent
* tor
);
1123 tr_bool
tr_torrentGetSeedRatio( const tr_torrent
*, double * ratio
);
1127 ***** Idle Time Limits
1132 TR_IDLELIMIT_GLOBAL
= 0, /* follow the global settings */
1133 TR_IDLELIMIT_SINGLE
= 1, /* override the global settings, seeding until a certain idle time */
1134 TR_IDLELIMIT_UNLIMITED
= 2 /* override the global settings, seeding regardless of activity */
1138 void tr_torrentSetIdleMode ( tr_torrent
* tor
,
1139 tr_idlelimit mode
);
1141 tr_idlelimit
tr_torrentGetIdleMode ( const tr_torrent
* tor
);
1143 void tr_torrentSetIdleLimit( tr_torrent
* tor
,
1144 uint16_t idleMinutes
);
1146 uint16_t tr_torrentGetIdleLimit( const tr_torrent
* tor
);
1149 tr_bool
tr_torrentGetSeedIdle( const tr_torrent
*, uint16_t * idleMinutes
);
1155 void tr_torrentSetPeerLimit( tr_torrent
* tor
,
1156 uint16_t peerLimit
);
1158 uint16_t tr_torrentGetPeerLimit( const tr_torrent
* tor
);
1161 ***** File Priorities
1167 TR_PRI_NORMAL
= 0, /* since NORMAL is 0, memset initializes nicely */
1172 * @brief Set a batch of files to a particular priority.
1174 * @param priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW
1176 void tr_torrentSetFilePriorities( tr_torrent
* torrent
,
1177 const tr_file_index_t
* files
,
1178 tr_file_index_t fileCount
,
1179 tr_priority_t priority
);
1182 * @brief Get this torrent's file priorities.
1184 * @return A malloc()ed array of tor->info.fileCount items,
1185 * each holding a TR_PRI_NORMAL, TR_PRI_HIGH, or TR_PRI_LOW.
1186 * It's the caller's responsibility to free() this.
1188 tr_priority_t
* tr_torrentGetFilePriorities( const tr_torrent
* torrent
);
1190 /** @brief Set a batch of files to be downloaded or not. */
1191 void tr_torrentSetFileDLs( tr_torrent
* torrent
,
1192 const tr_file_index_t
* files
,
1193 tr_file_index_t fileCount
,
1194 tr_bool do_download
);
1197 const tr_info
* tr_torrentInfo( const tr_torrent
* torrent
);
1199 /* Raw function to change the torrent's downloadDir field.
1200 This should only be used by libtransmission or to bootstrap
1201 a newly-instantiated tr_torrent object. */
1202 void tr_torrentSetDownloadDir( tr_torrent
* torrent
, const char * path
);
1204 const char * tr_torrentGetDownloadDir( const tr_torrent
* torrent
);
1207 * Returns the root directory of where the torrent is.
1209 * This will usually be the downloadDir. However if the torrent
1210 * has an incompleteDir enabled and hasn't finished downloading
1211 * yet, that will be returned instead.
1213 const char * tr_torrentGetCurrentDir( const tr_torrent
* tor
);
1217 * Returns a newly-allocated string with a magnet link of the torrent.
1218 * Use tr_free() to free the string when done.
1220 char* tr_torrentGetMagnetLink( const tr_torrent
* tor
);
1227 /** @brief a part of tr_info that represents a single tracker */
1228 typedef struct tr_tracker_info
1233 uint32_t id
; /* unique identifier used to match to a tr_tracker_stat */
1238 * @brief Modify a torrent's tracker list.
1240 * This updates both the `torrent' object's tracker list
1241 * and the metainfo file in tr_sessionGetConfigDir()'s torrent subdirectory.
1243 * @param torrent The torrent whose tracker list is to be modified
1244 * @param trackers An array of trackers, sorted by tier from first to last.
1245 * NOTE: only the `tier' and `announce' fields are used.
1246 * libtransmission derives `scrape' from `announce'
1247 * and reassigns 'id'.
1248 * @param trackerCount size of the `trackers' array
1251 tr_torrentSetAnnounceList( tr_torrent
* torrent
,
1252 const tr_tracker_info
* trackers
,
1262 TR_LEECH
, /* doesn't have all the desired pieces */
1263 TR_SEED
, /* has the entire torrent */
1264 TR_PARTIAL_SEED
/* has the desired pieces, but not the entire torrent */
1269 * @param wasRunning whether or not the torrent was running when
1270 * it changed its completeness state
1272 typedef void ( tr_torrent_completeness_func
)( tr_torrent
* torrent
,
1273 tr_completeness completeness
,
1277 typedef void ( tr_torrent_ratio_limit_hit_func
)( tr_torrent
* torrent
,
1280 typedef void ( tr_torrent_idle_limit_hit_func
)( tr_torrent
* torrent
,
1285 * Register to be notified whenever a torrent's "completeness"
1286 * changes. This will be called, for example, when a torrent
1287 * finishes downloading and changes from TR_LEECH to
1288 * either TR_SEED or TR_PARTIAL_SEED.
1290 * func is invoked FROM LIBTRANSMISSION'S THREAD!
1291 * This means func must be fast (to avoid blocking peers),
1292 * shouldn't call libtransmission functions (to avoid deadlock),
1293 * and shouldn't modify client-level memory without using a mutex!
1295 * @see tr_completeness
1297 void tr_torrentSetCompletenessCallback(
1298 tr_torrent
* torrent
,
1299 tr_torrent_completeness_func func
,
1302 void tr_torrentClearCompletenessCallback( tr_torrent
* torrent
);
1306 typedef void ( tr_torrent_metadata_func
)( tr_torrent
* torrent
,
1309 * Register to be notified whenever a torrent changes from
1310 * having incomplete metadata to having complete metadata.
1311 * This happens when a magnet link finishes downloading
1312 * metadata from its peers.
1314 void tr_torrentSetMetadataCallback (
1316 tr_torrent_metadata_func func
,
1320 * Register to be notified whenever a torrent's ratio limit
1321 * has been hit. This will be called when the torrent's
1322 * ul/dl ratio has met or exceeded the designated ratio limit.
1324 * Has the same restrictions as tr_torrentSetCompletenessCallback
1326 void tr_torrentSetRatioLimitHitCallback(
1327 tr_torrent
* torrent
,
1328 tr_torrent_ratio_limit_hit_func func
,
1331 void tr_torrentClearRatioLimitHitCallback( tr_torrent
* torrent
);
1334 * Register to be notified whenever a torrent's idle limit
1335 * has been hit. This will be called when the seeding torrent's
1336 * idle time has met or exceeded the designated idle limit.
1338 * Has the same restrictions as tr_torrentSetCompletenessCallback
1340 void tr_torrentSetIdleLimitHitCallback(
1341 tr_torrent
* torrent
,
1342 tr_torrent_idle_limit_hit_func func
,
1345 void tr_torrentClearIdleLimitHitCallback( tr_torrent
* torrent
);
1351 * Trackers usually set an announce interval of 15 or 30 minutes.
1352 * Users can send one-time announce requests that override this
1353 * interval by calling tr_torrentManualUpdate().
1355 * The wait interval for tr_torrentManualUpdate() is much smaller.
1356 * You can test whether or not a manual update is possible
1357 * (for example, to desensitize the button) by calling
1358 * tr_torrentCanManualUpdate().
1361 void tr_torrentManualUpdate( tr_torrent
* torrent
);
1363 tr_bool
tr_torrentCanManualUpdate( const tr_torrent
* torrent
);
1369 typedef struct tr_peer_stat
1371 tr_bool isEncrypted
;
1372 tr_bool isDownloadingFrom
;
1373 tr_bool isUploadingTo
;
1376 tr_bool peerIsChoked
;
1377 tr_bool peerIsInterested
;
1378 tr_bool clientIsChoked
;
1379 tr_bool clientIsInterested
;
1385 char addr
[TR_INET6_ADDRSTRLEN
];
1390 double rateToPeer_KBps
;
1391 double rateToClient_KBps
;
1395 **** THESE NEXT FOUR FIELDS ARE EXPERIMENTAL.
1396 **** They're currently being used in the GTK+ client to help tune the new download congestion code
1397 **** and probably won't make the cut for 2.0.
1399 /* how many blocks we've sent to this peer in the last 120 seconds */
1400 uint32_t blocksToPeer
;
1401 /* how many blocks this client's sent to us in the last 120 seconds */
1402 uint32_t blocksToClient
;
1403 /* how many requests to this peer that we've cancelled in the last 120 seconds */
1404 uint32_t cancelsToPeer
;
1405 /* how many requests this peer made of us, then cancelled, in the last 120 seconds */
1406 uint32_t cancelsToClient
;
1408 /* how many requests the peer has made that we haven't responded to yet */
1409 int pendingReqsToClient
;
1411 /* how many requests we've made and are currently awaiting a response for */
1412 int pendingReqsToPeer
;
1416 tr_peer_stat
* tr_torrentPeers( const tr_torrent
* torrent
,
1419 void tr_torrentPeersFree( tr_peer_stat
* peerStats
,
1423 **** tr_tracker_stat
1428 /* we won't (announce,scrape) this torrent to this tracker because
1429 * the torrent is stopped, or because of an error, or whatever */
1430 TR_TRACKER_INACTIVE
= 0,
1432 /* we will (announce,scrape) this torrent to this tracker, and are
1433 * waiting for enough time to pass to satisfy the tracker's interval */
1434 TR_TRACKER_WAITING
= 1,
1436 /* it's time to (announce,scrape) this torrent, and we're waiting on a
1437 * a free slot to open up in the announce manager */
1438 TR_TRACKER_QUEUED
= 2,
1440 /* we're (announcing,scraping) this torrent right now */
1441 TR_TRACKER_ACTIVE
= 3
1447 /* how many downloads this tracker knows of (-1 means it does not know) */
1450 /* whether or not we've ever sent this tracker an announcement */
1451 tr_bool hasAnnounced
;
1453 /* whether or not we've ever scraped to this tracker */
1456 /* ex: http://www.legaltorrents.com:7070 */
1459 /* the full announce URL */
1460 char announce
[1024];
1462 /* the full scrape URL */
1465 /* Transmission uses one tracker per tier,
1466 * and the others are kept as backups */
1469 /* is the tracker announcing, waiting, queued, etc */
1470 tr_tracker_state announceState
;
1472 /* is the tracker scraping, waiting, queued, etc */
1473 tr_tracker_state scrapeState
;
1475 /* number of peers the tracker told us about last time.
1476 * if "lastAnnounceSucceeded" is false, this field is undefined */
1477 int lastAnnouncePeerCount
;
1479 /* human-readable string with the result of the last announce.
1480 if "hasAnnounced" is false, this field is undefined */
1481 char lastAnnounceResult
[128];
1483 /* when the last announce was sent to the tracker.
1484 * if "hasAnnounced" is false, this field is undefined */
1485 time_t lastAnnounceStartTime
;
1487 /* whether or not the last announce was a success.
1488 if "hasAnnounced" is false, this field is undefined */
1489 tr_bool lastAnnounceSucceeded
;
1491 /* whether or not the last announce timed out. */
1492 tr_bool lastAnnounceTimedOut
;
1494 /* when the last announce was completed.
1495 if "hasAnnounced" is false, this field is undefined */
1496 time_t lastAnnounceTime
;
1498 /* human-readable string with the result of the last scrape.
1499 * if "hasScraped" is false, this field is undefined */
1500 char lastScrapeResult
[128];
1502 /* when the last scrape was sent to the tracker.
1503 * if "hasScraped" is false, this field is undefined */
1504 time_t lastScrapeStartTime
;
1506 /* whether or not the last scrape was a success.
1507 if "hasAnnounced" is false, this field is undefined */
1508 tr_bool lastScrapeSucceeded
;
1510 /* whether or not the last scrape timed out. */
1511 tr_bool lastScrapeTimedOut
;
1513 /* when the last scrape was completed.
1514 if "hasScraped" is false, this field is undefined */
1515 time_t lastScrapeTime
;
1517 /* number of leechers this tracker knows of (-1 means it does not know) */
1520 /* when the next periodic announce message will be sent out.
1521 if announceState isn't TR_TRACKER_WAITING, this field is undefined */
1522 time_t nextAnnounceTime
;
1524 /* when the next periodic scrape message will be sent out.
1525 if scrapeState isn't TR_TRACKER_WAITING, this field is undefined */
1526 time_t nextScrapeTime
;
1528 /* number of seeders this tracker knows of (-1 means it does not know) */
1531 /* which tier this tracker is in */
1534 /* used to match to a tr_tracker_info */
1539 tr_tracker_stat
* tr_torrentTrackers( const tr_torrent
* torrent
,
1540 int * setmeTrackerCount
);
1542 void tr_torrentTrackersFree( tr_tracker_stat
* trackerStats
,
1548 * @brief get the download speeds for each of this torrent's webseed sources.
1550 * @return an array of tor->info.webseedCount floats giving download speeds.
1551 * Each speed in the array corresponds to the webseed at the same
1552 * array index in tor->info.webseeds.
1553 * To differentiate "idle" and "stalled" status, idle webseeds will
1554 * return -1 instead of 0 KiB/s.
1555 * NOTE: always free this array with tr_free() when you're done with it.
1557 double* tr_torrentWebSpeeds_KBps( const tr_torrent
* torrent
);
1559 typedef struct tr_file_stat
1561 uint64_t bytesCompleted
;
1566 tr_file_stat
* tr_torrentFiles( const tr_torrent
* torrent
,
1567 tr_file_index_t
* fileCount
);
1569 void tr_torrentFilesFree( tr_file_stat
* files
,
1570 tr_file_index_t fileCount
);
1573 /***********************************************************************
1574 * tr_torrentAvailability
1575 ***********************************************************************
1576 * Use this to draw an advanced progress bar which is 'size' pixels
1577 * wide. Fills 'tab' which you must have allocated: each byte is set
1578 * to either -1 if we have the piece, otherwise it is set to the number
1579 * of connected peers who have the piece.
1580 **********************************************************************/
1581 void tr_torrentAvailability( const tr_torrent
* torrent
,
1585 void tr_torrentAmountFinished( const tr_torrent
* torrent
,
1589 void tr_torrentVerify( tr_torrent
* torrent
);
1591 /***********************************************************************
1593 **********************************************************************/
1595 /** @brief a part of tr_info that represents a single file of the torrent's content */
1596 typedef struct tr_file
1598 uint64_t length
; /* Length of the file, in bytes */
1599 char * name
; /* Path to the file */
1600 int8_t priority
; /* TR_PRI_HIGH, _NORMAL, or _LOW */
1601 int8_t dnd
; /* nonzero if the file shouldn't be
1603 tr_piece_index_t firstPiece
; /* We need pieces [firstPiece... */
1604 tr_piece_index_t lastPiece
; /* ...lastPiece] to dl this file */
1605 uint64_t offset
; /* file begins at the torrent's nth byte */
1609 /** @brief a part of tr_info that represents a single piece of the torrent's content */
1610 typedef struct tr_piece
1612 uint8_t hash
[SHA_DIGEST_LENGTH
]; /* pieces hash */
1613 int8_t priority
; /* TR_PRI_HIGH, _NORMAL, or _LOW */
1614 int8_t dnd
; /* nonzero if the piece shouldn't be
1619 /** @brief information about a torrent that comes from its metainfo file */
1622 /* total size of the torrent, in bytes */
1625 /* the torrent's name */
1628 /* Path to torrent Transmission's internal copy of the .torrent file. */
1638 /* these trackers are sorted by tier */
1639 tr_tracker_info
* trackers
;
1646 tr_file_index_t fileCount
;
1648 tr_piece_index_t pieceCount
;
1651 uint8_t hash
[SHA_DIGEST_LENGTH
];
1652 char hashString
[2 * SHA_DIGEST_LENGTH
+ 1];
1654 /* hash, escaped as per rfc2396 for tracker announces */
1655 char hashEscaped
[3 * SHA_DIGEST_LENGTH
+ 1];
1659 tr_bool isMultifile
;
1662 static inline tr_bool
tr_torrentHasMetadata( const tr_torrent
* tor
)
1664 return tr_torrentInfo( tor
)->fileCount
> 0;
1668 * What the torrent is doing right now.
1670 * Note: these values will become a straight enum at some point in the future.
1671 * Do not rely on their current `bitfield' implementation
1675 TR_STATUS_CHECK_WAIT
= ( 1 << 0 ), /* Waiting in queue to check files */
1676 TR_STATUS_CHECK
= ( 1 << 1 ), /* Checking files */
1677 TR_STATUS_DOWNLOAD
= ( 1 << 2 ), /* Downloading */
1678 TR_STATUS_SEED
= ( 1 << 3 ), /* Seeding */
1679 TR_STATUS_STOPPED
= ( 1 << 4 ) /* Torrent is stopped */
1681 tr_torrent_activity
;
1685 TR_PEER_FROM_INCOMING
= 0, /* connections made to the listening port */
1686 TR_PEER_FROM_LPD
, /* peers found by local announcements */
1687 TR_PEER_FROM_TRACKER
, /* peers found from a tracker */
1688 TR_PEER_FROM_DHT
, /* peers found from the DHT */
1689 TR_PEER_FROM_PEX
, /* peers found from PEX */
1690 TR_PEER_FROM_RESUME
, /* peers found in the .resume file */
1691 TR_PEER_FROM_LTEP
, /* peer address provided in an LTEP handshake */
1697 /* everything's fine */
1700 /* when we anounced to the tracker, we got a warning in the response */
1701 TR_STAT_TRACKER_WARNING
= 1,
1703 /* when we anounced to the tracker, we got an error in the response */
1704 TR_STAT_TRACKER_ERROR
= 2,
1706 /* local trouble, such as disk full or permissions error */
1707 TR_STAT_LOCAL_ERROR
= 3
1711 /** @brief Used by tr_torrentStat() to tell clients about a torrent's state and statistics */
1712 typedef struct tr_stat
1714 /** The torrent's unique Id.
1715 @see tr_torrentId() */
1718 /** What is this torrent doing right now? */
1719 tr_torrent_activity activity
;
1721 /** Defines what kind of text is in errorString.
1723 tr_stat_errtype error
;
1725 /** A warning or error message regarding the torrent.
1727 char errorString
[512];
1729 /** When tr_stat.activity is TR_STATUS_CHECK or TR_STATUS_CHECK_WAIT,
1730 this is the percentage of how much of the files has been
1731 verified. When it gets to 1, the verify process is done.
1733 @see tr_stat.activity */
1734 double recheckProgress
;
1736 /** How much has been downloaded of the entire torrent.
1738 double percentComplete
;
1740 /** How much of the metadata the torrent has.
1741 For torrents added from a .torrent this will always be 1.
1742 For magnet links, this number will from from 0 to 1 as the metadata is downloaded.
1744 double metadataPercentComplete
;
1746 /** How much has been downloaded of the files the user wants. This differs
1747 from percentComplete if the user wants only some of the torrent's files.
1749 @see tr_stat.leftUntilDone */
1752 /** How much has been uploaded to satisfy the seed ratio.
1753 This is 1 if the ratio is reached or the torrent is set to seed forever.
1755 double seedRatioPercentDone
;
1757 /** Speed all data being sent for this torrent.
1758 This includes piece data, protocol messages, and TCP overhead */
1759 double rawUploadSpeed_KBps
;
1761 /** Speed all data being received for this torrent.
1762 This includes piece data, protocol messages, and TCP overhead */
1763 double rawDownloadSpeed_KBps
;
1765 /** Speed all piece being sent for this torrent.
1766 This ONLY counts piece data. */
1767 double pieceUploadSpeed_KBps
;
1769 /** Speed all piece being received for this torrent.
1770 This ONLY counts piece data. */
1771 double pieceDownloadSpeed_KBps
;
1773 #define TR_ETA_NOT_AVAIL -1
1774 #define TR_ETA_UNKNOWN -2
1775 /** If downloading, estimated number of seconds left until the torrent is done.
1776 If seeding, estimated number of seconds left until seed ratio is reached. */
1778 /** If seeding, number of seconds left until the idle time limit is reached. */
1781 /** Number of peers that the tracker says this torrent has */
1784 /** Number of peers that we're connected to */
1787 /** How many peers we found out about from the tracker, or from pex,
1788 or from incoming connections, or from our resume file. */
1789 int peersFrom
[TR_PEER_FROM__MAX
];
1791 /** Number of peers that are sending data to us. */
1792 int peersSendingToUs
;
1794 /** Number of peers that we're sending data to */
1795 int peersGettingFromUs
;
1797 /** Number of webseeds that are sending data to us. */
1798 int webseedsSendingToUs
;
1800 //TorrentFlux -START-
1801 /** Number of seeders that the tracker says this torrent has */
1804 /** Number of leechers that the tracker says this torrent has */
1807 /** Number of downloaders that the tracker says this torrent has.
1808 This is a new key introduced in BEP 21 and may not be supported by some trackers.
1809 If the tracker doesn't support this key, the value here will be -1. */
1812 /** Number of finished downloads that the tracker says torrent has */
1816 /** Byte count of all the piece data we'll have downloaded when we're done,
1817 whether or not we have it yet. This may be less than tr_info.totalSize
1818 if only some of the torrent's files are wanted.
1819 [0...tr_info.totalSize] */
1820 uint64_t sizeWhenDone
;
1822 /** Byte count of how much data is left to be downloaded until we've got
1823 all the pieces that we want. [0...tr_info.sizeWhenDone] */
1824 uint64_t leftUntilDone
;
1826 /** Byte count of all the piece data we want and don't have yet,
1827 but that a connected peer does have. [0...leftUntilDone] */
1828 uint64_t desiredAvailable
;
1830 /** Byte count of all the corrupt data you've ever downloaded for
1831 this torrent. If you're on a poisoned torrent, this number can
1833 uint64_t corruptEver
;
1835 /** Byte count of all data you've ever uploaded for this torrent. */
1836 uint64_t uploadedEver
;
1838 /** Byte count of all the non-corrupt data you've ever downloaded
1839 for this torrent. If you deleted the files and downloaded a second
1840 time, this will be 2*totalSize.. */
1841 uint64_t downloadedEver
;
1843 /** Byte count of all the checksum-verified data we have for this torrent.
1847 /** Byte count of all the partial piece data we have for this torrent.
1848 As pieces become complete, this value may decrease as portions of it
1849 are moved to `corrupt' or `haveValid'. */
1850 uint64_t haveUnchecked
;
1852 /** time when one or more of the torrent's trackers will
1853 allow you to manually ask for more peers,
1854 or 0 if you can't */
1855 time_t manualAnnounceTime
;
1857 #define TR_RATIO_NA -1
1858 #define TR_RATIO_INF -2
1859 /** TR_RATIO_INF, TR_RATIO_NA, or a regular ratio */
1862 /** When the torrent was first added. */
1865 /** When the torrent finished downloading. */
1868 /** When the torrent was last started. */
1871 /** The last time we uploaded or downloaded piece data on this torrent. */
1872 time_t activityDate
;
1874 /** Number of seconds since the last activity (or since started).
1875 -1 if activity is not seeding or downloading. */
1878 /** A torrent is considered finished if it has met its seed ratio.
1879 As a result, only paused torrents can be finished. */
1884 /** Return a pointer to an tr_stat structure with updated information
1885 on the torrent. This is typically called by the GUI clients every
1886 second or so to get a new snapshot of the torrent's status. */
1887 const tr_stat
* tr_torrentStat( tr_torrent
* torrent
);
1889 /** Like tr_torrentStat(), but only recalculates the statistics if it's
1890 been longer than a second since they were last calculated. This can
1891 reduce the CPU load if you're calling tr_torrentStat() frequently. */
1892 const tr_stat
* tr_torrentStatCached( tr_torrent
* torrent
);
1895 void tr_torrentSetAddedDate( tr_torrent
* torrent
,
1899 void tr_torrentSetActivityDate( tr_torrent
* torrent
,
1900 time_t activityDate
);
1903 void tr_torrentSetDoneDate( tr_torrent
* torrent
, time_t doneDate
);
1907 /** @brief Sanity checker to test that the direction is TR_UP or TR_DOWN */
1908 static inline tr_bool
tr_isDirection( tr_direction d
) { return d
==TR_UP
|| d
==TR_DOWN
; }
1910 /** @brief Sanity checker to test that a bool is TRUE or FALSE */
1911 static inline tr_bool
tr_isBool( tr_bool b
) { return b
==1 || b
==0; }