source: trunk/libtransmission/session.h @ 11512

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

(trunk) #3817 "use the OS' proxy support" -- implemented for libtransmission, transmission-gtk

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