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