source: trunk/libtransmission/session.h @ 10635

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

(trunk) #3060 "Local Peer Discovery" -- in the code, rename LDS as LPD for Local Peer Discovery

  • Property svn:keywords set to Date Rev Author Id
File size: 6.9 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 10635 2010-05-08 08:42:45Z 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                      isLPDEnabled;
88    tr_bool                      isBlocklistEnabled;
89    tr_bool                      isProxyEnabled;
90    tr_bool                      isProxyAuthEnabled;
91    tr_bool                      isClosed;
92    tr_bool                      useLazyBitfield;
93    tr_bool                      isIncompleteFileNamingEnabled;
94    tr_bool                      isRatioLimited;
95    tr_bool                      isIncompleteDirEnabled;
96    tr_bool                      pauseAddedTorrent;
97    tr_bool                      deleteSourceTorrent;
98
99    tr_benc                      removedTorrents;
100
101    int                          umask;
102
103    int                          speedLimit[2];
104    tr_bool                      speedLimitEnabled[2];
105
106    struct tr_turtle_info        turtle;
107
108    struct tr_fdInfo           * fdInfo;
109
110    int                          magicNumber;
111
112    tr_encryption_mode           encryptionMode;
113
114    tr_preallocation_mode        preallocationMode;
115
116    struct tr_event_handle *     events;
117
118    uint16_t                     peerLimitPerTorrent;
119
120    int                          uploadSlotsPerTorrent;
121
122    tr_port                      peerPort;
123    tr_port                      randomPortLow;
124    tr_port                      randomPortHigh;
125
126    int                          proxyPort;
127    int                          peerSocketTOS;
128    char *                       peer_congestion_algorithm;
129
130    int                          torrentCount;
131    tr_torrent *                 torrentList;
132
133    char *                       tag;
134    char *                       configDir;
135    char *                       downloadDir;
136    char *                       resumeDir;
137    char *                       torrentDir;
138    char *                       incompleteDir;
139
140    tr_proxy_type                proxyType;
141    char *                       proxy;
142    char *                       proxyUsername;
143    char *                       proxyPassword;
144
145    struct tr_list *             blocklists;
146    struct tr_peerMgr *          peerMgr;
147    struct tr_shared *           shared;
148
149    struct tr_lock *             lock;
150
151    struct tr_web *              web;
152
153    struct tr_rpc_server *       rpcServer;
154    tr_rpc_func                  rpc_func;
155    void *                       rpc_func_user_data;
156
157    struct tr_stats_handle     * sessionStats;
158
159    struct tr_announcer        * announcer;
160
161    tr_benc                    * metainfoLookup;
162
163    struct event               * nowTimer;
164    struct event               * saveTimer;
165
166    /* monitors the "global pool" speeds */
167    struct tr_bandwidth        * bandwidth;
168
169    double                       desiredRatio;
170
171    struct tr_bindinfo         * public_ipv4;
172    struct tr_bindinfo         * public_ipv6;
173
174    /* a page-aligned buffer for use by the libtransmission thread.
175     * @see SESSION_BUFFER_SIZE */
176    void * buffer;
177
178    tr_bool bufferInUse;
179};
180
181tr_bool      tr_sessionAllowsDHT( const tr_session * session );
182
183tr_bool      tr_sessionAllowsLPD( const tr_session * session );
184
185const char * tr_sessionFindTorrentFile( const tr_session * session,
186                                        const char *       hashString );
187
188void         tr_sessionSetTorrentFile( tr_session * session,
189                                       const char * hashString,
190                                       const char * filename );
191
192tr_bool      tr_sessionIsAddressBlocked( const tr_session        * session,
193                                         const struct tr_address * addr );
194
195void         tr_sessionLock( tr_session * );
196
197void         tr_sessionUnlock( tr_session * );
198
199tr_bool      tr_sessionIsLocked( const tr_session * );
200
201const struct tr_address*  tr_sessionGetPublicAddress( const tr_session *, int tr_af_type );
202
203struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * );
204
205int tr_sessionCountTorrents( const tr_session * session ); 
206
207enum
208{
209    SESSION_MAGIC_NUMBER = 3845,
210
211    /* @see tr_session.buffer */
212    SESSION_BUFFER_SIZE = (16*1024)
213};
214
215void* tr_sessionGetBuffer( tr_session * session );
216
217void tr_sessionReleaseBuffer( tr_session * session );
218
219static inline tr_bool tr_isSession( const tr_session * session )
220{
221    return ( session != NULL ) && ( session->magicNumber == SESSION_MAGIC_NUMBER );
222}
223
224static inline tr_bool tr_isPreallocationMode( tr_preallocation_mode m  )
225{
226    return ( m == TR_PREALLOCATE_NONE )
227        || ( m == TR_PREALLOCATE_SPARSE )
228        || ( m == TR_PREALLOCATE_FULL );
229}
230
231static inline tr_bool tr_isEncryptionMode( tr_encryption_mode m )
232{
233    return ( m == TR_CLEAR_PREFERRED )
234        || ( m == TR_ENCRYPTION_PREFERRED )
235        || ( m == TR_ENCRYPTION_REQUIRED );
236}
237
238static inline tr_bool tr_isPriority( tr_priority_t p )
239{
240    return ( p == TR_PRI_LOW )
241        || ( p == TR_PRI_NORMAL )
242        || ( p == TR_PRI_HIGH );
243}
244
245#endif
Note: See TracBrowser for help on using the repository browser.