source: trunk/libtransmission/torrent.h @ 7055

Last change on this file since 7055 was 7055, checked in by charles, 13 years ago

update NEWS

  • Property svn:keywords set to Date Rev Author Id
File size: 8.7 KB
Line 
1/******************************************************************************
2 * $Id: torrent.h 7055 2008-11-06 02:56:51Z 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
28struct tr_ratecontrol;
29
30/**
31***  Package-visible ctor API
32**/
33
34void        tr_ctorSetSave( tr_ctor * ctor,
35                            int       saveMetadataInOurTorrentsDir );
36
37int         tr_ctorGetSave( const tr_ctor * ctor );
38
39/**
40***
41**/
42
43/* just like tr_torrentSetFileDLs but doesn't trigger a fastresume save */
44void        tr_torrentInitFileDLs( tr_torrent *      tor,
45                                   tr_file_index_t * files,
46                                   tr_file_index_t   fileCount,
47                                   int               do_download );
48
49int         tr_torrentIsPrivate( const tr_torrent * );
50
51void        tr_torrentRecheckCompleteness( tr_torrent * );
52
53void        tr_torrentResetTransferStats( tr_torrent * );
54
55void        tr_torrentSetHasPiece( tr_torrent *     tor,
56                                   tr_piece_index_t pieceIndex,
57                                   int              has );
58
59void        tr_torrentLock( const tr_torrent * session );
60
61void        tr_torrentUnlock( const tr_torrent * session );
62
63int         tr_torrentIsSeed( const tr_torrent * session );
64
65void        tr_torrentChangeMyPort( tr_torrent * session );
66
67int         tr_torrentExists( const tr_session * session,
68                              const uint8_t    * hash );
69
70tr_torrent* tr_torrentFindFromId( tr_session * session,
71                                  int          id );
72
73tr_torrent* tr_torrentFindFromHash( tr_session *    session,
74                                    const uint8_t * hash );
75
76tr_torrent* tr_torrentFindFromHashString( tr_session * session,
77                                          const char * hashString );
78
79tr_torrent* tr_torrentFindFromObfuscatedHash( tr_session    * session,
80                                              const uint8_t * hash );
81
82int         tr_torrentAllowsPex( const tr_torrent * );
83
84/* get the index of this piece's first block */
85#define tr_torPieceFirstBlock( tor, piece ) ( ( piece ) *\
86                                             ( tor )->blockCountInPiece )
87
88/* what piece index is this block in? */
89#define tr_torBlockPiece( tor, block ) ( ( block ) /\
90                                        ( tor )->blockCountInPiece )
91
92/* how many blocks are in this piece? */
93#define tr_torPieceCountBlocks( tor, piece ) \
94    ( ( ( piece ) ==\
95       ( ( tor )->info.pieceCount - \
96        1 ) ) ? ( tor )->blockCountInLastPiece : ( tor )->blockCountInPiece )
97
98/* how many bytes are in this piece? */
99#define tr_torPieceCountBytes( tor, piece ) \
100    ( ( ( piece ) ==\
101       ( ( tor )->info.pieceCount - \
102        1 ) ) ? ( tor )->lastPieceSize : ( tor )->info.pieceSize )
103
104/* how many bytes are in this block? */
105#define tr_torBlockCountBytes( tor, block ) \
106    ( ( ( block ) ==\
107       ( ( tor )->blockCount - \
108        1 ) ) ? ( tor )->lastBlockSize : ( tor )->blockSize )
109
110#define tr_block( a, b ) _tr_block( tor, a, b )
111tr_block_index_t _tr_block( const tr_torrent * tor,
112                            tr_piece_index_t   index,
113                            uint32_t           offset );
114
115int              tr_torrentReqIsValid( const tr_torrent * tor,
116                                       tr_piece_index_t   index,
117                                       uint32_t           offset,
118                                       uint32_t           length );
119
120uint64_t         tr_pieceOffset( const tr_torrent * tor,
121                                 tr_piece_index_t   index,
122                                 uint32_t           offset,
123                                 uint32_t           length );
124
125void             tr_torrentInitFilePriority( tr_torrent       * tor,
126                                             tr_file_index_t    fileIndex,
127                                             tr_priority_t      priority );
128
129
130int              tr_torrentCountUncheckedPieces( const tr_torrent * );
131
132int              tr_torrentIsPieceChecked( const tr_torrent  * tor,
133                                           tr_piece_index_t    piece );
134
135int              tr_torrentIsFileChecked( const tr_torrent  * tor,
136                                          tr_file_index_t     file );
137
138void             tr_torrentSetPieceChecked( tr_torrent       * tor,
139                                            tr_piece_index_t   piece,
140                                            int                isChecked );
141
142void             tr_torrentSetFileChecked( tr_torrent       * tor,
143                                           tr_file_index_t    file,
144                                           int                isChecked );
145
146void             tr_torrentUncheck( tr_torrent * tor );
147
148int              tr_torrentPromoteTracker( tr_torrent   * tor,
149                                           int            trackerIndex );
150
151time_t*          tr_torrentGetMTimes( const tr_torrent  * tor,
152                                      size_t            * setmeCount );
153
154typedef enum
155{
156    TR_VERIFY_NONE,
157    TR_VERIFY_WAIT,
158    TR_VERIFY_NOW
159}
160tr_verify_state;
161
162struct tr_torrent
163{
164    tr_session *             session;
165    tr_info                  info;
166
167    int                      uploadLimit;
168    tr_speedlimit            uploadLimitMode;
169    int                      downloadLimit;
170    tr_speedlimit            downloadLimitMode;
171
172    struct tr_ratecontrol *  swarmSpeed;
173
174    int                      error;
175    char                     errorString[128];
176
177    uint8_t                  obfuscatedHash[SHA_DIGEST_LENGTH];
178
179    /* Where to download */
180    char *  downloadDir;
181
182    /* How many bytes we ask for per request */
183    uint32_t                   blockSize;
184    tr_block_index_t           blockCount;
185
186    uint32_t                   lastBlockSize;
187    uint32_t                   lastPieceSize;
188
189    uint32_t                   blockCountInPiece;
190    uint32_t                   blockCountInLastPiece;
191
192    struct tr_completion *     completion;
193
194    struct tr_bitfield *       checkedPieces;
195    tr_completeness            completeness;
196
197    struct tr_tracker *        tracker;
198    struct tr_publisher_tag *  trackerSubscription;
199
200    uint64_t                   downloadedCur;
201    uint64_t                   downloadedPrev;
202    uint64_t                   uploadedCur;
203    uint64_t                   uploadedPrev;
204    uint64_t                   corruptCur;
205    uint64_t                   corruptPrev;
206
207    time_t                     addedDate;
208    time_t                     activityDate;
209    time_t                     doneDate;
210    time_t                     startDate;
211
212    tr_torrent_completeness_func *   completeness_func;
213    void *                     completeness_func_user_data;
214
215    unsigned int               isRunning  : 1;
216    unsigned int               isDeleting : 1;
217
218    uint16_t                   maxConnectedPeers;
219
220    tr_verify_state            verifyState;
221
222    time_t                     lastStatTime;
223    tr_stat                    stats;
224
225    tr_torrent *               next;
226
227    int                        uniqueId;
228
229    /* this is the count of raw bytes transferred between the
230     * client and its peers over the past HISTORY time slices.
231     * this count is used for bandwidth allocation, and includes
232     * piece data, protocol overhead, and estimated tcp header overhead. */
233    double                     rateHistory[2][BANDWIDTH_PULSE_HISTORY];
234
235    /* the rate at which pieces are being transferred between client and
236     * its peers.  protocol overhead is NOT included; only the piece data */
237    struct tr_ratecontrol    * pieceSpeed[2];
238};
239
240#endif
Note: See TracBrowser for help on using the repository browser.