1 | /****************************************************************************** |
---|
2 | * $Id: internal.h 3744 2007-11-07 01:27:32Z charles $ |
---|
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_INTERNAL_H |
---|
26 | #define TR_INTERNAL_H 1 |
---|
27 | |
---|
28 | #define TR_NAME "Transmission" |
---|
29 | |
---|
30 | #ifdef __GNUC__ |
---|
31 | #define UNUSED __attribute__((unused)) |
---|
32 | #else |
---|
33 | #define UNUSED |
---|
34 | #endif |
---|
35 | |
---|
36 | typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t; |
---|
37 | |
---|
38 | #ifndef TRUE |
---|
39 | #define TRUE 1 |
---|
40 | #endif |
---|
41 | |
---|
42 | #ifndef FALSE |
---|
43 | #define FALSE 0 |
---|
44 | #endif |
---|
45 | |
---|
46 | |
---|
47 | void tr_torrentRecheckCompleteness( tr_torrent * ); |
---|
48 | |
---|
49 | int tr_trackerInfoInit( struct tr_tracker_info * info, |
---|
50 | const char * address, |
---|
51 | int address_len ); |
---|
52 | |
---|
53 | void tr_trackerInfoClear( struct tr_tracker_info * info ); |
---|
54 | |
---|
55 | void tr_peerIdNew ( char* buf, int buflen ); |
---|
56 | |
---|
57 | void tr_torrentResetTransferStats( tr_torrent * ); |
---|
58 | |
---|
59 | void tr_torrentSetHasPiece( tr_torrent * tor, int pieceIndex, int has ); |
---|
60 | |
---|
61 | void tr_torrentLock ( const tr_torrent * ); |
---|
62 | void tr_torrentUnlock ( const tr_torrent * ); |
---|
63 | |
---|
64 | int tr_torrentIsSeed ( const tr_torrent * ); |
---|
65 | |
---|
66 | void tr_torrentChangeMyPort ( tr_torrent * ); |
---|
67 | |
---|
68 | int tr_torrentExists( tr_handle *, const uint8_t * ); |
---|
69 | tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * ); |
---|
70 | tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* ); |
---|
71 | |
---|
72 | void tr_torrentGetRates( const tr_torrent *, float * toClient, float * toPeer ); |
---|
73 | |
---|
74 | /* get the index of this piece's first block */ |
---|
75 | #define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece ) |
---|
76 | |
---|
77 | /* what piece index is this block in? */ |
---|
78 | #define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece ) |
---|
79 | |
---|
80 | /* how many blocks are in this piece? */ |
---|
81 | #define tr_torPieceCountBlocks(tor,piece) \ |
---|
82 | ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece ) |
---|
83 | |
---|
84 | /* how many bytes are in this piece? */ |
---|
85 | #define tr_torPieceCountBytes(tor,piece) \ |
---|
86 | ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize ) |
---|
87 | |
---|
88 | /* how many bytes are in this block? */ |
---|
89 | #define tr_torBlockCountBytes(tor,block) \ |
---|
90 | ( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize ) |
---|
91 | |
---|
92 | #define tr_block(a,b) _tr_block(tor,a,b) |
---|
93 | int _tr_block( const tr_torrent * tor, int index, int begin ); |
---|
94 | |
---|
95 | uint64_t tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length ); |
---|
96 | |
---|
97 | typedef enum |
---|
98 | { |
---|
99 | TR_RECHECK_NONE, |
---|
100 | TR_RECHECK_WAIT, |
---|
101 | TR_RECHECK_NOW |
---|
102 | } |
---|
103 | tr_recheck_state; |
---|
104 | |
---|
105 | #define TR_ID_LEN 20 |
---|
106 | |
---|
107 | struct tr_torrent |
---|
108 | { |
---|
109 | tr_handle * handle; |
---|
110 | tr_info info; |
---|
111 | |
---|
112 | tr_speedlimit uploadLimitMode; |
---|
113 | tr_speedlimit downloadLimitMode; |
---|
114 | struct tr_ratecontrol * upload; |
---|
115 | struct tr_ratecontrol * download; |
---|
116 | struct tr_ratecontrol * swarmspeed; |
---|
117 | |
---|
118 | int error; |
---|
119 | char errorString[128]; |
---|
120 | |
---|
121 | uint8_t obfuscatedHash[SHA_DIGEST_LENGTH]; |
---|
122 | |
---|
123 | /* Where to download */ |
---|
124 | char * destination; |
---|
125 | |
---|
126 | /* How many bytes we ask for per request */ |
---|
127 | int blockSize; |
---|
128 | int blockCount; |
---|
129 | |
---|
130 | int lastBlockSize; |
---|
131 | int lastPieceSize; |
---|
132 | |
---|
133 | int blockCountInPiece; |
---|
134 | int blockCountInLastPiece; |
---|
135 | |
---|
136 | struct tr_completion * completion; |
---|
137 | |
---|
138 | struct tr_bitfield * uncheckedPieces; |
---|
139 | cp_status_t cpStatus; |
---|
140 | |
---|
141 | struct tr_tracker * tracker; |
---|
142 | struct tr_publisher_tag * trackerSubscription; |
---|
143 | |
---|
144 | uint64_t downloadedCur; |
---|
145 | uint64_t downloadedPrev; |
---|
146 | uint64_t uploadedCur; |
---|
147 | uint64_t uploadedPrev; |
---|
148 | uint64_t corruptCur; |
---|
149 | uint64_t corruptPrev; |
---|
150 | |
---|
151 | uint64_t startDate; |
---|
152 | uint64_t stopDate; |
---|
153 | uint64_t activityDate; |
---|
154 | |
---|
155 | tr_torrent_status_func * status_func; |
---|
156 | void * status_func_user_data; |
---|
157 | |
---|
158 | unsigned int pexDisabled : 1; |
---|
159 | unsigned int statCur : 1; |
---|
160 | unsigned int isRunning : 1; |
---|
161 | |
---|
162 | tr_recheck_state recheckState; |
---|
163 | |
---|
164 | tr_stat stats[2]; |
---|
165 | |
---|
166 | tr_torrent * next; |
---|
167 | }; |
---|
168 | |
---|
169 | struct tr_handle |
---|
170 | { |
---|
171 | tr_encryption_mode encryptionMode; |
---|
172 | |
---|
173 | struct tr_event_handle * events; |
---|
174 | |
---|
175 | int torrentCount; |
---|
176 | tr_torrent * torrentList; |
---|
177 | |
---|
178 | char * tag; |
---|
179 | int isPortSet; |
---|
180 | |
---|
181 | char useUploadLimit; |
---|
182 | char useDownloadLimit; |
---|
183 | struct tr_ratecontrol * upload; |
---|
184 | struct tr_ratecontrol * download; |
---|
185 | |
---|
186 | struct tr_peerMgr * peerMgr; |
---|
187 | struct tr_shared * shared; |
---|
188 | |
---|
189 | struct tr_lock * lock; |
---|
190 | |
---|
191 | tr_handle_status stats[2]; |
---|
192 | int statCur; |
---|
193 | |
---|
194 | uint8_t isClosed; |
---|
195 | }; |
---|
196 | |
---|
197 | void tr_globalLock ( struct tr_handle * ); |
---|
198 | void tr_globalUnlock ( struct tr_handle * ); |
---|
199 | int tr_globalIsLocked ( const struct tr_handle * ); |
---|
200 | |
---|
201 | |
---|
202 | #endif |
---|