source: trunk/libtransmission/session.h @ 12514

Last change on this file since 12514 was 12514, checked in by jordan, 10 years ago

(trunk libt) #4315 "Transmission 2.31 crashes (segfaults) immediately after launch" -- remove the "max-open-files" code.

max-open-files might have been a nice configuration option once, but (1) we've never advertised it in the gui apps, and (2) the crazy cases are causing more trouble than this feature is worth. It's more complicated now after #4164 -- see #4294, #4311, and this ticket.

  • Property svn:keywords set to Date Rev Author Id
File size: 9.2 KB
Line 
1/*
2 * This file Copyright (C) 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 12514 2011-06-24 22:39:20Z jordan $
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 "bandwidth.h"
31#include "bencode.h"
32#include "bitfield.h"
33#include "utils.h"
34
35typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
36
37enum
38{
39  PEER_ID_LEN = 20
40};
41
42void tr_peerIdInit( uint8_t * setme );
43
44struct event_base;
45struct evdns_base;
46
47struct tr_address;
48struct tr_announcer;
49struct tr_announcer_udp;
50struct tr_bindsockets;
51struct tr_cache;
52struct tr_fdInfo;
53
54typedef void ( tr_web_config_func )( tr_session * session, void * curl_pointer, const char * url, void * user_data );
55
56struct tr_turtle_info
57{
58    /* TR_UP and TR_DOWN speed limits */
59    int speedLimit_Bps[2];
60
61    /* is turtle mode on right now? */
62    bool isEnabled;
63
64    /* does turtle mode turn itself on and off at given times? */
65    bool isClockEnabled;
66
67    /* when clock mode is on, minutes after midnight to turn on turtle mode */
68    int beginMinute;
69
70    /* when clock mode is on, minutes after midnight to turn off turtle mode */
71    int endMinute;
72
73    /* only use clock mode on these days of the week */
74    tr_sched_day days;
75
76    /* called when isEnabled changes */
77    tr_altSpeedFunc * callback;
78
79    /* the callback's user_data argument */
80    void * callbackUserData;
81
82    /* the callback's changedByUser argument.
83     * indicates whether the change came from the user or from the clock. */
84    bool changedByUser;
85
86    /* bitfield of all the minutes in a week.
87     * Each bit's value indicates whether the scheduler wants turtle
88     * limits on or off at that given minute in the week. */
89    tr_bitfield minutes;
90};
91
92/** @brief handle to an active libtransmission session */
93struct tr_session
94{
95    bool                         isPortRandom;
96    bool                         isPexEnabled;
97    bool                         isDHTEnabled;
98    bool                         isUTPEnabled;
99    bool                         isLPDEnabled;
100    bool                         isBlocklistEnabled;
101    bool                         isPrefetchEnabled;
102    bool                         isTorrentDoneScriptEnabled;
103    bool                         isClosed;
104    bool                         isIncompleteFileNamingEnabled;
105    bool                         isRatioLimited;
106    bool                         isIdleLimited;
107    bool                         isIncompleteDirEnabled;
108    bool                         pauseAddedTorrent;
109    bool                         deleteSourceTorrent;
110
111    tr_benc                      removedTorrents;
112
113    int                          umask;
114
115    int                          speedLimit_Bps[2];
116    bool                         speedLimitEnabled[2];
117
118    struct tr_turtle_info        turtle;
119
120    struct tr_fdInfo           * fdInfo;
121
122    int                          magicNumber;
123
124    tr_encryption_mode           encryptionMode;
125
126    tr_preallocation_mode        preallocationMode;
127
128    struct event_base          * event_base;
129    struct evdns_base          * evdns_base;
130    struct tr_event_handle     * events;
131
132    uint16_t                     peerLimit;
133    uint16_t                     peerLimitPerTorrent;
134
135    int                          uploadSlotsPerTorrent;
136
137    /* The UDP sockets used for the DHT and uTP. */
138    tr_port                      udp_port;
139    int                          udp_socket;
140    int                          udp6_socket;
141    unsigned char *              udp6_bound;
142    struct event                 *udp_event;
143    struct event                 *udp6_event;
144
145    /* The open port on the local machine for incoming peer requests */
146    tr_port                      private_peer_port;
147
148    /**
149     * The open port on the public device for incoming peer requests.
150     * This is usually the same as private_peer_port but can differ
151     * if the public device is a router and it decides to use a different
152     * port than the one requested by Transmission.
153     */
154    tr_port                      public_peer_port;
155
156    tr_port                      randomPortLow;
157    tr_port                      randomPortHigh;
158
159    int                          peerSocketTOS;
160    char *                       peer_congestion_algorithm;
161
162    int                          torrentCount;
163    tr_torrent *                 torrentList;
164
165    char *                       torrentDoneScript;
166
167    char *                       tag;
168    char *                       configDir;
169    char *                       downloadDir;
170    char *                       resumeDir;
171    char *                       torrentDir;
172    char *                       incompleteDir;
173
174    char *                       blocklist_url;
175
176    struct tr_list *             blocklists;
177    struct tr_peerMgr *          peerMgr;
178    struct tr_shared *           shared;
179
180    struct tr_cache *            cache;
181
182    struct tr_lock *             lock;
183
184    struct tr_web *              web;
185
186    struct tr_rpc_server *       rpcServer;
187    tr_rpc_func                  rpc_func;
188    void *                       rpc_func_user_data;
189
190    struct tr_stats_handle     * sessionStats;
191
192    struct tr_announcer        * announcer;
193    struct tr_announcer_udp    * announcer_udp;
194
195    tr_benc                    * metainfoLookup;
196
197    struct event               * nowTimer;
198    struct event               * saveTimer;
199
200    /* monitors the "global pool" speeds */
201    struct tr_bandwidth          bandwidth;
202
203    float                        desiredRatio;
204
205    uint16_t                     idleLimitMinutes;
206
207    struct tr_bindinfo         * public_ipv4;
208    struct tr_bindinfo         * public_ipv6;
209
210    uint8_t peer_id[PEER_ID_LEN+1];
211};
212
213static inline tr_port
214tr_sessionGetPublicPeerPort( const tr_session * session )
215{
216    return session->public_peer_port;
217}
218
219static inline const uint8_t*
220tr_getPeerId( tr_session * session )
221{
222    return session->peer_id;
223}
224
225bool         tr_sessionAllowsDHT( const tr_session * session );
226
227bool         tr_sessionAllowsLPD( const tr_session * session );
228
229const char * tr_sessionFindTorrentFile( const tr_session * session,
230                                        const char *       hashString );
231
232void         tr_sessionSetTorrentFile( tr_session * session,
233                                       const char * hashString,
234                                       const char * filename );
235
236bool         tr_sessionIsAddressBlocked( const tr_session        * session,
237                                         const struct tr_address * addr );
238
239void         tr_sessionLock( tr_session * );
240
241void         tr_sessionUnlock( tr_session * );
242
243bool         tr_sessionIsLocked( const tr_session * );
244
245const struct tr_address*  tr_sessionGetPublicAddress( const tr_session  * session,
246                                                      int                 tr_af_type,
247                                                      bool              * is_default_value );
248
249
250struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * );
251
252int tr_sessionCountTorrents( const tr_session * session );
253
254enum
255{
256    SESSION_MAGIC_NUMBER = 3845,
257};
258
259static inline bool tr_isSession( const tr_session * session )
260{
261    return ( session != NULL ) && ( session->magicNumber == SESSION_MAGIC_NUMBER );
262}
263
264static inline bool tr_isPreallocationMode( tr_preallocation_mode m  )
265{
266    return ( m == TR_PREALLOCATE_NONE )
267        || ( m == TR_PREALLOCATE_SPARSE )
268        || ( m == TR_PREALLOCATE_FULL );
269}
270
271static inline bool tr_isEncryptionMode( tr_encryption_mode m )
272{
273    return ( m == TR_CLEAR_PREFERRED )
274        || ( m == TR_ENCRYPTION_PREFERRED )
275        || ( m == TR_ENCRYPTION_REQUIRED );
276}
277
278static inline bool tr_isPriority( tr_priority_t p )
279{
280    return ( p == TR_PRI_LOW )
281        || ( p == TR_PRI_NORMAL )
282        || ( p == TR_PRI_HIGH );
283}
284
285/***
286****
287***/
288
289static inline unsigned int toSpeedBytes ( unsigned int KBps ) { return KBps * tr_speed_K; }
290static inline double       toSpeedKBps  ( unsigned int Bps )  { return Bps / (double)tr_speed_K; }
291
292static inline uint64_t toMemBytes ( unsigned int MB ) { uint64_t B = tr_mem_K * tr_mem_K; B *= MB; return B; }
293static inline int      toMemMB    ( uint64_t B )      { return B / ( tr_mem_K * tr_mem_K ); }
294
295/**
296**/
297
298int  tr_sessionGetSpeedLimit_Bps( const tr_session *, tr_direction );
299int  tr_sessionGetAltSpeed_Bps  ( const tr_session *, tr_direction );
300int  tr_sessionGetRawSpeed_Bps  ( const tr_session *, tr_direction );
301int  tr_sessionGetPieceSpeed_Bps( const tr_session *, tr_direction );
302
303void tr_sessionSetSpeedLimit_Bps( tr_session *, tr_direction, int Bps );
304void tr_sessionSetAltSpeed_Bps  ( tr_session *, tr_direction, int Bps );
305
306bool  tr_sessionGetActiveSpeedLimit_Bps( const tr_session  * session,
307                                         tr_direction        dir,
308                                         int               * setme );
309
310#endif
Note: See TracBrowser for help on using the repository browser.