1 | /****************************************************************************** |
---|
2 | * $Id: transmission.h 8741 2009-06-24 04:36:18Z 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_LAZY_BITFIELD "lazy-bitfield-enabled" |
---|
172 | #define TR_PREFS_KEY_MSGLEVEL "message-level" |
---|
173 | #define TR_PREFS_KEY_OPEN_FILE_LIMIT "open-file-limit" |
---|
174 | #define TR_PREFS_KEY_PEER_LIMIT_GLOBAL "peer-limit-global" |
---|
175 | #define TR_PREFS_KEY_PEER_LIMIT_TORRENT "peer-limit-per-torrent" |
---|
176 | #define TR_PREFS_KEY_PEER_PORT "peer-port" |
---|
177 | #define TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START "peer-port-random-on-start" |
---|
178 | #define TR_PREFS_KEY_PEER_PORT_RANDOM_LOW "peer-port-random-low" |
---|
179 | #define TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH "peer-port-random-high" |
---|
180 | #define TR_PREFS_KEY_PEER_SOCKET_TOS "peer-socket-tos" |
---|
181 | #define TR_PREFS_KEY_PEX_ENABLED "pex-enabled" |
---|
182 | #define TR_PREFS_KEY_PORT_FORWARDING "port-forwarding-enabled" |
---|
183 | #define TR_PREFS_KEY_PROXY_AUTH_ENABLED "proxy-auth-enabled" |
---|
184 | #define TR_PREFS_KEY_PREALLOCATION "preallocation" |
---|
185 | #define TR_PREFS_KEY_PROXY_ENABLED "proxy-enabled" |
---|
186 | #define TR_PREFS_KEY_PROXY_PASSWORD "proxy-auth-password" |
---|
187 | #define TR_PREFS_KEY_PROXY_PORT "proxy-port" |
---|
188 | #define TR_PREFS_KEY_PROXY "proxy" |
---|
189 | #define TR_PREFS_KEY_PROXY_TYPE "proxy-type" |
---|
190 | #define TR_PREFS_KEY_PROXY_USERNAME "proxy-auth-username" |
---|
191 | #define TR_PREFS_KEY_RATIO "ratio-limit" |
---|
192 | #define TR_PREFS_KEY_RATIO_ENABLED "ratio-limit-enabled" |
---|
193 | #define TR_PREFS_KEY_RPC_AUTH_REQUIRED "rpc-authentication-required" |
---|
194 | #define TR_PREFS_KEY_RPC_BIND_ADDRESS "rpc-bind-address" |
---|
195 | #define TR_PREFS_KEY_RPC_ENABLED "rpc-enabled" |
---|
196 | #define TR_PREFS_KEY_RPC_PASSWORD "rpc-password" |
---|
197 | #define TR_PREFS_KEY_RPC_PORT "rpc-port" |
---|
198 | #define TR_PREFS_KEY_RPC_USERNAME "rpc-username" |
---|
199 | #define TR_PREFS_KEY_RPC_WHITELIST_ENABLED "rpc-whitelist-enabled" |
---|
200 | #define TR_PREFS_KEY_RPC_WHITELIST "rpc-whitelist" |
---|
201 | #define TR_PREFS_KEY_DSPEED "speed-limit-down" |
---|
202 | #define TR_PREFS_KEY_DSPEED_ENABLED "speed-limit-down-enabled" |
---|
203 | #define TR_PREFS_KEY_USPEED_ENABLED "speed-limit-up-enabled" |
---|
204 | #define TR_PREFS_KEY_USPEED "speed-limit-up" |
---|
205 | #define TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT "upload-slots-per-torrent" |
---|
206 | |
---|
207 | |
---|
208 | /** |
---|
209 | * Add libtransmission's default settings to the benc dictionary. |
---|
210 | * |
---|
211 | * Example: |
---|
212 | * @code |
---|
213 | * tr_benc settings; |
---|
214 | * int64_t i; |
---|
215 | * |
---|
216 | * tr_bencInitDict( &settings, 0 ); |
---|
217 | * tr_sessionGetDefaultSettings( &settings ); |
---|
218 | * if( tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT, &i ) ) |
---|
219 | * fprintf( stderr, "the default peer port is %d\n", (int)i ); |
---|
220 | * tr_bencFree( &settings ); |
---|
221 | * @endcode |
---|
222 | * |
---|
223 | * @param initme pointer to a tr_benc dictionary |
---|
224 | * @see tr_sessionLoadSettings() |
---|
225 | * @see tr_sessionInit() |
---|
226 | * @see tr_getDefaultConfigDir() |
---|
227 | */ |
---|
228 | void tr_sessionGetDefaultSettings( struct tr_benc * dictionary ); |
---|
229 | |
---|
230 | /** |
---|
231 | * Add the session's current configuration settings to the benc dictionary. |
---|
232 | * |
---|
233 | * FIXME: this probably belongs in libtransmissionapp |
---|
234 | * |
---|
235 | * @param session |
---|
236 | * @param dictionary |
---|
237 | * @see tr_sessionGetDefaultSettings() |
---|
238 | */ |
---|
239 | void tr_sessionGetSettings( tr_session *, struct tr_benc * dictionary ); |
---|
240 | |
---|
241 | /** |
---|
242 | * Load settings from the configuration directory's settings.json file, |
---|
243 | * using libtransmission's default settings as fallbacks for missing keys. |
---|
244 | * |
---|
245 | * FIXME: this belongs in libtransmissionapp |
---|
246 | * |
---|
247 | * @param dictionary pointer to an uninitialized tr_benc |
---|
248 | * @param configDir the configuration directory to find settings.json |
---|
249 | * @param appName if configDir is empty, appName is used to find the default dir. |
---|
250 | * @see tr_sessionGetDefaultSettings() |
---|
251 | * @see tr_sessionInit() |
---|
252 | * @see tr_sessionSaveSettings() |
---|
253 | */ |
---|
254 | void tr_sessionLoadSettings( struct tr_benc * dictionary, |
---|
255 | const char * configDir, |
---|
256 | const char * appName ); |
---|
257 | |
---|
258 | /** |
---|
259 | * Add the session's configuration settings to the benc dictionary |
---|
260 | * and save it to the configuration directory's settings.json file. |
---|
261 | * |
---|
262 | * FIXME: this belongs in libtransmissionapp |
---|
263 | * |
---|
264 | * @param session |
---|
265 | * @param dictionary |
---|
266 | * @see tr_sessionLoadSettings() |
---|
267 | */ |
---|
268 | void tr_sessionSaveSettings( tr_session * session, |
---|
269 | const char * configDir, |
---|
270 | const struct tr_benc * dictonary ); |
---|
271 | |
---|
272 | /** |
---|
273 | * @brief Initialize a libtransmission session. |
---|
274 | * |
---|
275 | * For example, this will instantiate a session with all the default values: |
---|
276 | * @code |
---|
277 | * tr_benc settings; |
---|
278 | * tr_session * session; |
---|
279 | * const char * configDir; |
---|
280 | * |
---|
281 | * tr_bencInitDict( &settings, 0 ); |
---|
282 | * tr_sessionGetDefaultSettings( &settings ); |
---|
283 | * configDir = tr_getDefaultConfigDir( "Transmission" ); |
---|
284 | * session = tr_sessionInit( "mac", configDir, true, &settings ); |
---|
285 | * |
---|
286 | * tr_bencFree( &settings ); |
---|
287 | * @endcode |
---|
288 | * |
---|
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() |
---|
296 | */ |
---|
297 | tr_session * tr_sessionInit( const char * tag, |
---|
298 | const char * configDir, |
---|
299 | tr_bool messageQueueingEnabled, |
---|
300 | struct tr_benc * settings ); |
---|
301 | |
---|
302 | /** @brief End a libtransmission session |
---|
303 | @see tr_sessionInit() */ |
---|
304 | void tr_sessionClose( tr_session * ); |
---|
305 | |
---|
306 | /** |
---|
307 | * @brief Return the session's configuration directory. |
---|
308 | * |
---|
309 | * This is where transmission stores its .torrent files, .resume files, |
---|
310 | * blocklists, etc. It's set in tr_transmissionInit() and is immutable |
---|
311 | * during the session. |
---|
312 | */ |
---|
313 | const char * tr_sessionGetConfigDir( const tr_session * ); |
---|
314 | |
---|
315 | /** |
---|
316 | * @brief Set the per-session default download folder for new torrents. |
---|
317 | * @see tr_sessionInit() |
---|
318 | * @see tr_sessionGetDownloadDir() |
---|
319 | * @see tr_ctorSetDownloadDir() |
---|
320 | */ |
---|
321 | void tr_sessionSetDownloadDir( tr_session * session, const char * downloadDir ); |
---|
322 | |
---|
323 | /** |
---|
324 | * @brief Get the default download folder for new torrents. |
---|
325 | * |
---|
326 | * This is set by tr_sessionInit() or tr_sessionSetDownloadDir(), |
---|
327 | * and can be overridden on a per-torrent basis by tr_ctorSetDownloadDir(). |
---|
328 | */ |
---|
329 | const char * tr_sessionGetDownloadDir( const tr_session * session ); |
---|
330 | |
---|
331 | /** |
---|
332 | * @brief Set whether or not RPC calls are allowed in this session. |
---|
333 | * |
---|
334 | * @details If true, libtransmission will open a server socket to listen |
---|
335 | * for incoming http RPC requests as described in docs/rpc-spec.txt. |
---|
336 | * |
---|
337 | * This is intially set by tr_sessionInit() and can be |
---|
338 | * queried by tr_sessionIsRPCEnabled(). |
---|
339 | */ |
---|
340 | void tr_sessionSetRPCEnabled( tr_session * session, |
---|
341 | tr_bool isEnabled ); |
---|
342 | |
---|
343 | /** @brief Get whether or not RPC calls are allowed in this session. |
---|
344 | @see tr_sessionInit() |
---|
345 | @see tr_sessionSetRPCEnabled() */ |
---|
346 | tr_bool tr_sessionIsRPCEnabled( const tr_session * session ); |
---|
347 | |
---|
348 | /** @brief Specify which port to listen for RPC requests on. |
---|
349 | @see tr_sessionInit() |
---|
350 | @see tr_sessionGetRPCPort */ |
---|
351 | void tr_sessionSetRPCPort( tr_session * session, |
---|
352 | tr_port port ); |
---|
353 | |
---|
354 | /** @brief Get which port to listen for RPC requests on. |
---|
355 | @see tr_sessionInit() |
---|
356 | @see tr_sessionSetRPCPort */ |
---|
357 | tr_port tr_sessionGetRPCPort( const tr_session * session ); |
---|
358 | |
---|
359 | /** |
---|
360 | * @brief Specify a whitelist for remote RPC access |
---|
361 | * |
---|
362 | * The whitelist is a comma-separated list of dotted-quad IP addresses |
---|
363 | * to be allowed. Wildmat notation is supported, meaning that |
---|
364 | * '?' is interpreted as a single-character wildcard and |
---|
365 | * '*' is interprted as a multi-character wildcard. |
---|
366 | */ |
---|
367 | void tr_sessionSetRPCWhitelist( tr_session * session, |
---|
368 | const char * whitelist ); |
---|
369 | |
---|
370 | /** @brief get the Access Control List for allowing/denying RPC requests. |
---|
371 | @return a comma-separated string of whitelist domains. |
---|
372 | @see tr_sessionInit |
---|
373 | @see tr_sessionSetRPCWhitelist */ |
---|
374 | const char* tr_sessionGetRPCWhitelist( const tr_session * ); |
---|
375 | |
---|
376 | void tr_sessionSetRPCWhitelistEnabled( tr_session * session, |
---|
377 | tr_bool isEnabled ); |
---|
378 | |
---|
379 | tr_bool tr_sessionGetRPCWhitelistEnabled( const tr_session * session ); |
---|
380 | |
---|
381 | void tr_sessionSetRPCPassword( tr_session * session, |
---|
382 | const char * password ); |
---|
383 | |
---|
384 | void tr_sessionSetRPCUsername( tr_session * session, |
---|
385 | const char * username ); |
---|
386 | |
---|
387 | /** @brief get the password used to restrict RPC requests. |
---|
388 | @return the password string. |
---|
389 | @see tr_sessionInit() |
---|
390 | @see tr_sessionSetRPCPassword() */ |
---|
391 | const char* tr_sessionGetRPCPassword( const tr_session * session ); |
---|
392 | |
---|
393 | const char* tr_sessionGetRPCUsername( const tr_session * session ); |
---|
394 | |
---|
395 | void tr_sessionSetRPCPasswordEnabled( tr_session * session, |
---|
396 | tr_bool isEnabled ); |
---|
397 | |
---|
398 | tr_bool tr_sessionIsRPCPasswordEnabled( const tr_session * session ); |
---|
399 | |
---|
400 | const char* tr_sessionGetRPCBindAddress( const tr_session * session ); |
---|
401 | |
---|
402 | |
---|
403 | typedef enum |
---|
404 | { |
---|
405 | TR_RPC_TORRENT_ADDED, |
---|
406 | TR_RPC_TORRENT_STARTED, |
---|
407 | TR_RPC_TORRENT_STOPPED, |
---|
408 | TR_RPC_TORRENT_REMOVING, |
---|
409 | TR_RPC_TORRENT_CHANGED, /* catch-all for the "torrent-set" rpc method */ |
---|
410 | TR_RPC_SESSION_CHANGED |
---|
411 | } |
---|
412 | tr_rpc_callback_type; |
---|
413 | |
---|
414 | typedef enum |
---|
415 | { |
---|
416 | /* no special handling is needed by the caller */ |
---|
417 | TR_RPC_OK = 0, |
---|
418 | |
---|
419 | /* indicates to the caller that the client will take care of |
---|
420 | * removing the torrent itself. For example the client may |
---|
421 | * need to keep the torrent alive long enough to cleanly close |
---|
422 | * some resources in another thread. */ |
---|
423 | TR_RPC_NOREMOVE = ( 1 << 1 ) |
---|
424 | } |
---|
425 | tr_rpc_callback_status; |
---|
426 | |
---|
427 | typedef tr_rpc_callback_status (*tr_rpc_func)(tr_session * session, |
---|
428 | tr_rpc_callback_type type, |
---|
429 | struct tr_torrent * tor_or_null, |
---|
430 | void * user_data ); |
---|
431 | |
---|
432 | /** |
---|
433 | * Register to be notified whenever something is changed via RPC, |
---|
434 | * such as a torrent being added, removed, started, stopped, etc. |
---|
435 | * |
---|
436 | * func is invoked FROM LIBTRANSMISSION'S THREAD! |
---|
437 | * This means func must be fast (to avoid blocking peers), |
---|
438 | * shouldn't call libtransmission functions (to avoid deadlock), |
---|
439 | * and shouldn't modify client-level memory without using a mutex! |
---|
440 | */ |
---|
441 | void tr_sessionSetRPCCallback( tr_session * session, |
---|
442 | tr_rpc_func func, |
---|
443 | void * user_data ); |
---|
444 | |
---|
445 | /** |
---|
446 | *** |
---|
447 | **/ |
---|
448 | |
---|
449 | tr_bool tr_sessionIsProxyEnabled( const tr_session * ); |
---|
450 | |
---|
451 | tr_bool tr_sessionIsProxyAuthEnabled( const tr_session * ); |
---|
452 | |
---|
453 | const char* tr_sessionGetProxy( const tr_session * ); |
---|
454 | |
---|
455 | tr_port tr_sessionGetProxyPort( const tr_session * ); |
---|
456 | |
---|
457 | tr_proxy_type tr_sessionGetProxyType( const tr_session * ); |
---|
458 | |
---|
459 | const char* tr_sessionGetProxyUsername( const tr_session * ); |
---|
460 | |
---|
461 | const char* tr_sessionGetProxyPassword( const tr_session * ); |
---|
462 | |
---|
463 | void tr_sessionSetProxyEnabled( tr_session * session, |
---|
464 | tr_bool isEnabled ); |
---|
465 | |
---|
466 | void tr_sessionSetProxyAuthEnabled( tr_session * session, |
---|
467 | tr_bool isEnabled ); |
---|
468 | |
---|
469 | void tr_sessionSetProxy( tr_session * session, |
---|
470 | const char * proxy ); |
---|
471 | |
---|
472 | void tr_sessionSetProxyPort( tr_session * session, |
---|
473 | tr_port port ); |
---|
474 | |
---|
475 | void tr_sessionSetProxyType( tr_session * session, |
---|
476 | tr_proxy_type proxy_type ); |
---|
477 | |
---|
478 | void tr_sessionSetProxyUsername( tr_session * session, |
---|
479 | const char * username ); |
---|
480 | |
---|
481 | void tr_sessionSetProxyPassword( tr_session * session, |
---|
482 | const char * password ); |
---|
483 | |
---|
484 | /** |
---|
485 | *** |
---|
486 | **/ |
---|
487 | |
---|
488 | typedef struct tr_session_stats |
---|
489 | { |
---|
490 | float ratio; /* TR_RATIO_INF, TR_RATIO_NA, or total up/down */ |
---|
491 | uint64_t uploadedBytes; /* total up */ |
---|
492 | uint64_t downloadedBytes; /* total down */ |
---|
493 | uint64_t filesAdded; /* number of files added */ |
---|
494 | uint64_t sessionCount; /* program started N times */ |
---|
495 | uint64_t secondsActive; /* how long Transmisson's been running */ |
---|
496 | } |
---|
497 | tr_session_stats; |
---|
498 | |
---|
499 | /* stats from the current session. */ |
---|
500 | void tr_sessionGetStats( const tr_session * session, |
---|
501 | tr_session_stats * setme ); |
---|
502 | |
---|
503 | /* stats from the current and past sessions. */ |
---|
504 | void tr_sessionGetCumulativeStats( const tr_session * session, |
---|
505 | tr_session_stats * setme ); |
---|
506 | |
---|
507 | void tr_sessionClearStats( tr_session * session ); |
---|
508 | |
---|
509 | /** |
---|
510 | * Set whether or not torrents are allowed to do peer exchanges. |
---|
511 | * PEX is always disabled in private torrents regardless of this. |
---|
512 | * In public torrents, PEX is enabled by default. |
---|
513 | */ |
---|
514 | void tr_sessionSetPexEnabled( tr_session * session, |
---|
515 | tr_bool isEnabled ); |
---|
516 | |
---|
517 | tr_bool tr_sessionIsPexEnabled( const tr_session * session ); |
---|
518 | |
---|
519 | tr_bool tr_sessionIsDHTEnabled( const tr_session * session ); |
---|
520 | |
---|
521 | void tr_sessionSetDHTEnabled( tr_session * session, tr_bool ); |
---|
522 | |
---|
523 | void tr_sessionSetLazyBitfieldEnabled( tr_session * session, |
---|
524 | tr_bool enabled ); |
---|
525 | |
---|
526 | tr_bool tr_sessionIsLazyBitfieldEnabled( const tr_session * session ); |
---|
527 | |
---|
528 | tr_encryption_mode tr_sessionGetEncryption( tr_session * session ); |
---|
529 | |
---|
530 | void tr_sessionSetEncryption( tr_session * session, |
---|
531 | tr_encryption_mode mode ); |
---|
532 | |
---|
533 | |
---|
534 | /*********************************************************************** |
---|
535 | ** Incoming Peer Connections Port |
---|
536 | */ |
---|
537 | |
---|
538 | void tr_sessionSetPortForwardingEnabled( tr_session * session, |
---|
539 | tr_bool enabled ); |
---|
540 | |
---|
541 | tr_bool tr_sessionIsPortForwardingEnabled( const tr_session * session ); |
---|
542 | |
---|
543 | void tr_sessionSetPeerPort( tr_session * session, |
---|
544 | tr_port port); |
---|
545 | |
---|
546 | tr_port tr_sessionGetPeerPort( const tr_session * session ); |
---|
547 | |
---|
548 | tr_port tr_sessionSetPeerPortRandom( tr_session * session ); |
---|
549 | |
---|
550 | void tr_sessionSetPeerPortRandomOnStart( tr_session * session, |
---|
551 | tr_bool random ); |
---|
552 | |
---|
553 | tr_bool tr_sessionGetPeerPortRandomOnStart( tr_session * session ); |
---|
554 | |
---|
555 | typedef enum |
---|
556 | { |
---|
557 | TR_PORT_ERROR, |
---|
558 | TR_PORT_UNMAPPED, |
---|
559 | TR_PORT_UNMAPPING, |
---|
560 | TR_PORT_MAPPING, |
---|
561 | TR_PORT_MAPPED |
---|
562 | } |
---|
563 | tr_port_forwarding; |
---|
564 | |
---|
565 | tr_port_forwarding tr_sessionGetPortForwarding( const tr_session * session ); |
---|
566 | |
---|
567 | int tr_sessionCountTorrents( const tr_session * session ); |
---|
568 | |
---|
569 | typedef enum |
---|
570 | { |
---|
571 | TR_CLIENT_TO_PEER = 0, TR_UP = 0, |
---|
572 | TR_PEER_TO_CLIENT = 1, TR_DOWN = 1 |
---|
573 | } |
---|
574 | tr_direction; |
---|
575 | |
---|
576 | /*** |
---|
577 | **** |
---|
578 | ***/ |
---|
579 | |
---|
580 | /*** |
---|
581 | **** Primary session speed limits |
---|
582 | ***/ |
---|
583 | |
---|
584 | void tr_sessionSetSpeedLimit ( tr_session *, tr_direction, int KB_s ); |
---|
585 | int tr_sessionGetSpeedLimit ( const tr_session *, tr_direction ); |
---|
586 | |
---|
587 | void tr_sessionLimitSpeed ( tr_session *, tr_direction, tr_bool ); |
---|
588 | tr_bool tr_sessionIsSpeedLimited ( const tr_session *, tr_direction ); |
---|
589 | |
---|
590 | |
---|
591 | /*** |
---|
592 | **** Alternative speed limits that are used during scheduled times |
---|
593 | ***/ |
---|
594 | |
---|
595 | void tr_sessionSetAltSpeed ( tr_session *, tr_direction, int KB_s ); |
---|
596 | int tr_sessionGetAltSpeed ( const tr_session *, tr_direction ); |
---|
597 | |
---|
598 | void tr_sessionUseAltSpeed ( tr_session *, tr_bool ); |
---|
599 | tr_bool tr_sessionUsesAltSpeed ( const tr_session * ); |
---|
600 | |
---|
601 | void tr_sessionUseAltSpeedTime ( tr_session *, tr_bool ); |
---|
602 | tr_bool tr_sessionUsesAltSpeedTime ( const tr_session * ); |
---|
603 | |
---|
604 | void tr_sessionSetAltSpeedBegin ( tr_session *, int minsSinceMidnight ); |
---|
605 | int tr_sessionGetAltSpeedBegin ( const tr_session * ); |
---|
606 | |
---|
607 | void tr_sessionSetAltSpeedEnd ( tr_session *, int minsSinceMidnight ); |
---|
608 | int tr_sessionGetAltSpeedEnd ( const tr_session * ); |
---|
609 | |
---|
610 | typedef enum |
---|
611 | { |
---|
612 | TR_SCHED_SUN = (1<<0), |
---|
613 | TR_SCHED_MON = (1<<1), |
---|
614 | TR_SCHED_TUES = (1<<2), |
---|
615 | TR_SCHED_WED = (1<<3), |
---|
616 | TR_SCHED_THURS = (1<<4), |
---|
617 | TR_SCHED_FRI = (1<<5), |
---|
618 | TR_SCHED_SAT = (1<<6), |
---|
619 | TR_SCHED_WEEKDAY = (TR_SCHED_MON|TR_SCHED_TUES|TR_SCHED_WED|TR_SCHED_THURS|TR_SCHED_FRI), |
---|
620 | TR_SCHED_WEEKEND = (TR_SCHED_SUN|TR_SCHED_SAT), |
---|
621 | TR_SCHED_ALL = (TR_SCHED_WEEKDAY|TR_SCHED_WEEKEND) |
---|
622 | } |
---|
623 | tr_sched_day; |
---|
624 | |
---|
625 | void tr_sessionSetAltSpeedDay ( tr_session *, tr_sched_day day ); |
---|
626 | tr_sched_day tr_sessionGetAltSpeedDay ( const tr_session * ); |
---|
627 | |
---|
628 | typedef void ( tr_altSpeedFunc ) ( tr_session *, tr_bool active, tr_bool userDriven, void * ); |
---|
629 | void tr_sessionClearAltSpeedFunc ( tr_session * ); |
---|
630 | void tr_sessionSetAltSpeedFunc ( tr_session *, tr_altSpeedFunc *, void * ); |
---|
631 | |
---|
632 | /*** |
---|
633 | **** |
---|
634 | ***/ |
---|
635 | |
---|
636 | double tr_sessionGetRawSpeed ( const tr_session *, tr_direction ); |
---|
637 | double tr_sessionGetPieceSpeed ( const tr_session *, tr_direction ); |
---|
638 | |
---|
639 | |
---|
640 | void tr_sessionSetRatioLimited ( tr_session *, tr_bool isLimited ); |
---|
641 | tr_bool tr_sessionIsRatioLimited ( const tr_session * ); |
---|
642 | |
---|
643 | void tr_sessionSetRatioLimit ( tr_session *, double desiredRatio ); |
---|
644 | double tr_sessionGetRatioLimit ( const tr_session * ); |
---|
645 | |
---|
646 | void tr_sessionSetPeerLimit( tr_session *, uint16_t maxGlobalPeers ); |
---|
647 | uint16_t tr_sessionGetPeerLimit( const tr_session * ); |
---|
648 | |
---|
649 | void tr_sessionSetPeerLimitPerTorrent( tr_session *, uint16_t maxGlobalPeers ); |
---|
650 | uint16_t tr_sessionGetPeerLimitPerTorrent( const tr_session * ); |
---|
651 | |
---|
652 | tr_priority_t tr_torrentGetPriority( const tr_torrent * ); |
---|
653 | void tr_torrentSetPriority( tr_torrent *, tr_priority_t ); |
---|
654 | |
---|
655 | |
---|
656 | /** |
---|
657 | * Load all the torrents in tr_getTorrentDir(). |
---|
658 | * This can be used at startup to kickstart all the torrents |
---|
659 | * from the previous session. |
---|
660 | */ |
---|
661 | tr_torrent ** tr_sessionLoadTorrents( tr_session * session, |
---|
662 | tr_ctor * ctor, |
---|
663 | int * setmeCount ); |
---|
664 | |
---|
665 | int tr_sessionGetActiveTorrentCount( tr_session * session ); |
---|
666 | |
---|
667 | /** @} */ |
---|
668 | |
---|
669 | /** |
---|
670 | *** |
---|
671 | **/ |
---|
672 | |
---|
673 | |
---|
674 | /*********************************************************************** |
---|
675 | ** Message Logging |
---|
676 | */ |
---|
677 | |
---|
678 | enum |
---|
679 | { |
---|
680 | TR_MSG_ERR = 1, |
---|
681 | TR_MSG_INF = 2, |
---|
682 | TR_MSG_DBG = 3 |
---|
683 | }; |
---|
684 | void tr_setMessageLevel( int ); |
---|
685 | |
---|
686 | int tr_getMessageLevel( void ); |
---|
687 | |
---|
688 | typedef struct tr_msg_list |
---|
689 | { |
---|
690 | /* TR_MSG_ERR, TR_MSG_INF, or TR_MSG_DBG */ |
---|
691 | uint8_t level; |
---|
692 | |
---|
693 | /* The line number in the source file where this message originated */ |
---|
694 | int line; |
---|
695 | |
---|
696 | /* Time the message was generated */ |
---|
697 | time_t when; |
---|
698 | |
---|
699 | /* The torrent associated with this message, |
---|
700 | * or a module name such as "Port Forwarding" for non-torrent messages, |
---|
701 | * or NULL. */ |
---|
702 | char * name; |
---|
703 | |
---|
704 | /* The message */ |
---|
705 | char * message; |
---|
706 | |
---|
707 | /* The source file where this message originated */ |
---|
708 | const char * file; |
---|
709 | |
---|
710 | /* linked list of messages */ |
---|
711 | struct tr_msg_list * next; |
---|
712 | } |
---|
713 | tr_msg_list; |
---|
714 | |
---|
715 | void tr_setMessageQueuing( tr_bool isEnabled ); |
---|
716 | |
---|
717 | tr_bool tr_getMessageQueuing( void ); |
---|
718 | |
---|
719 | tr_msg_list * tr_getQueuedMessages( void ); |
---|
720 | |
---|
721 | void tr_freeMessageList( tr_msg_list * freeme ); |
---|
722 | |
---|
723 | /** @addtogroup Blocklists |
---|
724 | @{ */ |
---|
725 | |
---|
726 | /** |
---|
727 | * Specify a range of IPs for Transmission to block. |
---|
728 | * |
---|
729 | * filename must be an uncompressed ascii file, |
---|
730 | * using the same format as the bluetack level1 file. |
---|
731 | * |
---|
732 | * libtransmission does not keep a handle to `filename' |
---|
733 | * after this call returns, so the caller is free to |
---|
734 | * keep or delete `filename' as it wishes. |
---|
735 | * libtransmission makes its own copy of the file |
---|
736 | * massaged into a format easier to search. |
---|
737 | * |
---|
738 | * The caller only needs to invoke this when the blocklist |
---|
739 | * has changed. |
---|
740 | * |
---|
741 | * Passing NULL for a filename will clear the blocklist. |
---|
742 | */ |
---|
743 | int tr_blocklistSetContent ( tr_session * session, |
---|
744 | const char * filename ); |
---|
745 | |
---|
746 | int tr_blocklistGetRuleCount ( const tr_session * session ); |
---|
747 | |
---|
748 | tr_bool tr_blocklistExists ( const tr_session * session ); |
---|
749 | |
---|
750 | tr_bool tr_blocklistIsEnabled ( const tr_session * session ); |
---|
751 | |
---|
752 | void tr_blocklistSetEnabled ( tr_session * session, |
---|
753 | tr_bool isEnabled ); |
---|
754 | |
---|
755 | |
---|
756 | /** @} */ |
---|
757 | |
---|
758 | |
---|
759 | /** @addtogroup tr_ctor Torrent Constructors |
---|
760 | @{ |
---|
761 | |
---|
762 | Instantiating a tr_torrent had gotten more complicated as features were |
---|
763 | added. At one point there were four functions to check metainfo and five |
---|
764 | to create tr_torrent. |
---|
765 | |
---|
766 | To remedy this, a Torrent Constructor (struct tr_ctor) has been introduced: |
---|
767 | - Simplifies the API to two functions: tr_torrentParse() and tr_torrentNew() |
---|
768 | - You can set the fields you want; the system sets defaults for the rest. |
---|
769 | - You can specify whether or not your fields should supercede resume's. |
---|
770 | - We can add new features to tr_ctor without breaking tr_torrentNew()'s API. |
---|
771 | |
---|
772 | All the tr_ctor{Get,Set}*() functions with a return value return |
---|
773 | an error number, or zero if no error occurred. |
---|
774 | |
---|
775 | You must call one of the SetMetainfo() functions before creating |
---|
776 | a torrent with a tr_ctor. The other functions are optional. |
---|
777 | |
---|
778 | You can reuse a single tr_ctor to create a batch of torrents -- |
---|
779 | just call one of the SetMetainfo() functions between each |
---|
780 | tr_torrentNew() call. |
---|
781 | |
---|
782 | Every call to tr_ctorSetMetainfo*() frees the previous metainfo. |
---|
783 | */ |
---|
784 | |
---|
785 | typedef enum |
---|
786 | { |
---|
787 | TR_FALLBACK, /* indicates the ctor value should be used only |
---|
788 | in case of missing resume settings */ |
---|
789 | |
---|
790 | TR_FORCE, /* indicates the ctor value should be used |
---|
791 | regardless of what's in the resume settings */ |
---|
792 | } |
---|
793 | tr_ctorMode; |
---|
794 | |
---|
795 | struct tr_benc; |
---|
796 | |
---|
797 | /* it's okay to use NULL here if you're only parsing the torrent. |
---|
798 | * @see tr_torrentParse() */ |
---|
799 | tr_ctor* tr_ctorNew( const tr_session * session_or_NULL ); |
---|
800 | |
---|
801 | void tr_ctorFree( tr_ctor * ctor ); |
---|
802 | |
---|
803 | void tr_ctorSetDeleteSource( tr_ctor * ctor, |
---|
804 | tr_bool doDelete ); |
---|
805 | |
---|
806 | int tr_ctorSetMetainfo( tr_ctor * ctor, |
---|
807 | const uint8_t * metainfo, |
---|
808 | size_t len ); |
---|
809 | |
---|
810 | int tr_ctorSetMetainfoFromFile( tr_ctor * ctor, |
---|
811 | const char * filename ); |
---|
812 | |
---|
813 | int tr_ctorSetMetainfoFromHash( tr_ctor * ctor, |
---|
814 | const char * hashString ); |
---|
815 | |
---|
816 | /** Set the maximum number of peers this torrent can connect to. |
---|
817 | (Default: 50) */ |
---|
818 | void tr_ctorSetPeerLimit( tr_ctor * ctor, |
---|
819 | tr_ctorMode mode, |
---|
820 | uint16_t peerLimit ); |
---|
821 | |
---|
822 | /** Set the download folder for the torrent being added with this ctor. |
---|
823 | @see tr_ctorSetDownloadDir() |
---|
824 | @see tr_sessionInit() */ |
---|
825 | void tr_ctorSetDownloadDir( tr_ctor * ctor, |
---|
826 | tr_ctorMode mode, |
---|
827 | const char * directory ); |
---|
828 | |
---|
829 | /** Set whether or not the torrent begins downloading/seeding when created. |
---|
830 | (Default: not paused) */ |
---|
831 | void tr_ctorSetPaused( tr_ctor * ctor, |
---|
832 | tr_ctorMode mode, |
---|
833 | tr_bool isPaused ); |
---|
834 | |
---|
835 | void tr_ctorSetFilePriorities( tr_ctor * ctor, |
---|
836 | const tr_file_index_t * files, |
---|
837 | tr_file_index_t fileCount, |
---|
838 | tr_priority_t priority ); |
---|
839 | |
---|
840 | void tr_ctorSetFilesWanted( tr_ctor * ctor, |
---|
841 | const tr_file_index_t * fileIndices, |
---|
842 | tr_file_index_t fileCount, |
---|
843 | tr_bool wanted ); |
---|
844 | |
---|
845 | |
---|
846 | int tr_ctorGetPeerLimit( const tr_ctor * ctor, |
---|
847 | tr_ctorMode mode, |
---|
848 | uint16_t * setmeCount ); |
---|
849 | |
---|
850 | int tr_ctorGetPaused( const tr_ctor * ctor, |
---|
851 | tr_ctorMode mode, |
---|
852 | tr_bool * setmeIsPaused ); |
---|
853 | |
---|
854 | int tr_ctorGetDownloadDir( const tr_ctor * ctor, |
---|
855 | tr_ctorMode mode, |
---|
856 | const char ** setmeDownloadDir ); |
---|
857 | |
---|
858 | int tr_ctorGetMetainfo( const tr_ctor * ctor, |
---|
859 | const struct tr_benc ** setme ); |
---|
860 | |
---|
861 | int tr_ctorGetDeleteSource( const tr_ctor * ctor, |
---|
862 | tr_bool * setmeDoDelete ); |
---|
863 | |
---|
864 | tr_session* tr_ctorGetSession( const tr_ctor * ctor ); |
---|
865 | |
---|
866 | /* returns NULL if tr_ctorSetMetainfoFromFile() wasn't used */ |
---|
867 | const char* tr_ctorGetSourceFile( const tr_ctor * ctor ); |
---|
868 | |
---|
869 | #define TR_EINVALID 1 |
---|
870 | #define TR_EDUPLICATE 2 |
---|
871 | |
---|
872 | /** |
---|
873 | * Parses the specified metainfo. |
---|
874 | * Returns 0 if it parsed successfully and can be added to Transmission. |
---|
875 | * Returns TR_EINVALID if it couldn't be parsed. |
---|
876 | * Returns TR_EDUPLICATE if it parsed but can't be added. |
---|
877 | * "download-dir" must be set to test for TR_EDUPLICATE. |
---|
878 | * |
---|
879 | * If setme_info is non-NULL and parsing is successful |
---|
880 | * (that is, if TR_EINVALID is not returned), then the parsed |
---|
881 | * metainfo is stored in setme_info and should be freed by the |
---|
882 | * caller via tr_metainfoFree(). |
---|
883 | * |
---|
884 | * If the constructor's session variable is NULL, |
---|
885 | * info.torrent will be NULL and the duplicate check will not be performed. |
---|
886 | */ |
---|
887 | int tr_torrentParse( const tr_ctor * ctor, |
---|
888 | tr_info * setme_info_or_NULL ); |
---|
889 | |
---|
890 | /** @brief free a metainfo |
---|
891 | @see tr_torrentParse */ |
---|
892 | void tr_metainfoFree( tr_info * inf ); |
---|
893 | |
---|
894 | |
---|
895 | /** Instantiate a single torrent. |
---|
896 | @return 0 on success, |
---|
897 | TR_EINVALID if the torrent couldn't be parsed, or |
---|
898 | TR_EDUPLICATE if there's already a matching torrent object. */ |
---|
899 | tr_torrent * tr_torrentNew( const tr_ctor * ctor, |
---|
900 | int * setmeError ); |
---|
901 | |
---|
902 | /** @} */ |
---|
903 | |
---|
904 | /*********************************************************************** |
---|
905 | *** |
---|
906 | *** TORRENTS |
---|
907 | **/ |
---|
908 | |
---|
909 | /** @addtogroup tr_torrent Torrents |
---|
910 | @{ */ |
---|
911 | |
---|
912 | /** @brief Frees memory allocated by tr_torrentNew(). |
---|
913 | Running torrents are stopped first. */ |
---|
914 | void tr_torrentFree( tr_torrent * torrent ); |
---|
915 | |
---|
916 | /** @brief Removes our .torrent and .resume files for |
---|
917 | this torrent, then calls tr_torrentFree(). */ |
---|
918 | void tr_torrentRemove( tr_torrent * torrent ); |
---|
919 | |
---|
920 | /** @brief Start a torrent */ |
---|
921 | void tr_torrentStart( tr_torrent * torrent ); |
---|
922 | |
---|
923 | /** @brief Stop (pause) a torrent */ |
---|
924 | void tr_torrentStop( tr_torrent * torrent ); |
---|
925 | |
---|
926 | typedef int tr_fileFunc( const char * filename ); |
---|
927 | |
---|
928 | enum |
---|
929 | { |
---|
930 | TR_LOC_MOVING, |
---|
931 | TR_LOC_DONE, |
---|
932 | TR_LOC_ERROR |
---|
933 | }; |
---|
934 | |
---|
935 | /** @brief Tell transmsision where to find this torrent's local data */ |
---|
936 | void tr_torrentSetLocation( tr_torrent * torrent, |
---|
937 | const char * location, |
---|
938 | tr_bool move_from_previous_location, |
---|
939 | double * setme_progress, |
---|
940 | int * setme_state ); |
---|
941 | |
---|
942 | /** |
---|
943 | * @brief Deletes the torrent's local data. |
---|
944 | * @param torrent |
---|
945 | * @param fileFunc Pass in "unlink" to destroy the files or, on platforms with |
---|
946 | * recycle bins, pass in a function that uses it instead. |
---|
947 | * tr_torrentDeleteLocalData() ignores fileFunc's return value. |
---|
948 | */ |
---|
949 | void tr_torrentDeleteLocalData( tr_torrent * torrent, tr_fileFunc fileFunc ); |
---|
950 | |
---|
951 | uint64_t tr_torrentGetBytesLeftToAllocate( const tr_torrent * torrent ); |
---|
952 | |
---|
953 | /** |
---|
954 | * @brief Returns this torrent's unique ID. |
---|
955 | * |
---|
956 | * IDs are good as simple lookup keys, but are not persistent |
---|
957 | * between sessions. If you need that, use tr_info.hash or |
---|
958 | * tr_info.hashString. |
---|
959 | */ |
---|
960 | int tr_torrentId( const tr_torrent * torrent ); |
---|
961 | |
---|
962 | tr_torrent* tr_torrentFindFromId( tr_session * session, int id ); |
---|
963 | |
---|
964 | |
---|
965 | /*** |
---|
966 | **** Torrent speed limits |
---|
967 | **** |
---|
968 | ***/ |
---|
969 | |
---|
970 | void tr_torrentSetSpeedLimit ( tr_torrent *, tr_direction, int KB_s ); |
---|
971 | int tr_torrentGetSpeedLimit ( const tr_torrent *, tr_direction ); |
---|
972 | |
---|
973 | void tr_torrentUseSpeedLimit ( tr_torrent *, tr_direction, tr_bool ); |
---|
974 | tr_bool tr_torrentUsesSpeedLimit ( const tr_torrent *, tr_direction ); |
---|
975 | |
---|
976 | void tr_torrentUseSessionLimits ( tr_torrent *, tr_bool ); |
---|
977 | tr_bool tr_torrentUsesSessionLimits ( const tr_torrent * ); |
---|
978 | |
---|
979 | |
---|
980 | /**** |
---|
981 | ***** Ratio Limits |
---|
982 | ****/ |
---|
983 | |
---|
984 | typedef enum |
---|
985 | { |
---|
986 | TR_RATIOLIMIT_GLOBAL = 0, /* follow the global settings */ |
---|
987 | TR_RATIOLIMIT_SINGLE = 1, /* override the global settings, seeding until a certain ratio */ |
---|
988 | TR_RATIOLIMIT_UNLIMITED = 2 /* override the global settings, seeding regardless of ratio */ |
---|
989 | } |
---|
990 | tr_ratiolimit; |
---|
991 | |
---|
992 | void tr_torrentSetRatioMode( tr_torrent * tor, |
---|
993 | tr_ratiolimit mode ); |
---|
994 | |
---|
995 | tr_ratiolimit tr_torrentGetRatioMode( const tr_torrent * tor ); |
---|
996 | |
---|
997 | void tr_torrentSetRatioLimit( tr_torrent * tor, |
---|
998 | double ratio ); |
---|
999 | |
---|
1000 | double tr_torrentGetRatioLimit( const tr_torrent * tor ); |
---|
1001 | |
---|
1002 | |
---|
1003 | tr_bool tr_torrentGetSeedRatio( const tr_torrent *, double * ratio ); |
---|
1004 | |
---|
1005 | /**** |
---|
1006 | ***** Peer Limits |
---|
1007 | ****/ |
---|
1008 | |
---|
1009 | void tr_torrentSetPeerLimit( tr_torrent * tor, |
---|
1010 | uint16_t peerLimit ); |
---|
1011 | |
---|
1012 | uint16_t tr_torrentGetPeerLimit( const tr_torrent * tor ); |
---|
1013 | |
---|
1014 | /**** |
---|
1015 | ***** File Priorities |
---|
1016 | ****/ |
---|
1017 | |
---|
1018 | enum |
---|
1019 | { |
---|
1020 | TR_PRI_LOW = -1, |
---|
1021 | TR_PRI_NORMAL = 0, /* since NORMAL is 0, memset initializes nicely */ |
---|
1022 | TR_PRI_HIGH = 1 |
---|
1023 | }; |
---|
1024 | |
---|
1025 | /** |
---|
1026 | * @brief Set a batch of files to a particular priority. |
---|
1027 | * |
---|
1028 | * @param priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW |
---|
1029 | */ |
---|
1030 | void tr_torrentSetFilePriorities( tr_torrent * torrent, |
---|
1031 | tr_file_index_t * files, |
---|
1032 | tr_file_index_t fileCount, |
---|
1033 | tr_priority_t priority ); |
---|
1034 | |
---|
1035 | /** |
---|
1036 | * @brief Get this torrent's file priorities. |
---|
1037 | * |
---|
1038 | * @return A malloc()ed array of tor->info.fileCount items, |
---|
1039 | * each holding a TR_PRI_NORMAL, TR_PRI_HIGH, or TR_PRI_LOW. |
---|
1040 | * It's the caller's responsibility to free() this. |
---|
1041 | */ |
---|
1042 | tr_priority_t* tr_torrentGetFilePriorities( const tr_torrent * torrent ); |
---|
1043 | |
---|
1044 | /** |
---|
1045 | * @brief Single-file form of tr_torrentGetFilePriorities. |
---|
1046 | * @return TR_PRI_NORMAL, TR_PRI_HIGH, or TR_PRI_LOW. |
---|
1047 | */ |
---|
1048 | tr_priority_t tr_torrentGetFilePriority( const tr_torrent * torrent, |
---|
1049 | tr_file_index_t file ); |
---|
1050 | |
---|
1051 | /** |
---|
1052 | * @brief See if a file's `download' flag is set. |
---|
1053 | * @return true if the file's `download' flag is set. |
---|
1054 | */ |
---|
1055 | int tr_torrentGetFileDL( const tr_torrent * torrent, |
---|
1056 | tr_file_index_t file ); |
---|
1057 | |
---|
1058 | /** @brief Set a batch of files to be downloaded or not. */ |
---|
1059 | void tr_torrentSetFileDLs( tr_torrent * torrent, |
---|
1060 | tr_file_index_t * files, |
---|
1061 | tr_file_index_t fileCount, |
---|
1062 | tr_bool do_download ); |
---|
1063 | |
---|
1064 | |
---|
1065 | const tr_info * tr_torrentInfo( const tr_torrent * torrent ); |
---|
1066 | |
---|
1067 | /* Raw function to change the torrent's downloadDir field. |
---|
1068 | This should only be used by libtransmission or to bootstrap |
---|
1069 | a newly-instantiated tr_torrent object. */ |
---|
1070 | void tr_torrentSetDownloadDir( tr_torrent * torrent, const char * path ); |
---|
1071 | |
---|
1072 | const char * tr_torrentGetDownloadDir( const tr_torrent * torrent ); |
---|
1073 | |
---|
1074 | /** |
---|
1075 | *** |
---|
1076 | **/ |
---|
1077 | |
---|
1078 | /** @brief a part of tr_info that represents a single tracker */ |
---|
1079 | typedef struct tr_tracker_info |
---|
1080 | { |
---|
1081 | int tier; |
---|
1082 | char * announce; |
---|
1083 | char * scrape; |
---|
1084 | } |
---|
1085 | tr_tracker_info; |
---|
1086 | |
---|
1087 | /** |
---|
1088 | * @brief Modify a torrent's tracker list. |
---|
1089 | * |
---|
1090 | * This updates both the `torrent' object's tracker list |
---|
1091 | * and the metainfo file in tr_sessionGetConfigDir()'s torrent subdirectory. |
---|
1092 | * |
---|
1093 | * @param torrent The torrent whose tracker list is to be modified |
---|
1094 | * @param trackers An array of trackers, sorted by tier from first to last. |
---|
1095 | * NOTE: only the `tier' and `announce' fields are used. |
---|
1096 | * libtransmission derives `scrape' from `announce'. |
---|
1097 | * @param trackerCount size of the `trackers' array |
---|
1098 | */ |
---|
1099 | void tr_torrentSetAnnounceList( tr_torrent * torrent, |
---|
1100 | const tr_tracker_info * trackers, |
---|
1101 | int trackerCount ); |
---|
1102 | |
---|
1103 | |
---|
1104 | /** |
---|
1105 | *** |
---|
1106 | **/ |
---|
1107 | |
---|
1108 | typedef enum |
---|
1109 | { |
---|
1110 | TR_LEECH, /* doesn't have all the desired pieces */ |
---|
1111 | TR_SEED, /* has the entire torrent */ |
---|
1112 | TR_PARTIAL_SEED /* has the desired pieces, but not the entire torrent */ |
---|
1113 | } |
---|
1114 | tr_completeness; |
---|
1115 | |
---|
1116 | typedef void ( tr_torrent_completeness_func )( tr_torrent * torrent, |
---|
1117 | tr_completeness completeness, |
---|
1118 | void * user_data ); |
---|
1119 | |
---|
1120 | typedef void ( tr_torrent_ratio_limit_hit_func )( tr_torrent * torrent, |
---|
1121 | void * user_data ); |
---|
1122 | |
---|
1123 | /** |
---|
1124 | * Register to be notified whenever a torrent's "completeness" |
---|
1125 | * changes. This will be called, for example, when a torrent |
---|
1126 | * finishes downloading and changes from TR_LEECH to |
---|
1127 | * either TR_SEED or TR_PARTIAL_SEED. |
---|
1128 | * |
---|
1129 | * func is invoked FROM LIBTRANSMISSION'S THREAD! |
---|
1130 | * This means func must be fast (to avoid blocking peers), |
---|
1131 | * shouldn't call libtransmission functions (to avoid deadlock), |
---|
1132 | * and shouldn't modify client-level memory without using a mutex! |
---|
1133 | * |
---|
1134 | * @see tr_completeness |
---|
1135 | */ |
---|
1136 | void tr_torrentSetCompletenessCallback( |
---|
1137 | tr_torrent * torrent, |
---|
1138 | tr_torrent_completeness_func func, |
---|
1139 | void * user_data ); |
---|
1140 | |
---|
1141 | void tr_torrentClearCompletenessCallback( tr_torrent * torrent ); |
---|
1142 | |
---|
1143 | |
---|
1144 | /** |
---|
1145 | * Register to be notified whenever a torrent's ratio limit |
---|
1146 | * has been hit. This will be called when the torrent's |
---|
1147 | * ul/dl ratio has met or exceeded the designated ratio limit. |
---|
1148 | * |
---|
1149 | * Has the same restrictions as tr_torrentSetCompletenessCallback |
---|
1150 | */ |
---|
1151 | void tr_torrentSetRatioLimitHitCallback( |
---|
1152 | tr_torrent * torrent, |
---|
1153 | tr_torrent_ratio_limit_hit_func func, |
---|
1154 | void * user_data ); |
---|
1155 | |
---|
1156 | void tr_torrentClearRatioLimitHitCallback( tr_torrent * torrent ); |
---|
1157 | |
---|
1158 | |
---|
1159 | /** |
---|
1160 | * MANUAL ANNOUNCE |
---|
1161 | * |
---|
1162 | * Trackers usually set an announce interval of 15 or 30 minutes. |
---|
1163 | * Users can send one-time announce requests that override this |
---|
1164 | * interval by calling tr_torrentManualUpdate(). |
---|
1165 | * |
---|
1166 | * The wait interval for tr_torrentManualUpdate() is much smaller. |
---|
1167 | * You can test whether or not a manual update is possible |
---|
1168 | * (for example, to desensitize the button) by calling |
---|
1169 | * tr_torrentCanManualUpdate(). |
---|
1170 | */ |
---|
1171 | |
---|
1172 | void tr_torrentManualUpdate( tr_torrent * torrent ); |
---|
1173 | |
---|
1174 | tr_bool tr_torrentCanManualUpdate( const tr_torrent * torrent ); |
---|
1175 | |
---|
1176 | /*********************************************************************** |
---|
1177 | * tr_torrentPeers |
---|
1178 | ***********************************************************************/ |
---|
1179 | |
---|
1180 | typedef struct tr_peer_stat |
---|
1181 | { |
---|
1182 | tr_bool isEncrypted; |
---|
1183 | tr_bool isDownloadingFrom; |
---|
1184 | tr_bool isUploadingTo; |
---|
1185 | tr_bool isSeed; |
---|
1186 | |
---|
1187 | tr_bool peerIsChoked; |
---|
1188 | tr_bool peerIsInterested; |
---|
1189 | tr_bool clientIsChoked; |
---|
1190 | tr_bool clientIsInterested; |
---|
1191 | tr_bool isIncoming; |
---|
1192 | |
---|
1193 | uint8_t from; |
---|
1194 | tr_port port; |
---|
1195 | |
---|
1196 | char addr[TR_INET6_ADDRSTRLEN]; |
---|
1197 | char client[80]; |
---|
1198 | char flagStr[32]; |
---|
1199 | |
---|
1200 | float progress; |
---|
1201 | float rateToPeer; |
---|
1202 | float rateToClient; |
---|
1203 | } |
---|
1204 | tr_peer_stat; |
---|
1205 | |
---|
1206 | tr_peer_stat * tr_torrentPeers( const tr_torrent * torrent, |
---|
1207 | int * peerCount ); |
---|
1208 | |
---|
1209 | void tr_torrentPeersFree( tr_peer_stat * peerStats, |
---|
1210 | int peerCount ); |
---|
1211 | |
---|
1212 | /** |
---|
1213 | * @brief get the download speeds for each of this torrent's webseed sources. |
---|
1214 | * |
---|
1215 | * @return an array of tor->info.webseedCount floats giving download speeds. |
---|
1216 | * Each speed in the array corresponds to the webseed at the same |
---|
1217 | * array index in tor->info.webseeds. |
---|
1218 | * To differentiate "idle" and "stalled" status, idle webseeds will |
---|
1219 | * return -1 instead of 0 KiB/s. |
---|
1220 | * NOTE: always free this array with tr_free() when you're done with it. |
---|
1221 | */ |
---|
1222 | float* tr_torrentWebSpeeds( const tr_torrent * torrent ); |
---|
1223 | |
---|
1224 | typedef struct tr_file_stat |
---|
1225 | { |
---|
1226 | uint64_t bytesCompleted; |
---|
1227 | float progress; |
---|
1228 | } |
---|
1229 | tr_file_stat; |
---|
1230 | |
---|
1231 | tr_file_stat * tr_torrentFiles( const tr_torrent * torrent, |
---|
1232 | tr_file_index_t * fileCount ); |
---|
1233 | |
---|
1234 | void tr_torrentFilesFree( tr_file_stat * files, |
---|
1235 | tr_file_index_t fileCount ); |
---|
1236 | |
---|
1237 | |
---|
1238 | /*********************************************************************** |
---|
1239 | * tr_torrentAvailability |
---|
1240 | *********************************************************************** |
---|
1241 | * Use this to draw an advanced progress bar which is 'size' pixels |
---|
1242 | * wide. Fills 'tab' which you must have allocated: each byte is set |
---|
1243 | * to either -1 if we have the piece, otherwise it is set to the number |
---|
1244 | * of connected peers who have the piece. |
---|
1245 | **********************************************************************/ |
---|
1246 | void tr_torrentAvailability( const tr_torrent * torrent, |
---|
1247 | int8_t * tab, |
---|
1248 | int size ); |
---|
1249 | |
---|
1250 | void tr_torrentAmountFinished( const tr_torrent * torrent, |
---|
1251 | float * tab, |
---|
1252 | int size ); |
---|
1253 | |
---|
1254 | void tr_torrentVerify( tr_torrent * torrent ); |
---|
1255 | |
---|
1256 | /*********************************************************************** |
---|
1257 | * tr_info |
---|
1258 | **********************************************************************/ |
---|
1259 | |
---|
1260 | /** @brief a part of tr_info that represents a single file of the torrent's content */ |
---|
1261 | typedef struct tr_file |
---|
1262 | { |
---|
1263 | uint64_t length; /* Length of the file, in bytes */ |
---|
1264 | char * name; /* Path to the file */ |
---|
1265 | int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ |
---|
1266 | int8_t dnd; /* nonzero if the file shouldn't be |
---|
1267 | downloaded */ |
---|
1268 | tr_piece_index_t firstPiece; /* We need pieces [firstPiece... */ |
---|
1269 | tr_piece_index_t lastPiece; /* ...lastPiece] to dl this file */ |
---|
1270 | uint64_t offset; /* file begins at the torrent's nth byte */ |
---|
1271 | } |
---|
1272 | tr_file; |
---|
1273 | |
---|
1274 | /** @brief a part of tr_info that represents a single piece of the torrent's content */ |
---|
1275 | typedef struct tr_piece |
---|
1276 | { |
---|
1277 | uint8_t hash[SHA_DIGEST_LENGTH]; /* pieces hash */ |
---|
1278 | int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ |
---|
1279 | int8_t dnd; /* nonzero if the piece shouldn't be |
---|
1280 | downloaded */ |
---|
1281 | } |
---|
1282 | tr_piece; |
---|
1283 | |
---|
1284 | /** @brief information about a torrent that comes from its metainfo file */ |
---|
1285 | struct tr_info |
---|
1286 | { |
---|
1287 | /* total size of the torrent, in bytes */ |
---|
1288 | uint64_t totalSize; |
---|
1289 | |
---|
1290 | /* the torrent's name */ |
---|
1291 | char * name; |
---|
1292 | |
---|
1293 | /* Path to torrent Transmission's internal copy of the .torrent file. */ |
---|
1294 | char * torrent; |
---|
1295 | |
---|
1296 | char ** webseeds; |
---|
1297 | |
---|
1298 | char * comment; |
---|
1299 | char * creator; |
---|
1300 | tr_file * files; |
---|
1301 | tr_piece * pieces; |
---|
1302 | |
---|
1303 | /* these trackers are sorted by tier */ |
---|
1304 | tr_tracker_info * trackers; |
---|
1305 | |
---|
1306 | /* Torrent info */ |
---|
1307 | time_t dateCreated; |
---|
1308 | |
---|
1309 | int trackerCount; |
---|
1310 | int webseedCount; |
---|
1311 | tr_file_index_t fileCount; |
---|
1312 | uint32_t pieceSize; |
---|
1313 | tr_piece_index_t pieceCount; |
---|
1314 | |
---|
1315 | /* General info */ |
---|
1316 | uint8_t hash[SHA_DIGEST_LENGTH]; |
---|
1317 | char hashString[2 * SHA_DIGEST_LENGTH + 1]; |
---|
1318 | |
---|
1319 | /* Flags */ |
---|
1320 | tr_bool isPrivate; |
---|
1321 | tr_bool isMultifile; |
---|
1322 | }; |
---|
1323 | |
---|
1324 | /** |
---|
1325 | * What the torrent is doing right now. |
---|
1326 | * |
---|
1327 | * Note: these values will become a straight enum at some point in the future. |
---|
1328 | * Do not rely on their current `bitfield' implementation |
---|
1329 | */ |
---|
1330 | typedef enum |
---|
1331 | { |
---|
1332 | TR_STATUS_CHECK_WAIT = ( 1 << 0 ), /* Waiting in queue to check files */ |
---|
1333 | TR_STATUS_CHECK = ( 1 << 1 ), /* Checking files */ |
---|
1334 | TR_STATUS_DOWNLOAD = ( 1 << 2 ), /* Downloading */ |
---|
1335 | TR_STATUS_SEED = ( 1 << 3 ), /* Seeding */ |
---|
1336 | TR_STATUS_STOPPED = ( 1 << 4 ) /* Torrent is stopped */ |
---|
1337 | } |
---|
1338 | tr_torrent_activity; |
---|
1339 | |
---|
1340 | tr_torrent_activity tr_torrentGetActivity( tr_torrent * ); |
---|
1341 | |
---|
1342 | typedef enum |
---|
1343 | { |
---|
1344 | TR_LOCKFILE_SUCCESS = 0, |
---|
1345 | TR_LOCKFILE_EOPEN, |
---|
1346 | TR_LOCKFILE_ELOCK |
---|
1347 | } |
---|
1348 | tr_lockfile_state_t; |
---|
1349 | |
---|
1350 | enum |
---|
1351 | { |
---|
1352 | TR_PEER_FROM_INCOMING = 0, /* connections made to the listening port */ |
---|
1353 | TR_PEER_FROM_TRACKER = 1, /* peers received from a tracker */ |
---|
1354 | TR_PEER_FROM_DHT = 2, /* peers learnt from the DHT */ |
---|
1355 | TR_PEER_FROM_CACHE = 3, /* peers read from the peer cache */ |
---|
1356 | TR_PEER_FROM_PEX = 4, /* peers discovered via PEX */ |
---|
1357 | TR_PEER_FROM__MAX |
---|
1358 | }; |
---|
1359 | |
---|
1360 | /** Can be used as a mnemonic for "no error" errno */ |
---|
1361 | #define TR_OK 0 |
---|
1362 | |
---|
1363 | /** |
---|
1364 | * The current status of a torrent. |
---|
1365 | * @see tr_torrentStat() |
---|
1366 | */ |
---|
1367 | typedef struct tr_stat |
---|
1368 | { |
---|
1369 | /** The torrent's unique Id. |
---|
1370 | @see tr_torrentId() */ |
---|
1371 | int id; |
---|
1372 | |
---|
1373 | /** What is this torrent doing right now? */ |
---|
1374 | tr_torrent_activity activity; |
---|
1375 | |
---|
1376 | /** Our current announce URL, or NULL if none. |
---|
1377 | This URL may change during the session if the torrent's |
---|
1378 | metainfo has multiple trackers and the current one |
---|
1379 | becomes unreachable. */ |
---|
1380 | char * announceURL; |
---|
1381 | |
---|
1382 | /** Our current scrape URL, or NULL if none. |
---|
1383 | This URL may change during the session if the torrent's |
---|
1384 | metainfo has multiple trackers and the current one |
---|
1385 | becomes unreachable. */ |
---|
1386 | char * scrapeURL; |
---|
1387 | |
---|
1388 | /** The errno status for this torrent. 0 means everything's fine. */ |
---|
1389 | int error; |
---|
1390 | |
---|
1391 | /** Typically an error string returned from the tracker. */ |
---|
1392 | char errorString[128]; |
---|
1393 | |
---|
1394 | /** When tr_stat.status is TR_STATUS_CHECK or TR_STATUS_CHECK_WAIT, |
---|
1395 | this is the percentage of how much of the files has been |
---|
1396 | verified. When it gets to 1, the verify process is done. |
---|
1397 | Range is [0..1] |
---|
1398 | @see tr_stat.status */ |
---|
1399 | float recheckProgress; |
---|
1400 | |
---|
1401 | /** How much has been downloaded of the entire torrent. |
---|
1402 | Range is [0..1] */ |
---|
1403 | float percentComplete; |
---|
1404 | |
---|
1405 | /** How much has been downloaded of the files the user wants. This differs |
---|
1406 | from percentComplete if the user wants only some of the torrent's files. |
---|
1407 | Range is [0..1] |
---|
1408 | @see tr_stat.leftUntilDone */ |
---|
1409 | float percentDone; |
---|
1410 | |
---|
1411 | /** The percentage of the actual ratio to the seed ratio. This will be |
---|
1412 | equal to 1 if the ratio is reached or the torrent is set to seed forever. |
---|
1413 | Range is [0..1] */ |
---|
1414 | float percentRatio; |
---|
1415 | |
---|
1416 | /** Speed all data being sent for this torrent. (KiB/s) |
---|
1417 | This includes piece data, protocol messages, and TCP overhead */ |
---|
1418 | double rawUploadSpeed; |
---|
1419 | |
---|
1420 | /** Speed all data being received for this torrent. (KiB/s) |
---|
1421 | This includes piece data, protocol messages, and TCP overhead */ |
---|
1422 | double rawDownloadSpeed; |
---|
1423 | |
---|
1424 | /** Speed all piece being sent for this torrent. (KiB/s) |
---|
1425 | This ONLY counts piece data. */ |
---|
1426 | double pieceUploadSpeed; |
---|
1427 | |
---|
1428 | /** Speed all piece being received for this torrent. (KiB/s) |
---|
1429 | This ONLY counts piece data. */ |
---|
1430 | double pieceDownloadSpeed; |
---|
1431 | |
---|
1432 | #define TR_ETA_NOT_AVAIL -1 |
---|
1433 | #define TR_ETA_UNKNOWN -2 |
---|
1434 | /** If downloading, estimated number of seconds left until the torrent is done. |
---|
1435 | If seeding, estimated number of seconds left until seed ratio is reached. */ |
---|
1436 | int eta; |
---|
1437 | |
---|
1438 | /** Number of peers that the tracker says this torrent has */ |
---|
1439 | int peersKnown; |
---|
1440 | |
---|
1441 | /** Number of peers that we're connected to */ |
---|
1442 | int peersConnected; |
---|
1443 | |
---|
1444 | /** How many peers we found out about from the tracker, or from pex, |
---|
1445 | or from incoming connections, or from our resume file. */ |
---|
1446 | int peersFrom[TR_PEER_FROM__MAX]; |
---|
1447 | |
---|
1448 | /** Number of peers that are sending data to us. */ |
---|
1449 | int peersSendingToUs; |
---|
1450 | |
---|
1451 | /** Number of peers that we're sending data to */ |
---|
1452 | int peersGettingFromUs; |
---|
1453 | |
---|
1454 | /** Number of webseeds that are sending data to us. */ |
---|
1455 | int webseedsSendingToUs; |
---|
1456 | |
---|
1457 | /** Number of seeders that the tracker says this torrent has */ |
---|
1458 | int seeders; |
---|
1459 | |
---|
1460 | /** Number of leechers that the tracker says this torrent has */ |
---|
1461 | int leechers; |
---|
1462 | |
---|
1463 | /** Number of downloaders that the tracker says this torrent has. |
---|
1464 | This is a new key introduced in BEP 21 and may not be supported by some trackers. |
---|
1465 | If the tracker doesn't support this key, the value here will be -1. */ |
---|
1466 | int downloaders; |
---|
1467 | |
---|
1468 | /** Number of finished downloads that the tracker says torrent has */ |
---|
1469 | int timesCompleted; |
---|
1470 | |
---|
1471 | /** Byte count of all the piece data we'll have downloaded when we're done, |
---|
1472 | whether or not we have it yet. This may be less than tr_info.totalSize |
---|
1473 | if only some of the torrent's files are wanted. |
---|
1474 | [0...tr_info.totalSize] */ |
---|
1475 | uint64_t sizeWhenDone; |
---|
1476 | |
---|
1477 | /** Byte count of how much data is left to be downloaded until we've got |
---|
1478 | all the pieces that we want. [0...tr_info.sizeWhenDone] */ |
---|
1479 | uint64_t leftUntilDone; |
---|
1480 | |
---|
1481 | /** Byte count of all the piece data we want and don't have yet, |
---|
1482 | but that a connected peer does have. [0...leftUntilDone] */ |
---|
1483 | uint64_t desiredAvailable; |
---|
1484 | |
---|
1485 | /** Byte count of all the corrupt data you've ever downloaded for |
---|
1486 | this torrent. If you're on a poisoned torrent, this number can |
---|
1487 | grow very large. */ |
---|
1488 | uint64_t corruptEver; |
---|
1489 | |
---|
1490 | /** Byte count of all data you've ever uploaded for this torrent. */ |
---|
1491 | uint64_t uploadedEver; |
---|
1492 | |
---|
1493 | /** Byte count of all the non-corrupt data you've ever downloaded |
---|
1494 | for this torrent. If you deleted the files and downloaded a second |
---|
1495 | time, this will be 2*totalSize.. */ |
---|
1496 | uint64_t downloadedEver; |
---|
1497 | |
---|
1498 | /** Byte count of all the checksum-verified data we have for this torrent. |
---|
1499 | */ |
---|
1500 | uint64_t haveValid; |
---|
1501 | |
---|
1502 | /** Byte count of all the partial piece data we have for this torrent. |
---|
1503 | As pieces become complete, this value may decrease as portions of it |
---|
1504 | are moved to `corrupt' or `haveValid'. */ |
---|
1505 | uint64_t haveUnchecked; |
---|
1506 | |
---|
1507 | /** This is the unmodified string returned by the tracker in response |
---|
1508 | to the torrent's most recent scrape request. If no request was |
---|
1509 | sent or there was no response, this string is empty. */ |
---|
1510 | char scrapeResponse[64]; |
---|
1511 | |
---|
1512 | /** The unmodified string returned by the tracker in response |
---|
1513 | to the torrent's most recent scrape request. If no request was |
---|
1514 | sent or there was no response, this string is empty. */ |
---|
1515 | char announceResponse[64]; |
---|
1516 | |
---|
1517 | /** Time the most recent scrape request was sent, |
---|
1518 | or zero if one hasn't been sent yet. */ |
---|
1519 | time_t lastScrapeTime; |
---|
1520 | |
---|
1521 | /** Time when the next scrape request will be sent, |
---|
1522 | or 0 if an error has occured that stops scraping, |
---|
1523 | or 1 if a scrape is currently in progress s.t. |
---|
1524 | we haven't set a timer for the next one yet. */ |
---|
1525 | time_t nextScrapeTime; |
---|
1526 | |
---|
1527 | /** Time the most recent announce request was sent, |
---|
1528 | or zero if one hasn't been sent yet. */ |
---|
1529 | time_t lastAnnounceTime; |
---|
1530 | |
---|
1531 | /** Time when the next reannounce request will be sent, |
---|
1532 | or 0 if the torrent is stopped, |
---|
1533 | or 1 if an announce is currently in progress s.t. |
---|
1534 | we haven't set a timer for the next one yet */ |
---|
1535 | time_t nextAnnounceTime; |
---|
1536 | |
---|
1537 | /** If the torrent is running, this is the time at which |
---|
1538 | the client can manually ask the torrent's tracker |
---|
1539 | for more peers, |
---|
1540 | or 0 if the torrent is stopped or doesn't allow manual, |
---|
1541 | or 1 if an announce is currently in progress s.t. |
---|
1542 | we haven't set a timer for the next one yet */ |
---|
1543 | time_t manualAnnounceTime; |
---|
1544 | |
---|
1545 | /** A very rough estimate in KiB/s of how quickly data is being |
---|
1546 | passed around between all the peers we're connected to. |
---|
1547 | Don't put too much weight in this number. */ |
---|
1548 | float swarmSpeed; |
---|
1549 | |
---|
1550 | #define TR_RATIO_NA -1 |
---|
1551 | #define TR_RATIO_INF -2 |
---|
1552 | /** TR_RATIO_INF, TR_RATIO_NA, or a regular ratio */ |
---|
1553 | float ratio; |
---|
1554 | |
---|
1555 | /** When the torrent was first added. */ |
---|
1556 | time_t addedDate; |
---|
1557 | |
---|
1558 | /** When the torrent finished downloading. */ |
---|
1559 | time_t doneDate; |
---|
1560 | |
---|
1561 | /** When the torrent was last started. */ |
---|
1562 | time_t startDate; |
---|
1563 | |
---|
1564 | /** The last time we uploaded or downloaded piece data on this torrent. */ |
---|
1565 | time_t activityDate; |
---|
1566 | } |
---|
1567 | tr_stat; |
---|
1568 | |
---|
1569 | /** Return a pointer to an tr_stat structure with updated information |
---|
1570 | on the torrent. This is typically called by the GUI clients every |
---|
1571 | second or so to get a new snapshot of the torrent's status. */ |
---|
1572 | const tr_stat * tr_torrentStat( tr_torrent * torrent ); |
---|
1573 | |
---|
1574 | /** Like tr_torrentStat(), but only recalculates the statistics if it's |
---|
1575 | been longer than a second since they were last calculated. This can |
---|
1576 | reduce the CPU load if you're calling tr_torrentStat() frequently. */ |
---|
1577 | const tr_stat * tr_torrentStatCached( tr_torrent * torrent ); |
---|
1578 | |
---|
1579 | /** @deprecated */ |
---|
1580 | void tr_torrentSetAddedDate( tr_torrent * torrent, |
---|
1581 | time_t addedDate ); |
---|
1582 | |
---|
1583 | /** @deprecated */ |
---|
1584 | void tr_torrentSetActivityDate( tr_torrent * torrent, |
---|
1585 | time_t activityDate ); |
---|
1586 | |
---|
1587 | /** @deprecated */ |
---|
1588 | void tr_torrentSetDoneDate( tr_torrent * torrent, time_t doneDate ); |
---|
1589 | |
---|
1590 | /** @} */ |
---|
1591 | |
---|
1592 | /** @brief Sanity checker to test that the direction is TR_UP or TR_DOWN */ |
---|
1593 | static TR_INLINE tr_bool tr_isDirection( tr_direction d ) { return d==TR_UP || d==TR_DOWN; } |
---|
1594 | |
---|
1595 | /** @brief Sanity checker to test that a bool is TRUE or FALSE */ |
---|
1596 | static TR_INLINE tr_bool tr_isBool( tr_bool b ) { return b==1 || b==0; } |
---|
1597 | |
---|
1598 | #ifdef __cplusplus |
---|
1599 | } |
---|
1600 | #endif |
---|
1601 | |
---|
1602 | #endif |
---|