source: trunk/libtransmission/internal.h @ 261

Last change on this file since 261 was 261, checked in by titer, 16 years ago

Updated svn:keywords

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