source: trunk/libtransmission/torrent.h @ 7266

Last change on this file since 7266 was 7266, checked in by charles, 12 years ago

(libT) #1557: handshake peer-id doesn't match the peer-id sent in the tracker announce

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