source: trunk/libtransmission/internal.h @ 920

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

Merge nat-traversal branch to trunk.

  • Property svn:keywords set to Date Rev Author Id
File size: 5.8 KB
Line 
1/******************************************************************************
2 * $Id: internal.h 920 2006-09-25 18:37:45Z joshe $
3 *
4 * Copyright (c) 2005-2006 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#include <stdlib.h>
37#include <string.h>
38#include <unistd.h>
39#include <errno.h>
40#include <limits.h>
41#include <signal.h>
42#include <time.h>
43#include <sys/time.h>
44#include <sys/types.h>
45#include <sys/stat.h>
46#ifndef __AMIGAOS4__
47#include <sys/resource.h>
48#endif
49#include <netdb.h>
50#include <sys/socket.h>
51#include <netinet/in.h>
52#include <fcntl.h>
53#include <assert.h>
54#ifdef BEOS_NETSERVER
55#  define in_port_t uint16_t
56#  define socklen_t uint32_t
57#else
58#  include <arpa/inet.h>
59#endif
60
61#ifndef INADDR_NONE
62#define INADDR_NONE             0xffffffff
63#endif
64
65#ifdef __GNUC__
66#  define UNUSED __attribute__((unused))
67#  define PRINTF( fmt, args ) __attribute__((format (printf, fmt, args)))
68#else
69#  define UNUSED
70#  define PRINTF( fmt, args )
71#endif
72
73/* We use OpenSSL whenever possible, since it is likely to be more
74   optimized and it is ok to use it with a MIT-licensed application.
75   Otherwise, we use the included implementation by vi@nwr.jp. */
76#ifdef HAVE_OPENSSL
77#  undef SHA_DIGEST_LENGTH
78#  include <openssl/sha.h>
79#else
80#  include "sha1.h"
81#  define SHA1(p,i,h) \
82   { \
83     sha1_state_s pms; \
84     sha1_init( &pms ); \
85     sha1_update( &pms, (sha1_byte_t *) p, i ); \
86     sha1_finish( &pms, (sha1_byte_t *) h ); \
87   }
88#endif
89
90/* Convenient macros to perform uint32_t endian conversions with
91   char pointers */
92#define TR_NTOHL(p,a) (a) = tr_ntohl((p))
93#define TR_HTONL(a,p) tr_htonl((a), (p))
94static inline uint32_t tr_ntohl( uint8_t * p )
95{
96        uint32_t u;
97        memcpy( &u, p, sizeof( uint32_t ) );
98        return ntohl( u );
99}
100static inline void tr_htonl( uint32_t a, uint8_t * p )
101{
102        uint32_t u;
103        u = htonl( a );
104        memcpy ( p, &u, sizeof( uint32_t ) );
105}
106
107/* Sometimes the system defines MAX/MIN, sometimes not. In the latter
108   case, define those here since we will use them */
109#ifndef MAX
110#define MAX(a,b) ((a)>(b)?(a):(b))
111#endif
112#ifndef MIN
113#define MIN(a,b) ((a)>(b)?(b):(a))
114#endif
115
116#define TR_MAX_PEER_COUNT 60
117
118typedef struct tr_completion_s tr_completion_t;
119
120typedef enum { TR_OK, TR_ERROR, TR_WAIT } tr_tristate_t;
121
122#include "platform.h"
123#include "bencode.h"
124#include "metainfo.h"
125#include "tracker.h"
126#include "fdlimit.h"
127#include "peer.h"
128#include "net.h"
129#include "inout.h"
130#include "ratecontrol.h"
131#include "clients.h"
132#include "choking.h"
133#include "natpmp.h"
134#include "upnp.h"
135#include "http.h"
136#include "xml.h"
137
138struct tr_torrent_s
139{
140    tr_info_t info;
141
142    tr_ratecontrol_t * globalUpload;
143    tr_ratecontrol_t * globalDownload;
144    tr_ratecontrol_t * upload;
145    tr_ratecontrol_t * download;
146    tr_ratecontrol_t * swarmspeed;
147    tr_fd_t          * fdlimit;
148
149    int               status;
150    int               error;
151    char              trackerError[128];
152    int               finished;
153
154    char            * id;
155    char            * key;
156    int             * bindPort;
157
158    /* An escaped string used to include the hash in HTTP queries */
159    char              hashString[3*SHA_DIGEST_LENGTH+1];
160
161    char              scrape[MAX_PATH_LENGTH];
162
163    /* Where to download */
164    char            * destination;
165   
166    /* How many bytes we ask for per request */
167    int               blockSize;
168    int               blockCount;
169   
170    tr_completion_t * completion;
171
172    volatile char     die;
173    tr_thread_t       thread;
174    tr_lock_t         lock;
175
176    tr_tracker_t    * tracker;
177    tr_io_t         * io;
178    uint64_t          stopDate;
179
180    int               peerCount;
181    tr_peer_t       * peers[TR_MAX_PEER_COUNT];
182
183    uint64_t          date;
184    uint64_t          downloaded;
185    uint64_t          uploaded;
186
187    tr_stat_t         stats[2];
188    int               statCur;
189
190    tr_torrent_t    * prev;
191    tr_torrent_t    * next;
192};
193
194#include "utils.h"
195#include "completion.h"
196
197struct tr_handle_s
198{
199    int            torrentCount;
200    tr_torrent_t * torrentList;
201
202    tr_ratecontrol_t * upload;
203    tr_ratecontrol_t * download;
204    tr_fd_t      * fdlimit;
205    tr_choking_t * choking;
206    tr_natpmp_t  * natpmp;
207    tr_upnp_t    * upnp;
208
209    int            bindPort;
210    int            bindSocket;
211
212    int            acceptPeerCount;
213    tr_peer_t    * acceptPeers[TR_MAX_PEER_COUNT];
214
215    char           id[21];
216    char           key[21];
217
218    volatile char  acceptDie;
219    tr_thread_t    acceptThread;
220    tr_lock_t      acceptLock;
221};
222
223#endif
Note: See TracBrowser for help on using the repository browser.