source: branches/daemon/libtransmission/transmission.h @ 1712

Last change on this file since 1712 was 1712, checked in by joshe, 15 years ago

Merge libT revs 1616:1711 from trunk to daemon branch.

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