source: trunk/libtransmission/transmission.h @ 764

Last change on this file since 764 was 764, checked in by livings124, 15 years ago

Some changes to getting peers in libtransmission. Now it uses a separate structure for the GUI accessing peers.

  • Property svn:keywords set to Date Rev Author Id
File size: 13.4 KB
Line 
1/******************************************************************************
2 * $Id: transmission.h 764 2006-08-13 19:43:15Z livings124 $
3 *
4 * Copyright (c) 2005-2006 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
39#define SHA_DIGEST_LENGTH 20
40#ifdef __BEOS__
41# include <StorageDefs.h>
42# define MAX_PATH_LENGTH  B_FILE_NAME_LENGTH
43#else
44# define MAX_PATH_LENGTH  1024
45#endif
46
47#define TR_DEFAULT_PORT   9090
48#define TR_NOERROR        0
49
50/***********************************************************************
51 * tr_init
52 ***********************************************************************
53 * Initializes a libtransmission instance. Returns a obscure handle to
54 * be passed to all functions below.
55 **********************************************************************/
56typedef struct tr_handle_s tr_handle_t;
57tr_handle_t * tr_init();
58
59/***********************************************************************
60 * tr_setErrorFunction
61 ***********************************************************************
62 * Sets the function used to display libtransmission errors.  A NULL
63 * function means to use the default, which simple prints the message
64 * to stderr.  The function's prototype should look like this:
65 * void myErrFunc( const char * errstr );
66 **********************************************************************/
67void tr_setErrorFunction( void (*func)( const char * ) );
68
69/***********************************************************************
70 * tr_getPrefsDirectory
71 ***********************************************************************
72 * Returns the full path to a directory which can be used to store
73 * preferences. The string belongs to libtransmission, do not free it.
74 **********************************************************************/
75char * tr_getPrefsDirectory();
76
77/***********************************************************************
78 * tr_setBindPort
79 ***********************************************************************
80 * Sets a "start" port: everytime we start a torrent, we try to bind
81 * this port, then the next one and so on until we are successful.
82 **********************************************************************/
83void tr_setBindPort( tr_handle_t *, int );
84
85/***********************************************************************
86 * tr_setUploadLimit
87 ***********************************************************************
88 * Sets the total upload rate limit in KB/s
89 **********************************************************************/
90void tr_setUploadLimit( tr_handle_t *, int );
91
92/***********************************************************************
93 * tr_setDownloadLimit
94 ***********************************************************************
95 * Sets the total download rate limit in KB/s
96 **********************************************************************/
97void tr_setDownloadLimit( tr_handle_t *, int );
98
99/***********************************************************************
100 * tr_torrentCount
101 ***********************************************************************
102 * Returns the count of open torrents
103 **********************************************************************/
104int tr_torrentCount( tr_handle_t * h );
105
106/***********************************************************************
107 * tr_torrentIterate
108 ***********************************************************************
109 * Iterates on open torrents
110 **********************************************************************/
111typedef struct tr_torrent_s tr_torrent_t;
112typedef void (*tr_callback_t) ( tr_torrent_t *, void * );
113void tr_torrentIterate( tr_handle_t *, tr_callback_t, void * );
114
115/***********************************************************************
116 * tr_torrentRates
117 ***********************************************************************
118 * Gets the total download and upload rates
119 **********************************************************************/
120void tr_torrentRates( tr_handle_t *, float *, float * );
121
122/***********************************************************************
123 * tr_close
124 ***********************************************************************
125 * Frees memory allocated by tr_init.
126 **********************************************************************/
127void tr_close( tr_handle_t * );
128
129/***********************************************************************
130 * tr_torrentInit
131 ***********************************************************************
132 * Opens and parses torrent file at 'path'. If the file exists and is a
133 * valid torrent file, returns an handle and adds it to the list of
134 * torrents (but doesn't start it). Returns NULL and sets *error
135 * otherwise.  If the TR_FSAVEPRIVATE flag is passed then a private copy
136 * of the torrent file will be saved.
137 **********************************************************************/
138#define TR_EINVALID     1
139#define TR_EUNSUPPORTED 2
140#define TR_EDUPLICATE   3
141#define TR_EOTHER       666
142tr_torrent_t * tr_torrentInit( tr_handle_t *, const char * path,
143                               int flags, int * error );
144
145/***********************************************************************
146 * tr_torrentInitSaved
147 ***********************************************************************
148 * Opens and parses a torrent file as with tr_torrentInit, only taking
149 * the hash string of a saved torrent file instead of a filename.  There
150 * are currently no valid flags for this function.
151 **********************************************************************/
152tr_torrent_t * tr_torrentInitSaved( tr_handle_t *, const char * hashStr,
153                                    int flags, int * error );
154
155typedef struct tr_info_s tr_info_t;
156tr_info_t * tr_torrentInfo( tr_torrent_t * );
157
158/***********************************************************************
159 * tr_torrentScrape
160 ***********************************************************************
161 * Asks the tracker for the count of seeders and leechers. Returns 0
162 * and fills 's' and 'l' if successful. Otherwise returns 1 if the
163 * tracker doesn't support the scrape protocol, is unreachable or
164 * replied with some error. tr_torrentScrape may block up to 20 seconds
165 * before returning.
166 **********************************************************************/
167int tr_torrentScrape( tr_torrent_t *, int * s, int * l );
168
169/***********************************************************************
170 * tr_torrentStart
171 ***********************************************************************
172 * Starts downloading. The download is launched in a seperate thread,
173 * therefore tr_torrentStart returns immediately.
174 **********************************************************************/
175void   tr_torrentSetFolder( tr_torrent_t *, const char * );
176char * tr_torrentGetFolder( tr_torrent_t * );
177void   tr_torrentStart( tr_torrent_t * );
178
179/***********************************************************************
180 * tr_torrentStop
181 ***********************************************************************
182 * Stops downloading and notices the tracker that we are leaving. The
183 * thread keeps running while doing so.
184 * The thread will eventually be joined, either:
185 * - by tr_torrentStat when the tracker has been successfully noticed,
186 * - by tr_torrentStat if the tracker could not be noticed within 60s,
187 * - by tr_torrentClose if you choose to remove the torrent without
188 *   waiting any further.
189 **********************************************************************/
190void tr_torrentStop( tr_torrent_t * );
191
192/***********************************************************************
193 * tr_getFinished
194 ***********************************************************************
195 * The first call after a torrent is completed returns 1. Returns 0
196 * in other cases.
197 **********************************************************************/
198int tr_getFinished( tr_torrent_t * );
199
200/***********************************************************************
201 * tr_torrentStat
202 ***********************************************************************
203 * Returns a pointer to an tr_stat_t structure with updated information
204 * on the torrent. The structure belongs to libtransmission (do not
205 * free it) and is guaranteed to be unchanged until the next call to
206 * tr_torrentStat.
207 * The interface should call this function every second or so in order
208 * to update itself.
209 **********************************************************************/
210typedef struct tr_stat_s tr_stat_t;
211tr_stat_t * tr_torrentStat( tr_torrent_t * );
212
213/***********************************************************************
214 * tr_torrentAvailability
215 ***********************************************************************
216 * Use this to draw an advanced progress bar which is 'size' pixels
217 * wide. Fills 'tab' which you must have allocated: each byte is set
218 * to either -1 if we have the piece, otherwise it is set to the number
219 * of connected peers who have the piece.
220 **********************************************************************/
221void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size );
222
223/***********************************************************************
224 * tr_torrentRemoveSaved
225 ***********************************************************************
226 * Removes the private saved copy of a torrent file for torrents which
227 * the TR_FSAVEPRIVATE flag is set.
228 **********************************************************************/
229void tr_torrentRemoveSaved( tr_torrent_t * );
230
231/***********************************************************************
232 * tr_torrentClose
233 ***********************************************************************
234 * Frees memory allocated by tr_torrentInit. If the torrent was running,
235 * you must call tr_torrentStop() before closing it.
236 **********************************************************************/
237void tr_torrentClose( tr_handle_t *, tr_torrent_t * );
238
239/***********************************************************************
240 * tr_info_s
241 **********************************************************************/
242typedef struct tr_file_s
243{
244    uint64_t length;                /* Length of the file, in bytes */
245    char     name[MAX_PATH_LENGTH]; /* Path to the file */
246}
247tr_file_t;
248struct tr_info_s
249{
250    /* Path to torrent */
251    char        torrent[MAX_PATH_LENGTH];
252
253    /* General info */
254    uint8_t     hash[SHA_DIGEST_LENGTH];
255    char        hashString[2*SHA_DIGEST_LENGTH+1];
256    char        name[MAX_PATH_LENGTH];
257
258    /* Flags */
259#define TR_FSAVEPRIVATE 0x01    /* save a private copy of the torrent */
260    int         flags;
261
262    /* Tracker info */
263    char        trackerAddress[256];
264    int         trackerPort;
265    char        trackerAnnounce[MAX_PATH_LENGTH];
266
267    /* Pieces info */
268    int         pieceSize;
269    int         pieceCount;
270    uint64_t    totalSize;
271    uint8_t   * pieces;
272
273    /* Files info */
274    int         multifile;
275    int         fileCount;
276    tr_file_t * files;
277};
278
279/***********************************************************************
280 * tr_stat_s
281 **********************************************************************/
282typedef struct tr_peer_stat_s
283{
284    char    client[25];
285   
286    int     isDownloading;
287    int     isUploading;
288}
289tr_peer_stat_t;
290struct tr_stat_s
291{
292#define TR_STATUS_CHECK    0x001 /* Checking files */
293#define TR_STATUS_DOWNLOAD 0x002 /* Downloading */
294#define TR_STATUS_SEED     0x004 /* Seeding */
295#define TR_STATUS_STOPPING 0x008 /* Sending 'stopped' to the tracker */
296#define TR_STATUS_STOPPED  0x010 /* Sent 'stopped' but thread still
297                                    running (for internal use only) */
298#define TR_STATUS_PAUSE    0x020 /* Paused */
299
300#define TR_STATUS_ACTIVE   (TR_STATUS_CHECK|TR_STATUS_DOWNLOAD|TR_STATUS_SEED)
301#define TR_STATUS_INACTIVE (TR_STATUS_STOPPING|TR_STATUS_STOPPED|TR_STATUS_PAUSE)
302    int                 status;
303
304#define TR_ETRACKER 1
305#define TR_EINOUT   2
306    int                 error;
307    char                trackerError[128];
308
309    float               progress;
310    float               rateDownload;
311    float               rateUpload;
312    int                 eta;
313    int                 peersTotal;
314    tr_peer_stat_t *    peers;
315    int                 peersUploading;
316    int                 peersDownloading;
317    int                 seeders;
318    int                 leechers;
319
320    uint64_t            downloaded;
321    uint64_t            uploaded;
322};
323
324#ifdef __TRANSMISSION__
325#  include "internal.h"
326#endif
327
328#ifdef __cplusplus
329}
330#endif
331
332#endif
Note: See TracBrowser for help on using the repository browser.