source: trunk/libtransmission/transmission.h @ 1579

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

Merge PEX branch, I hope this works.

  • Property svn:keywords set to Date Rev Author Id
File size: 19.0 KB
Line 
1/******************************************************************************
2 * $Id: transmission.h 1579 2007-03-23 08:28:01Z 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_torrentInitSaved
218 ***********************************************************************
219 * Opens and parses a torrent file as with tr_torrentInit, only taking
220 * the hash string of a saved torrent file instead of a filename. There
221 * are currently no valid flags for this function.
222 **********************************************************************/
223tr_torrent_t * tr_torrentInitSaved( tr_handle_t *, const char * hashStr,
224                                    int flags, int * error );
225
226typedef struct tr_info_s tr_info_t;
227tr_info_t * tr_torrentInfo( tr_torrent_t * );
228
229/***********************************************************************
230 * tr_torrentScrape
231 ***********************************************************************
232 * Asks the tracker for the count of seeders and leechers. Returns 0
233 * and fills 's' and 'l' if successful. Otherwise returns 1 if the
234 * tracker doesn't support the scrape protocol, is unreachable or
235 * replied with some error. tr_torrentScrape may block up to 20 seconds
236 * before returning.
237 **********************************************************************/
238int tr_torrentScrape( tr_torrent_t *, int * s, int * l, int * d );
239
240/***********************************************************************
241 * tr_torrentStart
242 ***********************************************************************
243 * Starts downloading. The download is launched in a seperate thread,
244 * therefore tr_torrentStart returns immediately.
245 **********************************************************************/
246void   tr_torrentSetFolder( tr_torrent_t *, const char * );
247char * tr_torrentGetFolder( tr_torrent_t * );
248void   tr_torrentStart( tr_torrent_t * );
249
250/***********************************************************************
251 * tr_torrentStop
252 ***********************************************************************
253 * Stops downloading and notices the tracker that we are leaving. The
254 * thread keeps running while doing so.
255 * The thread will eventually be joined, either:
256 * - by tr_torrentStat when the tracker has been successfully noticed,
257 * - by tr_torrentStat if the tracker could not be noticed within 60s,
258 * - by tr_torrentClose if you choose to remove the torrent without
259 *   waiting any further.
260 **********************************************************************/
261void tr_torrentStop( tr_torrent_t * );
262
263/***********************************************************************
264 * tr_getFinished
265 ***********************************************************************
266 * The first call after a torrent is completed returns 1. Returns 0
267 * in other cases.
268 **********************************************************************/
269int tr_getFinished( tr_torrent_t * );
270
271/***********************************************************************
272 * tr_manualUpdate
273 ***********************************************************************
274 * Reannounce to tracker regardless of wait interval
275 **********************************************************************/
276void tr_manualUpdate( tr_torrent_t * );
277
278/***********************************************************************
279 * tr_torrentStat
280 ***********************************************************************
281 * Returns a pointer to an tr_stat_t structure with updated information
282 * on the torrent. The structure belongs to libtransmission (do not
283 * free it) and is guaranteed to be unchanged until the next call to
284 * tr_torrentStat.
285 * The interface should call this function every second or so in order
286 * to update itself.
287 **********************************************************************/
288typedef struct tr_stat_s tr_stat_t;
289tr_stat_t * tr_torrentStat( tr_torrent_t * );
290
291/***********************************************************************
292 * tr_torrentPeers
293 ***********************************************************************/
294typedef struct tr_peer_stat_s tr_peer_stat_t;
295tr_peer_stat_t * tr_torrentPeers( tr_torrent_t *, int * peerCount );
296void tr_torrentPeersFree( tr_peer_stat_t *, int peerCount );
297
298/***********************************************************************
299 * tr_torrentAvailability
300 ***********************************************************************
301 * Use this to draw an advanced progress bar which is 'size' pixels
302 * wide. Fills 'tab' which you must have allocated: each byte is set
303 * to either -1 if we have the piece, otherwise it is set to the number
304 * of connected peers who have the piece.
305 **********************************************************************/
306void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size );
307
308void tr_torrentAmountFinished( tr_torrent_t * tor, float * tab, int size );
309
310/***********************************************************************
311 * tr_torrentCompletion
312 ***********************************************************************
313 * Returns the completion progress for each file in the torrent as an
314 * array of floats the same size and order as in tr_info_t. Free the
315 * array when done.
316 **********************************************************************/
317float * tr_torrentCompletion( tr_torrent_t * tor );
318
319/***********************************************************************
320 * tr_torrentRemoveSaved
321 ***********************************************************************
322 * Removes the saved copy of a torrent file for torrents which the
323 * TR_FLAG_SAVE flag is set.
324 **********************************************************************/
325void tr_torrentRemoveSaved( tr_torrent_t * );
326
327/***********************************************************************
328 * tr_torrentClose
329 ***********************************************************************
330 * Frees memory allocated by tr_torrentInit. If the torrent was running,
331 * you must call tr_torrentStop() before closing it.
332 **********************************************************************/
333void tr_torrentClose( tr_handle_t *, tr_torrent_t * );
334
335/***********************************************************************
336 * tr_info_s
337 **********************************************************************/
338typedef struct tr_file_s
339{
340    uint64_t length;                /* Length of the file, in bytes */
341    char     name[MAX_PATH_LENGTH]; /* Path to the file */
342}
343tr_file_t;
344struct tr_info_s
345{
346    /* Path to torrent */
347    char                 torrent[MAX_PATH_LENGTH];
348
349    /* General info */
350    uint8_t              hash[SHA_DIGEST_LENGTH];
351    char                 hashString[2*SHA_DIGEST_LENGTH+1];
352    char                 name[MAX_PATH_LENGTH];
353
354    /* Flags */
355#define TR_FLAG_SAVE    0x01 /* save a copy of the torrent file */
356#define TR_FLAG_PRIVATE 0x02 /* do not share information for this torrent */
357    int                  flags;
358
359    /* Tracker info */
360    struct
361    {
362        tr_tracker_info_t * list;
363        int                 count;
364    }                  * trackerList;
365    int                  trackerTiers;
366
367    /* Torrent info */
368    char                 comment[MAX_PATH_LENGTH];
369    char                 creator[MAX_PATH_LENGTH];
370    int                  dateCreated;
371
372    /* Pieces info */
373    int                  pieceSize;
374    int                  pieceCount;
375    uint64_t             totalSize;
376    uint8_t            * pieces;
377
378    /* Files info */
379    int                  multifile;
380    int                  fileCount;
381    tr_file_t          * files;
382};
383
384/***********************************************************************
385 * tr_stat_s
386 **********************************************************************/
387struct tr_stat_s
388{
389#define TR_STATUS_CHECK    0x001 /* Checking files */
390#define TR_STATUS_DOWNLOAD 0x002 /* Downloading */
391#define TR_STATUS_SEED     0x004 /* Seeding */
392#define TR_STATUS_STOPPING 0x008 /* Sending 'stopped' to the tracker */
393#define TR_STATUS_STOPPED  0x010 /* Sent 'stopped' but thread still
394                                    running (for internal use only) */
395#define TR_STATUS_PAUSE    0x020 /* Paused */
396
397#define TR_STATUS_ACTIVE   (TR_STATUS_CHECK|TR_STATUS_DOWNLOAD|TR_STATUS_SEED)
398#define TR_STATUS_INACTIVE (TR_STATUS_STOPPING|TR_STATUS_STOPPED|TR_STATUS_PAUSE)
399    int                 status;
400
401    int                 error;
402    char                errorString[128];
403    int                 cannotConnect;
404
405    tr_tracker_info_t * tracker;
406
407    float               progress;
408    float               rateDownload;
409    float               rateUpload;
410    int                 eta;
411    int                 peersTotal;
412    int                 peersFrom[TR_PEER_FROM__MAX];
413    int                 peersUploading;
414    int                 peersDownloading;
415    int                 seeders;
416    int                 leechers;
417    int                 completedFromTracker;
418
419    uint64_t            downloaded;
420    uint64_t            uploaded;
421    float               swarmspeed;
422
423#define TR_RATIO_NA  -1
424#define TR_RATIO_INF -2
425    float               ratio;
426};
427
428struct tr_peer_stat_s
429{
430    char    addr[INET_ADDRSTRLEN];
431    char *  client;
432   
433    int     isConnected;
434    int     from;
435    float   progress;
436    int     port;
437   
438    int     isDownloading;
439    int     isUploading;
440    float   downloadFromRate;
441    float   uploadToRate;
442};
443
444struct tr_msg_list_s
445{
446    int                    level;
447    time_t                 when;
448    char                 * message;
449    struct tr_msg_list_s * next;
450};
451
452struct tr_tracker_info_s
453{
454    char * address;
455    int    port;
456    char * announce;
457    char * scrape;
458};
459
460struct tr_handle_status_s
461{
462#define TR_NAT_TRAVERSAL_MAPPING        1
463#define TR_NAT_TRAVERSAL_MAPPED         2
464#define TR_NAT_TRAVERSAL_NOTFOUND       3
465#define TR_NAT_TRAVERSAL_ERROR          4
466#define TR_NAT_TRAVERSAL_UNMAPPING      5
467#define TR_NAT_TRAVERSAL_DISABLED       6
468#define TR_NAT_TRAVERSAL_IS_DISABLED( st ) \
469  ( TR_NAT_TRAVERSAL_DISABLED == (st) || TR_NAT_TRAVERSAL_UNMAPPING == (st) )
470    int natTraversalStatus;
471    int publicPort;
472};
473
474#ifdef __TRANSMISSION__
475#  include "internal.h"
476#endif
477
478#ifdef __cplusplus
479}
480#endif
481
482#endif
Note: See TracBrowser for help on using the repository browser.