source: trunk/libtransmission/torrent.h @ 5204

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

#751: more digging to try to figure out where the problem is.

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