source: branches/new_api/libtransmission/internal.h @ 137

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

Adds a permanent handle for every torrent.
Removed the limit on the number of open torrents.

File size: 4.8 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) = 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_completion_s tr_completion_t;
86
87#include "platform.h"
88#include "bencode.h"
89#include "metainfo.h"
90#include "tracker.h"
91#include "fdlimit.h"
92#include "peer.h"
93#include "net.h"
94#include "inout.h"
95#include "ratecontrol.h"
96#include "clients.h"
97#include "choking.h"
98
99struct tr_torrent_s
100{
101    tr_info_t info;
102
103    tr_ratecontrol_t * globalUpload;
104    tr_ratecontrol_t * globalDownload;
105    tr_ratecontrol_t * upload;
106    tr_ratecontrol_t * download;
107    tr_fd_t          * fdlimit;
108
109    int               status;
110        int                               finished;
111    char              error[128];
112
113    char            * id;
114    char            * key;
115
116    /* An escaped string used to include the hash in HTTP queries */
117    char              hashString[3*SHA_DIGEST_LENGTH+1];
118
119    char              scrape[MAX_PATH_LENGTH];
120
121    /* Where to download */
122    char            * destination;
123   
124    /* How many bytes we ask for per request */
125    int               blockSize;
126    int               blockCount;
127   
128    tr_completion_t * completion;
129
130    volatile char     die;
131    tr_thread_t       thread;
132    tr_lock_t         lock;
133
134    tr_tracker_t    * tracker;
135    tr_io_t         * io;
136    uint64_t          stopDate;
137
138    int               peerCount;
139    tr_peer_t       * peers[TR_MAX_PEER_COUNT];
140
141    uint64_t          date;
142    uint64_t          downloaded;
143    uint64_t          uploaded;
144
145    tr_stat_t         stats[2];
146    int               statCur;
147
148    tr_torrent_t    * prev;
149    tr_torrent_t    * next;
150};
151
152#include "utils.h"
153#include "completion.h"
154
155struct tr_handle_s
156{
157    int            torrentCount;
158    tr_torrent_t * torrentList;
159
160    tr_ratecontrol_t * upload;
161    tr_ratecontrol_t * download;
162    tr_fd_t      * fdlimit;
163    tr_choking_t * choking;
164
165    int            bindPort;
166    int            bindSocket;
167
168    int            acceptPeerCount;
169    tr_peer_t    * acceptPeers[TR_MAX_PEER_COUNT];
170
171    char           id[21];
172    char           key[21];
173
174    volatile char  acceptDie;
175    tr_thread_t    acceptThread;
176    tr_lock_t      acceptLock;
177};
178
179#endif
Note: See TracBrowser for help on using the repository browser.