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