source: trunk/libtransmission/session.h @ 10638

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

(trunk) #1796 "run script after torrent completion" -- implemented for libT, RPC, and the GTK+ and Qt clients

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