source: trunk/libtransmission/session.h @ 11368

Last change on this file since 11368 was 11368, checked in by charles, 11 years ago

(trunk) #3697 "make blocklist URL configurable" -- implemented in GTK+, Qt, and RPC

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