1 | /****************************************************************************** |
---|
2 | * $Id: transmission.h 7241 2008-12-02 23:16:01Z 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 suitable for public consumption are bencode.h |
---|
29 | * and utils.h. Most of the remaining headers in libtransmission |
---|
30 | * should be considered private to libtransmission. |
---|
31 | */ |
---|
32 | #ifndef TR_TRANSMISSION_H |
---|
33 | #define TR_TRANSMISSION_H 1 |
---|
34 | |
---|
35 | #ifdef __cplusplus |
---|
36 | extern "C" { |
---|
37 | #endif |
---|
38 | |
---|
39 | #include "version.h" |
---|
40 | |
---|
41 | #include <inttypes.h> /* uintN_t */ |
---|
42 | #ifndef PRId64 |
---|
43 | #define PRId64 "lld" |
---|
44 | #endif |
---|
45 | #ifndef PRIu64 |
---|
46 | #define PRIu64 "llu" |
---|
47 | #endif |
---|
48 | #ifndef PRIu32 |
---|
49 | #define PRIu32 "lu" |
---|
50 | #endif |
---|
51 | #include <time.h> /* time_t */ |
---|
52 | #include <netinet/in.h> /* INET6_ADDRSTRLEN */ |
---|
53 | |
---|
54 | #define SHA_DIGEST_LENGTH 20 |
---|
55 | |
---|
56 | typedef uint32_t tr_file_index_t; |
---|
57 | typedef uint32_t tr_piece_index_t; |
---|
58 | typedef uint64_t tr_block_index_t; |
---|
59 | typedef uint16_t tr_port; |
---|
60 | typedef uint8_t tr_bool; |
---|
61 | |
---|
62 | /** |
---|
63 | * @brief returns Transmission's default configuration file directory. |
---|
64 | * |
---|
65 | * The default configuration directory is determined this way: |
---|
66 | * 1. If the TRANSMISSION_HOME environmental variable is set, its value is used. |
---|
67 | * 2. On Darwin, "${HOME}/Library/Application Support/Transmission" is used. |
---|
68 | * 3. On Windows, "${CSIDL_APPDATA}/Transmission" is used. |
---|
69 | * 4. If XDG_CONFIG_HOME is set, "${XDG_CONFIG_HOME}/transmission" is used. |
---|
70 | * 5. ${HOME}/.config/transmission" is used as a last resort. |
---|
71 | */ |
---|
72 | const char* tr_getDefaultConfigDir( void ); |
---|
73 | |
---|
74 | /** |
---|
75 | * @brief returns Transmisson's default download directory. |
---|
76 | * |
---|
77 | * The default download directory is determined this way: |
---|
78 | * 1. If the HOME environmental variable is set, "${HOME}/Downloads" is used. |
---|
79 | * 2. On Windows, "${CSIDL_MYDOCUMENTS}/Downloads" is used. |
---|
80 | * 3. Otherwise, getpwuid(getuid())->pw_dir + "/Downloads" is used. |
---|
81 | */ |
---|
82 | const char* tr_getDefaultDownloadDir( void ); |
---|
83 | |
---|
84 | typedef struct tr_ctor tr_ctor; |
---|
85 | typedef struct tr_handle tr_handle; |
---|
86 | typedef struct tr_info tr_info; |
---|
87 | typedef struct tr_torrent tr_torrent; |
---|
88 | typedef tr_handle tr_session; |
---|
89 | |
---|
90 | |
---|
91 | /** |
---|
92 | * @addtogroup tr_session Session |
---|
93 | * |
---|
94 | * A libtransmission session is created by calling either tr_sessionInitFull() |
---|
95 | * or tr_sessionInit(). libtransmission creates a thread for itself so that |
---|
96 | * it can operate independently of the caller's event loop. The session will |
---|
97 | * continue until tr_sessionClose() is called. |
---|
98 | * |
---|
99 | * @{ |
---|
100 | */ |
---|
101 | |
---|
102 | typedef enum |
---|
103 | { |
---|
104 | TR_PROXY_HTTP, |
---|
105 | TR_PROXY_SOCKS4, |
---|
106 | TR_PROXY_SOCKS5 |
---|
107 | } |
---|
108 | tr_proxy_type; |
---|
109 | |
---|
110 | /** @see tr_sessionInitFull */ |
---|
111 | #define TR_DEFAULT_CONFIG_DIR tr_getDefaultConfigDir( ) |
---|
112 | /** @see tr_sessionInitFull */ |
---|
113 | #define TR_DEFAULT_DOWNLOAD_DIR tr_getDefaultDownloadDir( ) |
---|
114 | /** @see tr_sessionInitFull */ |
---|
115 | #ifdef TR_EMBEDDED |
---|
116 | #define TR_DEFAULT_ENCRYPTION TR_CLEAR_PREFERRED |
---|
117 | #else |
---|
118 | #define TR_DEFAULT_ENCRYPTION TR_ENCRYPTION_PREFERRED |
---|
119 | #endif |
---|
120 | /** @see tr_sessionInitFull */ |
---|
121 | #define TR_DEFAULT_PEX_ENABLED 1 |
---|
122 | /** @see tr_sessionInitFull */ |
---|
123 | #define TR_DEFAULT_PORT_FORWARDING_ENABLED 0 |
---|
124 | /** @see tr_sessionInitFull */ |
---|
125 | #define TR_DEFAULT_PORT 51413 |
---|
126 | /** @see tr_sessionInitFull */ |
---|
127 | #define TR_DEFAULT_PORT_STR "51413" |
---|
128 | /** @see tr_sessionInitFull */ |
---|
129 | #define TR_DEFAULT_LAZY_BITFIELD_ENABLED 1 |
---|
130 | /** @see tr_sessionInitFull */ |
---|
131 | #define TR_DEFAULT_GLOBAL_PEER_LIMIT 200 |
---|
132 | /** @see tr_sessionInitFull */ |
---|
133 | #define TR_DEFAULT_PEER_SOCKET_TOS 8 |
---|
134 | /** @see tr_sessionInitFull */ |
---|
135 | #define TR_DEFAULT_PEER_SOCKET_TOS_STR "8" |
---|
136 | /** @see tr_sessionInitFull */ |
---|
137 | #define TR_DEFAULT_BLOCKLIST_ENABLED 0 |
---|
138 | /** @see tr_sessionInitFull */ |
---|
139 | #define TR_DEFAULT_RPC_ENABLED 0 |
---|
140 | /** @see tr_sessionInitFull */ |
---|
141 | #define TR_DEFAULT_RPC_PORT 9091 |
---|
142 | /** @see tr_sessionInitFull */ |
---|
143 | #define TR_DEFAULT_RPC_PORT_STR "9091" |
---|
144 | /** @see tr_sessionInitFull */ |
---|
145 | #define TR_DEFAULT_RPC_WHITELIST "127.0.0.1" |
---|
146 | /** @see tr_sessionInitFull */ |
---|
147 | #define TR_DEFAULT_RPC_WHITELIST_ENABLED 0 |
---|
148 | /** @see tr_sessionInitFull */ |
---|
149 | #define TR_DEFAULT_PROXY_ENABLED 0 |
---|
150 | /** @see tr_sessionInitFull */ |
---|
151 | #define TR_DEFAULT_PROXY NULL |
---|
152 | /** @see tr_sessionInitFull */ |
---|
153 | #define TR_DEFAULT_PROXY_PORT 80 |
---|
154 | /** @see tr_sessionInitFull */ |
---|
155 | #define TR_DEFAULT_PROXY_TYPE TR_PROXY_HTTP |
---|
156 | /** @see tr_sessionInitFull */ |
---|
157 | #define TR_DEFAULT_PROXY_AUTH_ENABLED 0 |
---|
158 | /** @see tr_sessionInitFull */ |
---|
159 | #define TR_DEFAULT_PROXY_USERNAME NULL |
---|
160 | /** @see tr_sessionInitFull */ |
---|
161 | #define TR_DEFAULT_PROXY_PASSWORD NULL |
---|
162 | |
---|
163 | typedef enum |
---|
164 | { |
---|
165 | TR_CLEAR_PREFERRED, |
---|
166 | TR_ENCRYPTION_PREFERRED, |
---|
167 | TR_ENCRYPTION_REQUIRED |
---|
168 | } |
---|
169 | tr_encryption_mode; |
---|
170 | |
---|
171 | /** |
---|
172 | * @brief Start a libtransmission session. |
---|
173 | * @return an opaque handle to the new session |
---|
174 | * |
---|
175 | * @param configDir |
---|
176 | * The config directory where libtransmission config subdirectories |
---|
177 | * will be found, such as "torrents", "resume", and "blocklists". |
---|
178 | * #TR_DEFAULT_CONFIG_DIR can be used as a default. |
---|
179 | * |
---|
180 | * @param downloadDir |
---|
181 | * The default directory to save added torrents. |
---|
182 | * This can be changed per-session with |
---|
183 | * tr_sessionSetDownloadDir() and per-torrent with |
---|
184 | * tr_ctorSetDownloadDir(). |
---|
185 | * |
---|
186 | * @param tag |
---|
187 | * Obsolete. Only used now for locating legacy fastresume files. |
---|
188 | * This will be removed at some point in the future. |
---|
189 | * Valid tags: beos cli daemon gtk macos wx |
---|
190 | * |
---|
191 | * @param isPexEnabled |
---|
192 | * whether or not PEX is allowed for non-private torrents. |
---|
193 | * This can be changed per-session with |
---|
194 | * tr_sessionSetPexEnabled(). |
---|
195 | * #TR_DEFAULT_PEX_ENABLED is the default. |
---|
196 | * |
---|
197 | * @param isPortForwardingEnabled |
---|
198 | * If true, libtransmission will attempt |
---|
199 | * to find a local UPnP-enabled or NATPMP-enabled |
---|
200 | * router and forward a port from there to the local |
---|
201 | * machine. This is so remote peers can initiate |
---|
202 | * connections with us. |
---|
203 | * #TR_DEFAULT_PORT_FORWARDING_ENABLED is the default. |
---|
204 | * |
---|
205 | * @param publicPort |
---|
206 | * Port number to open for incoming peer connections. |
---|
207 | * #TR_DEFAULT_PORT is the default. |
---|
208 | * |
---|
209 | * @param encryptionMode |
---|
210 | * Must be one of #TR_CLEAR_PREFERRED, |
---|
211 | * #TR_ENCRYPTION_PREFERRED, or #TR_ENCRYPTION_REQUIRED. |
---|
212 | * |
---|
213 | * @param isUploadLimitEnabled |
---|
214 | * If true, libtransmission will limit the entire |
---|
215 | * session's upload speed from "uploadLimit". |
---|
216 | * |
---|
217 | * @param uploadLimit |
---|
218 | * The speed limit to use for the entire session when |
---|
219 | * "isUploadLimitEnabled" is true. Units are KiB/s. |
---|
220 | * |
---|
221 | * @param isDownloadLimitEnabled |
---|
222 | * If true, libtransmission will limit the entire |
---|
223 | * session's download speed from "downloadLimit". |
---|
224 | * |
---|
225 | * @param downloadLimit |
---|
226 | * The speed limit to use for the entire session when |
---|
227 | * "isDownloadLimitEnabled" is true. Units are KiB/s. |
---|
228 | * |
---|
229 | * @param peerLimit |
---|
230 | * The maximum number of peer connections allowed in a session. |
---|
231 | * #TR_DEFAULT_GLOBAL_PEER_LIMIT can be used as a default. |
---|
232 | * |
---|
233 | * @param messageLevel |
---|
234 | * Verbosity level of libtransmission's logging mechanism. |
---|
235 | * Must be one of #TR_MSG_ERR, #TR_MSG_INF, #TR_MSG_DBG. |
---|
236 | * |
---|
237 | * @param isMessageQueueingEnabled |
---|
238 | * If true, then messages will build up in a queue until |
---|
239 | * processed by the client application. |
---|
240 | * |
---|
241 | * @param isBlocklistEnabled |
---|
242 | * If true, then Transmission will not allow peer connections |
---|
243 | * to the IP addressess specified in the blocklist. |
---|
244 | * |
---|
245 | * @param peerSocketTOS |
---|
246 | * |
---|
247 | * @param rpcIsEnabled |
---|
248 | * If true, then libtransmission will open an http server port |
---|
249 | * to listen for incoming RPC requests. |
---|
250 | * |
---|
251 | * @param rpcPort |
---|
252 | * The port on which to listen for incoming RPC requests |
---|
253 | * |
---|
254 | * @param rpcWhitelist |
---|
255 | * The list of IP addresses allowed to make RPC connections. |
---|
256 | * @see tr_sessionSetRPCWhitelist() |
---|
257 | * |
---|
258 | * @see TR_DEFAULT_PEER_SOCKET_TOS |
---|
259 | * @see TR_DEFAULT_BLOCKLIST_ENABLED |
---|
260 | * @see TR_DEFAULT_RPC_ENABLED |
---|
261 | * @see TR_DEFAULT_RPC_PORT |
---|
262 | * @see TR_DEFAULT_RPC_WHITELIST |
---|
263 | * @see TR_DEFAULT_RPC_WHITELIST_ENABLED |
---|
264 | * @see tr_sessionClose() |
---|
265 | */ |
---|
266 | tr_session * tr_sessionInitFull( const char * configDir, |
---|
267 | const char * tag, |
---|
268 | const char * downloadDir, |
---|
269 | int isPexEnabled, |
---|
270 | int isPortForwardingEnabled, |
---|
271 | int publicPort, |
---|
272 | tr_encryption_mode encryptionMode, |
---|
273 | int useLazyBitfield, |
---|
274 | int useUploadLimit, |
---|
275 | int uploadLimit, |
---|
276 | int useDownloadLimit, |
---|
277 | int downloadLimit, |
---|
278 | int peerLimit, |
---|
279 | int messageLevel, |
---|
280 | int isMessageQueueingEnabled, |
---|
281 | int isBlocklistEnabled, |
---|
282 | int peerSocketTOS, |
---|
283 | int rpcIsEnabled, |
---|
284 | tr_port rpcPort, |
---|
285 | int rpcWhitelistIsEnabled, |
---|
286 | const char * rpcWhitelist, |
---|
287 | int rpcPasswordIsEnabled, |
---|
288 | const char * rpcUsername, |
---|
289 | const char * rpcPassword, |
---|
290 | int proxyIsEnabled, |
---|
291 | const char * proxy, |
---|
292 | int proxyPort, |
---|
293 | tr_proxy_type proxyType, |
---|
294 | int proxyAuthIsEnabled, |
---|
295 | const char * proxyUsername, |
---|
296 | const char * proxyPassword ); |
---|
297 | |
---|
298 | |
---|
299 | /** @brief Shorter form of tr_sessionInitFull() |
---|
300 | @deprecated Use tr_sessionInitFull() instead. */ |
---|
301 | tr_session * tr_sessionInit( const char * configDir, |
---|
302 | const char * tag ); |
---|
303 | |
---|
304 | /** @brief End a libtransmission session |
---|
305 | @see tr_sessionInitFull() */ |
---|
306 | void tr_sessionClose( tr_session * ); |
---|
307 | |
---|
308 | /** |
---|
309 | * @brief Return the session's configuration directory |
---|
310 | * |
---|
311 | * This is where transmission stores its .torrent files, .resume files, |
---|
312 | * blocklists, etc. |
---|
313 | */ |
---|
314 | const char * tr_sessionGetConfigDir( const tr_session * ); |
---|
315 | |
---|
316 | /** |
---|
317 | * @brief Set the per-session default download folder for new torrents. |
---|
318 | * @see tr_sessionInitFull() |
---|
319 | * @see tr_sessionGetDownloadDir() |
---|
320 | * @see tr_ctorSetDownloadDir() |
---|
321 | */ |
---|
322 | void tr_sessionSetDownloadDir( tr_session * session, |
---|
323 | const char * downloadDir ); |
---|
324 | |
---|
325 | /** |
---|
326 | * @brief Get the default download folder for new torrents. |
---|
327 | * |
---|
328 | * This is set by tr_sessionInitFull() or tr_sessionSetDownloadDir(), |
---|
329 | * and can be overridden on a per-torrent basis by tr_ctorSetDownloadDir(). |
---|
330 | */ |
---|
331 | const char * tr_sessionGetDownloadDir( const tr_session * session ); |
---|
332 | |
---|
333 | /** |
---|
334 | * @brief Set whether or not RPC calls are allowed in this session. |
---|
335 | * |
---|
336 | * @details If true, libtransmission will open a server socket to listen |
---|
337 | * for incoming http RPC requests as described in docs/rpc-spec.txt. |
---|
338 | * |
---|
339 | * This is intially set by tr_sessionInitFull() and can be |
---|
340 | * queried by tr_sessionIsRPCEnabled(). |
---|
341 | */ |
---|
342 | void tr_sessionSetRPCEnabled( tr_session * session, |
---|
343 | int isEnabled ); |
---|
344 | |
---|
345 | /** @brief Get whether or not RPC calls are allowed in this session. |
---|
346 | @see tr_sessionInitFull() |
---|
347 | @see tr_sessionSetRPCEnabled() */ |
---|
348 | int tr_sessionIsRPCEnabled( const tr_session * session ); |
---|
349 | |
---|
350 | /** @brief Specify which port to listen for RPC requests on. |
---|
351 | @see tr_sessionInitFull() |
---|
352 | @see tr_sessionGetRPCPort */ |
---|
353 | void tr_sessionSetRPCPort( tr_session * session, |
---|
354 | tr_port port ); |
---|
355 | |
---|
356 | /** @brief Get which port to listen for RPC requests on. |
---|
357 | @see tr_sessionInitFull() |
---|
358 | @see tr_sessionSetRPCPort */ |
---|
359 | tr_port tr_sessionGetRPCPort( const tr_session * session ); |
---|
360 | |
---|
361 | /** |
---|
362 | * @brief Specify a whitelist for remote RPC access |
---|
363 | * |
---|
364 | * The whitelist is a comma-separated list of dotted-quad IP addresses |
---|
365 | * to be allowed. Wildmat notation is supported, meaning that |
---|
366 | * '?' is interpreted as a single-character wildcard and |
---|
367 | * '*' is interprted as a multi-character wildcard. |
---|
368 | */ |
---|
369 | void tr_sessionSetRPCWhitelist( tr_session * session, |
---|
370 | const char * whitelist ); |
---|
371 | |
---|
372 | /** @brief get the Access Control List for allowing/denying RPC requests. |
---|
373 | @return a comma-separated string of whitelist domains. tr_free() when done. |
---|
374 | @see tr_sessionInitFull |
---|
375 | @see tr_sessionSetRPCWhitelist */ |
---|
376 | char* tr_sessionGetRPCWhitelist( const tr_session * ); |
---|
377 | |
---|
378 | void tr_sessionSetRPCWhitelistEnabled( tr_session * session, |
---|
379 | int isEnabled ); |
---|
380 | |
---|
381 | int tr_sessionGetRPCWhitelistEnabled( const tr_session * session ); |
---|
382 | |
---|
383 | void tr_sessionSetRPCPassword( tr_session * session, |
---|
384 | const char * password ); |
---|
385 | |
---|
386 | void tr_sessionSetRPCUsername( tr_session * session, |
---|
387 | const char * username ); |
---|
388 | |
---|
389 | /** @brief get the password used to restrict RPC requests. |
---|
390 | @return the password string. tr_free() when done. |
---|
391 | @see tr_sessionInitFull() |
---|
392 | @see tr_sessionSetRPCPassword() */ |
---|
393 | char* tr_sessionGetRPCPassword( const tr_session * session ); |
---|
394 | |
---|
395 | char* tr_sessionGetRPCUsername( const tr_session * session ); |
---|
396 | |
---|
397 | void tr_sessionSetRPCPasswordEnabled( tr_session * session, |
---|
398 | int isEnabled ); |
---|
399 | |
---|
400 | int tr_sessionIsRPCPasswordEnabled( 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 | int tr_sessionIsProxyEnabled( const tr_session * ); |
---|
450 | |
---|
451 | int tr_sessionIsProxyAuthEnabled( const tr_session * ); |
---|
452 | |
---|
453 | const char* tr_sessionGetProxy( const tr_session * ); |
---|
454 | |
---|
455 | int 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 *, |
---|
464 | int isEnabled ); |
---|
465 | |
---|
466 | void tr_sessionSetProxyAuthEnabled( tr_session *, |
---|
467 | int isEnabled ); |
---|
468 | |
---|
469 | void tr_sessionSetProxy( |
---|
470 | tr_session *, |
---|
471 | const char * |
---|
472 | proxy ); |
---|
473 | |
---|
474 | void tr_sessionSetProxyPort( tr_session *, |
---|
475 | int port ); |
---|
476 | |
---|
477 | void tr_sessionSetProxyType( tr_session *, |
---|
478 | tr_proxy_type ); |
---|
479 | |
---|
480 | void tr_sessionSetProxyUsername( |
---|
481 | tr_session *, |
---|
482 | const char * |
---|
483 | username ); |
---|
484 | |
---|
485 | void tr_sessionSetProxyPassword( |
---|
486 | tr_session *, |
---|
487 | const char * |
---|
488 | password ); |
---|
489 | |
---|
490 | /** |
---|
491 | *** |
---|
492 | **/ |
---|
493 | |
---|
494 | typedef struct tr_session_stats |
---|
495 | { |
---|
496 | float ratio; /* TR_RATIO_INF, TR_RATIO_NA, or total up/down */ |
---|
497 | uint64_t uploadedBytes; /* total up */ |
---|
498 | uint64_t downloadedBytes; /* total down */ |
---|
499 | uint64_t filesAdded; /* number of files added */ |
---|
500 | uint64_t sessionCount; /* program started N times */ |
---|
501 | uint64_t secondsActive; /* how long Transmisson's been running */ |
---|
502 | } |
---|
503 | tr_session_stats; |
---|
504 | |
---|
505 | /* stats from the current session. */ |
---|
506 | void tr_sessionGetStats( const tr_session * session, |
---|
507 | tr_session_stats * setme ); |
---|
508 | |
---|
509 | /* stats from the current and past sessions. */ |
---|
510 | void tr_sessionGetCumulativeStats( const tr_session * session, |
---|
511 | tr_session_stats * setme ); |
---|
512 | |
---|
513 | void tr_sessionClearStats( tr_session * session ); |
---|
514 | |
---|
515 | /** |
---|
516 | * Set whether or not torrents are allowed to do peer exchanges. |
---|
517 | * PEX is always disabled in private torrents regardless of this. |
---|
518 | * In public torrents, PEX is enabled by default. |
---|
519 | */ |
---|
520 | void tr_sessionSetPexEnabled( tr_session * session, |
---|
521 | int isEnabled ); |
---|
522 | |
---|
523 | int tr_sessionIsPexEnabled( const tr_session * session ); |
---|
524 | |
---|
525 | void tr_sessionSetLazyBitfieldEnabled( tr_session * session, |
---|
526 | int enabled ); |
---|
527 | |
---|
528 | int tr_sessionIsLazyBitfieldEnabled( const tr_session * session ); |
---|
529 | |
---|
530 | tr_encryption_mode tr_sessionGetEncryption( tr_session * session ); |
---|
531 | |
---|
532 | void tr_sessionSetEncryption( tr_session * session, |
---|
533 | tr_encryption_mode mode ); |
---|
534 | |
---|
535 | |
---|
536 | /*********************************************************************** |
---|
537 | ** Incoming Peer Connections Port |
---|
538 | */ |
---|
539 | |
---|
540 | void tr_sessionSetPortForwardingEnabled( tr_session * session, |
---|
541 | int enabled ); |
---|
542 | |
---|
543 | int tr_sessionIsPortForwardingEnabled( const tr_session * session ); |
---|
544 | |
---|
545 | void tr_sessionSetPeerPort( tr_session * session, |
---|
546 | int port); |
---|
547 | |
---|
548 | int tr_sessionGetPeerPort( const tr_session * session ); |
---|
549 | |
---|
550 | typedef enum |
---|
551 | { |
---|
552 | TR_PORT_ERROR, |
---|
553 | TR_PORT_UNMAPPED, |
---|
554 | TR_PORT_UNMAPPING, |
---|
555 | TR_PORT_MAPPING, |
---|
556 | TR_PORT_MAPPED |
---|
557 | } |
---|
558 | tr_port_forwarding; |
---|
559 | |
---|
560 | tr_port_forwarding tr_sessionGetPortForwarding( const tr_session * session ); |
---|
561 | |
---|
562 | int tr_sessionCountTorrents( const tr_session * session ); |
---|
563 | |
---|
564 | typedef enum |
---|
565 | { |
---|
566 | TR_CLIENT_TO_PEER = 0, TR_UP = 0, |
---|
567 | TR_PEER_TO_CLIENT = 1, TR_DOWN = 1 |
---|
568 | } |
---|
569 | tr_direction; |
---|
570 | |
---|
571 | void tr_sessionSetSpeedLimitEnabled( tr_session * session, |
---|
572 | tr_direction direction, |
---|
573 | int isEnabled ); |
---|
574 | |
---|
575 | double tr_sessionGetRawSpeed( const tr_session * session, |
---|
576 | tr_direction direection ); |
---|
577 | |
---|
578 | double tr_sessionGetPieceSpeed( const tr_session * session, |
---|
579 | tr_direction direection ); |
---|
580 | |
---|
581 | int tr_sessionIsSpeedLimitEnabled( const tr_session * session, |
---|
582 | tr_direction direction ); |
---|
583 | |
---|
584 | void tr_sessionSetSpeedLimit( tr_session * session, |
---|
585 | tr_direction direction, |
---|
586 | int KiB_sec ); |
---|
587 | |
---|
588 | int tr_sessionGetSpeedLimit( const tr_session * session, |
---|
589 | tr_direction direction ); |
---|
590 | |
---|
591 | void tr_sessionSetPeerLimit( tr_session * session, |
---|
592 | uint16_t maxGlobalPeers ); |
---|
593 | |
---|
594 | uint16_t tr_sessionGetPeerLimit( const tr_session * session ); |
---|
595 | |
---|
596 | |
---|
597 | /** |
---|
598 | * Load all the torrents in tr_getTorrentDir(). |
---|
599 | * This can be used at startup to kickstart all the torrents |
---|
600 | * from the previous session. |
---|
601 | */ |
---|
602 | tr_torrent ** tr_sessionLoadTorrents( tr_session * session, |
---|
603 | tr_ctor * ctor, |
---|
604 | int * setmeCount ); |
---|
605 | |
---|
606 | /** @} */ |
---|
607 | |
---|
608 | /** |
---|
609 | *** |
---|
610 | **/ |
---|
611 | |
---|
612 | |
---|
613 | /*********************************************************************** |
---|
614 | ** Message Logging |
---|
615 | */ |
---|
616 | |
---|
617 | enum |
---|
618 | { |
---|
619 | TR_MSG_ERR = 1, |
---|
620 | TR_MSG_INF = 2, |
---|
621 | TR_MSG_DBG = 3 |
---|
622 | }; |
---|
623 | void tr_setMessageLevel( int ); |
---|
624 | |
---|
625 | int tr_getMessageLevel( void ); |
---|
626 | |
---|
627 | typedef struct tr_msg_list |
---|
628 | { |
---|
629 | /* TR_MSG_ERR, TR_MSG_INF, or TR_MSG_DBG */ |
---|
630 | uint8_t level; |
---|
631 | |
---|
632 | /* The line number in the source file where this message originated */ |
---|
633 | int line; |
---|
634 | |
---|
635 | /* Time the message was generated */ |
---|
636 | time_t when; |
---|
637 | |
---|
638 | /* The torrent associated with this message, |
---|
639 | * or a module name such as "Port Forwarding" for non-torrent messages, |
---|
640 | * or NULL. */ |
---|
641 | char * name; |
---|
642 | |
---|
643 | /* The message */ |
---|
644 | char * message; |
---|
645 | |
---|
646 | /* The source file where this message originated */ |
---|
647 | const char * file; |
---|
648 | |
---|
649 | /* linked list of messages */ |
---|
650 | struct tr_msg_list * next; |
---|
651 | } |
---|
652 | tr_msg_list; |
---|
653 | |
---|
654 | void tr_setMessageQueuing( int isEnabled ); |
---|
655 | |
---|
656 | int tr_getMessageQueuing( void ); |
---|
657 | |
---|
658 | tr_msg_list * tr_getQueuedMessages( void ); |
---|
659 | |
---|
660 | void tr_freeMessageList( tr_msg_list * freeme ); |
---|
661 | |
---|
662 | /** @addtogroup Blocklists |
---|
663 | @{ */ |
---|
664 | |
---|
665 | /** |
---|
666 | * Specify a range of IPs for Transmission to block. |
---|
667 | * |
---|
668 | * filename must be an uncompressed ascii file, |
---|
669 | * using the same format as the bluetack level1 file. |
---|
670 | * |
---|
671 | * libtransmission does not keep a handle to `filename' |
---|
672 | * after this call returns, so the caller is free to |
---|
673 | * keep or delete `filename' as it wishes. |
---|
674 | * libtransmission makes its own copy of the file |
---|
675 | * massaged into a format easier to search. |
---|
676 | * |
---|
677 | * The caller only needs to invoke this when the blocklist |
---|
678 | * has changed. |
---|
679 | * |
---|
680 | * Passing NULL for a filename will clear the blocklist. |
---|
681 | */ |
---|
682 | int tr_blocklistSetContent( tr_session * session, |
---|
683 | const char * filename ); |
---|
684 | |
---|
685 | int tr_blocklistGetRuleCount( const tr_session * session ); |
---|
686 | |
---|
687 | int tr_blocklistExists( const tr_session * session ); |
---|
688 | |
---|
689 | int tr_blocklistIsEnabled( const tr_session * session ); |
---|
690 | |
---|
691 | void tr_blocklistSetEnabled( tr_session * session, |
---|
692 | int isEnabled ); |
---|
693 | |
---|
694 | |
---|
695 | /** @} */ |
---|
696 | |
---|
697 | |
---|
698 | /** @addtogroup tr_ctor Torrent Instantiation |
---|
699 | @{ |
---|
700 | |
---|
701 | Instantiating a tr_torrent had gotten more complicated as features were |
---|
702 | added. At one point there were four functions to check metainfo and five |
---|
703 | to create tr_torrent. |
---|
704 | |
---|
705 | To remedy this, a Torrent Constructor (struct tr_ctor) has been introduced: |
---|
706 | - Simplifies the API to two functions: tr_torrentParse() and tr_torrentNew() |
---|
707 | - You can set the fields you want; the system sets defaults for the rest. |
---|
708 | - You can specify whether or not your fields should supercede resume's. |
---|
709 | - We can add new features to tr_ctor without breaking tr_torrentNew()'s API. |
---|
710 | |
---|
711 | All the tr_ctor{Get,Set}*() functions with a return value return |
---|
712 | an error number, or zero if no error occurred. |
---|
713 | |
---|
714 | You must call one of the SetMetainfo() functions before creating |
---|
715 | a torrent with a tr_ctor. The other functions are optional. |
---|
716 | |
---|
717 | You can reuse a single tr_ctor to create a batch of torrents -- |
---|
718 | just call one of the SetMetainfo() functions between each |
---|
719 | tr_torrentNew() call. |
---|
720 | |
---|
721 | Every call to tr_ctorSetMetainfo*() frees the previous metainfo. |
---|
722 | */ |
---|
723 | |
---|
724 | typedef enum |
---|
725 | { |
---|
726 | TR_FALLBACK, /* indicates the ctor value should be used only |
---|
727 | in case of missing resume settings */ |
---|
728 | |
---|
729 | TR_FORCE, /* indicates the ctor value should be used |
---|
730 | regardless of what's in the resume settings */ |
---|
731 | } |
---|
732 | tr_ctorMode; |
---|
733 | |
---|
734 | struct tr_benc; |
---|
735 | |
---|
736 | tr_ctor* tr_ctorNew( const tr_session * session ); |
---|
737 | |
---|
738 | void tr_ctorFree( tr_ctor * ctor ); |
---|
739 | |
---|
740 | void tr_ctorSetDeleteSource( tr_ctor * ctor, |
---|
741 | uint8_t doDelete ); |
---|
742 | |
---|
743 | int tr_ctorSetMetainfo( tr_ctor * ctor, |
---|
744 | const uint8_t * metainfo, |
---|
745 | size_t len ); |
---|
746 | |
---|
747 | int tr_ctorSetMetainfoFromFile( tr_ctor * ctor, |
---|
748 | const char * filename ); |
---|
749 | |
---|
750 | int tr_ctorSetMetainfoFromHash( tr_ctor * ctor, |
---|
751 | const char * hashString ); |
---|
752 | |
---|
753 | /** Set the maximum number of peers this torrent can connect to. |
---|
754 | (Default: 50) */ |
---|
755 | void tr_ctorSetPeerLimit( tr_ctor * ctor, |
---|
756 | tr_ctorMode mode, |
---|
757 | uint16_t peerLimit ); |
---|
758 | |
---|
759 | /** Set the download folder for the torrent being added with this ctor. |
---|
760 | @see tr_ctorSetDownloadDir() |
---|
761 | @see tr_sessionInitFull() */ |
---|
762 | void tr_ctorSetDownloadDir( tr_ctor * ctor, |
---|
763 | tr_ctorMode mode, |
---|
764 | const char * directory ); |
---|
765 | |
---|
766 | /** Set whether or not the torrent begins downloading/seeding when created. |
---|
767 | (Default: not paused) */ |
---|
768 | void tr_ctorSetPaused( tr_ctor * ctor, |
---|
769 | tr_ctorMode mode, |
---|
770 | uint8_t isPaused ); |
---|
771 | |
---|
772 | int tr_ctorGetPeerLimit( const tr_ctor * ctor, |
---|
773 | tr_ctorMode mode, |
---|
774 | uint16_t * setmeCount ); |
---|
775 | |
---|
776 | int tr_ctorGetPaused( const tr_ctor * ctor, |
---|
777 | tr_ctorMode mode, |
---|
778 | uint8_t * setmeIsPaused ); |
---|
779 | |
---|
780 | int tr_ctorGetDownloadDir( const tr_ctor * ctor, |
---|
781 | tr_ctorMode mode, |
---|
782 | const char ** setmeDownloadDir ); |
---|
783 | |
---|
784 | int tr_ctorGetMetainfo( const tr_ctor * ctor, |
---|
785 | const struct tr_benc ** setme ); |
---|
786 | |
---|
787 | int tr_ctorGetDeleteSource( const tr_ctor * ctor, |
---|
788 | uint8_t * setmeDoDelete ); |
---|
789 | |
---|
790 | /* returns NULL if tr_ctorSetMetainfoFromFile() wasn't used */ |
---|
791 | const char* tr_ctorGetSourceFile( const tr_ctor * ctor ); |
---|
792 | |
---|
793 | #define TR_EINVALID 1 |
---|
794 | #define TR_EDUPLICATE 2 |
---|
795 | |
---|
796 | /** |
---|
797 | * Parses the specified metainfo. |
---|
798 | * Returns 0 if it parsed successfully and can be added to Transmission. |
---|
799 | * Returns TR_EINVALID if it couldn't be parsed. |
---|
800 | * Returns TR_EDUPLICATE if it parsed but can't be added. |
---|
801 | * "download-dir" must be set to test for TR_EDUPLICATE. |
---|
802 | * |
---|
803 | * If setme_info is non-NULL and parsing is successful |
---|
804 | * (that is, if TR_EINVALID is not returned), then the parsed |
---|
805 | * metainfo is stored in setme_info and should be freed by the |
---|
806 | * caller via tr_metainfoFree(). |
---|
807 | */ |
---|
808 | int tr_torrentParse( const tr_session * session, |
---|
809 | const tr_ctor * ctor, |
---|
810 | tr_info * setme_info_or_NULL ); |
---|
811 | |
---|
812 | /** @brief free a metainfo |
---|
813 | @see tr_torrentParse */ |
---|
814 | void tr_metainfoFree( tr_info * inf ); |
---|
815 | |
---|
816 | |
---|
817 | /** Instantiate a single torrent. |
---|
818 | @return 0 on success, |
---|
819 | TR_EINVALID if the torrent couldn't be parsed, or |
---|
820 | TR_EDUPLICATE if there's already a matching torrent object. */ |
---|
821 | tr_torrent * tr_torrentNew( tr_session * session, |
---|
822 | const tr_ctor * ctor, |
---|
823 | int * setmeError ); |
---|
824 | |
---|
825 | /** @} */ |
---|
826 | |
---|
827 | /*********************************************************************** |
---|
828 | *** |
---|
829 | *** TORRENTS |
---|
830 | **/ |
---|
831 | |
---|
832 | /** @addtogroup tr_torrent Torrents |
---|
833 | @{ */ |
---|
834 | |
---|
835 | /** @brief Frees memory allocated by tr_torrentNew(). |
---|
836 | Running torrents are stopped first. */ |
---|
837 | void tr_torrentFree( tr_torrent * torrent ); |
---|
838 | |
---|
839 | /** @brief Removes our .torrent and .resume files for |
---|
840 | this torrent, then calls tr_torrentFree(). */ |
---|
841 | void tr_torrentRemove( tr_torrent * torrent ); |
---|
842 | |
---|
843 | /** @brief Start a torrent */ |
---|
844 | void tr_torrentStart( tr_torrent * torrent ); |
---|
845 | |
---|
846 | /** @brief Stop (pause) a torrent */ |
---|
847 | void tr_torrentStop( tr_torrent * torrent ); |
---|
848 | |
---|
849 | /** |
---|
850 | * @brief Iterate through the torrents. |
---|
851 | * |
---|
852 | * Pass in a NULL pointer to get the first torrent. |
---|
853 | */ |
---|
854 | tr_torrent* tr_torrentNext( tr_session * session, |
---|
855 | tr_torrent * current ); |
---|
856 | |
---|
857 | |
---|
858 | uint64_t tr_torrentGetBytesLeftToAllocate( const tr_torrent * torrent ); |
---|
859 | |
---|
860 | /** |
---|
861 | * @brief Returns this torrent's unique ID. |
---|
862 | * |
---|
863 | * IDs are good as simple lookup keys, but are not persistent |
---|
864 | * between sessions. If you need that, use tr_info.hash or |
---|
865 | * tr_info.hashString. |
---|
866 | */ |
---|
867 | int tr_torrentId( const tr_torrent * torrent ); |
---|
868 | |
---|
869 | /**** |
---|
870 | ***** Speed Limits |
---|
871 | ****/ |
---|
872 | |
---|
873 | typedef enum |
---|
874 | { |
---|
875 | TR_SPEEDLIMIT_GLOBAL, /* only follow the overall speed limit */ |
---|
876 | TR_SPEEDLIMIT_SINGLE, /* only follow the per-torrent limit */ |
---|
877 | TR_SPEEDLIMIT_UNLIMITED /* no limits at all */ |
---|
878 | } |
---|
879 | tr_speedlimit; |
---|
880 | |
---|
881 | void tr_torrentSetSpeedMode( tr_torrent * tor, |
---|
882 | tr_direction up_or_down, |
---|
883 | tr_speedlimit mode ); |
---|
884 | |
---|
885 | tr_speedlimit tr_torrentGetSpeedMode( const tr_torrent * tor, |
---|
886 | tr_direction direction ); |
---|
887 | |
---|
888 | void tr_torrentSetSpeedLimit( tr_torrent * tor, |
---|
889 | tr_direction up_or_down, |
---|
890 | int KiB_sec ); |
---|
891 | |
---|
892 | int tr_torrentGetSpeedLimit( const tr_torrent * tor, |
---|
893 | tr_direction direction ); |
---|
894 | |
---|
895 | /**** |
---|
896 | ***** Peer Limits |
---|
897 | ****/ |
---|
898 | |
---|
899 | void tr_torrentSetPeerLimit( tr_torrent * tor, |
---|
900 | uint16_t peerLimit ); |
---|
901 | |
---|
902 | uint16_t tr_torrentGetPeerLimit( const tr_torrent * tor ); |
---|
903 | |
---|
904 | /**** |
---|
905 | ***** File Priorities |
---|
906 | ****/ |
---|
907 | |
---|
908 | enum |
---|
909 | { |
---|
910 | TR_PRI_LOW = -1, |
---|
911 | TR_PRI_NORMAL = 0, /* since NORMAL is 0, memset initializes nicely */ |
---|
912 | TR_PRI_HIGH = 1 |
---|
913 | }; |
---|
914 | |
---|
915 | typedef int8_t tr_priority_t; |
---|
916 | |
---|
917 | /** |
---|
918 | * @brief Set a batch of files to a particular priority. |
---|
919 | * |
---|
920 | * @param priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW |
---|
921 | */ |
---|
922 | void tr_torrentSetFilePriorities( tr_torrent * torrent, |
---|
923 | tr_file_index_t * files, |
---|
924 | tr_file_index_t fileCount, |
---|
925 | tr_priority_t priority ); |
---|
926 | |
---|
927 | /** |
---|
928 | * @brief Get this torrent's file priorities. |
---|
929 | * |
---|
930 | * @return A malloc()ed array of tor->info.fileCount items, |
---|
931 | * each holding a TR_PRI_NORMAL, TR_PRI_HIGH, or TR_PRI_LOW. |
---|
932 | * It's the caller's responsibility to free() this. |
---|
933 | */ |
---|
934 | tr_priority_t* tr_torrentGetFilePriorities( const tr_torrent * torrent ); |
---|
935 | |
---|
936 | /** |
---|
937 | * @brief Single-file form of tr_torrentGetFilePriorities. |
---|
938 | * @return TR_PRI_NORMAL, TR_PRI_HIGH, or TR_PRI_LOW. |
---|
939 | */ |
---|
940 | tr_priority_t tr_torrentGetFilePriority( const tr_torrent * torrent, |
---|
941 | tr_file_index_t file ); |
---|
942 | |
---|
943 | /** |
---|
944 | * @brief See if a file's `download' flag is set. |
---|
945 | * @return true if the file's `download' flag is set. |
---|
946 | */ |
---|
947 | int tr_torrentGetFileDL( const tr_torrent * torrent, |
---|
948 | tr_file_index_t file ); |
---|
949 | |
---|
950 | /** @brief Set a batch of files to be downloaded or not. */ |
---|
951 | void tr_torrentSetFileDLs( tr_torrent * torrent, |
---|
952 | tr_file_index_t * files, |
---|
953 | tr_file_index_t fileCount, |
---|
954 | int do_download ); |
---|
955 | |
---|
956 | |
---|
957 | const tr_info * tr_torrentInfo( const tr_torrent * torrent ); |
---|
958 | |
---|
959 | void tr_torrentSetDownloadDir( tr_torrent * torrent, |
---|
960 | const char * path ); |
---|
961 | |
---|
962 | const char * tr_torrentGetDownloadDir( const tr_torrent * torrent ); |
---|
963 | |
---|
964 | /** |
---|
965 | *** |
---|
966 | **/ |
---|
967 | |
---|
968 | typedef struct tr_tracker_info |
---|
969 | { |
---|
970 | int tier; |
---|
971 | char * announce; |
---|
972 | char * scrape; |
---|
973 | } |
---|
974 | tr_tracker_info; |
---|
975 | |
---|
976 | /** |
---|
977 | * @brief Modify a torrent's tracker list. |
---|
978 | * |
---|
979 | * This updates both the `torrent' object's tracker list |
---|
980 | * and the metainfo file in tr_sessionGetConfigDir()'s torrent subdirectory. |
---|
981 | * |
---|
982 | * @param torrent The torrent whose tracker list is to be modified |
---|
983 | * @param trackers An array of trackers, sorted by tier from first to last. |
---|
984 | * NOTE: only the `tier' and `announce' fields are used. |
---|
985 | * libtransmission derives `scrape' from `announce'. |
---|
986 | * @param trackerCount size of the `trackers' array |
---|
987 | */ |
---|
988 | void tr_torrentSetAnnounceList( tr_torrent * torrent, |
---|
989 | const tr_tracker_info * trackers, |
---|
990 | int trackerCount ); |
---|
991 | |
---|
992 | |
---|
993 | /** |
---|
994 | *** |
---|
995 | **/ |
---|
996 | |
---|
997 | typedef enum |
---|
998 | { |
---|
999 | TR_LEECH, /* doesn't have all the desired pieces */ |
---|
1000 | TR_SEED, /* has the entire torrent */ |
---|
1001 | TR_PARTIAL_SEED /* has the desired pieces, but not the entire torrent */ |
---|
1002 | } |
---|
1003 | tr_completeness; |
---|
1004 | |
---|
1005 | typedef void ( tr_torrent_completeness_func )( tr_torrent * torrent, |
---|
1006 | tr_completeness completeness, |
---|
1007 | void * user_data ); |
---|
1008 | |
---|
1009 | /** |
---|
1010 | * Register to be notified whenever a torrent's "completeness" |
---|
1011 | * changes. This will be called, for example, when a torrent |
---|
1012 | * finishes downloading and changes from TR_LEECH to |
---|
1013 | * either TR_SEED or TR_PARTIAL_SEED. |
---|
1014 | * |
---|
1015 | * func is invoked FROM LIBTRANSMISSION'S THREAD! |
---|
1016 | * This means func must be fast (to avoid blocking peers), |
---|
1017 | * shouldn't call libtransmission functions (to avoid deadlock), |
---|
1018 | * and shouldn't modify client-level memory without using a mutex! |
---|
1019 | * |
---|
1020 | * @see tr_completeness |
---|
1021 | */ |
---|
1022 | void tr_torrentSetCompletenessCallback( |
---|
1023 | tr_torrent * torrent, |
---|
1024 | tr_torrent_completeness_func func, |
---|
1025 | void * user_data ); |
---|
1026 | |
---|
1027 | void tr_torrentClearCompletenessCallback( tr_torrent * torrent ); |
---|
1028 | |
---|
1029 | |
---|
1030 | /** |
---|
1031 | * MANUAL ANNOUNCE |
---|
1032 | * |
---|
1033 | * Trackers usually set an announce interval of 15 or 30 minutes. |
---|
1034 | * Users can send one-time announce requests that override this |
---|
1035 | * interval by calling tr_torrentManualUpdate(). |
---|
1036 | * |
---|
1037 | * The wait interval for tr_torrentManualUpdate() is much smaller. |
---|
1038 | * You can test whether or not a manual update is possible |
---|
1039 | * (for example, to desensitize the button) by calling |
---|
1040 | * tr_torrentCanManualUpdate(). |
---|
1041 | */ |
---|
1042 | |
---|
1043 | void tr_torrentManualUpdate( tr_torrent * torrent ); |
---|
1044 | |
---|
1045 | int tr_torrentCanManualUpdate( const tr_torrent * torrent ); |
---|
1046 | |
---|
1047 | /*********************************************************************** |
---|
1048 | * tr_torrentPeers |
---|
1049 | ***********************************************************************/ |
---|
1050 | |
---|
1051 | typedef struct tr_peer_stat |
---|
1052 | { |
---|
1053 | tr_bool isEncrypted; |
---|
1054 | tr_bool isDownloadingFrom; |
---|
1055 | tr_bool isUploadingTo; |
---|
1056 | tr_bool isSeed; |
---|
1057 | |
---|
1058 | tr_bool peerIsChoked; |
---|
1059 | tr_bool peerIsInterested; |
---|
1060 | tr_bool clientIsChoked; |
---|
1061 | tr_bool clientIsInterested; |
---|
1062 | tr_bool isIncoming; |
---|
1063 | |
---|
1064 | uint8_t from; |
---|
1065 | tr_port port; |
---|
1066 | |
---|
1067 | char addr[INET6_ADDRSTRLEN]; |
---|
1068 | char client[80]; |
---|
1069 | char flagStr[32]; |
---|
1070 | |
---|
1071 | float progress; |
---|
1072 | float rateToPeer; |
---|
1073 | float rateToClient; |
---|
1074 | } |
---|
1075 | tr_peer_stat; |
---|
1076 | |
---|
1077 | tr_peer_stat * tr_torrentPeers( const tr_torrent * torrent, |
---|
1078 | int * peerCount ); |
---|
1079 | |
---|
1080 | void tr_torrentPeersFree( tr_peer_stat * peerStats, |
---|
1081 | int peerCount ); |
---|
1082 | |
---|
1083 | /** |
---|
1084 | * @brief get the download speeds for each of this torrent's webseed sources. |
---|
1085 | * |
---|
1086 | * @return an array of tor->info.webseedCount floats giving download speeds. |
---|
1087 | * Each speed in the array corresponds to the webseed at the same |
---|
1088 | * array index in tor->info.webseeds. |
---|
1089 | * To differentiate "idle" and "stalled" status, idle webseeds will |
---|
1090 | * return -1 instead of 0 KiB/s. |
---|
1091 | * NOTE: always free this array with tr_free() when you're done with it. |
---|
1092 | */ |
---|
1093 | float* tr_torrentWebSpeeds( const tr_torrent * torrent ); |
---|
1094 | |
---|
1095 | typedef struct tr_file_stat |
---|
1096 | { |
---|
1097 | uint64_t bytesCompleted; |
---|
1098 | float progress; |
---|
1099 | } |
---|
1100 | tr_file_stat; |
---|
1101 | |
---|
1102 | tr_file_stat * tr_torrentFiles( const tr_torrent * torrent, |
---|
1103 | tr_file_index_t * fileCount ); |
---|
1104 | |
---|
1105 | void tr_torrentFilesFree( tr_file_stat * files, |
---|
1106 | tr_file_index_t fileCount ); |
---|
1107 | |
---|
1108 | |
---|
1109 | /*********************************************************************** |
---|
1110 | * tr_torrentAvailability |
---|
1111 | *********************************************************************** |
---|
1112 | * Use this to draw an advanced progress bar which is 'size' pixels |
---|
1113 | * wide. Fills 'tab' which you must have allocated: each byte is set |
---|
1114 | * to either -1 if we have the piece, otherwise it is set to the number |
---|
1115 | * of connected peers who have the piece. |
---|
1116 | **********************************************************************/ |
---|
1117 | void tr_torrentAvailability( const tr_torrent * torrent, |
---|
1118 | int8_t * tab, |
---|
1119 | int size ); |
---|
1120 | |
---|
1121 | void tr_torrentAmountFinished( const tr_torrent * torrent, |
---|
1122 | float * tab, |
---|
1123 | int size ); |
---|
1124 | |
---|
1125 | void tr_torrentVerify( tr_torrent * torrent ); |
---|
1126 | |
---|
1127 | /*********************************************************************** |
---|
1128 | * tr_info |
---|
1129 | **********************************************************************/ |
---|
1130 | |
---|
1131 | typedef struct tr_file |
---|
1132 | { |
---|
1133 | uint64_t length; /* Length of the file, in bytes */ |
---|
1134 | char * name; /* Path to the file */ |
---|
1135 | int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ |
---|
1136 | int8_t dnd; /* nonzero if the file shouldn't be |
---|
1137 | downloaded */ |
---|
1138 | tr_piece_index_t firstPiece; /* We need pieces [firstPiece... */ |
---|
1139 | tr_piece_index_t lastPiece; /* ...lastPiece] to dl this file */ |
---|
1140 | uint64_t offset; /* file begins at the torrent's nth byte */ |
---|
1141 | } |
---|
1142 | tr_file; |
---|
1143 | |
---|
1144 | typedef struct tr_piece |
---|
1145 | { |
---|
1146 | uint8_t hash[SHA_DIGEST_LENGTH]; /* pieces hash */ |
---|
1147 | int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ |
---|
1148 | int8_t dnd; /* nonzero if the piece shouldn't be |
---|
1149 | downloaded */ |
---|
1150 | } |
---|
1151 | tr_piece; |
---|
1152 | |
---|
1153 | struct tr_info |
---|
1154 | { |
---|
1155 | /* Flags */ |
---|
1156 | tr_bool isPrivate; |
---|
1157 | tr_bool isMultifile; |
---|
1158 | |
---|
1159 | /* General info */ |
---|
1160 | uint8_t hash[SHA_DIGEST_LENGTH]; |
---|
1161 | char hashString[2 * SHA_DIGEST_LENGTH + 1]; |
---|
1162 | char * name; |
---|
1163 | |
---|
1164 | /* Path to torrent Transmission's internal copy of the .torrent file. |
---|
1165 | This field exists for compatability reasons in the Mac OS X client |
---|
1166 | and should not be used in new code. */ |
---|
1167 | char * torrent; |
---|
1168 | |
---|
1169 | /* these trackers are sorted by tier */ |
---|
1170 | tr_tracker_info * trackers; |
---|
1171 | int trackerCount; |
---|
1172 | |
---|
1173 | char ** webseeds; |
---|
1174 | int webseedCount; |
---|
1175 | |
---|
1176 | /* Torrent info */ |
---|
1177 | char * comment; |
---|
1178 | char * creator; |
---|
1179 | time_t dateCreated; |
---|
1180 | |
---|
1181 | /* Pieces info */ |
---|
1182 | uint32_t pieceSize; |
---|
1183 | tr_piece_index_t pieceCount; |
---|
1184 | uint64_t totalSize; |
---|
1185 | tr_piece * pieces; |
---|
1186 | |
---|
1187 | /* Files info */ |
---|
1188 | tr_file_index_t fileCount; |
---|
1189 | tr_file * files; |
---|
1190 | }; |
---|
1191 | |
---|
1192 | /** |
---|
1193 | * What the torrent is doing right now. |
---|
1194 | * |
---|
1195 | * Note: these values will become a straight enum at some point in the future. |
---|
1196 | * Do not rely on their current `bitfield' implementation |
---|
1197 | */ |
---|
1198 | typedef enum |
---|
1199 | { |
---|
1200 | TR_STATUS_CHECK_WAIT = ( 1 << 0 ), /* Waiting in queue to check files */ |
---|
1201 | TR_STATUS_CHECK = ( 1 << 1 ), /* Checking files */ |
---|
1202 | TR_STATUS_DOWNLOAD = ( 1 << 2 ), /* Downloading */ |
---|
1203 | TR_STATUS_SEED = ( 1 << 3 ), /* Seeding */ |
---|
1204 | TR_STATUS_STOPPED = ( 1 << 4 ) /* Torrent is stopped */ |
---|
1205 | } |
---|
1206 | tr_torrent_activity; |
---|
1207 | |
---|
1208 | tr_torrent_activity tr_torrentGetActivity( tr_torrent * ); |
---|
1209 | |
---|
1210 | #define TR_STATUS_IS_ACTIVE( s ) ( ( s ) != TR_STATUS_STOPPED ) |
---|
1211 | |
---|
1212 | typedef enum |
---|
1213 | { |
---|
1214 | TR_LOCKFILE_SUCCESS = 0, |
---|
1215 | TR_LOCKFILE_EOPEN, |
---|
1216 | TR_LOCKFILE_ELOCK |
---|
1217 | } |
---|
1218 | tr_lockfile_state_t; |
---|
1219 | |
---|
1220 | enum |
---|
1221 | { |
---|
1222 | TR_PEER_FROM_INCOMING = 0, /* connections made to the listening port */ |
---|
1223 | TR_PEER_FROM_TRACKER = 1, /* peers received from a tracker */ |
---|
1224 | TR_PEER_FROM_CACHE = 2, /* peers read from the peer cache */ |
---|
1225 | TR_PEER_FROM_PEX = 3, /* peers discovered via PEX */ |
---|
1226 | TR_PEER_FROM__MAX |
---|
1227 | }; |
---|
1228 | |
---|
1229 | /** Can be used as a mnemonic for "no error" errno */ |
---|
1230 | #define TR_OK 0 |
---|
1231 | |
---|
1232 | /** |
---|
1233 | * The current status of a torrent. |
---|
1234 | * @see tr_torrentStat() |
---|
1235 | */ |
---|
1236 | typedef struct tr_stat |
---|
1237 | { |
---|
1238 | /** The torrent's unique Id. |
---|
1239 | @see tr_torrentId() */ |
---|
1240 | int id; |
---|
1241 | |
---|
1242 | /** What is this torrent doing right now? */ |
---|
1243 | tr_torrent_activity activity; |
---|
1244 | |
---|
1245 | /** Our current announce URL, or NULL if none. |
---|
1246 | This URL may change during the session if the torrent's |
---|
1247 | metainfo has multiple trackers and the current one |
---|
1248 | becomes unreachable. */ |
---|
1249 | char * announceURL; |
---|
1250 | |
---|
1251 | /** Our current scrape URL, or NULL if none. |
---|
1252 | This URL may change during the session if the torrent's |
---|
1253 | metainfo has multiple trackers and the current one |
---|
1254 | becomes unreachable. */ |
---|
1255 | char * scrapeURL; |
---|
1256 | |
---|
1257 | /** The errno status for this torrent. 0 means everything's fine. */ |
---|
1258 | int error; |
---|
1259 | |
---|
1260 | /** Typically an error string returned from the tracker. */ |
---|
1261 | char errorString[128]; |
---|
1262 | |
---|
1263 | /** When tr_stat.status is TR_STATUS_CHECK or TR_STATUS_CHECK_WAIT, |
---|
1264 | this is the percentage of how much of the files has been |
---|
1265 | verified. When it gets to 1, the verify process is done. |
---|
1266 | Range is [0..1] |
---|
1267 | @see tr_stat.status */ |
---|
1268 | float recheckProgress; |
---|
1269 | |
---|
1270 | /** How much has been downloaded of the entire torrent. |
---|
1271 | Range is [0..1] */ |
---|
1272 | float percentComplete; |
---|
1273 | |
---|
1274 | /** How much has been downloaded of the files the user wants. This differs |
---|
1275 | from percentComplete if the user wants only some of the torrent's files. |
---|
1276 | Range is [0..1] |
---|
1277 | @see tr_stat.leftUntilDone */ |
---|
1278 | float percentDone; |
---|
1279 | |
---|
1280 | /** Speed all data being sent for this torrent. (KiB/s) |
---|
1281 | This includes piece data, protocol messages, and TCP overhead */ |
---|
1282 | double rawUploadSpeed; |
---|
1283 | |
---|
1284 | /** Speed all data being received for this torrent. (KiB/s) |
---|
1285 | This includes piece data, protocol messages, and TCP overhead */ |
---|
1286 | double rawDownloadSpeed; |
---|
1287 | |
---|
1288 | /** Speed all piece being sent for this torrent. (KiB/s) |
---|
1289 | This ONLY counts piece data. */ |
---|
1290 | double pieceUploadSpeed; |
---|
1291 | |
---|
1292 | /** Speed all piece being received for this torrent. (KiB/s) |
---|
1293 | This ONLY counts piece data. */ |
---|
1294 | double pieceDownloadSpeed; |
---|
1295 | |
---|
1296 | #define TR_ETA_NOT_AVAIL -1 |
---|
1297 | #define TR_ETA_UNKNOWN -2 |
---|
1298 | /** Estimated number of seconds left until the torrent is done, |
---|
1299 | or TR_ETA_NOT_AVAIL or TR_ETA_UNKNOWN */ |
---|
1300 | int eta; |
---|
1301 | |
---|
1302 | /** Number of peers that the tracker says this torrent has */ |
---|
1303 | int peersKnown; |
---|
1304 | |
---|
1305 | /** Number of peers that we're connected to */ |
---|
1306 | int peersConnected; |
---|
1307 | |
---|
1308 | /** How many peers we found out about from the tracker, or from pex, |
---|
1309 | or from incoming connections, or from our resume file. */ |
---|
1310 | int peersFrom[TR_PEER_FROM__MAX]; |
---|
1311 | |
---|
1312 | /** Number of peers that are sending data to us. */ |
---|
1313 | int peersSendingToUs; |
---|
1314 | |
---|
1315 | /** Number of peers that we're sending data to */ |
---|
1316 | int peersGettingFromUs; |
---|
1317 | |
---|
1318 | /** Number of webseeds that are sending data to us. */ |
---|
1319 | int webseedsSendingToUs; |
---|
1320 | |
---|
1321 | /** Number of seeders that the tracker says this torrent has */ |
---|
1322 | int seeders; |
---|
1323 | |
---|
1324 | /** Number of leechers that the tracker says this torrent has */ |
---|
1325 | int leechers; |
---|
1326 | |
---|
1327 | /** Number of downloaders that the tracker says this torrent has. |
---|
1328 | This is a new key introduced in BEP 21 and may not be supported by some trackers. |
---|
1329 | If the tracker doesn't support this key, the value here will be -1. */ |
---|
1330 | int downloaders; |
---|
1331 | |
---|
1332 | /** Number of finished downloads that the tracker says torrent has */ |
---|
1333 | int timesCompleted; |
---|
1334 | |
---|
1335 | /** Byte count of all the piece data we'll have downloaded when we're done, |
---|
1336 | whether or not we have it yet. This may be less than tr_info.totalSize |
---|
1337 | if only some of the torrent's files are wanted. |
---|
1338 | [0...tr_info.totalSize] */ |
---|
1339 | uint64_t sizeWhenDone; |
---|
1340 | |
---|
1341 | /** Byte count of how much data is left to be downloaded until we've got |
---|
1342 | all the pieces that we want. [0...tr_info.sizeWhenDone] */ |
---|
1343 | uint64_t leftUntilDone; |
---|
1344 | |
---|
1345 | /** Byte count of all the piece data we want and don't have yet, |
---|
1346 | but that a connected peer does have. [0...leftUntilDone] */ |
---|
1347 | uint64_t desiredAvailable; |
---|
1348 | |
---|
1349 | /** Byte count of all the corrupt data you've ever downloaded for |
---|
1350 | this torrent. If you're on a poisoned torrent, this number can |
---|
1351 | grow very large. */ |
---|
1352 | uint64_t corruptEver; |
---|
1353 | |
---|
1354 | /** Byte count of all data you've ever uploaded for this torrent. */ |
---|
1355 | uint64_t uploadedEver; |
---|
1356 | |
---|
1357 | /** Byte count of all the non-corrupt data you've ever downloaded |
---|
1358 | for this torrent. If you deleted the files and downloaded a second |
---|
1359 | time, this will be 2*totalSize.. */ |
---|
1360 | uint64_t downloadedEver; |
---|
1361 | |
---|
1362 | /** Byte count of all the checksum-verified data we have for this torrent. |
---|
1363 | */ |
---|
1364 | uint64_t haveValid; |
---|
1365 | |
---|
1366 | /** Byte count of all the partial piece data we have for this torrent. |
---|
1367 | As pieces become complete, this value may decrease as portions of it |
---|
1368 | are moved to `corrupt' or `haveValid'. */ |
---|
1369 | uint64_t haveUnchecked; |
---|
1370 | |
---|
1371 | /** This is the unmodified string returned by the tracker in response |
---|
1372 | to the torrent's most recent scrape request. If no request was |
---|
1373 | sent or there was no response, this string is empty. */ |
---|
1374 | char scrapeResponse[64]; |
---|
1375 | |
---|
1376 | /** The unmodified string returned by the tracker in response |
---|
1377 | to the torrent's most recent scrape request. If no request was |
---|
1378 | sent or there was no response, this string is empty. */ |
---|
1379 | char announceResponse[64]; |
---|
1380 | |
---|
1381 | /** Time the most recent scrape request was sent, |
---|
1382 | or zero if one hasn't been sent yet. */ |
---|
1383 | time_t lastScrapeTime; |
---|
1384 | |
---|
1385 | /** Time when the next scrape request will be sent, |
---|
1386 | or 0 if an error has occured that stops scraping, |
---|
1387 | or 1 if a scrape is currently in progress s.t. |
---|
1388 | we haven't set a timer for the next one yet. */ |
---|
1389 | time_t nextScrapeTime; |
---|
1390 | |
---|
1391 | /** Time the most recent announce request was sent, |
---|
1392 | or zero if one hasn't been sent yet. */ |
---|
1393 | time_t lastAnnounceTime; |
---|
1394 | |
---|
1395 | /** Time when the next reannounce request will be sent, |
---|
1396 | or 0 if the torrent is stopped, |
---|
1397 | or 1 if an announce is currently in progress s.t. |
---|
1398 | we haven't set a timer for the next one yet */ |
---|
1399 | time_t nextAnnounceTime; |
---|
1400 | |
---|
1401 | /** If the torrent is running, this is the time at which |
---|
1402 | the client can manually ask the torrent's tracker |
---|
1403 | for more peers, |
---|
1404 | or 0 if the torrent is stopped or doesn't allow manual, |
---|
1405 | or 1 if an announce is currently in progress s.t. |
---|
1406 | we haven't set a timer for the next one yet */ |
---|
1407 | time_t manualAnnounceTime; |
---|
1408 | |
---|
1409 | /** A very rough estimate in KiB/s of how quickly data is being |
---|
1410 | passed around between all the peers we're connected to. |
---|
1411 | Don't put too much weight in this number. */ |
---|
1412 | float swarmSpeed; |
---|
1413 | |
---|
1414 | #define TR_RATIO_NA -1 |
---|
1415 | #define TR_RATIO_INF -2 |
---|
1416 | /** TR_RATIO_INF, TR_RATIO_NA, or a regular ratio */ |
---|
1417 | float ratio; |
---|
1418 | |
---|
1419 | /** When the torrent was first added. */ |
---|
1420 | time_t addedDate; |
---|
1421 | |
---|
1422 | /** When the torrent finished downloading. */ |
---|
1423 | time_t doneDate; |
---|
1424 | |
---|
1425 | /** When the torrent was last started. */ |
---|
1426 | time_t startDate; |
---|
1427 | |
---|
1428 | /** The last time we uploaded or downloaded piece data on this torrent. */ |
---|
1429 | time_t activityDate; |
---|
1430 | } |
---|
1431 | tr_stat; |
---|
1432 | |
---|
1433 | /** Return a pointer to an tr_stat structure with updated information |
---|
1434 | on the torrent. This is typically called by the GUI clients every |
---|
1435 | second or so to get a new snapshot of the torrent's status. */ |
---|
1436 | const tr_stat * tr_torrentStat( tr_torrent * torrent ); |
---|
1437 | |
---|
1438 | /** Like tr_torrentStat(), but only recalculates the statistics if it's |
---|
1439 | been longer than a second since they were last calculated. This can |
---|
1440 | reduce the CPU load if you're calling tr_torrentStat() frequently. */ |
---|
1441 | const tr_stat * tr_torrentStatCached( tr_torrent * torrent ); |
---|
1442 | |
---|
1443 | /** @deprecated this method will be removed in 1.40 */ |
---|
1444 | void tr_torrentSetAddedDate( tr_torrent * torrent, |
---|
1445 | time_t addedDate ); |
---|
1446 | |
---|
1447 | /** @deprecated this method will be removed in 1.40 */ |
---|
1448 | void tr_torrentSetActivityDate( tr_torrent * torrent, |
---|
1449 | time_t activityDate ); |
---|
1450 | |
---|
1451 | /** @deprecated this method will be removed in 1.40 */ |
---|
1452 | void tr_torrentSetDoneDate( tr_torrent * torrent, |
---|
1453 | time_t doneDate ); |
---|
1454 | |
---|
1455 | /** @} */ |
---|
1456 | |
---|
1457 | #ifdef __TRANSMISSION__ |
---|
1458 | #include "session.h" |
---|
1459 | #endif |
---|
1460 | |
---|
1461 | #ifdef __cplusplus |
---|
1462 | } |
---|
1463 | #endif |
---|
1464 | |
---|
1465 | #endif |
---|