source: trunk/libtransmission/internal.h @ 26

Last change on this file since 26 was 26, checked in by root, 16 years ago

Update 2006-01-11

File size: 4.8 KB
Line 
1/******************************************************************************
2 * Copyright (c) 2005 Eric Petit
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) = ntohl(*((uint32_t*)(p)))
72#define TR_HTONL(a,p) *((uint32_t*)(p)) = htonl((a))
73
74/* Sometimes the system defines MAX/MIN, sometimes not. In the latter
75   case, define those here since we will use them */
76#ifndef MAX
77#define MAX(a,b) ((a)>(b)?(a):(b))
78#endif
79#ifndef MIN
80#define MIN(a,b) ((a)>(b)?(b):(a))
81#endif
82
83#define TR_MAX_PEER_COUNT 60
84
85typedef struct tr_torrent_s tr_torrent_t;
86typedef struct tr_completion_s tr_completion_t;
87
88#include "platform.h"
89#include "bencode.h"
90#include "metainfo.h"
91#include "tracker.h"
92#include "fdlimit.h"
93#include "peer.h"
94#include "net.h"
95#include "inout.h"
96#include "upload.h"
97#include "clients.h"
98
99struct tr_torrent_s
100{
101    tr_info_t info;
102
103    tr_upload_t     * upload;
104    tr_fd_t         * fdlimit;
105
106    int               status;
107        int                               finished;
108    char              error[128];
109
110    char            * id;
111    char            * key;
112
113    /* An escaped string used to include the hash in HTTP queries */
114    char              hashString[3*SHA_DIGEST_LENGTH+1];
115
116    char              scrape[MAX_PATH_LENGTH];
117
118    /* Where to download */
119    char            * destination;
120   
121    /* How many bytes we ask for per request */
122    int               blockSize;
123    int               blockCount;
124   
125#if 0
126    /* Status for each block
127       -1 = we have it
128        n = we are downloading it from n peers */
129    char            * blockHave;
130    int               blockHaveCount;
131    uint8_t         * bitfield;
132#endif
133    tr_completion_t * completion;
134
135    volatile char     die;
136    tr_thread_t       thread;
137    tr_lock_t         lock;
138
139    tr_tracker_t    * tracker;
140    tr_io_t         * io;
141    uint64_t          stopDate;
142
143    int               peerCount;
144    tr_peer_t       * peers[TR_MAX_PEER_COUNT];
145
146    uint64_t          dates[10];
147    uint64_t          downloaded[10];
148    uint64_t          uploaded[10];
149};
150
151#include "utils.h"
152#include "completion.h"
153
154struct tr_handle_s
155{
156    int            torrentCount;
157    tr_torrent_t * torrents[TR_MAX_TORRENT_COUNT];
158
159    tr_upload_t  * upload;
160    tr_fd_t      * fdlimit;
161
162    int            bindPort;
163    int            bindSocket;
164
165    int            acceptPeerCount;
166    tr_peer_t    * acceptPeers[TR_MAX_PEER_COUNT];
167
168    char           id[21];
169    char           key[21];
170
171    volatile char  acceptDie;
172    tr_thread_t    acceptThread;
173    tr_lock_t      acceptLock;
174};
175
176#endif
Note: See TracBrowser for help on using the repository browser.