source: branches/daemon/libtransmission/internal.h @ 1712

Last change on this file since 1712 was 1712, checked in by joshe, 15 years ago

Merge libT revs 1616:1711 from trunk to daemon branch.

  • Property svn:keywords set to Date Rev Author Id
File size: 6.4 KB
Line 
1/******************************************************************************
2 * $Id: internal.h 1712 2007-04-14 06:34:52Z joshe $
3 *
4 * Copyright (c) 2005-2007 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#ifndef TR_INTERNAL_H
26#define TR_INTERNAL_H 1
27
28/* Standard headers used here and there.
29   That is probably ugly to put them all here, but it is sooo
30   convenient */
31#if ( defined( __unix__ ) || defined( unix ) ) && !defined( USG )
32#include <sys/param.h>
33#endif
34#include <stdio.h>
35#include <stdarg.h>
36#ifdef SYS_BEOS
37/* BeOS doesn't declare vasprintf in its headers, but actually
38 * implements it */
39int vasprintf( char **, const char *, va_list );
40#endif
41#include <stdlib.h>
42#include <string.h>
43#include <unistd.h>
44#include <ctype.h>
45#include <errno.h>
46#include <limits.h>
47#include <signal.h>
48#include <time.h>
49#include <sys/time.h>
50#include <sys/types.h>
51#include <sys/stat.h>
52#ifndef __AMIGAOS4__
53#include <sys/resource.h>
54#endif
55#include <netdb.h>
56#include <sys/socket.h>
57#include <netinet/in.h>
58#include <fcntl.h>
59#include <assert.h>
60#ifdef SYS_BEOS
61#  define socklen_t uint32_t
62#endif
63#ifdef BEOS_NETSERVER
64#  define in_port_t uint16_t
65#else
66#  include <arpa/inet.h>
67#endif
68
69#define TR_NAME                 "Transmission"
70
71#ifndef INADDR_NONE
72#define INADDR_NONE             0xffffffff
73#endif
74
75#ifdef __GNUC__
76#  define UNUSED __attribute__((unused))
77#  define PRINTF( fmt, args ) __attribute__((format (printf, fmt, args)))
78#else
79#  define UNUSED
80#  define PRINTF( fmt, args )
81#endif
82
83/* We use OpenSSL whenever possible, since it is likely to be more
84   optimized and it is ok to use it with a MIT-licensed application.
85   Otherwise, we use the included implementation by vi@nwr.jp. */
86#ifdef HAVE_OPENSSL
87#  undef SHA_DIGEST_LENGTH
88#  include <openssl/sha.h>
89#else
90#  include "sha1.h"
91#  define SHA1(p,i,h) \
92   { \
93     sha1_state_s pms; \
94     sha1_init( &pms ); \
95     sha1_update( &pms, (sha1_byte_t *) p, i ); \
96     sha1_finish( &pms, (sha1_byte_t *) h ); \
97   }
98#endif
99
100/* Convenient macros to perform uint32_t endian conversions with
101   char pointers */
102#define TR_NTOHL(p,a) (a) = tr_ntohl((p))
103#define TR_HTONL(a,p) tr_htonl((a), ( uint8_t * )(p))
104static inline uint32_t tr_ntohl( uint8_t * p )
105{
106        uint32_t u;
107        memcpy( &u, p, sizeof( uint32_t ) );
108        return ntohl( u );
109}
110static inline void tr_htonl( uint32_t a, uint8_t * p )
111{
112        uint32_t u;
113        u = htonl( a );
114        memcpy ( p, &u, sizeof( uint32_t ) );
115}
116
117/* Sometimes the system defines MAX/MIN, sometimes not. In the latter
118   case, define those here since we will use them */
119#ifndef MAX
120#define MAX(a,b) ((a)>(b)?(a):(b))
121#endif
122#ifndef MIN
123#define MIN(a,b) ((a)>(b)?(b):(a))
124#endif
125
126#define TR_MAX_PEER_COUNT 60
127
128typedef struct tr_completion_s tr_completion_t;
129typedef struct tr_shared_s tr_shared_t;
130typedef struct tr_bitfield_s tr_bitfield_t;
131
132typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
133
134#include "trcompat.h"
135#include "bsdqueue.h"
136#include "bsdtree.h"
137#include "platform.h"
138#include "bencode.h"
139#include "metainfo.h"
140#include "tracker.h"
141#include "fdlimit.h"
142#include "peer.h"
143#include "net.h"
144#include "inout.h"
145#include "ratecontrol.h"
146#include "clients.h"
147#include "choking.h"
148#include "natpmp.h"
149#include "upnp.h"
150#include "http.h"
151#include "xml.h"
152
153int tr_torrentAddCompact( tr_torrent_t * tor, int from,
154                           uint8_t * buf, int count );
155int tr_torrentAttachPeer( tr_torrent_t * tor, tr_peer_t * peer );
156
157struct tr_torrent_s
158{
159    tr_handle_t * handle;
160    tr_info_t info;
161
162    int                customUploadLimit;
163    int                customDownloadLimit;
164    tr_ratecontrol_t * upload;
165    tr_ratecontrol_t * download;
166    tr_ratecontrol_t * swarmspeed;
167
168    int               status;
169    int               error;
170    char              errorString[128];
171    int               finished;
172
173    char            * id;
174    char            * key;
175    uint8_t         * azId;
176    int               publicPort;
177
178    /* An escaped string used to include the hash in HTTP queries */
179    char              escapedHashString[3*SHA_DIGEST_LENGTH+1];
180
181    /* Where to download */
182    char            * destination;
183   
184    /* How many bytes we ask for per request */
185    int               blockSize;
186    int               blockCount;
187   
188    tr_completion_t * completion;
189
190    volatile char     die;
191    tr_thread_t       thread;
192    tr_lock_t         lock;
193    tr_cond_t         cond;
194
195    tr_tracker_t    * tracker;
196    tr_io_t         * io;
197    uint64_t          stopDate;
198
199    int               peerCount;
200    tr_peer_t       * peers[TR_MAX_PEER_COUNT];
201
202    uint64_t          date;
203    uint64_t          downloadedCur;
204    uint64_t          downloadedPrev;
205    uint64_t          uploadedCur;
206    uint64_t          uploadedPrev;
207
208    uint8_t           pexDisabled;
209
210    tr_stat_t         stats[2];
211    int               statCur;
212
213    tr_torrent_t    * prev;
214    tr_torrent_t    * next;
215};
216
217#include "utils.h"
218#include "completion.h"
219
220struct tr_handle_s
221{
222    int            torrentCount;
223    tr_torrent_t * torrentList;
224
225    char         * tag;
226    int            isPortSet;
227    int            uploadLimit;
228    int            downloadLimit;
229    tr_shared_t  * shared;
230
231#define TR_ID_LEN               20
232    char           id[TR_ID_LEN+1];
233#define TR_KEY_LEN              20
234    char           key[TR_KEY_LEN+1];
235
236    tr_handle_status_t stats[2];
237    int                statCur;
238#define TR_AZ_ID_LEN            20
239    uint8_t        azId[TR_AZ_ID_LEN];
240};
241
242#endif
Note: See TracBrowser for help on using the repository browser.