1 | /****************************************************************************** |
---|
2 | * $Id:$ |
---|
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 */ |
---|
29 | void tr_torrentInitFileDLs( tr_torrent * tor, |
---|
30 | int * files, |
---|
31 | int fileCount, |
---|
32 | int do_download ); |
---|
33 | |
---|
34 | int tr_torrentIsPrivate( const tr_torrent * ); |
---|
35 | |
---|
36 | void tr_torrentRecheckCompleteness( tr_torrent * ); |
---|
37 | |
---|
38 | void tr_torrentResetTransferStats( tr_torrent * ); |
---|
39 | |
---|
40 | void tr_torrentSetHasPiece( tr_torrent * tor, int pieceIndex, int has ); |
---|
41 | |
---|
42 | void tr_torrentLock ( const tr_torrent * ); |
---|
43 | void tr_torrentUnlock ( const tr_torrent * ); |
---|
44 | |
---|
45 | int tr_torrentIsSeed ( const tr_torrent * ); |
---|
46 | |
---|
47 | void tr_torrentChangeMyPort ( tr_torrent * ); |
---|
48 | |
---|
49 | int tr_torrentExists( tr_handle *, const uint8_t * ); |
---|
50 | tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * ); |
---|
51 | tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* ); |
---|
52 | |
---|
53 | void tr_torrentGetRates( const tr_torrent *, float * toClient, float * toPeer ); |
---|
54 | |
---|
55 | int 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) |
---|
76 | int _tr_block( const tr_torrent * tor, int index, int begin ); |
---|
77 | |
---|
78 | uint64_t tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length ); |
---|
79 | |
---|
80 | void tr_torrentInitFilePriority( tr_torrent * tor, |
---|
81 | int fileIndex, |
---|
82 | tr_priority_t priority ); |
---|
83 | |
---|
84 | |
---|
85 | int tr_torrentCountUncheckedPieces( const tr_torrent * ); |
---|
86 | int tr_torrentIsPieceChecked ( const tr_torrent *, int piece ); |
---|
87 | void tr_torrentSetPieceChecked ( tr_torrent *, int piece, int isChecked ); |
---|
88 | void tr_torrentSetFileChecked ( tr_torrent *, int file, int isChecked ); |
---|
89 | void tr_torrentUncheck ( tr_torrent * ); |
---|
90 | |
---|
91 | typedef enum |
---|
92 | { |
---|
93 | TR_RECHECK_NONE, |
---|
94 | TR_RECHECK_WAIT, |
---|
95 | TR_RECHECK_NOW |
---|
96 | } |
---|
97 | tr_recheck_state; |
---|
98 | |
---|
99 | struct tr_torrent |
---|
100 | { |
---|
101 | tr_handle * handle; |
---|
102 | tr_info info; |
---|
103 | |
---|
104 | tr_speedlimit uploadLimitMode; |
---|
105 | tr_speedlimit downloadLimitMode; |
---|
106 | struct tr_ratecontrol * upload; |
---|
107 | struct tr_ratecontrol * download; |
---|
108 | struct tr_ratecontrol * swarmspeed; |
---|
109 | |
---|
110 | int error; |
---|
111 | char errorString[128]; |
---|
112 | |
---|
113 | uint8_t obfuscatedHash[SHA_DIGEST_LENGTH]; |
---|
114 | |
---|
115 | /* Where to download */ |
---|
116 | char * destination; |
---|
117 | |
---|
118 | /* How many bytes we ask for per request */ |
---|
119 | int blockSize; |
---|
120 | int blockCount; |
---|
121 | |
---|
122 | int lastBlockSize; |
---|
123 | int lastPieceSize; |
---|
124 | |
---|
125 | int blockCountInPiece; |
---|
126 | int blockCountInLastPiece; |
---|
127 | |
---|
128 | struct tr_completion * completion; |
---|
129 | |
---|
130 | struct tr_bitfield * checkedPieces; |
---|
131 | cp_status_t cpStatus; |
---|
132 | |
---|
133 | struct tr_tracker * tracker; |
---|
134 | struct tr_publisher_tag * trackerSubscription; |
---|
135 | |
---|
136 | uint64_t downloadedCur; |
---|
137 | uint64_t downloadedPrev; |
---|
138 | uint64_t uploadedCur; |
---|
139 | uint64_t uploadedPrev; |
---|
140 | uint64_t corruptCur; |
---|
141 | uint64_t corruptPrev; |
---|
142 | |
---|
143 | uint64_t startDate; |
---|
144 | uint64_t stopDate; |
---|
145 | uint64_t activityDate; |
---|
146 | |
---|
147 | tr_torrent_status_func * status_func; |
---|
148 | void * status_func_user_data; |
---|
149 | |
---|
150 | tr_torrent_active_func * active_func; |
---|
151 | void * active_func_user_data; |
---|
152 | |
---|
153 | unsigned int statCur : 1; |
---|
154 | unsigned int isRunning : 1; |
---|
155 | |
---|
156 | uint8_t maxUnchokedPeers; |
---|
157 | uint16_t maxConnectedPeers; |
---|
158 | |
---|
159 | tr_recheck_state recheckState; |
---|
160 | |
---|
161 | time_t lastStatTime; |
---|
162 | tr_stat stats[2]; |
---|
163 | |
---|
164 | tr_torrent * next; |
---|
165 | }; |
---|
166 | |
---|
167 | #endif |
---|