source: branches/1.9x/libtransmission/session.h @ 10593

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

(1.9x libT) backport r10352 and r10366 for #3026 "Speed Limit mode not honoring limits on other days"

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