source: trunk/libtransmission/internal.h @ 233

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

Portability fix (platforms such as sparc64 need uint32_t pointers to be
32-bits aligned)

Patch by Christian Weisgerber

File size: 5.1 KB
Line 
1/******************************************************************************
2 * Copyright (c) 2005-2006 Transmission authors and contributors
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 *****************************************************************************/
22
23#ifndef TR_INTERNAL_H
24#define TR_INTERNAL_H 1
25
26/* Standard headers used here and there.
27   That is probably ugly to put them all here, but it is sooo
28   convenient */
29#include <stdio.h>
30#include <stdarg.h>
31#include <stdlib.h>
32#include <string.h>
33#include <unistd.h>
34#include <errno.h>
35#include <limits.h>
36#include <signal.h>
37#include <time.h>
38#include <sys/time.h>
39#include <sys/types.h>
40#include <sys/stat.h>
41#include <sys/resource.h>
42#include <netdb.h>
43#include <sys/socket.h>
44#include <netinet/in.h>
45#include <fcntl.h>
46#ifdef BEOS_NETSERVER
47#  define in_port_t uint16_t
48#else
49#  include <arpa/inet.h>
50#endif
51
52/* We use OpenSSL whenever possible, since it is likely to be more
53   optimized and it is ok to use it with a MIT-licensed application.
54   Otherwise, we use the included implementation by vi@nwr.jp. */
55#ifdef HAVE_OPENSSL
56#  undef SHA_DIGEST_LENGTH
57#  include <openssl/sha.h>
58#else
59#  include "sha1.h"
60#  define SHA1(p,i,h) \
61   { \
62     sha1_state_s pms; \
63     sha1_init( &pms ); \
64     sha1_update( &pms, (sha1_byte_t *) p, i ); \
65     sha1_finish( &pms, (sha1_byte_t *) h ); \
66   }
67#endif
68
69/* Convenient macros to perform uint32_t endian conversions with
70   char pointers */
71#define TR_NTOHL(p,a) (a) = tr_ntohl((p))
72#define TR_HTONL(a,p) tr_htonl((a), (p))
73static inline uint32_t tr_ntohl( uint8_t * p )
74{
75        uint32_t u;
76        memcpy( &u, p, sizeof( uint32_t ) );
77        return ntohl( u );
78}
79static inline void tr_htonl( uint32_t a, uint8_t * p )
80{
81        uint32_t u;
82        u = htonl( a );
83        memcpy ( p, &u, sizeof( uint32_t ) );
84}
85
86/* Sometimes the system defines MAX/MIN, sometimes not. In the latter
87   case, define those here since we will use them */
88#ifndef MAX
89#define MAX(a,b) ((a)>(b)?(a):(b))
90#endif
91#ifndef MIN
92#define MIN(a,b) ((a)>(b)?(b):(a))
93#endif
94
95#define TR_MAX_PEER_COUNT 60
96
97typedef struct tr_completion_s tr_completion_t;
98
99#include "platform.h"
100#include "bencode.h"
101#include "metainfo.h"
102#include "tracker.h"
103#include "fdlimit.h"
104#include "peer.h"
105#include "net.h"
106#include "inout.h"
107#include "ratecontrol.h"
108#include "clients.h"
109#include "choking.h"
110
111struct tr_torrent_s
112{
113    tr_info_t info;
114
115    tr_ratecontrol_t * globalUpload;
116    tr_ratecontrol_t * globalDownload;
117    tr_ratecontrol_t * upload;
118    tr_ratecontrol_t * download;
119    tr_fd_t          * fdlimit;
120
121    int               status;
122    int               error;
123    char              trackerError[128];
124    int               finished;
125
126    char            * id;
127    char            * key;
128    int             * bindPort;
129
130    /* An escaped string used to include the hash in HTTP queries */
131    char              hashString[3*SHA_DIGEST_LENGTH+1];
132
133    char              scrape[MAX_PATH_LENGTH];
134
135    /* Where to download */
136    char            * destination;
137   
138    /* How many bytes we ask for per request */
139    int               blockSize;
140    int               blockCount;
141   
142    tr_completion_t * completion;
143
144    volatile char     die;
145    tr_thread_t       thread;
146    tr_lock_t         lock;
147
148    tr_tracker_t    * tracker;
149    tr_io_t         * io;
150    uint64_t          stopDate;
151
152    int               peerCount;
153    tr_peer_t       * peers[TR_MAX_PEER_COUNT];
154
155    uint64_t          date;
156    uint64_t          downloaded;
157    uint64_t          uploaded;
158
159    tr_stat_t         stats[2];
160    int               statCur;
161
162    tr_torrent_t    * prev;
163    tr_torrent_t    * next;
164};
165
166#include "utils.h"
167#include "completion.h"
168
169struct tr_handle_s
170{
171    int            torrentCount;
172    tr_torrent_t * torrentList;
173
174    tr_ratecontrol_t * upload;
175    tr_ratecontrol_t * download;
176    tr_fd_t      * fdlimit;
177    tr_choking_t * choking;
178
179    int            bindPort;
180    int            bindSocket;
181
182    int            acceptPeerCount;
183    tr_peer_t    * acceptPeers[TR_MAX_PEER_COUNT];
184
185    char           id[21];
186    char           key[21];
187
188    volatile char  acceptDie;
189    tr_thread_t    acceptThread;
190    tr_lock_t      acceptLock;
191};
192
193#endif
Note: See TracBrowser for help on using the repository browser.