source: trunk/libtransmission/internal.h @ 679

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

AmigaOS4 patch by Andrea Palmate

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