source: trunk/libtransmission/transmission.h @ 210

Last change on this file since 210 was 210, checked in by titer, 16 years ago

Adds download rate limit

File size: 11.3 KB
Line 
1/******************************************************************************
2 * Copyright (c) 2005-2006 Transmission authors and contributors
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 *****************************************************************************/
22
23#ifndef TR_TRANSMISSION_H
24#define TR_TRANSMISSION_H 1
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <inttypes.h>
31
32#define SHA_DIGEST_LENGTH 20
33#ifdef __BEOS__
34# include <StorageDefs.h>
35# define MAX_PATH_LENGTH  B_FILE_NAME_LENGTH
36#else
37# define MAX_PATH_LENGTH  1024
38#endif
39
40#define TR_DEFAULT_PORT   9090
41#define TR_NOERROR        0
42
43/***********************************************************************
44 * tr_init
45 ***********************************************************************
46 * Initializes a libtransmission instance. Returns a obscure handle to
47 * be passed to all functions below.
48 **********************************************************************/
49typedef struct tr_handle_s tr_handle_t;
50tr_handle_t * tr_init();
51
52/***********************************************************************
53 * tr_getPrefsDirectory
54 ***********************************************************************
55 * Returns the full path to the directory used by libtransmission to
56 * store the resume files. The string belongs to libtransmission, do
57 * not free it.
58 **********************************************************************/
59char * tr_getPrefsDirectory();
60
61/***********************************************************************
62 * tr_setBindPort
63 ***********************************************************************
64 * Sets a "start" port: everytime we start a torrent, we try to bind
65 * this port, then the next one and so on until we are successful.
66 **********************************************************************/
67void tr_setBindPort( tr_handle_t *, int );
68
69/***********************************************************************
70 * tr_setUploadLimit
71 ***********************************************************************
72 * Sets the total upload rate limit in KB/s
73 **********************************************************************/
74void tr_setUploadLimit( tr_handle_t *, int );
75
76/***********************************************************************
77 * tr_setDownloadLimit
78 ***********************************************************************
79 * Sets the total download rate limit in KB/s
80 **********************************************************************/
81void tr_setDownloadLimit( tr_handle_t *, int );
82
83/***********************************************************************
84 * tr_torrentCount
85 ***********************************************************************
86 * Returns the count of open torrents
87 **********************************************************************/
88int tr_torrentCount( tr_handle_t * h );
89
90/***********************************************************************
91 * tr_torrentIterate
92 ***********************************************************************
93 * Iterates on open torrents
94 **********************************************************************/
95typedef struct tr_torrent_s tr_torrent_t;
96typedef void (*tr_callback_t) ( tr_torrent_t *, void * );
97void tr_torrentIterate( tr_handle_t *, tr_callback_t, void * );
98
99/***********************************************************************
100 * tr_torrentRates
101 ***********************************************************************
102 * Gets the total download and upload rates
103 **********************************************************************/
104void tr_torrentRates( tr_handle_t *, float *, float * );
105
106/***********************************************************************
107 * tr_close
108 ***********************************************************************
109 * Frees memory allocated by tr_init.
110 **********************************************************************/
111void tr_close( tr_handle_t * );
112
113/***********************************************************************
114 * tr_torrentInit
115 ***********************************************************************
116 * Opens and parses torrent file at 'path'. If the file exists and is a
117 * valid torrent file, returns an handle and adds it to the list of
118 * torrents (but doesn't start it). Returns NULL and sets *error
119 * otherwise.
120 **********************************************************************/
121#define TR_EINVALID     1
122#define TR_EUNSUPPORTED 2
123#define TR_EDUPLICATE   3
124#define TR_EOTHER       666
125tr_torrent_t * tr_torrentInit( tr_handle_t *, const char * path,
126                               int * error );
127
128typedef struct tr_info_s tr_info_t;
129tr_info_t * tr_torrentInfo( tr_torrent_t * );
130
131/***********************************************************************
132 * tr_torrentScrape
133 ***********************************************************************
134 * Asks the tracker for the count of seeders and leechers. Returns 0
135 * and fills 's' and 'l' if successful. Otherwise returns 1 if the
136 * tracker doesn't support the scrape protocol, is unreachable or
137 * replied with some error. tr_torrentScrape may block up to 20 seconds
138 * before returning.
139 **********************************************************************/
140int tr_torrentScrape( tr_torrent_t *, int * s, int * l );
141
142/***********************************************************************
143 * tr_torrentStart
144 ***********************************************************************
145 * Starts downloading. The download is launched in a seperate thread,
146 * therefore tr_torrentStart returns immediately.
147 **********************************************************************/
148void   tr_torrentSetFolder( tr_torrent_t *, const char * );
149char * tr_torrentGetFolder( tr_torrent_t * );
150void   tr_torrentStart( tr_torrent_t * );
151
152/***********************************************************************
153 * tr_torrentStop
154 ***********************************************************************
155 * Stops downloading and notices the tracker that we are leaving. The
156 * thread keeps running while doing so.
157 * The thread will eventually be joined, either:
158 * - by tr_torrentStat when the tracker has been successfully noticed,
159 * - by tr_torrentStat if the tracker could not be noticed within 60s,
160 * - by tr_torrentClose if you choose to remove the torrent without
161 *   waiting any further.
162 **********************************************************************/
163void tr_torrentStop( tr_torrent_t * );
164
165/***********************************************************************
166 * tr_getFinished
167 ***********************************************************************
168 * The first call after a torrent is completed returns 1. Returns 0
169 * in other cases.
170 **********************************************************************/
171int tr_getFinished( tr_torrent_t * );
172
173/***********************************************************************
174 * tr_torrentStat
175 ***********************************************************************
176 * Returns a pointer to an tr_stat_t structure with updated information
177 * on the torrent. The structure belongs to libtransmission (do not
178 * free it) and is guaranteed to be unchanged until the next call to
179 * tr_torrentStat.
180 * The interface should call this function every second or so in order
181 * to update itself.
182 **********************************************************************/
183typedef struct tr_stat_s tr_stat_t;
184tr_stat_t * tr_torrentStat( tr_torrent_t * );
185
186/***********************************************************************
187 * tr_torrentAvailability
188 ***********************************************************************
189 * Use this to draw an advanced progress bar which is 'size' pixels
190 * wide. Fills 'tab' which you must have allocated: each byte is set
191 * to either -1 if we have the piece, otherwise it is set to the number
192 * of connected peers who have the piece.
193 **********************************************************************/
194void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size );
195
196/***********************************************************************
197 * tr_torrentClose
198 ***********************************************************************
199 * Frees memory allocated by tr_torrentInit. If the torrent was running,
200 * you must call tr_torrentStop() before closing it.
201 **********************************************************************/
202void tr_torrentClose( tr_handle_t *, tr_torrent_t * );
203
204
205/***********************************************************************
206 * tr_info_s
207 **********************************************************************/
208typedef struct tr_file_s
209{
210    uint64_t length;                /* Length of the file, in bytes */
211    char     name[MAX_PATH_LENGTH]; /* Path to the file */
212}
213tr_file_t;
214struct tr_info_s
215{
216    /* Path to torrent */
217    char        torrent[MAX_PATH_LENGTH];
218
219    /* General info */
220    uint8_t     hash[SHA_DIGEST_LENGTH];
221    char        name[MAX_PATH_LENGTH];
222
223    /* Tracker info */
224    char        trackerAddress[256];
225    int         trackerPort;
226    char        trackerAnnounce[MAX_PATH_LENGTH];
227
228    /* Pieces info */
229    int         pieceSize;
230    int         pieceCount;
231    uint64_t    totalSize;
232    uint8_t   * pieces;
233
234    /* Files info */
235    int         fileCount;
236    tr_file_t * files;
237};
238
239/***********************************************************************
240 * tr_stat_s
241 **********************************************************************/
242struct tr_stat_s
243{
244#define TR_STATUS_CHECK    0x001 /* Checking files */
245#define TR_STATUS_DOWNLOAD 0x002 /* Downloading */
246#define TR_STATUS_SEED     0x004 /* Seeding */
247#define TR_STATUS_STOPPING 0x008 /* Sending 'stopped' to the tracker */
248#define TR_STATUS_STOPPED  0x010 /* Sent 'stopped' but thread still
249                                    running (for internal use only) */
250#define TR_STATUS_PAUSE    0x020 /* Paused */
251
252#define TR_STATUS_ACTIVE   (TR_STATUS_CHECK|TR_STATUS_DOWNLOAD|TR_STATUS_SEED)
253#define TR_STATUS_INACTIVE (TR_STATUS_STOPPING|TR_STATUS_STOPPED|TR_STATUS_PAUSE)
254    int         status;
255
256#define TR_ETRACKER 1
257#define TR_EINOUT   2
258    int         error;
259    char        trackerError[128];
260
261    float       progress;
262    float       rateDownload;
263    float       rateUpload;
264    int         eta;
265    int         peersTotal;
266    int         peersUploading;
267    int         peersDownloading;
268    int         seeders;
269    int         leechers;
270
271    uint64_t    downloaded;
272    uint64_t    uploaded;
273};
274
275#ifdef __TRANSMISSION__
276#  include "internal.h"
277#endif
278
279#ifdef __cplusplus
280}
281#endif
282
283#endif
Note: See TracBrowser for help on using the repository browser.