source: trunk/libtransmission/torrent.h @ 6784

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

add new compile-time throttle options suggested by persept

  • Property svn:keywords set to Date Rev Author Id
File size: 6.8 KB
Line 
1/******************************************************************************
2 * $Id: torrent.h 6784 2008-09-18 03:55:31Z 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
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
104int tr_torrentPromoteTracker       ( tr_torrent *, int trackerIndex );
105
106time_t* tr_torrentGetMTimes        ( const tr_torrent *, size_t * setmeCount );
107
108typedef enum
109{
110   TR_VERIFY_NONE,
111   TR_VERIFY_WAIT,
112   TR_VERIFY_NOW
113}
114tr_verify_state;
115
116struct tr_torrent
117{
118    tr_handle                * handle;
119    tr_info                    info;
120
121    int                        uploadLimit;
122    tr_speedlimit              uploadLimitMode;
123    int                        downloadLimit;
124    tr_speedlimit              downloadLimitMode;
125
126    struct tr_ratecontrol    * swarmSpeed;
127
128    int                        error;
129    char                       errorString[128];
130
131    uint8_t                    obfuscatedHash[SHA_DIGEST_LENGTH];
132
133    /* Where to download */
134    char                     * downloadDir;
135   
136    /* How many bytes we ask for per request */
137    uint32_t                   blockSize;
138    tr_block_index_t           blockCount;
139
140    uint32_t                   lastBlockSize;
141    uint32_t                   lastPieceSize;
142
143    uint32_t                   blockCountInPiece;
144    uint32_t                   blockCountInLastPiece;
145   
146    struct tr_completion     * completion;
147
148    struct tr_bitfield       * checkedPieces;
149    cp_status_t                cpStatus;
150
151    struct tr_tracker        * tracker;
152    struct tr_publisher_tag  * trackerSubscription;
153
154    uint64_t                   downloadedCur;
155    uint64_t                   downloadedPrev;
156    uint64_t                   uploadedCur;
157    uint64_t                   uploadedPrev;
158    uint64_t                   corruptCur;
159    uint64_t                   corruptPrev;
160
161    time_t                     addedDate;
162    time_t                     activityDate;
163    time_t                     doneDate;
164    time_t                     startDate;
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    double                     rateHistory[2][BANDWIDTH_PULSE_HISTORY];
184
185};
186
187#endif
Note: See TracBrowser for help on using the repository browser.