source: trunk/libtransmission/transmission.h @ 4314

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

add message queueing flag to tr_initFull() too

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