source: trunk/libtransmission/session.h @ 10276

Last change on this file since 10276 was 10276, checked in by charles, 12 years ago

(trunk libT) use jch's suggestion of having a per-session page-aligned memory buffer for general reuse. (http://trac.transmissionbt.com/ticket/2551#comment:5)

  • Property svn:keywords set to Date Rev Author Id
File size: 7.3 KB
Line 
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 10276 2010-02-23 07:20:57Z 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
32typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
33
34uint8_t*       tr_peerIdNew( void );
35
36const uint8_t* tr_getPeerId( void );
37
38struct tr_address;
39struct tr_announcer;
40struct tr_bandwidth;
41struct tr_bindsockets;
42struct tr_fdInfo;
43
44/**
45 * How clock mode works:
46 *
47 * ._nextChangeAt, ._nextChangeValue and ._nextChangeAllowed are private fields
48 * that are derived from .days, .beginMinute, .endMinute and the current time.
49 * They're rebuilt when either (a) the user changes the clock settings or
50 * (b) when the time at ._nextChangeAt is reached.
51 *
52 * When ._nextChangeAt is reached, if .isClockEnabled and ._nextChangeAllowed
53 * are both true, then turtle mode's flag is set to ._nextChangeValue.
54 */
55struct tr_turtle_info
56{
57    /* TR_UP and TR_DOWN speed limits */
58    int speedLimit[2];
59
60    /* is turtle mode on right now? */
61    tr_bool isEnabled;
62
63    /* does turtle mode turn itself on and off at given times? */
64    tr_bool isClockEnabled;
65
66    /* when clock mode is on, minutes after midnight to turn on turtle mode */
67    int beginMinute;
68
69    /* when clock mode is on, minutes after midnight to turn off turtle mode */
70    int endMinute;
71
72    /* only use clock mode on these days of the week */
73    tr_sched_day days;
74
75    /* called when isEnabled changes */
76    tr_altSpeedFunc * callback;
77
78    /* the callback's user_data argument */
79    void * callbackUserData;
80
81    /* the callback's changedByUser argument.
82     * indicates whether the change came from the user or from the clock. */
83    tr_bool changedByUser;
84
85    /* this is the next time the clock will set turtle mode */
86    time_t _nextChangeAt;
87
88    /* the clock will set turtle mode to this flag. */
89    tr_bool _nextChangeValue;
90
91    /* When clock mode is on, only toggle turtle mode if this is true.
92     * This flag is used to filter out changes that fall on days when
93     * clock mode is disabled. */
94    tr_bool _nextChangeAllowed;
95
96    /* The last time the clock tested to see if _nextChangeAt was reached */
97    time_t testedAt;
98};
99
100/** @brief handle to an active libtransmission session */
101struct tr_session
102{
103    tr_bool                      isPortRandom;
104    tr_bool                      isPexEnabled;
105    tr_bool                      isDHTEnabled;
106    tr_bool                      isBlocklistEnabled;
107    tr_bool                      isProxyEnabled;
108    tr_bool                      isProxyAuthEnabled;
109    tr_bool                      isClosed;
110    tr_bool                      useLazyBitfield;
111    tr_bool                      isIncompleteFileNamingEnabled;
112    tr_bool                      isRatioLimited;
113    tr_bool                      isIncompleteDirEnabled;
114
115    tr_benc                      removedTorrents;
116
117    int                          umask;
118
119    int                          speedLimit[2];
120    tr_bool                      speedLimitEnabled[2];
121
122    struct tr_turtle_info        turtle;
123
124    struct tr_fdInfo           * fdInfo;
125
126    int                          magicNumber;
127
128    tr_encryption_mode           encryptionMode;
129
130    tr_preallocation_mode        preallocationMode;
131
132    struct tr_event_handle *     events;
133
134    uint16_t                     peerLimitPerTorrent;
135
136    int                          uploadSlotsPerTorrent;
137
138    tr_port                      peerPort;
139    tr_port                      randomPortLow;
140    tr_port                      randomPortHigh;
141
142    int                          proxyPort;
143    int                          peerSocketTOS;
144
145    int                          torrentCount;
146    tr_torrent *                 torrentList;
147
148    char *                       tag;
149    char *                       configDir;
150    char *                       downloadDir;
151    char *                       resumeDir;
152    char *                       torrentDir;
153    char *                       incompleteDir;
154
155    tr_proxy_type                proxyType;
156    char *                       proxy;
157    char *                       proxyUsername;
158    char *                       proxyPassword;
159
160    struct tr_list *             blocklists;
161    struct tr_peerMgr *          peerMgr;
162    struct tr_shared *           shared;
163
164    struct tr_lock *             lock;
165
166    struct tr_web *              web;
167
168    struct tr_rpc_server *       rpcServer;
169    tr_rpc_func                  rpc_func;
170    void *                       rpc_func_user_data;
171
172    struct tr_stats_handle     * sessionStats;
173
174    struct tr_announcer        * announcer;
175
176    tr_benc                    * metainfoLookup;
177
178    struct event               * nowTimer;
179    struct event               * saveTimer;
180
181    /* monitors the "global pool" speeds */
182    struct tr_bandwidth        * bandwidth;
183
184    double                       desiredRatio;
185
186    struct tr_bindinfo         * public_ipv4;
187    struct tr_bindinfo         * public_ipv6;
188
189    /* a page-aligned buffer for use by the libtransmission thread.
190     * @see SESSION_BUFFER_SIZE */
191    void * buffer;
192
193    tr_bool bufferInUse;
194};
195
196tr_bool      tr_sessionAllowsDHT( const tr_session * session );
197
198const char * tr_sessionFindTorrentFile( const tr_session * session,
199                                        const char *       hashString );
200
201void         tr_sessionSetTorrentFile( tr_session * session,
202                                       const char * hashString,
203                                       const char * filename );
204
205tr_bool      tr_sessionIsAddressBlocked( const tr_session        * session,
206                                         const struct tr_address * addr );
207
208void         tr_sessionLock( tr_session * );
209
210void         tr_sessionUnlock( tr_session * );
211
212tr_bool      tr_sessionIsLocked( const tr_session * );
213
214const struct tr_address*  tr_sessionGetPublicAddress( const tr_session *, int tr_af_type );
215
216struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * );
217
218enum
219{
220    SESSION_MAGIC_NUMBER = 3845,
221
222    /* @see tr_session.buffer */
223    SESSION_BUFFER_SIZE = (16*1024)
224};
225
226void* tr_sessionGetBuffer( tr_session * session );
227
228void tr_sessionReleaseBuffer( tr_session * session );
229
230static inline tr_bool tr_isSession( const tr_session * session )
231{
232    return ( session != NULL ) && ( session->magicNumber == SESSION_MAGIC_NUMBER );
233}
234
235static inline tr_bool tr_isPreallocationMode( tr_preallocation_mode m  )
236{
237    return ( m == TR_PREALLOCATE_NONE )
238        || ( m == TR_PREALLOCATE_SPARSE )
239        || ( m == TR_PREALLOCATE_FULL );
240}
241
242static inline tr_bool tr_isEncryptionMode( tr_encryption_mode m )
243{
244    return ( m == TR_CLEAR_PREFERRED )
245        || ( m == TR_ENCRYPTION_PREFERRED )
246        || ( m == TR_ENCRYPTION_REQUIRED );
247}
248
249static inline tr_bool tr_isPriority( tr_priority_t p )
250{
251    return ( p == TR_PRI_LOW )
252        || ( p == TR_PRI_NORMAL )
253        || ( p == TR_PRI_HIGH );
254}
255
256#endif
Note: See TracBrowser for help on using the repository browser.