transmission: update from 2.13 to 2.22
[tomato.git] / release / src / router / transmission / libtransmission / session.h
blob2eaaa4fef422fc4a0bfd74c56c6f28143fdd7622
1 /*
2 * This file Copyright (C) Mnemosyne LLC
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.
10 * $Id: session.h 12060 2011-03-01 15:23:22Z jordan $
13 #ifndef __TRANSMISSION__
14 #error only libtransmission should #include this header.
15 #endif
17 #ifndef TR_INTERNAL_H
18 #define TR_INTERNAL_H 1
20 #define TR_NAME "Transmission"
22 #ifndef UNUSED
23 #ifdef __GNUC__
24 #define UNUSED __attribute__ ( ( unused ) )
25 #else
26 #define UNUSED
27 #endif
28 #endif
30 #include "bencode.h"
31 #include "bitfield.h"
32 #include "utils.h"
34 typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
36 uint8_t* tr_peerIdNew( void );
38 const uint8_t* tr_getPeerId( void );
40 struct event_base;
41 struct tr_address;
42 struct tr_announcer;
43 struct tr_bandwidth;
44 struct tr_bindsockets;
45 struct tr_cache;
46 struct tr_fdInfo;
48 typedef void ( tr_web_config_func )( tr_session * session, void * curl_pointer, const char * url );
50 struct tr_turtle_info
52 /* TR_UP and TR_DOWN speed limits */
53 int speedLimit_Bps[2];
55 /* is turtle mode on right now? */
56 tr_bool isEnabled;
58 /* does turtle mode turn itself on and off at given times? */
59 tr_bool isClockEnabled;
61 /* when clock mode is on, minutes after midnight to turn on turtle mode */
62 int beginMinute;
64 /* when clock mode is on, minutes after midnight to turn off turtle mode */
65 int endMinute;
67 /* only use clock mode on these days of the week */
68 tr_sched_day days;
70 /* called when isEnabled changes */
71 tr_altSpeedFunc * callback;
73 /* the callback's user_data argument */
74 void * callbackUserData;
76 /* the callback's changedByUser argument.
77 * indicates whether the change came from the user or from the clock. */
78 tr_bool changedByUser;
80 /* bitfield of all the minutes in a week.
81 * Each bit's value indicates whether the scheduler wants turtle
82 * limits on or off at that given minute in the week. */
83 tr_bitfield minutes;
86 /** @brief handle to an active libtransmission session */
87 struct tr_session
89 tr_bool isPortRandom;
90 tr_bool isPexEnabled;
91 tr_bool isDHTEnabled;
92 tr_bool isLPDEnabled;
93 tr_bool isBlocklistEnabled;
94 tr_bool isPrefetchEnabled;
95 tr_bool isTorrentDoneScriptEnabled;
96 tr_bool isClosed;
97 tr_bool useLazyBitfield;
98 tr_bool isIncompleteFileNamingEnabled;
99 tr_bool isRatioLimited;
100 tr_bool isIdleLimited;
101 tr_bool isIncompleteDirEnabled;
102 tr_bool pauseAddedTorrent;
103 tr_bool deleteSourceTorrent;
105 tr_benc removedTorrents;
107 int umask;
109 int speedLimit_Bps[2];
110 tr_bool speedLimitEnabled[2];
112 struct tr_turtle_info turtle;
114 struct tr_fdInfo * fdInfo;
116 int magicNumber;
118 tr_encryption_mode encryptionMode;
120 tr_preallocation_mode preallocationMode;
122 struct event_base * event_base;
123 struct tr_event_handle * events;
125 uint16_t peerLimitPerTorrent;
127 int uploadSlotsPerTorrent;
129 /* The UDP sockets used for the DHT and uTP. */
130 tr_port udp_port;
131 int udp_socket;
132 int udp6_socket;
133 unsigned char * udp6_bound;
134 struct event *udp_event;
135 struct event *udp6_event;
137 /* The open port on the local machine for incoming peer requests */
138 tr_port private_peer_port;
141 * The open port on the public device for incoming peer requests.
142 * This is usually the same as private_peer_port but can differ
143 * if the public device is a router and it decides to use a different
144 * port than the one requested by Transmission.
146 tr_port public_peer_port;
148 tr_port randomPortLow;
149 tr_port randomPortHigh;
151 int peerSocketTOS;
152 char * peer_congestion_algorithm;
154 int torrentCount;
155 tr_torrent * torrentList;
157 char * torrentDoneScript;
159 char * tag;
160 char * configDir;
161 char * downloadDir;
162 char * resumeDir;
163 char * torrentDir;
164 char * incompleteDir;
166 char * blocklist_url;
168 struct tr_list * blocklists;
169 struct tr_peerMgr * peerMgr;
170 struct tr_shared * shared;
172 struct tr_cache * cache;
174 struct tr_lock * lock;
176 struct tr_web * web;
178 struct tr_rpc_server * rpcServer;
179 tr_rpc_func rpc_func;
180 void * rpc_func_user_data;
182 struct tr_stats_handle * sessionStats;
184 struct tr_announcer * announcer;
186 tr_benc * metainfoLookup;
188 struct event * nowTimer;
189 struct event * saveTimer;
191 /* monitors the "global pool" speeds */
192 struct tr_bandwidth * bandwidth;
194 double desiredRatio;
196 uint16_t idleLimitMinutes;
198 struct tr_bindinfo * public_ipv4;
199 struct tr_bindinfo * public_ipv6;
201 /* a page-aligned buffer for use by the libtransmission thread.
202 * @see SESSION_BUFFER_SIZE */
203 void * buffer;
205 tr_bool bufferInUse;
207 tr_web_config_func * curl_easy_config_func;
210 static inline tr_port
211 tr_sessionGetPublicPeerPort( const tr_session * session )
213 return session->public_peer_port;
216 tr_bool tr_sessionAllowsDHT( const tr_session * session );
218 tr_bool tr_sessionAllowsLPD( const tr_session * session );
220 const char * tr_sessionFindTorrentFile( const tr_session * session,
221 const char * hashString );
223 void tr_sessionSetTorrentFile( tr_session * session,
224 const char * hashString,
225 const char * filename );
227 tr_bool tr_sessionIsAddressBlocked( const tr_session * session,
228 const struct tr_address * addr );
230 void tr_sessionLock( tr_session * );
232 void tr_sessionUnlock( tr_session * );
234 tr_bool tr_sessionIsLocked( const tr_session * );
236 const struct tr_address* tr_sessionGetPublicAddress( const tr_session * session,
237 int tr_af_type,
238 tr_bool * is_default_value );
241 struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * );
243 int tr_sessionCountTorrents( const tr_session * session );
245 enum
247 SESSION_MAGIC_NUMBER = 3845,
249 /* @see tr_session.buffer */
250 SESSION_BUFFER_SIZE = (16*1024)
253 void* tr_sessionGetBuffer( tr_session * session );
255 void tr_sessionReleaseBuffer( tr_session * session );
257 static inline tr_bool tr_isSession( const tr_session * session )
259 return ( session != NULL ) && ( session->magicNumber == SESSION_MAGIC_NUMBER );
262 static inline tr_bool tr_isPreallocationMode( tr_preallocation_mode m )
264 return ( m == TR_PREALLOCATE_NONE )
265 || ( m == TR_PREALLOCATE_SPARSE )
266 || ( m == TR_PREALLOCATE_FULL );
269 static inline tr_bool tr_isEncryptionMode( tr_encryption_mode m )
271 return ( m == TR_CLEAR_PREFERRED )
272 || ( m == TR_ENCRYPTION_PREFERRED )
273 || ( m == TR_ENCRYPTION_REQUIRED );
276 static inline tr_bool tr_isPriority( tr_priority_t p )
278 return ( p == TR_PRI_LOW )
279 || ( p == TR_PRI_NORMAL )
280 || ( p == TR_PRI_HIGH );
283 /***
284 ****
285 ***/
287 static inline unsigned int toSpeedBytes ( unsigned int KBps ) { return KBps * tr_speed_K; }
288 static inline double toSpeedKBps ( unsigned int Bps ) { return Bps / (double)tr_speed_K; }
290 static inline uint64_t toMemBytes ( unsigned int MB ) { uint64_t B = tr_mem_K * tr_mem_K; B *= MB; return B; }
291 static inline int toMemMB ( uint64_t B ) { return B / ( tr_mem_K * tr_mem_K ); }
296 int tr_sessionGetSpeedLimit_Bps( const tr_session *, tr_direction );
297 int tr_sessionGetAltSpeed_Bps ( const tr_session *, tr_direction );
298 int tr_sessionGetRawSpeed_Bps ( const tr_session *, tr_direction );
299 int tr_sessionGetPieceSpeed_Bps( const tr_session *, tr_direction );
301 void tr_sessionSetSpeedLimit_Bps( tr_session *, tr_direction, int Bps );
302 void tr_sessionSetAltSpeed_Bps ( tr_session *, tr_direction, int Bps );
304 tr_bool tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session,
305 tr_direction dir,
306 int * setme );
308 #endif