1 | /* |
---|
2 | * This file Copyright (C) 2008-2010 Mnemosyne LLC |
---|
3 | * |
---|
4 | * This file is licensed by the GPL version 2. Works owned by the |
---|
5 | * Transmission project are granted a special exemption to clause 2(b) |
---|
6 | * so that the bulk of its code can remain under the MIT license. |
---|
7 | * This exemption does not extend to derived works not owned by |
---|
8 | * the Transmission project. |
---|
9 | * |
---|
10 | * $Id: session.h 10391 2010-03-17 19:23:03Z charles $ |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef __TRANSMISSION__ |
---|
14 | #error only libtransmission should #include this header. |
---|
15 | #endif |
---|
16 | |
---|
17 | #ifndef TR_INTERNAL_H |
---|
18 | #define TR_INTERNAL_H 1 |
---|
19 | |
---|
20 | #define TR_NAME "Transmission" |
---|
21 | |
---|
22 | #ifndef UNUSED |
---|
23 | #ifdef __GNUC__ |
---|
24 | #define UNUSED __attribute__ ( ( unused ) ) |
---|
25 | #else |
---|
26 | #define UNUSED |
---|
27 | #endif |
---|
28 | #endif |
---|
29 | |
---|
30 | #include "bencode.h" |
---|
31 | #include "bitfield.h" |
---|
32 | |
---|
33 | typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t; |
---|
34 | |
---|
35 | uint8_t* tr_peerIdNew( void ); |
---|
36 | |
---|
37 | const uint8_t* tr_getPeerId( void ); |
---|
38 | |
---|
39 | struct tr_address; |
---|
40 | struct tr_announcer; |
---|
41 | struct tr_bandwidth; |
---|
42 | struct tr_bindsockets; |
---|
43 | struct tr_fdInfo; |
---|
44 | |
---|
45 | struct tr_turtle_info |
---|
46 | { |
---|
47 | /* TR_UP and TR_DOWN speed limits */ |
---|
48 | int speedLimit[2]; |
---|
49 | |
---|
50 | /* is turtle mode on right now? */ |
---|
51 | tr_bool isEnabled; |
---|
52 | |
---|
53 | /* does turtle mode turn itself on and off at given times? */ |
---|
54 | tr_bool isClockEnabled; |
---|
55 | |
---|
56 | /* when clock mode is on, minutes after midnight to turn on turtle mode */ |
---|
57 | int beginMinute; |
---|
58 | |
---|
59 | /* when clock mode is on, minutes after midnight to turn off turtle mode */ |
---|
60 | int endMinute; |
---|
61 | |
---|
62 | /* only use clock mode on these days of the week */ |
---|
63 | tr_sched_day days; |
---|
64 | |
---|
65 | /* called when isEnabled changes */ |
---|
66 | tr_altSpeedFunc * callback; |
---|
67 | |
---|
68 | /* the callback's user_data argument */ |
---|
69 | void * callbackUserData; |
---|
70 | |
---|
71 | /* the callback's changedByUser argument. |
---|
72 | * indicates whether the change came from the user or from the clock. */ |
---|
73 | tr_bool changedByUser; |
---|
74 | |
---|
75 | /* bitfield of all the minutes in a week. |
---|
76 | * Each bit's value indicates whether the scheduler wants turtle |
---|
77 | * limits on or off at that given minute in the week. */ |
---|
78 | tr_bitfield minutes; |
---|
79 | }; |
---|
80 | |
---|
81 | /** @brief handle to an active libtransmission session */ |
---|
82 | struct tr_session |
---|
83 | { |
---|
84 | tr_bool isPortRandom; |
---|
85 | tr_bool isPexEnabled; |
---|
86 | tr_bool isDHTEnabled; |
---|
87 | tr_bool isBlocklistEnabled; |
---|
88 | tr_bool isProxyEnabled; |
---|
89 | tr_bool isProxyAuthEnabled; |
---|
90 | tr_bool isClosed; |
---|
91 | tr_bool useLazyBitfield; |
---|
92 | tr_bool isIncompleteFileNamingEnabled; |
---|
93 | tr_bool isRatioLimited; |
---|
94 | tr_bool isIncompleteDirEnabled; |
---|
95 | tr_bool pauseAddedTorrent; |
---|
96 | tr_bool deleteSourceTorrent; |
---|
97 | |
---|
98 | tr_benc removedTorrents; |
---|
99 | |
---|
100 | int umask; |
---|
101 | |
---|
102 | int speedLimit[2]; |
---|
103 | tr_bool speedLimitEnabled[2]; |
---|
104 | |
---|
105 | struct tr_turtle_info turtle; |
---|
106 | |
---|
107 | struct tr_fdInfo * fdInfo; |
---|
108 | |
---|
109 | int magicNumber; |
---|
110 | |
---|
111 | tr_encryption_mode encryptionMode; |
---|
112 | |
---|
113 | tr_preallocation_mode preallocationMode; |
---|
114 | |
---|
115 | struct tr_event_handle * events; |
---|
116 | |
---|
117 | uint16_t peerLimitPerTorrent; |
---|
118 | |
---|
119 | int uploadSlotsPerTorrent; |
---|
120 | |
---|
121 | tr_port peerPort; |
---|
122 | tr_port randomPortLow; |
---|
123 | tr_port randomPortHigh; |
---|
124 | |
---|
125 | int proxyPort; |
---|
126 | int peerSocketTOS; |
---|
127 | |
---|
128 | int torrentCount; |
---|
129 | tr_torrent * torrentList; |
---|
130 | |
---|
131 | char * tag; |
---|
132 | char * configDir; |
---|
133 | char * downloadDir; |
---|
134 | char * resumeDir; |
---|
135 | char * torrentDir; |
---|
136 | char * incompleteDir; |
---|
137 | |
---|
138 | tr_proxy_type proxyType; |
---|
139 | char * proxy; |
---|
140 | char * proxyUsername; |
---|
141 | char * proxyPassword; |
---|
142 | |
---|
143 | struct tr_list * blocklists; |
---|
144 | struct tr_peerMgr * peerMgr; |
---|
145 | struct tr_shared * shared; |
---|
146 | |
---|
147 | struct tr_lock * lock; |
---|
148 | |
---|
149 | struct tr_web * web; |
---|
150 | |
---|
151 | struct tr_rpc_server * rpcServer; |
---|
152 | tr_rpc_func rpc_func; |
---|
153 | void * rpc_func_user_data; |
---|
154 | |
---|
155 | struct tr_stats_handle * sessionStats; |
---|
156 | |
---|
157 | struct tr_announcer * announcer; |
---|
158 | |
---|
159 | tr_benc * metainfoLookup; |
---|
160 | |
---|
161 | struct event * nowTimer; |
---|
162 | struct event * saveTimer; |
---|
163 | |
---|
164 | /* monitors the "global pool" speeds */ |
---|
165 | struct tr_bandwidth * bandwidth; |
---|
166 | |
---|
167 | double desiredRatio; |
---|
168 | |
---|
169 | struct tr_bindinfo * public_ipv4; |
---|
170 | struct tr_bindinfo * public_ipv6; |
---|
171 | |
---|
172 | /* a page-aligned buffer for use by the libtransmission thread. |
---|
173 | * @see SESSION_BUFFER_SIZE */ |
---|
174 | void * buffer; |
---|
175 | |
---|
176 | tr_bool bufferInUse; |
---|
177 | }; |
---|
178 | |
---|
179 | tr_bool tr_sessionAllowsDHT( const tr_session * session ); |
---|
180 | |
---|
181 | const char * tr_sessionFindTorrentFile( const tr_session * session, |
---|
182 | const char * hashString ); |
---|
183 | |
---|
184 | void tr_sessionSetTorrentFile( tr_session * session, |
---|
185 | const char * hashString, |
---|
186 | const char * filename ); |
---|
187 | |
---|
188 | tr_bool tr_sessionIsAddressBlocked( const tr_session * session, |
---|
189 | const struct tr_address * addr ); |
---|
190 | |
---|
191 | void tr_sessionLock( tr_session * ); |
---|
192 | |
---|
193 | void tr_sessionUnlock( tr_session * ); |
---|
194 | |
---|
195 | tr_bool tr_sessionIsLocked( const tr_session * ); |
---|
196 | |
---|
197 | const struct tr_address* tr_sessionGetPublicAddress( const tr_session *, int tr_af_type ); |
---|
198 | |
---|
199 | struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * ); |
---|
200 | |
---|
201 | enum |
---|
202 | { |
---|
203 | SESSION_MAGIC_NUMBER = 3845, |
---|
204 | |
---|
205 | /* @see tr_session.buffer */ |
---|
206 | SESSION_BUFFER_SIZE = (16*1024) |
---|
207 | }; |
---|
208 | |
---|
209 | void* tr_sessionGetBuffer( tr_session * session ); |
---|
210 | |
---|
211 | void tr_sessionReleaseBuffer( tr_session * session ); |
---|
212 | |
---|
213 | static inline tr_bool tr_isSession( const tr_session * session ) |
---|
214 | { |
---|
215 | return ( session != NULL ) && ( session->magicNumber == SESSION_MAGIC_NUMBER ); |
---|
216 | } |
---|
217 | |
---|
218 | static inline tr_bool tr_isPreallocationMode( tr_preallocation_mode m ) |
---|
219 | { |
---|
220 | return ( m == TR_PREALLOCATE_NONE ) |
---|
221 | || ( m == TR_PREALLOCATE_SPARSE ) |
---|
222 | || ( m == TR_PREALLOCATE_FULL ); |
---|
223 | } |
---|
224 | |
---|
225 | static inline tr_bool tr_isEncryptionMode( tr_encryption_mode m ) |
---|
226 | { |
---|
227 | return ( m == TR_CLEAR_PREFERRED ) |
---|
228 | || ( m == TR_ENCRYPTION_PREFERRED ) |
---|
229 | || ( m == TR_ENCRYPTION_REQUIRED ); |
---|
230 | } |
---|
231 | |
---|
232 | static inline tr_bool tr_isPriority( tr_priority_t p ) |
---|
233 | { |
---|
234 | return ( p == TR_PRI_LOW ) |
---|
235 | || ( p == TR_PRI_NORMAL ) |
---|
236 | || ( p == TR_PRI_HIGH ); |
---|
237 | } |
---|
238 | |
---|
239 | #endif |
---|