source: trunk/libtransmission/transmission.h @ 4311

Last change on this file since 4311 was 4311, checked in by charles, 15 years ago

(gtk) fix startup port issue by hitting it with a damn big hammer

  • Property svn:keywords set to Date Rev Author Id
File size: 29.9 KB
Line 
1/******************************************************************************
2 * $Id: transmission.h 4311 2007-12-24 07:02:40Z charles $
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 PRId64
36# define PRId64 "lld"
37#endif
38#ifndef PRIu64
39# define PRIu64 "llu"
40#endif
41#include <time.h>
42
43#define SHA_DIGEST_LENGTH 20
44#ifdef __BEOS__
45# include <StorageDefs.h>
46# define MAX_PATH_LENGTH  B_FILE_NAME_LENGTH
47#else
48# define MAX_PATH_LENGTH  1024
49#endif
50
51#ifndef INET_ADDRSTRLEN
52#define INET_ADDRSTRLEN 16
53#endif
54
55#if defined(WIN32)
56#define TR_PATH_DELIMITER '\\'
57#define TR_PATH_DELIMITER_STR "\\"
58#else
59#define TR_PATH_DELIMITER '/'
60#define TR_PATH_DELIMITER_STR "/"
61#endif
62
63#define TR_DEFAULT_PORT   51413
64
65enum
66{
67    TR_PEER_FROM_INCOMING  = 0,  /* connections made to the listening port */
68    TR_PEER_FROM_TRACKER   = 1,  /* peers received from a tracker */
69    TR_PEER_FROM_CACHE     = 2,  /* peers read from the peer cache */
70    TR_PEER_FROM_PEX       = 3,  /* peers discovered via PEX */
71    TR_PEER_FROM__MAX
72};
73
74/***********************************************************************
75 * Error codes
76 **********************************************************************/
77/* General errors */
78#define TR_OK                       0x00000000
79#define TR_ERROR                    0x81000000
80#define TR_ERROR_ASSERT             0x82000000
81/* I/O errors */
82#define TR_ERROR_IO_MASK            0x000000FF
83#define TR_ERROR_IO_PERMISSIONS     0x80000002
84#define TR_ERROR_IO_SPACE           0x80000004
85#define TR_ERROR_IO_FILE_TOO_BIG    0x80000008
86#define TR_ERROR_IO_OPEN_FILES      0x80000010
87#define TR_ERROR_IO_DUP_DOWNLOAD    0x80000020
88#define TR_ERROR_IO_OTHER           0x80000040
89/* Misc */
90#define TR_ERROR_TC_MASK            0x00000F00
91#define TR_ERROR_TC_ERROR           0x80000100
92#define TR_ERROR_TC_WARNING         0x80000200
93
94#define TR_ERROR_ISSET( num, code ) ( (code) == ( (code) & (num) ) )
95
96/***********************************************************************
97 * tr_init
98 ***********************************************************************
99 * Initializes a libtransmission instance and returns an opaque handle
100 * to be passed to functions below. The tag argument is a short string
101 * unique to the program invoking tr_init(), it is currently used as
102 * part of saved torrent files' names to prevent one frontend from
103 * deleting a torrent used by another. The following tags are used:
104 *   beos cli daemon gtk macosx
105 **********************************************************************/
106
107typedef struct tr_handle tr_handle;
108
109tr_handle * tr_init( const char * tag );
110
111/* shut down a libtransmission instance created by tr_init(). */
112void tr_close( tr_handle * );
113
114tr_handle * tr_initFull( const char * tag,
115                         int          isPexEnabled,
116                         int          isNatEnabled,
117                         int          publicPort,
118                         int          encryptionMode,
119                         int          isUploadLimitEnabled,
120                         int          uploadLimit,
121                         int          isDownloadLimitEnabled,
122                         int          downloadLimit,
123                         int          globalPeerLimit );
124
125
126/**
127***
128**/
129
130typedef struct tr_session_stats
131{
132    uint64_t uploadedBytes;   /* total up */
133    uint64_t downloadedBytes; /* total down */
134    double ratio;             /* total up / total down */
135    uint64_t filesAdded;      /* number of files added */
136    uint64_t sessionCount;    /* program started N times */
137    uint64_t secondsActive;   /* how long Transmisson's been running */
138}
139tr_session_stats;
140
141/* stats from the current and past sessions. */
142void tr_getCumulativeSessionStats( const tr_handle   * handle,
143                                   tr_session_stats  * setme );
144
145/* stats from the current session. */
146void tr_getSessionStats( const tr_handle   * handle,
147                         tr_session_stats  * setme );
148
149
150/**
151***
152**/
153
154typedef enum
155{
156    TR_PLAINTEXT_PREFERRED,
157    TR_ENCRYPTION_PREFERRED,
158    TR_ENCRYPTION_REQUIRED
159}
160tr_encryption_mode;
161
162tr_encryption_mode tr_getEncryptionMode( tr_handle * handle );
163
164void tr_setEncryptionMode( tr_handle * handle, tr_encryption_mode mode );
165
166/***********************************************************************
167 * tr_setMessageLevel
168 ***********************************************************************
169 * Set the level of messages to be output or queued
170 **********************************************************************/
171#define TR_MSG_ERR 1
172#define TR_MSG_INF 2
173#define TR_MSG_DBG 3
174void tr_setMessageLevel( int );
175int tr_getMessageLevel( void );
176
177/***********************************************************************
178 * tr_setMessageQueuing
179 ***********************************************************************
180 * Enable or disable message queuing
181 **********************************************************************/
182typedef struct tr_msg_list tr_msg_list;
183void tr_setMessageQueuing( int );
184
185/***********************************************************************
186 * tr_getQueuedMessages
187 ***********************************************************************
188 * Return a list of queued messages
189 **********************************************************************/
190tr_msg_list * tr_getQueuedMessages( void );
191void tr_freeMessageList( tr_msg_list * list );
192
193/***********************************************************************
194 * tr_getPrefsDirectory
195 ***********************************************************************
196 * Returns the full path to a directory which can be used to store
197 * preferences. The string belongs to libtransmission, do not free it.
198 **********************************************************************/
199const char * tr_getPrefsDirectory( void );
200
201/***********************************************************************
202 * tr_setBindPort
203 ***********************************************************************
204 * Sets the port to listen for incoming peer connections.
205 * This can be safely called even with active torrents.
206 **********************************************************************/
207void tr_setBindPort( tr_handle *, int );
208
209int tr_getPublicPort( const tr_handle * );
210
211/***********************************************************************
212 * tr_natTraversalEnable
213 * tr_natTraversalDisable
214 ***********************************************************************
215 * Enable or disable NAT traversal using NAT-PMP or UPnP IGD.
216 **********************************************************************/
217void tr_natTraversalEnable( tr_handle *, int enable );
218
219/***********************************************************************
220 * tr_handleStatus
221 ***********************************************************************
222 * Returns some status info for the given handle.
223 **********************************************************************/
224typedef struct tr_handle_status tr_handle_status;
225tr_handle_status * tr_handleStatus( tr_handle * );
226
227
228/***********************************************************************
229 * tr_torrentCount
230 ***********************************************************************
231 * Returns the count of open torrents
232 **********************************************************************/
233int tr_torrentCount( tr_handle * h );
234
235
236/***********************************************************************
237 * tr_torrentIterate
238 ***********************************************************************
239 * Iterates on open torrents
240 **********************************************************************/
241typedef struct tr_torrent tr_torrent;
242typedef void (*tr_callback_t) ( tr_torrent *, void * );
243void tr_torrentIterate( tr_handle *, tr_callback_t, void * );
244
245
246/***********************************************************************
247*** Speed Limits
248**/
249
250enum { TR_UP, TR_DOWN };
251
252typedef enum
253{
254    TR_SPEEDLIMIT_GLOBAL,    /* only follow the overall speed limit */
255    TR_SPEEDLIMIT_SINGLE,    /* only follow the per-torrent limit */
256    TR_SPEEDLIMIT_UNLIMITED  /* no limits at all */
257}
258tr_speedlimit;
259
260void tr_torrentSetSpeedMode( tr_torrent   * tor,
261                             int            up_or_down,
262                             tr_speedlimit  mode );
263
264tr_speedlimit tr_torrentGetSpeedMode( const tr_torrent  * tor,
265                                      int                 up_or_down);
266
267void tr_torrentSetSpeedLimit( tr_torrent   * tor,
268                              int            up_or_down,
269                              int            single_KiB_sec );
270
271int tr_torrentGetSpeedLimit( const tr_torrent  * tor,
272                             int                 up_or_down );
273
274void tr_setUseGlobalSpeedLimit( tr_handle * handle,
275                                int           up_or_down,
276                                int           use_flag );
277
278void tr_setGlobalSpeedLimit( tr_handle * handle,
279                             int           up_or_down,
280                             int           global_KiB_sec );
281
282void tr_getGlobalSpeedLimit( tr_handle * handle,
283                             int           up_or_down,
284                             int         * setme_is_enabled,
285                             int         * setme_KiBsec );
286
287
288/***********************************************************************
289***  Peer Limits
290**/
291
292void tr_torrentSetMaxConnectedPeers( tr_torrent  * tor,
293                                     uint16_t      maxConnectedPeers);
294
295uint16_t tr_torrentGetMaxConnectedPeers( const tr_torrent  * tor );
296
297void tr_torrentSetMaxUnchokedPeers( tr_torrent  * tor,
298                                    uint8_t       maxUnchokedPeers );
299
300uint8_t tr_torrentGetMaxUnchokedPeers( const tr_torrent  * tor );
301
302void tr_setGlobalPeerLimit( tr_handle * handle,
303                            uint16_t    maxGlobalPeers );
304
305uint16_t tr_getGlobalPeerLimit( const tr_handle * handle );
306
307
308
309
310/***********************************************************************
311 * Torrent Priorities
312 **********************************************************************/
313
314enum
315{
316    TR_PRI_LOW    = -1,
317    TR_PRI_NORMAL =  0, /* since NORMAL is 0, memset initializes nicely */
318    TR_PRI_HIGH   =  1
319};
320
321typedef int8_t tr_priority_t;
322
323/* set a batch of files to a particular priority.
324 * priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW */
325void tr_torrentSetFilePriorities( tr_torrent        * tor,
326                                  int               * files,
327                                  int                 fileCount,
328                                  tr_priority_t       priority );
329
330/* returns a malloc()ed array of tor->info.fileCount items,
331 * each holding a value of TR_PRI_NORMAL, _HIGH, or _LOW.
332   free the array when done. */
333tr_priority_t* tr_torrentGetFilePriorities( const tr_torrent * );
334
335/* single-file form of tr_torrentGetFilePriorities.
336 * returns one of TR_PRI_NORMAL, _HIGH, or _LOW. */
337tr_priority_t tr_torrentGetFilePriority( const tr_torrent *, int file );
338
339/* returns true if the file's `download' flag is set */
340int tr_torrentGetFileDL( const tr_torrent *, int file );
341
342/* set a batch of files to be downloaded or not. */
343void tr_torrentSetFileDLs ( tr_torrent   * tor,
344                            int          * files,
345                            int            fileCount,
346                            int            do_download );
347
348/***********************************************************************
349 * tr_torrentRates
350 ***********************************************************************
351 * Gets the total download and upload rates
352 **********************************************************************/
353void tr_torrentRates( tr_handle *, float *, float * );
354
355
356
357/**
358 *  Torrent Instantiation
359 *
360 *  Instantiating a tr_torrent has gotten a lot more complaticated as we
361 *  add more options to them.  At the worst point there were four functions
362 *  to check metainfo, and four (or five) functions to create tr_torrents.
363 *  They all did mostly the same thing, but each was just *slightly* different.
364 *
365 *  To remedy this, a Torrent Constructor (struct tr_ctor) has been introduced:
366 *  + Simplifies the API down to two (non-deprecated) functions.
367 *  + You can set the fields you want; the system sets defaults for the rest.
368 *  + You can specify whether or not your fields should supercede fastresume's.
369 *  + We can add new features to tr_ctor without breaking tr_torrentNew()'s API.
370 *
371 *  All the tr_ctor{Get,Set}*() functions with a return value return
372 *  an error number, or zero if no error occurred.
373 *
374 *  You must call one of the SetMetainfo() functions before creating
375 *  a torrent with a tr_ctor.  The other functions are optional.
376 *
377 *  You can reuse a single tr_ctor to create a batch of torrents --
378 *  just call one of the SetMetainfo() functions between each
379 *  tr_torrentNew() call.
380 *
381 *  Every call to tr_ctorSetMetainfo*() frees the previous metainfo.
382 */
383
384typedef enum
385{
386    TR_FALLBACK, /* indicates the ctor value should be used only
387                    in case of missing fastresume settings */
388
389    TR_FORCE, /* indicates the ctor value should be used
390                 regardless of what's in the fastresume settings */
391}
392tr_ctorMode;
393
394typedef struct tr_ctor tr_ctor;
395struct benc_val_s;
396
397tr_ctor* tr_ctorNew                    ( const tr_handle  * handle);
398
399void     tr_ctorFree                   ( tr_ctor        * ctor );
400
401void     tr_ctorSetSave                ( tr_ctor        * ctor,
402                                         int              saveMetadataInOurTorrentsDir );
403
404int      tr_ctorSetMetainfo            ( tr_ctor        * ctor,
405                                         const uint8_t  * metainfo,
406                                         size_t           len );
407
408int      tr_ctorSetMetainfoFromFile    ( tr_ctor        * ctor,
409                                         const char     * filename );
410
411int      tr_ctorSetMetainfoFromHash    ( tr_ctor        * ctor,
412                                         const char     * hashString );
413
414void     tr_ctorSetMaxConnectedPeers   ( tr_ctor        * ctor,
415                                         tr_ctorMode      mode,
416                                         uint16_t         maxConnectedPeers );
417
418void     tr_ctorSetMaxUnchokedPeers    ( tr_ctor        * ctor,
419                                         tr_ctorMode      mode,
420                                         uint8_t          maxUnchokedPeers);
421
422void     tr_ctorSetDestination         ( tr_ctor        * ctor,
423                                         tr_ctorMode      mode,
424                                         const char     * directory );
425
426void     tr_ctorSetPaused              ( tr_ctor        * ctor,
427                                         tr_ctorMode      mode,
428                                         uint8_t          isPaused );
429
430int      tr_ctorGetMaxConnectedPeers   ( const tr_ctor  * ctor,
431                                         tr_ctorMode      mode,
432                                         uint16_t       * setmeCount );
433
434int      tr_ctorGetMaxUnchokedPeers    ( const tr_ctor  * ctor,
435                                         tr_ctorMode      mode,
436                                         uint8_t        * setmeCount );
437
438int      tr_ctorGetIsPaused            ( const tr_ctor  * ctor,
439                                         tr_ctorMode      mode,
440                                         uint8_t        * setmeIsPaused );
441
442int      tr_ctorGetDestination         ( const tr_ctor  * ctor,
443                                         tr_ctorMode      mode,
444                                         const char    ** setmeDestination );
445
446int      tr_ctorGetMetainfo            ( const tr_ctor  * ctor,
447                                         const struct benc_val_s ** setme );
448
449int      tr_ctorGetSave                ( const tr_ctor  * ctor );
450
451typedef struct tr_info tr_info;
452
453/**
454 * Parses the specified metainfo.
455 * Returns TR_OK if it parsed and can be added to Transmission.
456 * Returns TR_INVALID if it couldn't be parsed.
457 * Returns TR_EDUPLICATE if it parsed but can't be added.
458 *     "destination" must be set to test for TR_EDUPLICATE.
459 *
460 * "setme_info" can be NULL if you don't need the information.
461 * If the metainfo can be parsed and setme_info is non-NULL,
462 * it will be filled with the metainfo's info.  You'll need to
463 * call tr_metainfoFree( setme_info ) when done with it.
464 */
465int tr_torrentParse( const tr_handle  * handle,
466                     const tr_ctor    * ctor,
467                     tr_info          * setme_info );
468
469/**
470 * Instantiate a single torrent.
471 */
472#define TR_EINVALID     1
473#define TR_EUNSUPPORTED 2
474#define TR_EDUPLICATE   3
475#define TR_EOTHER       666
476tr_torrent * tr_torrentNew( tr_handle      * handle,
477                            const tr_ctor  * ctor,
478                            int            * setmeError );
479
480
481/**
482 *  Load all the torrents in tr_getTorrentsDirectory().
483 *  This can be used at startup to kickstart all the torrents
484 *  from the previous session.
485 */
486tr_torrent ** tr_loadTorrents ( tr_handle  * h,
487                                tr_ctor    * ctor,
488                                int        * setmeCount );
489
490
491
492/**
493 * Set whether or not torrents are allowed to do peer exchanges.
494 * By default, PEX is enabled.
495 * PEX is always disabled in private torrents regardless of this.
496 */
497void tr_setPexEnabled( tr_handle *, int isEnabled );
498
499int tr_isPexEnabled( const tr_handle * );
500
501const tr_info * tr_torrentInfo( const tr_torrent * );
502
503void   tr_torrentSetFolder( tr_torrent *, const char * );
504
505const char * tr_torrentGetFolder( const tr_torrent * );
506
507/***********************************************************************
508 * tr_torrentStart
509 ***********************************************************************
510 * Starts downloading. The download is launched in a seperate thread,
511 * therefore tr_torrentStart returns immediately.
512 **********************************************************************/
513void   tr_torrentStart( tr_torrent * );
514
515/***********************************************************************
516 * tr_torrentStop
517 ***********************************************************************
518 * Stops downloading and notices the tracker that we are leaving. The
519 * thread keeps running while doing so.
520 * The thread will eventually be joined, either:
521 * - by tr_torrentStat when the tracker has been successfully noticed,
522 * - by tr_torrentStat if the tracker could not be noticed within 60s,
523 * - by tr_torrentClose if you choose to remove the torrent without
524 *   waiting any further.
525 **********************************************************************/
526void tr_torrentStop( tr_torrent * );
527
528
529/**
530***  Register to be notified whenever a torrent's state changes.
531**/
532
533typedef enum
534{
535    TR_CP_INCOMPLETE,   /* doesn't have all the desired pieces */
536    TR_CP_DONE,         /* has all the pieces but the DND ones */
537    TR_CP_COMPLETE      /* has every piece */
538}
539cp_status_t;
540
541typedef void (tr_torrent_status_func)(tr_torrent   * torrent,
542                                      cp_status_t    status,
543                                      void         * user_data );
544
545void tr_torrentSetStatusCallback( tr_torrent             * torrent,
546                                  tr_torrent_status_func   func,
547                                  void                   * user_data );
548
549void tr_torrentClearStatusCallback( tr_torrent * torrent );
550
551/**
552 * MANUAL ANNOUNCE
553 *
554 * Trackers usually set an announce interval of 15 or 30 minutes.
555 * Users can send one-time announce requests that override this
556 * interval by calling tr_manualUpdate().
557 *
558 * The wait interval for tr_manualUpdate() is much smaller.
559 * You can test whether or not a manual update is possible
560 * (for example, to desensitize the button) by calling
561 * tr_torrentCanManualUpdate().
562 */
563
564void tr_manualUpdate( tr_torrent * );
565
566int tr_torrentCanManualUpdate( const tr_torrent * );
567
568/***********************************************************************
569 * tr_torrentStat
570 ***********************************************************************
571 * Returns a pointer to an tr_stat structure with updated information
572 * on the torrent. The structure belongs to libtransmission (do not
573 * free it) and is guaranteed to be unchanged until the next call to
574 * tr_torrentStat.
575 * The interface should call this function every second or so in order
576 * to update itself.
577 **********************************************************************/
578typedef struct tr_stat tr_stat;
579const tr_stat * tr_torrentStat( tr_torrent * );
580const tr_stat * tr_torrentStatCached( tr_torrent * );
581
582/***********************************************************************
583 * tr_torrentPeers
584 ***********************************************************************/
585typedef struct tr_peer_stat tr_peer_stat;
586tr_peer_stat * tr_torrentPeers( const tr_torrent *, int * peerCount );
587void tr_torrentPeersFree( tr_peer_stat *, int peerCount );
588
589typedef struct tr_file_stat tr_file_stat;
590tr_file_stat * tr_torrentFiles( const tr_torrent *, int * fileCount );
591void tr_torrentFilesFree( tr_file_stat *, int fileCount );
592
593
594/***********************************************************************
595 * tr_torrentAvailability
596 ***********************************************************************
597 * Use this to draw an advanced progress bar which is 'size' pixels
598 * wide. Fills 'tab' which you must have allocated: each byte is set
599 * to either -1 if we have the piece, otherwise it is set to the number
600 * of connected peers who have the piece.
601 **********************************************************************/
602void tr_torrentAvailability( const tr_torrent *, int8_t * tab, int size );
603
604void tr_torrentAmountFinished( const tr_torrent * tor, float * tab, int size );
605
606/***********************************************************************
607 * tr_torrentRemoveSaved
608 ***********************************************************************
609 * Removes the saved copy of a torrent file for torrents which the
610 * TR_FLAG_SAVE flag is set.
611 **********************************************************************/
612void tr_torrentRemoveSaved( tr_torrent * );
613
614void tr_torrentRecheck( tr_torrent * );
615
616/**
617 * Frees memory allocated by tr_torrentNew().
618 * Running torrents are stopped first.
619 */
620void tr_torrentClose( tr_torrent * );
621
622/***********************************************************************
623 * tr_info
624 **********************************************************************/
625
626typedef struct tr_file
627{
628    uint64_t length;                /* Length of the file, in bytes */
629    char     name[MAX_PATH_LENGTH]; /* Path to the file */
630    int8_t   priority;              /* TR_PRI_HIGH, _NORMAL, or _LOW */
631    int8_t   dnd;                   /* nonzero if the file shouldn't be downloaded */
632    int      firstPiece;            /* We need pieces [firstPiece... */
633    int      lastPiece;             /* ...lastPiece] to dl this file */
634    uint64_t offset;                /* file begins at the torrent's nth byte */
635}
636tr_file;
637
638typedef struct tr_piece
639{
640    uint8_t  hash[SHA_DIGEST_LENGTH];  /* pieces hash */
641    int8_t   priority;                 /* TR_PRI_HIGH, _NORMAL, or _LOW */
642    int8_t   dnd;                      /* nonzero if the piece shouldn't be downloaded */
643}
644tr_piece;
645   
646typedef struct tr_tracker_info
647{
648    char * address;
649    int    port;
650    char * announce;
651    char * scrape;
652}
653tr_tracker_info;
654
655struct tr_info
656{
657    /* Path to torrent */
658    char                 torrent[MAX_PATH_LENGTH];
659
660    /* General info */
661    uint8_t              hash[SHA_DIGEST_LENGTH];
662    char                 hashString[2*SHA_DIGEST_LENGTH+1];
663    char                 name[MAX_PATH_LENGTH];
664
665    /* Flags */
666    unsigned int isPrivate : 1;
667    unsigned int isMultifile : 1;
668
669    /* Tracker info */
670    struct
671    {
672        tr_tracker_info  * list;
673        int                 count;
674    }                  * trackerList;
675    int                  trackerTiers;
676    char               * primaryAddress;
677
678    /* Torrent info */
679    char                 comment[MAX_PATH_LENGTH];
680    char                 creator[MAX_PATH_LENGTH];
681    int                  dateCreated;
682
683    /* Pieces info */
684    int                  pieceSize;
685    int                  pieceCount;
686    uint64_t             totalSize;
687    tr_piece           * pieces;
688
689    /* Files info */
690    int                  fileCount;
691    tr_file            * files;
692};
693
694typedef enum
695{
696    TR_STATUS_CHECK_WAIT   = (1<<0), /* Waiting in queue to check files */
697    TR_STATUS_CHECK        = (1<<1), /* Checking files */
698    TR_STATUS_DOWNLOAD     = (1<<2), /* Downloading */
699    TR_STATUS_DONE         = (1<<3), /* not at 100% so can't tell the tracker
700                                        we're a seeder, but due to DND files
701                                        there's nothing we want right now */
702    TR_STATUS_SEED         = (1<<4), /* Seeding */
703    TR_STATUS_STOPPED      = (1<<5)  /* Torrent is stopped */
704}
705tr_torrent_status;
706
707#define TR_STATUS_IS_ACTIVE(s) ((s) != TR_STATUS_STOPPED)
708
709/***********************************************************************
710 * tr_stat
711 **********************************************************************/
712struct tr_stat
713{
714    tr_torrent_status   status;
715
716    int                 error;
717    char                errorString[128];
718
719    const tr_tracker_info * tracker;
720
721    float               recheckProgress;
722    float               percentComplete;
723    float               percentDone;
724    float               rateDownload;
725    float               rateUpload;
726    int                 eta;
727    int                 peersKnown;
728    int                 peersConnected;
729    int                 peersFrom[TR_PEER_FROM__MAX];
730    int                 peersSendingToUs;
731    int                 peersGettingFromUs;
732    int                 seeders;
733    int                 leechers;
734    int                 completedFromTracker;
735
736    /* Byte count of how much data is left to be downloaded until
737     * we're done -- that is, until we've got all the pieces we wanted. */
738    uint64_t            leftUntilDone;
739
740    /* Byte count of all the corrupt data you've ever downloaded for
741     * this torrent.  If you're on a poisoned torrent, this number can
742     * grow very large. */
743    uint64_t            corruptEver;
744
745    /* Byte count of all data you've ever uploaded for this torrent. */
746    uint64_t            uploadedEver;
747
748    /* Byte count of all the non-corrupt data you've ever downloaded
749     * for this torrent.  If you deleted the files and downloaded a second time,
750     * this will be 2*totalSize.. */
751    uint64_t            downloadedEver;
752
753    /* Byte count of all the checksum-verified data we have for this torrent. */
754    uint64_t            haveValid;
755
756    /* Byte count of all the partial piece data we have for this torrent.
757     * As pieces become complete, this value may decrease as portions of it are
758     * moved to `corrupt' or `haveValid'. */
759    uint64_t            haveUnchecked;
760
761    /* Byte count of all the non-DND piece data that either we already have,
762     * or that a peer we're connected to has. [0...desiredSize] */
763    uint64_t            desiredAvailable;
764
765    /* Byte count of all the piece data we want, whether we currently
766     * have it nor not. [0...tr_info.totalSize] */
767    uint64_t            desiredSize;
768
769    float               swarmspeed;
770
771#define TR_RATIO_NA  -1
772#define TR_RATIO_INF -2
773    float               ratio;
774   
775    uint64_t            startDate;
776    uint64_t            activityDate;
777};
778
779struct tr_file_stat
780{
781    uint64_t bytesCompleted;
782    float progress;
783};
784
785typedef enum
786{
787    TR_PEER_STATUS_HANDSHAKE             = (1<<0), /* we're handshaking with peer */
788
789    TR_PEER_STATUS_PEER_IS_SENDING       = (1<<1), /* peer is sending data to us */
790    TR_PEER_STATUS_PEER_IS_INTERESTED    = (1<<2), /* we have data the peer wants */
791    TR_PEER_STATUS_PEER_IS_CHOKED        = (1<<3), /* we refuse to send data to the peer */
792
793    TR_PEER_STATUS_CLIENT_IS_SENDING     = (1<<4), /* we're sending data to the peer */
794    TR_PEER_STATUS_CLIENT_SENT_REQUEST   = (1<<5), /* we've sent the peer a request */
795    TR_PEER_STATUS_CLIENT_IS_INTERESTED  = (1<<6), /* peer has data that we want */
796    TR_PEER_STATUS_CLIENT_IS_CHOKED      = (1<<7), /* peer refuses to send data to us */
797}
798tr_peer_status;
799
800struct tr_peer_stat
801{
802    char addr[INET_ADDRSTRLEN];
803    char client[80];
804   
805    unsigned int isEncrypted   : 1;
806    unsigned int isDownloading : 1;
807    unsigned int isUploading   : 1;
808
809    tr_peer_status status;
810
811    uint8_t  from;
812    uint16_t port;
813   
814    float progress;
815    float downloadFromRate;
816    float uploadToRate;
817};
818
819struct tr_msg_list
820{
821    uint8_t              level;
822    time_t               when;
823    char               * message;
824    const char         * file;
825    int                  line;
826    struct tr_msg_list * next;
827};
828
829typedef enum
830{
831    TR_NAT_TRAVERSAL_MAPPING,
832    TR_NAT_TRAVERSAL_MAPPED,
833    TR_NAT_TRAVERSAL_UNMAPPING,
834    TR_NAT_TRAVERSAL_UNMAPPED,
835    TR_NAT_TRAVERSAL_ERROR,
836}
837tr_nat_traversal_status;
838
839struct tr_handle_status
840{
841    tr_nat_traversal_status natTraversalStatus;
842    int publicPort;
843};
844
845#ifdef __TRANSMISSION__
846#  include "internal.h"
847#endif
848
849#ifdef __cplusplus
850}
851#endif
852
853#endif
Note: See TracBrowser for help on using the repository browser.