source: trunk/libtransmission/torrent.h @ 5994

Last change on this file since 5994 was 5994, checked in by charles, 14 years ago

#981: add tr_stat.dateAdded to libT; add "sort by age" to gtk+ client

  • Property svn:keywords set to Date Rev Author Id
File size: 6.7 KB
Line 
1/******************************************************************************
2 * $Id: torrent.h 5994 2008-06-02 04:41:55Z charles $
3 *
4 * Copyright (c) 2005-2008 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_TORRENT_H
26#define TR_TORRENT_H 1
27
28/* just like tr_torrentSetFileDLs but doesn't trigger a fastresume save */
29void tr_torrentInitFileDLs( tr_torrent       * tor,
30                            tr_file_index_t  * files,
31                            tr_file_index_t    fileCount,
32                            int                do_download );
33
34int tr_torrentIsPrivate( const tr_torrent * );
35
36void tr_torrentRecheckCompleteness( tr_torrent * );
37
38void tr_torrentResetTransferStats( tr_torrent * );
39
40void tr_torrentSetHasPiece( tr_torrent       * tor,
41                            tr_piece_index_t   pieceIndex,
42                            int                has );
43
44void tr_torrentLock    ( const tr_torrent * );
45void tr_torrentUnlock  ( const tr_torrent * );
46
47int  tr_torrentIsSeed  ( const tr_torrent * );
48
49void tr_torrentChangeMyPort  ( tr_torrent * );
50
51int tr_torrentExists( const tr_handle *, const uint8_t * );
52tr_torrent* tr_torrentFindFromId( tr_handle *, int id );
53tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * );
54tr_torrent* tr_torrentFindFromHashString( tr_handle *, const char * );
55tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* );
56
57void tr_torrentGetRates( const tr_torrent *, float * toClient, float * toPeer );
58
59int tr_torrentAllowsPex( const tr_torrent * );
60
61/* get the index of this piece's first block */
62#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
63
64/* what piece index is this block in? */
65#define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece )
66
67/* how many blocks are in this piece? */
68#define tr_torPieceCountBlocks(tor,piece) \
69    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece )
70
71/* how many bytes are in this piece? */
72#define tr_torPieceCountBytes(tor,piece) \
73    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize )
74
75/* how many bytes are in this block? */
76#define tr_torBlockCountBytes(tor,block) \
77    ( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize )
78
79#define tr_block(a,b) _tr_block(tor,a,b)
80tr_block_index_t _tr_block( const tr_torrent * tor,
81                            tr_piece_index_t   index,
82                            uint32_t           offset );
83
84int tr_torrentReqIsValid( const tr_torrent * tor,
85                          tr_piece_index_t   index,
86                          uint32_t           offset,
87                          uint32_t           length );
88
89uint64_t tr_pieceOffset( const tr_torrent * tor,
90                         tr_piece_index_t   index,
91                         uint32_t           offset,
92                         uint32_t           length );
93
94void tr_torrentInitFilePriority( tr_torrent       * tor,
95                                 tr_file_index_t    fileIndex,
96                                 tr_priority_t      priority );
97
98
99int  tr_torrentCountUncheckedPieces( const tr_torrent * );
100int  tr_torrentIsPieceChecked      ( const tr_torrent *, tr_piece_index_t piece );
101int  tr_torrentIsFileChecked       ( const tr_torrent *, tr_file_index_t file );
102void tr_torrentSetPieceChecked     ( tr_torrent *, tr_piece_index_t piece, int isChecked );
103void tr_torrentSetFileChecked      ( tr_torrent *, tr_file_index_t file, int isChecked );
104void tr_torrentUncheck             ( tr_torrent * );
105
106int tr_torrentPromoteTracker       ( tr_torrent *, int trackerIndex );
107
108time_t* tr_torrentGetMTimes        ( const tr_torrent *, int * setmeCount );
109
110typedef enum
111{
112   TR_VERIFY_NONE,
113   TR_VERIFY_WAIT,
114   TR_VERIFY_NOW
115}
116tr_verify_state;
117
118struct tr_torrent
119{
120    tr_handle                * handle;
121    tr_info                    info;
122
123    tr_speedlimit              uploadLimitMode;
124    tr_speedlimit              downloadLimitMode;
125    struct tr_ratecontrol    * upload;
126    struct tr_ratecontrol    * download;
127    struct tr_ratecontrol    * swarmSpeed;
128
129    int                        error;
130    char                       errorString[128];
131
132    uint8_t                    obfuscatedHash[SHA_DIGEST_LENGTH];
133
134    /* Where to download */
135    char                     * downloadDir;
136   
137    /* How many bytes we ask for per request */
138    uint32_t                   blockSize;
139    tr_block_index_t           blockCount;
140
141    uint32_t                   lastBlockSize;
142    uint32_t                   lastPieceSize;
143
144    uint32_t                   blockCountInPiece;
145    uint32_t                   blockCountInLastPiece;
146   
147    struct tr_completion     * completion;
148
149    struct tr_bitfield       * checkedPieces;
150    cp_status_t                cpStatus;
151
152    struct tr_tracker        * tracker;
153    struct tr_publisher_tag  * trackerSubscription;
154
155    uint64_t                   downloadedCur;
156    uint64_t                   downloadedPrev;
157    uint64_t                   uploadedCur;
158    uint64_t                   uploadedPrev;
159    uint64_t                   corruptCur;
160    uint64_t                   corruptPrev;
161
162    time_t                     addedDate;
163    time_t                     startDate;
164    time_t                     activityDate;
165
166    tr_torrent_status_func   * status_func;
167    void                     * status_func_user_data;
168
169    unsigned int               isRunning : 1;
170    unsigned int               isDeleting : 1;
171
172    uint16_t                   maxConnectedPeers;
173
174    tr_verify_state            verifyState;
175
176    time_t                     lastStatTime;
177    tr_stat                    stats;
178
179    tr_torrent               * next;
180
181    int                        uniqueId;
182};
183
184#endif
Note: See TracBrowser for help on using the repository browser.