source: trunk/libtransmission/torrent.h @ 7525

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

(trunk libT) avoid some unnecessary memory fragmentation... for composited objects that have a tr_bitfield, contain it directly rather than a pointer to one allocated elsewhere on the heap.

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