source: branches/0.7x/libtransmission/transmission.h @ 1787

Last change on this file since 1787 was 1787, checked in by titer, 15 years ago

Backport [1763]

  • Property svn:keywords set to Date Rev Author Id
File size: 20.4 KB
Line 
1/******************************************************************************
2 * $Id: transmission.h 1787 2007-04-23 20:16:16Z titer $
3 *
4 * Copyright (c) 2005-2007 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#ifndef TR_TRANSMISSION_H
26#define TR_TRANSMISSION_H 1
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include "version.h"
33
34#include <inttypes.h>
35#ifndef PRIu64
36# define PRIu64 "lld"
37#endif
38#include <time.h>
39
40#define SHA_DIGEST_LENGTH 20
41#ifdef __BEOS__
42# include <StorageDefs.h>
43# define MAX_PATH_LENGTH  B_FILE_NAME_LENGTH
44#else
45# define MAX_PATH_LENGTH  1024
46#endif
47
48#ifndef INET_ADDRSTRLEN
49#define INET_ADDRSTRLEN 16
50#endif
51
52#define TR_DEFAULT_PORT   9090
53
54#define TR_PEER_FROM__MAX       4
55#define TR_PEER_FROM_INCOMING   0 /* connections made to the listening port */
56#define TR_PEER_FROM_TRACKER    1 /* peers received from a tracker */
57#define TR_PEER_FROM_CACHE      2 /* peers read from the peer cache */
58#define TR_PEER_FROM_PEX        3 /* peers discovered via PEX */
59
60/***********************************************************************
61 * Error codes
62 **********************************************************************/
63/* General errors */
64#define TR_OK                   0x00000000
65#define TR_ERROR                0x81000000
66#define TR_ERROR_ASSERT         0x82000000
67/* I/O errors */
68#define TR_ERROR_IO_MASK        0x000000FF
69#define TR_ERROR_IO_PARENT      0x80000001
70#define TR_ERROR_IO_PERMISSIONS 0x80000002
71#define TR_ERROR_IO_SPACE       0x80000004
72#define TR_ERROR_IO_RESOURCES   0x80000008
73#define TR_ERROR_IO_OTHER       0x80000010
74/* Misc */
75#define TR_ERROR_TC_MASK        0x00000F00
76#define TR_ERROR_TC_ERROR       0x80000100
77#define TR_ERROR_TC_WARNING     0x80000200
78
79/***********************************************************************
80 * tr_init
81 ***********************************************************************
82 * Initializes a libtransmission instance. Returns a obscure handle to
83 * be passed to all functions below. The tag argument is a short string
84 * unique to the program invoking tr_init(), it is currently used as
85 * part of saved torrent files' names to prevent one frontend from
86 * deleting a torrent used by another. The following tags are used:
87 *   beos cli daemon gtk macosx
88 **********************************************************************/
89typedef struct tr_handle_s tr_handle_t;
90tr_handle_t * tr_init( const char * tag );
91
92typedef struct tr_tracker_info_s tr_tracker_info_t;
93
94/***********************************************************************
95 * tr_setMessageLevel
96 ***********************************************************************
97 * Set the level of messages to be output or queued
98 **********************************************************************/
99#define TR_MSG_ERR 1
100#define TR_MSG_INF 2
101#define TR_MSG_DBG 3
102void tr_setMessageLevel( int );
103int tr_getMessageLevel( void );
104
105/***********************************************************************
106 * tr_setMessageQueuing
107 ***********************************************************************
108 * Enable or disable message queuing
109 **********************************************************************/
110typedef struct tr_msg_list_s tr_msg_list_t;
111void tr_setMessageQueuing( int );
112
113/***********************************************************************
114 * tr_getQueuedMessages
115 ***********************************************************************
116 * Return a list of queued messages
117 **********************************************************************/
118tr_msg_list_t * tr_getQueuedMessages( void );
119void tr_freeMessageList( tr_msg_list_t * list );
120
121/***********************************************************************
122 * tr_getPrefsDirectory
123 ***********************************************************************
124 * Returns the full path to a directory which can be used to store
125 * preferences. The string belongs to libtransmission, do not free it.
126 **********************************************************************/
127char * tr_getPrefsDirectory();
128
129/***********************************************************************
130 * tr_setBindPort
131 ***********************************************************************
132 * Sets the port to listen for incoming peer connections.
133 * This can be safely called even with active torrents.
134 **********************************************************************/
135void tr_setBindPort( tr_handle_t *, int );
136
137/***********************************************************************
138 * tr_natTraversalEnable
139 * tr_natTraversalDisable
140 ***********************************************************************
141 * Enable or disable NAT traversal using NAT-PMP or UPnP IGD.
142 **********************************************************************/
143void tr_natTraversalEnable( tr_handle_t *, int enable );
144
145/***********************************************************************
146 * tr_handleStatus
147 ***********************************************************************
148 * Returns some status info for the given handle.
149 **********************************************************************/
150typedef struct tr_handle_status_s tr_handle_status_t;
151tr_handle_status_t * tr_handleStatus( tr_handle_t * );
152
153/***********************************************************************
154 * tr_setGlobalUploadLimit
155 ***********************************************************************
156 * Sets the total upload rate limit in KB/s
157 **********************************************************************/
158void tr_setGlobalUploadLimit( tr_handle_t *, int );
159
160/***********************************************************************
161 * tr_setGlobalDownloadLimit
162 ***********************************************************************
163 * Sets the total download rate limit in KB/s
164 **********************************************************************/
165void tr_setGlobalDownloadLimit( tr_handle_t *, int );
166
167/***********************************************************************
168 * tr_torrentCount
169 ***********************************************************************
170 * Returns the count of open torrents
171 **********************************************************************/
172int tr_torrentCount( tr_handle_t * h );
173
174/***********************************************************************
175 * tr_torrentIterate
176 ***********************************************************************
177 * Iterates on open torrents
178 **********************************************************************/
179typedef struct tr_torrent_s tr_torrent_t;
180typedef void (*tr_callback_t) ( tr_torrent_t *, void * );
181void tr_torrentIterate( tr_handle_t *, tr_callback_t, void * );
182
183void tr_setUseCustomLimit( tr_torrent_t * tor, int limit );
184void tr_setUploadLimit( tr_torrent_t * tor, int limit );
185void tr_setDownloadLimit( tr_torrent_t * tor, int limit );
186
187/***********************************************************************
188 * tr_torrentRates
189 ***********************************************************************
190 * Gets the total download and upload rates
191 **********************************************************************/
192void tr_torrentRates( tr_handle_t *, float *, float * );
193
194/***********************************************************************
195 * tr_close
196 ***********************************************************************
197 * Frees memory allocated by tr_init.
198 **********************************************************************/
199void tr_close( tr_handle_t * );
200
201/***********************************************************************
202 * tr_torrentInit
203 ***********************************************************************
204 * Opens and parses torrent file at 'path'. If the file exists and is
205 * a valid torrent file, returns an handle and adds it to the list of
206 * torrents (but doesn't start it). Returns NULL and sets *error
207 * otherwise. If hash is not NULL and the torrent is already loaded
208 * then it's 20-byte hash will be copied in. If the TR_FLAG_SAVE flag
209 * is passed then a copy of the torrent file will be saved.
210 **********************************************************************/
211#define TR_EINVALID     1
212#define TR_EUNSUPPORTED 2
213#define TR_EDUPLICATE   3
214#define TR_EOTHER       666
215tr_torrent_t * tr_torrentInit( tr_handle_t *, const char * path,
216                               uint8_t * hash, int flags, int * error );
217
218/***********************************************************************
219 * tr_torrentInitData
220 ***********************************************************************
221 * Like tr_torrentInit, except the actual torrent data is passed in
222 * instead of the filename.
223 **********************************************************************/
224tr_torrent_t * tr_torrentInitData( tr_handle_t *, uint8_t * data,
225                                   size_t size, uint8_t * hash,
226                                   int flags, int * error );
227
228/***********************************************************************
229 * tr_torrentInitSaved
230 ***********************************************************************
231 * Opens and parses a torrent file as with tr_torrentInit, only taking
232 * the hash string of a saved torrent file instead of a filename. There
233 * are currently no valid flags for this function.
234 **********************************************************************/
235tr_torrent_t * tr_torrentInitSaved( tr_handle_t *, const char * hashStr,
236                                    int flags, int * error );
237
238/***********************************************************************
239 * tr_torrentDisablePex
240 ***********************************************************************
241 * Disable or enable peer exchange for this torrent. Peer exchange is
242 * enabled by default, except for private torrents where pex is
243 * disabled and cannot be enabled.
244 **********************************************************************/
245void tr_torrentDisablePex( tr_torrent_t *, int disable );
246
247/***********************************************************************
248 * tr_torrentScrape
249 ***********************************************************************
250 * Return torrent metainfo.
251 **********************************************************************/
252typedef struct tr_info_s tr_info_t;
253tr_info_t * tr_torrentInfo( tr_torrent_t * );
254
255/***********************************************************************
256 * tr_torrentScrape
257 ***********************************************************************
258 * Asks the tracker for the count of seeders and leechers. Returns 0
259 * and fills 's' and 'l' if successful. Otherwise returns 1 if the
260 * tracker doesn't support the scrape protocol, is unreachable or
261 * replied with some error. tr_torrentScrape may block up to 20 seconds
262 * before returning.
263 **********************************************************************/
264int tr_torrentScrape( tr_torrent_t *, int * s, int * l, int * d );
265
266/***********************************************************************
267 * tr_torrentStart
268 ***********************************************************************
269 * Starts downloading. The download is launched in a seperate thread,
270 * therefore tr_torrentStart returns immediately.
271 **********************************************************************/
272void   tr_torrentSetFolder( tr_torrent_t *, const char * );
273char * tr_torrentGetFolder( tr_torrent_t * );
274void   tr_torrentStart( tr_torrent_t * );
275
276/***********************************************************************
277 * tr_torrentStop
278 ***********************************************************************
279 * Stops downloading and notices the tracker that we are leaving. The
280 * thread keeps running while doing so.
281 * The thread will eventually be joined, either:
282 * - by tr_torrentStat when the tracker has been successfully noticed,
283 * - by tr_torrentStat if the tracker could not be noticed within 60s,
284 * - by tr_torrentClose if you choose to remove the torrent without
285 *   waiting any further.
286 **********************************************************************/
287void tr_torrentStop( tr_torrent_t * );
288
289/***********************************************************************
290 * tr_getFinished
291 ***********************************************************************
292 * The first call after a torrent is completed returns 1. Returns 0
293 * in other cases.
294 **********************************************************************/
295int tr_getFinished( tr_torrent_t * );
296
297/***********************************************************************
298 * tr_manualUpdate
299 ***********************************************************************
300 * Reannounce to tracker regardless of wait interval
301 **********************************************************************/
302void tr_manualUpdate( tr_torrent_t * );
303
304/***********************************************************************
305 * tr_torrentStat
306 ***********************************************************************
307 * Returns a pointer to an tr_stat_t structure with updated information
308 * on the torrent. The structure belongs to libtransmission (do not
309 * free it) and is guaranteed to be unchanged until the next call to
310 * tr_torrentStat.
311 * The interface should call this function every second or so in order
312 * to update itself.
313 **********************************************************************/
314typedef struct tr_stat_s tr_stat_t;
315tr_stat_t * tr_torrentStat( tr_torrent_t * );
316
317/***********************************************************************
318 * tr_torrentPeers
319 ***********************************************************************/
320typedef struct tr_peer_stat_s tr_peer_stat_t;
321tr_peer_stat_t * tr_torrentPeers( tr_torrent_t *, int * peerCount );
322void tr_torrentPeersFree( tr_peer_stat_t *, int peerCount );
323
324/***********************************************************************
325 * tr_torrentAvailability
326 ***********************************************************************
327 * Use this to draw an advanced progress bar which is 'size' pixels
328 * wide. Fills 'tab' which you must have allocated: each byte is set
329 * to either -1 if we have the piece, otherwise it is set to the number
330 * of connected peers who have the piece.
331 **********************************************************************/
332void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size );
333
334void tr_torrentAmountFinished( tr_torrent_t * tor, float * tab, int size );
335
336/***********************************************************************
337 * tr_torrentCompletion
338 ***********************************************************************
339 * Returns the completion progress for each file in the torrent as an
340 * array of floats the same size and order as in tr_info_t. Free the
341 * array when done.
342 **********************************************************************/
343float * tr_torrentCompletion( tr_torrent_t * tor );
344
345/***********************************************************************
346 * tr_torrentRemoveSaved
347 ***********************************************************************
348 * Removes the saved copy of a torrent file for torrents which the
349 * TR_FLAG_SAVE flag is set.
350 **********************************************************************/
351void tr_torrentRemoveSaved( tr_torrent_t * );
352
353/***********************************************************************
354 * tr_torrentClose
355 ***********************************************************************
356 * Frees memory allocated by tr_torrentInit. If the torrent was running,
357 * you must call tr_torrentStop() before closing it.
358 **********************************************************************/
359void tr_torrentClose( tr_handle_t *, tr_torrent_t * );
360
361/***********************************************************************
362 * tr_info_s
363 **********************************************************************/
364typedef struct tr_file_s
365{
366    uint64_t length;                /* Length of the file, in bytes */
367    char     name[MAX_PATH_LENGTH]; /* Path to the file */
368}
369tr_file_t;
370struct tr_info_s
371{
372    /* Path to torrent */
373    char                 torrent[MAX_PATH_LENGTH];
374
375    /* General info */
376    uint8_t              hash[SHA_DIGEST_LENGTH];
377    char                 hashString[2*SHA_DIGEST_LENGTH+1];
378    char                 name[MAX_PATH_LENGTH];
379
380    /* Flags */
381#define TR_FLAG_SAVE    0x01 /* save a copy of the torrent file */
382#define TR_FLAG_PRIVATE 0x02 /* do not share information for this torrent */
383    int                  flags;
384
385    /* Tracker info */
386    struct
387    {
388        tr_tracker_info_t * list;
389        int                 count;
390    }                  * trackerList;
391    int                  trackerTiers;
392
393    /* Torrent info */
394    char                 comment[MAX_PATH_LENGTH];
395    char                 creator[MAX_PATH_LENGTH];
396    int                  dateCreated;
397
398    /* Pieces info */
399    int                  pieceSize;
400    int                  pieceCount;
401    uint64_t             totalSize;
402    uint8_t            * pieces;
403
404    /* Files info */
405    int                  multifile;
406    int                  fileCount;
407    tr_file_t          * files;
408};
409
410/***********************************************************************
411 * tr_stat_s
412 **********************************************************************/
413struct tr_stat_s
414{
415#define TR_STATUS_CHECK    0x001 /* Checking files */
416#define TR_STATUS_DOWNLOAD 0x002 /* Downloading */
417#define TR_STATUS_SEED     0x004 /* Seeding */
418#define TR_STATUS_STOPPING 0x008 /* Sending 'stopped' to the tracker */
419#define TR_STATUS_STOPPED  0x010 /* Sent 'stopped' but thread still
420                                    running (for internal use only) */
421#define TR_STATUS_PAUSE    0x020 /* Paused */
422
423#define TR_STATUS_ACTIVE   (TR_STATUS_CHECK|TR_STATUS_DOWNLOAD|TR_STATUS_SEED)
424#define TR_STATUS_INACTIVE (TR_STATUS_STOPPING|TR_STATUS_STOPPED|TR_STATUS_PAUSE)
425    int                 status;
426
427    int                 error;
428    char                errorString[128];
429    int                 cannotConnect;
430
431    tr_tracker_info_t * tracker;
432
433    float               progress;
434    float               rateDownload;
435    float               rateUpload;
436    int                 eta;
437    int                 peersTotal;
438    int                 peersFrom[TR_PEER_FROM__MAX];
439    int                 peersUploading;
440    int                 peersDownloading;
441    int                 seeders;
442    int                 leechers;
443    int                 completedFromTracker;
444
445    uint64_t            left;
446    uint64_t            downloaded;
447    uint64_t            uploaded;
448    float               swarmspeed;
449
450#define TR_RATIO_NA  -1
451    float               ratio;
452};
453
454struct tr_peer_stat_s
455{
456    char    addr[INET_ADDRSTRLEN];
457    const char * client;
458   
459    int     isConnected;
460    int     from;
461    float   progress;
462    int     port;
463   
464    int     isDownloading;
465    int     isUploading;
466    float   downloadFromRate;
467    float   uploadToRate;
468};
469
470struct tr_msg_list_s
471{
472    int                    level;
473    time_t                 when;
474    char                 * message;
475    struct tr_msg_list_s * next;
476};
477
478struct tr_tracker_info_s
479{
480    char * address;
481    int    port;
482    char * announce;
483    char * scrape;
484};
485
486struct tr_handle_status_s
487{
488#define TR_NAT_TRAVERSAL_MAPPING        1
489#define TR_NAT_TRAVERSAL_MAPPED         2
490#define TR_NAT_TRAVERSAL_NOTFOUND       3
491#define TR_NAT_TRAVERSAL_ERROR          4
492#define TR_NAT_TRAVERSAL_UNMAPPING      5
493#define TR_NAT_TRAVERSAL_DISABLED       6
494#define TR_NAT_TRAVERSAL_IS_DISABLED( st ) \
495  ( TR_NAT_TRAVERSAL_DISABLED == (st) || TR_NAT_TRAVERSAL_UNMAPPING == (st) )
496    int natTraversalStatus;
497    int publicPort;
498};
499
500#ifdef __TRANSMISSION__
501#  include "internal.h"
502#endif
503
504#ifdef __cplusplus
505}
506#endif
507
508#endif
Note: See TracBrowser for help on using the repository browser.