source: trunk/libtransmission/session.h @ 10352

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

(trunk libT) #3026 "Recent T doesn't honor weekend speed limit setting" -- fixed in trunk for 2.00

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