source: trunk/libtransmission/torrent.h @ 4326

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

fix another file priority bug.

File size: 5.5 KB
Line 
1/******************************************************************************
2 * $Id:$
3 *
4 * Copyright (c) 2005-2007 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
78uint64_t tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length );
79
80void tr_torrentInitFilePriority( tr_torrent   * tor,
81                                 int            fileIndex,
82                                 tr_priority_t  priority );
83
84
85typedef enum
86{
87   TR_RECHECK_NONE,
88   TR_RECHECK_WAIT,
89   TR_RECHECK_NOW
90}
91tr_recheck_state;
92
93#define TR_ID_LEN  20
94
95struct tr_torrent
96{
97    tr_handle                 * handle;
98    tr_info                     info;
99
100    tr_speedlimit               uploadLimitMode;
101    tr_speedlimit               downloadLimitMode;
102    struct tr_ratecontrol     * upload;
103    struct tr_ratecontrol     * download;
104    struct tr_ratecontrol     * swarmspeed;
105
106    int                        error;
107    char                       errorString[128];
108
109    uint8_t                    obfuscatedHash[SHA_DIGEST_LENGTH];
110
111    /* Where to download */
112    char                     * destination;
113   
114    /* How many bytes we ask for per request */
115    int                        blockSize;
116    int                        blockCount;
117
118    int                        lastBlockSize;
119    int                        lastPieceSize;
120
121    int                        blockCountInPiece;
122    int                        blockCountInLastPiece;
123   
124    struct tr_completion     * completion;
125
126    struct tr_bitfield       * uncheckedPieces;
127    cp_status_t                cpStatus;
128
129    struct tr_tracker        * tracker;
130    struct tr_publisher_tag  * trackerSubscription;
131
132    uint64_t                   downloadedCur;
133    uint64_t                   downloadedPrev;
134    uint64_t                   uploadedCur;
135    uint64_t                   uploadedPrev;
136    uint64_t                   corruptCur;
137    uint64_t                   corruptPrev;
138
139    uint64_t                   startDate;
140    uint64_t                   stopDate;
141    uint64_t                   activityDate;
142
143    tr_torrent_status_func   * status_func;
144    void                     * status_func_user_data;
145
146    unsigned int               statCur : 1;
147    unsigned int               isRunning : 1;
148
149    uint8_t                    maxUnchokedPeers;
150    uint16_t                   maxConnectedPeers;
151
152    tr_recheck_state           recheckState;
153
154    time_t                     lastStatTime;
155    tr_stat                    stats[2];
156
157    tr_torrent               * next;
158};
159
160#endif
Note: See TracBrowser for help on using the repository browser.