source: trunk/libtransmission/internal.h @ 788

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

Try to keep track of the overall speed of the swarm.
Patch by Denis Ahrens.

  • Property svn:keywords set to Date Rev Author Id
File size: 5.3 KB
Line 
1/******************************************************************************
2 * $Id: internal.h 788 2006-08-16 19:21:09Z joshe $
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_ratecontrol_t * swarmspeed;
131    tr_fd_t          * fdlimit;
132
133    int               status;
134    int               error;
135    char              trackerError[128];
136    int               finished;
137
138    char            * id;
139    char            * key;
140    int             * bindPort;
141
142    /* An escaped string used to include the hash in HTTP queries */
143    char              hashString[3*SHA_DIGEST_LENGTH+1];
144
145    char              scrape[MAX_PATH_LENGTH];
146
147    /* Where to download */
148    char            * destination;
149   
150    /* How many bytes we ask for per request */
151    int               blockSize;
152    int               blockCount;
153   
154    tr_completion_t * completion;
155
156    volatile char     die;
157    tr_thread_t       thread;
158    tr_lock_t         lock;
159
160    tr_tracker_t    * tracker;
161    tr_io_t         * io;
162    uint64_t          stopDate;
163
164    int               peerCount;
165    tr_peer_t       * peers[TR_MAX_PEER_COUNT];
166
167    uint64_t          date;
168    uint64_t          downloaded;
169    uint64_t          uploaded;
170
171    tr_stat_t         stats[2];
172    int               statCur;
173
174    tr_torrent_t    * prev;
175    tr_torrent_t    * next;
176};
177
178#include "utils.h"
179#include "completion.h"
180
181struct tr_handle_s
182{
183    int            torrentCount;
184    tr_torrent_t * torrentList;
185
186    tr_ratecontrol_t * upload;
187    tr_ratecontrol_t * download;
188    tr_fd_t      * fdlimit;
189    tr_choking_t * choking;
190
191    int            bindPort;
192    int            bindSocket;
193
194    int            acceptPeerCount;
195    tr_peer_t    * acceptPeers[TR_MAX_PEER_COUNT];
196
197    char           id[21];
198    char           key[21];
199
200    volatile char  acceptDie;
201    tr_thread_t    acceptThread;
202    tr_lock_t      acceptLock;
203};
204
205#endif
Note: See TracBrowser for help on using the repository browser.