source: trunk/libtransmission/torrent.h @ 6795

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

run libT, cli, daemon, gtk through the source-code formatter "uncrustify" as promised/threatened

  • Property svn:keywords set to Date Rev Author Id
File size: 7.7 KB
Line 
1/******************************************************************************
2 * $Id: torrent.h 6795 2008-09-23 19:11:04Z 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 * );
45
46void        tr_torrentUnlock( const tr_torrent * );
47
48int         tr_torrentIsSeed( const tr_torrent * );
49
50void        tr_torrentChangeMyPort( tr_torrent * );
51
52int         tr_torrentExists( const tr_handle *,
53                              const uint8_t * );
54
55tr_torrent* tr_torrentFindFromId(                     tr_handle *,
56                                                  int id );
57
58tr_torrent* tr_torrentFindFromHash(                               tr_handle *,
59                                                            const uint8_t * );
60
61tr_torrent* tr_torrentFindFromHashString(
62          tr_handle *,
63    const char * );
64
65tr_torrent* tr_torrentFindFromObfuscatedHash(
66    tr_handle *,
67    const
68    uint8_t* );
69
70int         tr_torrentAllowsPex( const tr_torrent * );
71
72/* get the index of this piece's first block */
73#define tr_torPieceFirstBlock( tor, piece ) ( ( piece ) *\
74                                             ( tor )->blockCountInPiece )
75
76/* what piece index is this block in? */
77#define tr_torBlockPiece( tor, block ) ( ( block ) /\
78                                        ( tor )->blockCountInPiece )
79
80/* how many blocks are in this piece? */
81#define tr_torPieceCountBlocks( tor, piece ) \
82    ( ( ( piece ) ==\
83       ( ( tor )->info.pieceCount - \
84        1 ) ) ? ( tor )->blockCountInLastPiece : ( tor )->blockCountInPiece )
85
86/* how many bytes are in this piece? */
87#define tr_torPieceCountBytes( tor, piece ) \
88    ( ( ( piece ) ==\
89       ( ( tor )->info.pieceCount - \
90        1 ) ) ? ( tor )->lastPieceSize : ( tor )->info.pieceSize )
91
92/* how many bytes are in this block? */
93#define tr_torBlockCountBytes( tor, block ) \
94    ( ( ( block ) ==\
95       ( ( tor )->blockCount - \
96        1 ) ) ? ( tor )->lastBlockSize : ( tor )->blockSize )
97
98#define tr_block( a, b ) _tr_block( tor, a, b )
99tr_block_index_t _tr_block( const tr_torrent * tor,
100                            tr_piece_index_t   index,
101                            uint32_t           offset );
102
103int              tr_torrentReqIsValid( const tr_torrent * tor,
104                                       tr_piece_index_t   index,
105                                       uint32_t           offset,
106                                       uint32_t           length );
107
108uint64_t         tr_pieceOffset( const tr_torrent * tor,
109                                 tr_piece_index_t   index,
110                                 uint32_t           offset,
111                                 uint32_t           length );
112
113void             tr_torrentInitFilePriority( tr_torrent *    tor,
114                                             tr_file_index_t fileIndex,
115                                             tr_priority_t   priority );
116
117
118int              tr_torrentCountUncheckedPieces( const tr_torrent * );
119
120int              tr_torrentIsPieceChecked( const            tr_torrent *,
121                                           tr_piece_index_t piece );
122
123int              tr_torrentIsFileChecked( const           tr_torrent *,
124                                          tr_file_index_t file );
125
126void             tr_torrentSetPieceChecked(
127                     tr_torrent *,
128    tr_piece_index_t piece,
129    int              isChecked );
130
131void             tr_torrentSetFileChecked(
132    tr_torrent *,
133    tr_file_index_t
134    file,
135    int
136    isChecked );
137
138void             tr_torrentUncheck( tr_torrent * );
139
140int              tr_torrentPromoteTracker(                 tr_torrent *,
141                                                       int trackerIndex );
142
143time_t*          tr_torrentGetMTimes( const    tr_torrent *,
144                                      size_t * setmeCount );
145
146typedef enum
147{
148    TR_VERIFY_NONE,
149    TR_VERIFY_WAIT,
150    TR_VERIFY_NOW
151}
152tr_verify_state;
153
154struct tr_torrent
155{
156    tr_handle *              handle;
157    tr_info                  info;
158
159    int                      uploadLimit;
160    tr_speedlimit            uploadLimitMode;
161    int                      downloadLimit;
162    tr_speedlimit            downloadLimitMode;
163
164    struct tr_ratecontrol *  swarmSpeed;
165
166    int                      error;
167    char                     errorString[128];
168
169    uint8_t                  obfuscatedHash[SHA_DIGEST_LENGTH];
170
171    /* Where to download */
172    char *  downloadDir;
173
174    /* How many bytes we ask for per request */
175    uint32_t                   blockSize;
176    tr_block_index_t           blockCount;
177
178    uint32_t                   lastBlockSize;
179    uint32_t                   lastPieceSize;
180
181    uint32_t                   blockCountInPiece;
182    uint32_t                   blockCountInLastPiece;
183
184    struct tr_completion *     completion;
185
186    struct tr_bitfield *       checkedPieces;
187    cp_status_t                cpStatus;
188
189    struct tr_tracker *        tracker;
190    struct tr_publisher_tag *  trackerSubscription;
191
192    uint64_t                   downloadedCur;
193    uint64_t                   downloadedPrev;
194    uint64_t                   uploadedCur;
195    uint64_t                   uploadedPrev;
196    uint64_t                   corruptCur;
197    uint64_t                   corruptPrev;
198
199    time_t                     addedDate;
200    time_t                     activityDate;
201    time_t                     doneDate;
202    time_t                     startDate;
203
204    tr_torrent_status_func *   status_func;
205    void *                     status_func_user_data;
206
207    unsigned int               isRunning  : 1;
208    unsigned int               isDeleting : 1;
209
210    uint16_t                   maxConnectedPeers;
211
212    tr_verify_state            verifyState;
213
214    time_t                     lastStatTime;
215    tr_stat                    stats;
216
217    tr_torrent *               next;
218
219    int                        uniqueId;
220
221    double                     rateHistory[2][BANDWIDTH_PULSE_HISTORY];
222};
223
224#endif
Note: See TracBrowser for help on using the repository browser.