1 | /****************************************************************************** |
---|
2 | * $Id: internal.h 2884 2007-08-20 23:36:18Z 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 | int tr_trackerInfoInit( struct tr_tracker_info_s * info, |
---|
49 | const char * address, |
---|
50 | int address_len ); |
---|
51 | |
---|
52 | void tr_trackerInfoClear( struct tr_tracker_info_s * info ); |
---|
53 | |
---|
54 | struct tr_peer_s; |
---|
55 | |
---|
56 | void tr_peerIdNew ( char* buf, int buflen ); |
---|
57 | |
---|
58 | void tr_torrentResetTransferStats( tr_torrent_t * ); |
---|
59 | |
---|
60 | int tr_torrentAddCompact( tr_torrent_t * tor, int from, |
---|
61 | const uint8_t * buf, int count ); |
---|
62 | int tr_torrentAttachPeer( tr_torrent_t * tor, struct tr_peer_s * ); |
---|
63 | |
---|
64 | void tr_torrentSetHasPiece( tr_torrent_t * tor, int pieceIndex, int has ); |
---|
65 | |
---|
66 | void tr_torrentReaderLock ( const tr_torrent_t * ); |
---|
67 | void tr_torrentReaderUnlock ( const tr_torrent_t * ); |
---|
68 | void tr_torrentWriterLock ( tr_torrent_t * ); |
---|
69 | void tr_torrentWriterUnlock ( tr_torrent_t * ); |
---|
70 | |
---|
71 | void tr_torrentChangeMyPort ( tr_torrent_t *, int port ); |
---|
72 | |
---|
73 | /* get the index of this piece's first block */ |
---|
74 | #define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece ) |
---|
75 | |
---|
76 | /* what piece index is this block in? */ |
---|
77 | #define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece ) |
---|
78 | |
---|
79 | /* how many blocks are in this piece? */ |
---|
80 | #define tr_torPieceCountBlocks(tor,piece) \ |
---|
81 | ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece ) |
---|
82 | |
---|
83 | /* how many bytes are in this piece? */ |
---|
84 | #define tr_torPieceCountBytes(tor,piece) \ |
---|
85 | ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize ) |
---|
86 | |
---|
87 | /* how many bytes are in this block? */ |
---|
88 | #define tr_torBlockCountBytes(tor,block) \ |
---|
89 | ( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize ) |
---|
90 | |
---|
91 | #define tr_block(a,b) _tr_block(tor,a,b) |
---|
92 | int _tr_block( const tr_torrent_t * tor, int index, int begin ); |
---|
93 | |
---|
94 | |
---|
95 | typedef enum |
---|
96 | { |
---|
97 | TR_RUN_CHECKING = (1<<0), /* checking files' checksums */ |
---|
98 | TR_RUN_RUNNING = (1<<1), /* seeding or leeching */ |
---|
99 | TR_RUN_STOPPING = (1<<2), /* stopping */ |
---|
100 | TR_RUN_STOPPING_NET_WAIT = (1<<3), /* waiting on network -- we're |
---|
101 | telling tracker we've stopped */ |
---|
102 | TR_RUN_STOPPED = (1<<4) /* stopped */ |
---|
103 | } |
---|
104 | run_status_t; |
---|
105 | |
---|
106 | #define TR_ID_LEN 20 |
---|
107 | |
---|
108 | struct tr_torrent_s |
---|
109 | { |
---|
110 | tr_handle_t * handle; |
---|
111 | tr_info_t info; |
---|
112 | |
---|
113 | tr_speedlimit_t uploadLimitMode; |
---|
114 | tr_speedlimit_t downloadLimitMode; |
---|
115 | struct tr_ratecontrol_s * upload; |
---|
116 | struct tr_ratecontrol_s * download; |
---|
117 | struct tr_ratecontrol_s * swarmspeed; |
---|
118 | |
---|
119 | int error; |
---|
120 | char errorString[128]; |
---|
121 | int hasChangedState; |
---|
122 | |
---|
123 | uint8_t * azId; |
---|
124 | int publicPort; |
---|
125 | |
---|
126 | /* Where to download */ |
---|
127 | char * destination; |
---|
128 | |
---|
129 | /* How many bytes we ask for per request */ |
---|
130 | int blockSize; |
---|
131 | int blockCount; |
---|
132 | |
---|
133 | int lastBlockSize; |
---|
134 | int lastPieceSize; |
---|
135 | |
---|
136 | int blockCountInPiece; |
---|
137 | int blockCountInLastPiece; |
---|
138 | |
---|
139 | struct tr_completion_s * completion; |
---|
140 | |
---|
141 | volatile char dieFlag; |
---|
142 | struct tr_bitfield_s * uncheckedPieces; |
---|
143 | run_status_t runStatus; |
---|
144 | run_status_t runStatusToSave; |
---|
145 | cp_status_t cpStatus; |
---|
146 | struct tr_thread_s * thread; |
---|
147 | struct tr_rwlock_s * lock; |
---|
148 | |
---|
149 | struct tr_tracker_s * tracker; |
---|
150 | struct tr_publisher_tag * trackerSubscription; |
---|
151 | struct tr_io_s * io; |
---|
152 | uint64_t startDate; |
---|
153 | uint64_t stopDate; |
---|
154 | char ioLoaded; |
---|
155 | char fastResumeDirty; |
---|
156 | |
---|
157 | int peerCount; |
---|
158 | struct tr_peer_s * peers[TR_MAX_PEER_COUNT]; |
---|
159 | |
---|
160 | uint64_t downloadedCur; |
---|
161 | uint64_t downloadedPrev; |
---|
162 | uint64_t uploadedCur; |
---|
163 | uint64_t uploadedPrev; |
---|
164 | uint64_t activityDate; |
---|
165 | |
---|
166 | uint8_t pexDisabled; |
---|
167 | |
---|
168 | int8_t statCur; |
---|
169 | tr_stat_t stats[2]; |
---|
170 | |
---|
171 | tr_torrent_t * next; |
---|
172 | }; |
---|
173 | |
---|
174 | struct tr_handle_s |
---|
175 | { |
---|
176 | struct tr_event_handle_s * events; |
---|
177 | |
---|
178 | int torrentCount; |
---|
179 | tr_torrent_t * torrentList; |
---|
180 | |
---|
181 | char * tag; |
---|
182 | int isPortSet; |
---|
183 | |
---|
184 | char useUploadLimit; |
---|
185 | char useDownloadLimit; |
---|
186 | struct tr_ratecontrol_s * upload; |
---|
187 | struct tr_ratecontrol_s * download; |
---|
188 | |
---|
189 | struct tr_shared_s * shared; |
---|
190 | |
---|
191 | tr_handle_status_t stats[2]; |
---|
192 | int statCur; |
---|
193 | |
---|
194 | #define TR_AZ_ID_LEN 20 |
---|
195 | uint8_t azId[TR_AZ_ID_LEN]; |
---|
196 | }; |
---|
197 | |
---|
198 | #endif |
---|