source: trunk/libtransmission/internal.h @ 346

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

Add support to libtransmission and the MacOS X GUI for saving private copies of

torrent files.

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