source: trunk/libtransmission/session.h @ 10798

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

(trunk) #1521 "memory cache to reduce disk IO" -- commit block-cache-rc1.diff to trunk for the nightlies.

  • Property svn:keywords set to Date Rev Author Id
File size: 7.1 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 10798 2010-06-19 14:25:11Z 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_cache;
44struct tr_fdInfo;
45
46struct tr_turtle_info
47{
48    /* TR_UP and TR_DOWN speed limits */
49    int speedLimit[2];
50
51    /* is turtle mode on right now? */
52    tr_bool isEnabled;
53
54    /* does turtle mode turn itself on and off at given times? */
55    tr_bool isClockEnabled;
56
57    /* when clock mode is on, minutes after midnight to turn on turtle mode */
58    int beginMinute;
59
60    /* when clock mode is on, minutes after midnight to turn off turtle mode */
61    int endMinute;
62
63    /* only use clock mode on these days of the week */
64    tr_sched_day days;
65
66    /* called when isEnabled changes */
67    tr_altSpeedFunc * callback;
68
69    /* the callback's user_data argument */
70    void * callbackUserData;
71
72    /* the callback's changedByUser argument.
73     * indicates whether the change came from the user or from the clock. */
74    tr_bool changedByUser;
75
76    /* bitfield of all the minutes in a week.
77     * Each bit's value indicates whether the scheduler wants turtle
78     * limits on or off at that given minute in the week. */
79    tr_bitfield minutes;
80};
81
82/** @brief handle to an active libtransmission session */
83struct tr_session
84{
85    tr_bool                      isPortRandom;
86    tr_bool                      isPexEnabled;
87    tr_bool                      isDHTEnabled;
88    tr_bool                      isLPDEnabled;
89    tr_bool                      isBlocklistEnabled;
90    tr_bool                      isProxyEnabled;
91    tr_bool                      isProxyAuthEnabled;
92    tr_bool                      isTorrentDoneScriptEnabled;
93    tr_bool                      isClosed;
94    tr_bool                      useLazyBitfield;
95    tr_bool                      isIncompleteFileNamingEnabled;
96    tr_bool                      isRatioLimited;
97    tr_bool                      isIncompleteDirEnabled;
98    tr_bool                      pauseAddedTorrent;
99    tr_bool                      deleteSourceTorrent;
100
101    tr_benc                      removedTorrents;
102
103    int                          umask;
104
105    int                          speedLimit[2];
106    tr_bool                      speedLimitEnabled[2];
107
108    struct tr_turtle_info        turtle;
109
110    struct tr_fdInfo           * fdInfo;
111
112    int                          magicNumber;
113
114    tr_encryption_mode           encryptionMode;
115
116    tr_preallocation_mode        preallocationMode;
117
118    struct tr_event_handle *     events;
119
120    uint16_t                     peerLimitPerTorrent;
121
122    int                          uploadSlotsPerTorrent;
123
124    tr_port                      peerPort;
125    tr_port                      randomPortLow;
126    tr_port                      randomPortHigh;
127
128    int                          proxyPort;
129    int                          peerSocketTOS;
130    char *                       peer_congestion_algorithm;
131
132    int                          torrentCount;
133    tr_torrent *                 torrentList;
134
135    char *                       torrentDoneScript;
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_cache *            cache;
154
155    struct tr_lock *             lock;
156
157    struct tr_web *              web;
158
159    struct tr_rpc_server *       rpcServer;
160    tr_rpc_func                  rpc_func;
161    void *                       rpc_func_user_data;
162
163    struct tr_stats_handle     * sessionStats;
164
165    struct tr_announcer        * announcer;
166
167    tr_benc                    * metainfoLookup;
168
169    struct event               * nowTimer;
170    struct event               * saveTimer;
171
172    /* monitors the "global pool" speeds */
173    struct tr_bandwidth        * bandwidth;
174
175    double                       desiredRatio;
176
177    struct tr_bindinfo         * public_ipv4;
178    struct tr_bindinfo         * public_ipv6;
179
180    /* a page-aligned buffer for use by the libtransmission thread.
181     * @see SESSION_BUFFER_SIZE */
182    void * buffer;
183
184    tr_bool bufferInUse;
185};
186
187tr_bool      tr_sessionAllowsDHT( const tr_session * session );
188
189tr_bool      tr_sessionAllowsLPD( const tr_session * session );
190
191const char * tr_sessionFindTorrentFile( const tr_session * session,
192                                        const char *       hashString );
193
194void         tr_sessionSetTorrentFile( tr_session * session,
195                                       const char * hashString,
196                                       const char * filename );
197
198tr_bool      tr_sessionIsAddressBlocked( const tr_session        * session,
199                                         const struct tr_address * addr );
200
201void         tr_sessionLock( tr_session * );
202
203void         tr_sessionUnlock( tr_session * );
204
205tr_bool      tr_sessionIsLocked( const tr_session * );
206
207const struct tr_address*  tr_sessionGetPublicAddress( const tr_session *, int tr_af_type );
208
209struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * );
210
211int tr_sessionCountTorrents( const tr_session * session ); 
212
213enum
214{
215    SESSION_MAGIC_NUMBER = 3845,
216
217    /* @see tr_session.buffer */
218    SESSION_BUFFER_SIZE = (16*1024)
219};
220
221void* tr_sessionGetBuffer( tr_session * session );
222
223void tr_sessionReleaseBuffer( tr_session * session );
224
225static inline tr_bool tr_isSession( const tr_session * session )
226{
227    return ( session != NULL ) && ( session->magicNumber == SESSION_MAGIC_NUMBER );
228}
229
230static inline tr_bool tr_isPreallocationMode( tr_preallocation_mode m  )
231{
232    return ( m == TR_PREALLOCATE_NONE )
233        || ( m == TR_PREALLOCATE_SPARSE )
234        || ( m == TR_PREALLOCATE_FULL );
235}
236
237static inline tr_bool tr_isEncryptionMode( tr_encryption_mode m )
238{
239    return ( m == TR_CLEAR_PREFERRED )
240        || ( m == TR_ENCRYPTION_PREFERRED )
241        || ( m == TR_ENCRYPTION_REQUIRED );
242}
243
244static inline tr_bool tr_isPriority( tr_priority_t p )
245{
246    return ( p == TR_PRI_LOW )
247        || ( p == TR_PRI_NORMAL )
248        || ( p == TR_PRI_HIGH );
249}
250
251#endif
Note: See TracBrowser for help on using the repository browser.