source: trunk/libtransmission/transmission.h @ 4346

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

dead code removal

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