source: trunk/libtransmission/session.h @ 11599

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

(trunk) Join the 21st century and use only 1 space at the end sentences. This commit is nearly as important as the semi-annual ones that remove trailing spaces from the ends of lines of code... :)

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