source: branches/multitracker/libtransmission/internal.h @ 1154

Last change on this file since 1154 was 1154, checked in by livings124, 15 years ago

initial support for announce-list (currently crashes when a tracker fails)

  • Property svn:keywords set to Date Rev Author Id
File size: 5.8 KB
Line 
1/******************************************************************************
2 * $Id: internal.h 1154 2006-12-05 00:14:52Z livings124 $
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 SYS_BEOS
55#  define socklen_t uint32_t
56#endif
57#ifdef BEOS_NETSERVER
58#  define in_port_t uint16_t
59#else
60#  include <arpa/inet.h>
61#endif
62
63#ifndef INADDR_NONE
64#define INADDR_NONE             0xffffffff
65#endif
66
67#ifdef __GNUC__
68#  define UNUSED __attribute__((unused))
69#  define PRINTF( fmt, args ) __attribute__((format (printf, fmt, args)))
70#else
71#  define UNUSED
72#  define PRINTF( fmt, args )
73#endif
74
75/* We use OpenSSL whenever possible, since it is likely to be more
76   optimized and it is ok to use it with a MIT-licensed application.
77   Otherwise, we use the included implementation by vi@nwr.jp. */
78#ifdef HAVE_OPENSSL
79#  undef SHA_DIGEST_LENGTH
80#  include <openssl/sha.h>
81#else
82#  include "sha1.h"
83#  define SHA1(p,i,h) \
84   { \
85     sha1_state_s pms; \
86     sha1_init( &pms ); \
87     sha1_update( &pms, (sha1_byte_t *) p, i ); \
88     sha1_finish( &pms, (sha1_byte_t *) h ); \
89   }
90#endif
91
92/* Convenient macros to perform uint32_t endian conversions with
93   char pointers */
94#define TR_NTOHL(p,a) (a) = tr_ntohl((p))
95#define TR_HTONL(a,p) tr_htonl((a), (p))
96static inline uint32_t tr_ntohl( uint8_t * p )
97{
98        uint32_t u;
99        memcpy( &u, p, sizeof( uint32_t ) );
100        return ntohl( u );
101}
102static inline void tr_htonl( uint32_t a, uint8_t * p )
103{
104        uint32_t u;
105        u = htonl( a );
106        memcpy ( p, &u, sizeof( uint32_t ) );
107}
108
109/* Sometimes the system defines MAX/MIN, sometimes not. In the latter
110   case, define those here since we will use them */
111#ifndef MAX
112#define MAX(a,b) ((a)>(b)?(a):(b))
113#endif
114#ifndef MIN
115#define MIN(a,b) ((a)>(b)?(b):(a))
116#endif
117
118#define TR_MAX_PEER_COUNT 60
119
120typedef struct tr_completion_s tr_completion_t;
121
122typedef enum { TR_OK, TR_ERROR, TR_WAIT } tr_tristate_t;
123
124#include "platform.h"
125#include "bencode.h"
126#include "metainfo.h"
127#include "tracker.h"
128#include "fdlimit.h"
129#include "peer.h"
130#include "net.h"
131#include "inout.h"
132#include "ratecontrol.h"
133#include "clients.h"
134#include "choking.h"
135#include "natpmp.h"
136#include "upnp.h"
137#include "http.h"
138#include "xml.h"
139
140struct tr_torrent_s
141{
142    tr_info_t info;
143
144    tr_ratecontrol_t * globalUpload;
145    tr_ratecontrol_t * globalDownload;
146    tr_ratecontrol_t * upload;
147    tr_ratecontrol_t * download;
148    tr_ratecontrol_t * swarmspeed;
149    tr_fd_t          * fdlimit;
150
151    int               status;
152    int               error;
153    char              trackerError[128];
154    int               finished;
155
156    char            * id;
157    char            * key;
158    int             * bindPort;
159
160    /* An escaped string used to include the hash in HTTP queries */
161    char              escapedHashString[3*SHA_DIGEST_LENGTH+1];
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          downloadedCur;
185    uint64_t          downloadedPrev;
186    uint64_t          uploadedCur;
187    uint64_t          uploadedPrev;
188
189    tr_stat_t         stats[2];
190    int               statCur;
191
192    tr_torrent_t    * prev;
193    tr_torrent_t    * next;
194};
195
196#include "utils.h"
197#include "completion.h"
198
199struct tr_handle_s
200{
201    int            torrentCount;
202    tr_torrent_t * torrentList;
203
204    tr_ratecontrol_t * upload;
205    tr_ratecontrol_t * download;
206    tr_fd_t      * fdlimit;
207    tr_choking_t * choking;
208    tr_natpmp_t  * natpmp;
209    tr_upnp_t    * upnp;
210
211    int            bindPort;
212    int            bindSocket;
213
214    int            acceptPeerCount;
215    tr_peer_t    * acceptPeers[TR_MAX_PEER_COUNT];
216
217    char           id[21];
218    char           key[21];
219
220    volatile char  acceptDie;
221    tr_thread_t    acceptThread;
222    tr_lock_t      acceptLock;
223};
224
225#endif
Note: See TracBrowser for help on using the repository browser.