1 | /****************************************************************************** |
---|
2 | * $Id: internal.h 3155 2007-09-23 23:38:39Z 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 | #define TR_MAX_PEER_COUNT 60 |
---|
37 | |
---|
38 | typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t; |
---|
39 | |
---|
40 | #ifndef TRUE |
---|
41 | #define TRUE 1 |
---|
42 | #endif |
---|
43 | |
---|
44 | #ifndef FALSE |
---|
45 | #define FALSE 0 |
---|
46 | #endif |
---|
47 | |
---|
48 | |
---|
49 | void tr_torrentRecheckCompleteness( tr_torrent * ); |
---|
50 | |
---|
51 | int tr_trackerInfoInit( struct tr_tracker_info * info, |
---|
52 | const char * address, |
---|
53 | int address_len ); |
---|
54 | |
---|
55 | void tr_trackerInfoClear( struct tr_tracker_info * info ); |
---|
56 | |
---|
57 | void tr_peerIdNew ( char* buf, int buflen ); |
---|
58 | |
---|
59 | void tr_torrentResetTransferStats( tr_torrent * ); |
---|
60 | |
---|
61 | void tr_torrentSetHasPiece( tr_torrent * tor, int pieceIndex, int has ); |
---|
62 | |
---|
63 | void tr_torrentLock ( const tr_torrent * ); |
---|
64 | void tr_torrentUnlock ( 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 | /* get the index of this piece's first block */ |
---|
73 | #define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece ) |
---|
74 | |
---|
75 | /* what piece index is this block in? */ |
---|
76 | #define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece ) |
---|
77 | |
---|
78 | /* how many blocks are in this piece? */ |
---|
79 | #define tr_torPieceCountBlocks(tor,piece) \ |
---|
80 | ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece ) |
---|
81 | |
---|
82 | /* how many bytes are in this piece? */ |
---|
83 | #define tr_torPieceCountBytes(tor,piece) \ |
---|
84 | ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize ) |
---|
85 | |
---|
86 | /* how many bytes are in this block? */ |
---|
87 | #define tr_torBlockCountBytes(tor,block) \ |
---|
88 | ( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize ) |
---|
89 | |
---|
90 | #define tr_block(a,b) _tr_block(tor,a,b) |
---|
91 | int _tr_block( const tr_torrent * tor, int index, int begin ); |
---|
92 | |
---|
93 | uint64_t tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length ); |
---|
94 | |
---|
95 | typedef enum |
---|
96 | { |
---|
97 | TR_RUN_CHECKING_WAIT = (1<<0), /* waiting to be checked */ |
---|
98 | TR_RUN_CHECKING = (1<<1), /* checking files' checksums */ |
---|
99 | TR_RUN_RUNNING = (1<<2), /* seeding or leeching */ |
---|
100 | TR_RUN_STOPPING = (1<<3), /* waiting for acknowledgment from tracker */ |
---|
101 | TR_RUN_STOPPED = (1<<4) /* stopped */ |
---|
102 | } |
---|
103 | run_status_t; |
---|
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 | struct tr_timer * saveTimer; |
---|
119 | |
---|
120 | int error; |
---|
121 | char errorString[128]; |
---|
122 | |
---|
123 | uint8_t obfuscatedHash[SHA_DIGEST_LENGTH]; |
---|
124 | |
---|
125 | uint8_t * azId; |
---|
126 | |
---|
127 | /* Where to download */ |
---|
128 | char * destination; |
---|
129 | |
---|
130 | /* How many bytes we ask for per request */ |
---|
131 | int blockSize; |
---|
132 | int blockCount; |
---|
133 | |
---|
134 | int lastBlockSize; |
---|
135 | int lastPieceSize; |
---|
136 | |
---|
137 | int blockCountInPiece; |
---|
138 | int blockCountInLastPiece; |
---|
139 | |
---|
140 | struct tr_completion * completion; |
---|
141 | |
---|
142 | struct tr_bitfield * uncheckedPieces; |
---|
143 | run_status_t runStatus; |
---|
144 | run_status_t runStatusToSave; |
---|
145 | cp_status_t cpStatus; |
---|
146 | struct tr_lock * lock; |
---|
147 | |
---|
148 | struct tr_tracker * tracker; |
---|
149 | struct tr_publisher_tag * trackerSubscription; |
---|
150 | |
---|
151 | uint64_t downloadedCur; |
---|
152 | uint64_t downloadedPrev; |
---|
153 | uint64_t uploadedCur; |
---|
154 | uint64_t uploadedPrev; |
---|
155 | uint64_t corruptCur; |
---|
156 | uint64_t corruptPrev; |
---|
157 | |
---|
158 | uint64_t startDate; |
---|
159 | uint64_t stopDate; |
---|
160 | uint64_t activityDate; |
---|
161 | |
---|
162 | uint8_t hasChangedState; |
---|
163 | |
---|
164 | unsigned int runStatusToSaveIsSet : 1; |
---|
165 | unsigned int pexDisabled : 1; |
---|
166 | unsigned int doStopAfterHashCheck : 1; |
---|
167 | unsigned int statCur : 1; |
---|
168 | |
---|
169 | tr_stat stats[2]; |
---|
170 | |
---|
171 | tr_torrent * next; |
---|
172 | }; |
---|
173 | |
---|
174 | struct tr_handle |
---|
175 | { |
---|
176 | tr_encryption_mode encryptionMode; |
---|
177 | |
---|
178 | struct tr_event_handle * events; |
---|
179 | |
---|
180 | int torrentCount; |
---|
181 | tr_torrent * torrentList; |
---|
182 | |
---|
183 | char * tag; |
---|
184 | int isPortSet; |
---|
185 | |
---|
186 | char useUploadLimit; |
---|
187 | char useDownloadLimit; |
---|
188 | struct tr_ratecontrol * upload; |
---|
189 | struct tr_ratecontrol * download; |
---|
190 | |
---|
191 | struct tr_peerMgr * peerMgr; |
---|
192 | struct tr_shared * shared; |
---|
193 | |
---|
194 | tr_handle_status stats[2]; |
---|
195 | int statCur; |
---|
196 | |
---|
197 | uint8_t isClosed; |
---|
198 | |
---|
199 | #define TR_AZ_ID_LEN 20 |
---|
200 | uint8_t azId[TR_AZ_ID_LEN]; |
---|
201 | }; |
---|
202 | |
---|
203 | #endif |
---|