source: trunk/libtransmission/torrent.h @ 5329

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

fix bug that caused very large torrents to crash Transmission

  • Property svn:keywords set to Date Rev Author Id
File size: 6.6 KB
Line 
1/******************************************************************************
2 * $Id: torrent.h 5329 2008-03-22 18:10: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 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( tr_handle *, const uint8_t * );
52tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * );
53tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* );
54
55void tr_torrentGetRates( const tr_torrent *, float * toClient, float * toPeer );
56
57int tr_torrentAllowsPex( const tr_torrent * );
58
59/* get the index of this piece's first block */
60#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
61
62/* what piece index is this block in? */
63#define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece )
64
65/* how many blocks are in this piece? */
66#define tr_torPieceCountBlocks(tor,piece) \
67    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece )
68
69/* how many bytes are in this piece? */
70#define tr_torPieceCountBytes(tor,piece) \
71    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize )
72
73/* how many bytes are in this block? */
74#define tr_torBlockCountBytes(tor,block) \
75    ( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize )
76
77#define tr_block(a,b) _tr_block(tor,a,b)
78tr_block_index_t _tr_block( const tr_torrent * tor,
79                            tr_piece_index_t   index,
80                            uint32_t           offset );
81
82int tr_torrentReqIsValid( const tr_torrent * tor,
83                          tr_piece_index_t   index,
84                          uint32_t           offset,
85                          uint32_t           length );
86
87uint64_t tr_pieceOffset( const tr_torrent * tor,
88                         tr_piece_index_t   index,
89                         uint32_t           offset,
90                         uint32_t           length );
91
92void tr_torrentInitFilePriority( tr_torrent       * tor,
93                                 tr_file_index_t    fileIndex,
94                                 tr_priority_t      priority );
95
96
97int  tr_torrentCountUncheckedPieces( const tr_torrent * );
98int  tr_torrentIsPieceChecked      ( const tr_torrent *, tr_piece_index_t piece );
99int  tr_torrentIsFileChecked       ( const tr_torrent *, tr_file_index_t file );
100void tr_torrentSetPieceChecked     ( tr_torrent *, tr_piece_index_t piece, int isChecked );
101void tr_torrentSetFileChecked      ( tr_torrent *, tr_file_index_t file, int isChecked );
102void tr_torrentUncheck             ( tr_torrent * );
103
104typedef enum
105{
106   TR_VERIFY_NONE,
107   TR_VERIFY_WAIT,
108   TR_VERIFY_NOW
109}
110tr_verify_state;
111
112struct tr_torrent
113{
114    tr_handle                 * handle;
115    tr_info                     info;
116
117    tr_speedlimit               uploadLimitMode;
118    tr_speedlimit               downloadLimitMode;
119    struct tr_ratecontrol     * upload;
120    struct tr_ratecontrol     * download;
121    struct tr_ratecontrol     * swarmspeed;
122
123    int                        error;
124    char                       errorString[128];
125
126    uint8_t                    obfuscatedHash[SHA_DIGEST_LENGTH];
127
128    /* Where to download */
129    char                     * destination;
130   
131    /* How many bytes we ask for per request */
132    uint32_t                   blockSize;
133    tr_block_index_t           blockCount;
134
135    uint32_t                   lastBlockSize;
136    uint32_t                   lastPieceSize;
137
138    uint32_t                   blockCountInPiece;
139    uint32_t                   blockCountInLastPiece;
140   
141    struct tr_completion     * completion;
142
143    struct tr_bitfield       * checkedPieces;
144    cp_status_t                cpStatus;
145
146    struct tr_tracker        * tracker;
147    struct tr_publisher_tag  * trackerSubscription;
148
149    uint64_t                   downloadedCur;
150    uint64_t                   downloadedPrev;
151    uint64_t                   uploadedCur;
152    uint64_t                   uploadedPrev;
153    uint64_t                   corruptCur;
154    uint64_t                   corruptPrev;
155
156    uint64_t                   startDate;
157    uint64_t                   stopDate;
158    uint64_t                   activityDate;
159
160    tr_torrent_status_func   * status_func;
161    void                     * status_func_user_data;
162
163    tr_torrent_active_func   * active_func;
164    void                     * active_func_user_data;
165
166    unsigned int               statCur : 1;
167    unsigned int               isRunning : 1;
168    unsigned int               isDeleting : 1;
169
170    uint16_t                   maxConnectedPeers;
171
172    tr_verify_state           verifyState;
173
174    time_t                     lastStatTime;
175    tr_stat                    stats[2];
176
177    tr_torrent               * next;
178};
179
180#endif
Note: See TracBrowser for help on using the repository browser.