1 | /****************************************************************************** |
---|
2 | * $Id: session.h 8398 2009-05-14 13:42:29Z charles $ |
---|
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 __TRANSMISSION__ |
---|
26 | #error only libtransmission should #include this header. |
---|
27 | #endif |
---|
28 | |
---|
29 | #ifndef TR_INTERNAL_H |
---|
30 | #define TR_INTERNAL_H 1 |
---|
31 | |
---|
32 | #define TR_NAME "Transmission" |
---|
33 | |
---|
34 | #ifndef UNUSED |
---|
35 | #ifdef __GNUC__ |
---|
36 | #define UNUSED __attribute__ ( ( unused ) ) |
---|
37 | #else |
---|
38 | #define UNUSED |
---|
39 | #endif |
---|
40 | #endif |
---|
41 | |
---|
42 | #include "bencode.h" |
---|
43 | |
---|
44 | typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t; |
---|
45 | |
---|
46 | uint8_t* tr_peerIdNew( void ); |
---|
47 | |
---|
48 | const uint8_t* tr_getPeerId( void ); |
---|
49 | |
---|
50 | struct tr_metainfo_lookup |
---|
51 | { |
---|
52 | char hashString[2 * SHA_DIGEST_LENGTH + 1]; |
---|
53 | char * filename; |
---|
54 | }; |
---|
55 | |
---|
56 | struct tr_address; |
---|
57 | struct tr_bandwidth; |
---|
58 | struct tr_bindsockets; |
---|
59 | |
---|
60 | struct tr_session |
---|
61 | { |
---|
62 | tr_bool isPortRandom; |
---|
63 | tr_bool isPexEnabled; |
---|
64 | tr_bool isBlocklistEnabled; |
---|
65 | tr_bool isProxyEnabled; |
---|
66 | tr_bool isProxyAuthEnabled; |
---|
67 | tr_bool isClosed; |
---|
68 | tr_bool isWaiting; |
---|
69 | tr_bool useLazyBitfield; |
---|
70 | tr_bool isRatioLimited; |
---|
71 | |
---|
72 | tr_benc removedTorrents; |
---|
73 | |
---|
74 | int speedLimit[2]; |
---|
75 | tr_bool speedLimitEnabled[2]; |
---|
76 | |
---|
77 | int altSpeed[2]; |
---|
78 | tr_bool altSpeedEnabled; |
---|
79 | |
---|
80 | int altSpeedTimeBegin; |
---|
81 | int altSpeedTimeEnd; |
---|
82 | tr_sched_day altSpeedTimeDay; |
---|
83 | tr_bool altSpeedTimeEnabled; |
---|
84 | tr_bool altSpeedChangedByUser; |
---|
85 | |
---|
86 | tr_altSpeedFunc * altCallback; |
---|
87 | void * altCallbackUserData; |
---|
88 | |
---|
89 | |
---|
90 | int magicNumber; |
---|
91 | |
---|
92 | tr_encryption_mode encryptionMode; |
---|
93 | |
---|
94 | tr_preallocation_mode preallocationMode; |
---|
95 | |
---|
96 | struct tr_event_handle * events; |
---|
97 | |
---|
98 | uint16_t peerLimitPerTorrent; |
---|
99 | uint16_t openFileLimit; |
---|
100 | |
---|
101 | int uploadSlotsPerTorrent; |
---|
102 | |
---|
103 | tr_port peerPort; |
---|
104 | tr_port randomPortLow; |
---|
105 | tr_port randomPortHigh; |
---|
106 | |
---|
107 | int proxyPort; |
---|
108 | int peerSocketTOS; |
---|
109 | |
---|
110 | int torrentCount; |
---|
111 | tr_torrent * torrentList; |
---|
112 | |
---|
113 | char * tag; |
---|
114 | char * configDir; |
---|
115 | char * downloadDir; |
---|
116 | char * resumeDir; |
---|
117 | char * torrentDir; |
---|
118 | |
---|
119 | tr_proxy_type proxyType; |
---|
120 | char * proxy; |
---|
121 | char * proxyUsername; |
---|
122 | char * proxyPassword; |
---|
123 | |
---|
124 | struct tr_list * blocklists; |
---|
125 | struct tr_peerMgr * peerMgr; |
---|
126 | struct tr_shared * shared; |
---|
127 | |
---|
128 | struct tr_lock * lock; |
---|
129 | |
---|
130 | struct tr_web * web; |
---|
131 | |
---|
132 | struct tr_rpc_server * rpcServer; |
---|
133 | tr_rpc_func rpc_func; |
---|
134 | void * rpc_func_user_data; |
---|
135 | |
---|
136 | struct tr_stats_handle * sessionStats; |
---|
137 | struct tr_tracker_handle * tracker; |
---|
138 | |
---|
139 | struct tr_metainfo_lookup * metainfoLookup; |
---|
140 | int metainfoLookupCount; |
---|
141 | |
---|
142 | struct event * altTimer; |
---|
143 | |
---|
144 | /* the size of the output buffer for peer connections */ |
---|
145 | int so_sndbuf; |
---|
146 | |
---|
147 | /* the size of the input buffer for peer connections */ |
---|
148 | int so_rcvbuf; |
---|
149 | |
---|
150 | /* monitors the "global pool" speeds */ |
---|
151 | struct tr_bandwidth * bandwidth; |
---|
152 | |
---|
153 | double desiredRatio; |
---|
154 | |
---|
155 | struct tr_bindinfo * public_ipv4; |
---|
156 | struct tr_bindinfo * public_ipv6; |
---|
157 | }; |
---|
158 | |
---|
159 | tr_bool tr_sessionGetActiveSpeedLimit( const tr_session * session, |
---|
160 | tr_direction dir, |
---|
161 | int * setme ); |
---|
162 | |
---|
163 | const char * tr_sessionFindTorrentFile( const tr_session * session, |
---|
164 | const char * hashString ); |
---|
165 | |
---|
166 | void tr_sessionSetTorrentFile( tr_session * session, |
---|
167 | const char * hashString, |
---|
168 | const char * filename ); |
---|
169 | |
---|
170 | tr_bool tr_sessionIsAddressBlocked( const tr_session * session, |
---|
171 | const struct tr_address * addr ); |
---|
172 | |
---|
173 | void tr_globalLock( tr_session * ); |
---|
174 | |
---|
175 | void tr_globalUnlock( tr_session * ); |
---|
176 | |
---|
177 | tr_bool tr_globalIsLocked( const tr_session * ); |
---|
178 | |
---|
179 | const struct tr_address* tr_sessionGetPublicAddress( const tr_session *, int tr_af_type ); |
---|
180 | |
---|
181 | struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * ); |
---|
182 | |
---|
183 | enum |
---|
184 | { |
---|
185 | SESSION_MAGIC_NUMBER = 3845 |
---|
186 | }; |
---|
187 | |
---|
188 | static inline tr_bool tr_isSession( const tr_session * session ) |
---|
189 | { |
---|
190 | return ( session != NULL ) && ( session->magicNumber == SESSION_MAGIC_NUMBER ); |
---|
191 | } |
---|
192 | |
---|
193 | #endif |
---|