source: trunk/libtransmission/internal.h @ 2441

Last change on this file since 2441 was 2441, checked in by charles, 15 years ago

more work on the speed limits as hammered out w/BentMyWookie

  • Property svn:keywords set to Date Rev Author Id
File size: 7.0 KB
Line 
1/******************************************************************************
2 * $Id: internal.h 2441 2007-07-20 03:24:04Z charles $
3 *
4 * Copyright (c) 2005-2007 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#if ( defined( __unix__ ) || defined( unix ) ) && !defined( USG )
32#include <sys/param.h>
33#endif
34#include <stdio.h>
35#ifdef SYS_BEOS
36/* BeOS doesn't declare vasprintf in its headers, but actually
37 * implements it */
38int vasprintf( char **, const char *, va_list );
39#endif
40#include <stdlib.h>
41#include <string.h>
42#include <errno.h>
43#include <time.h>
44#ifndef __AMIGAOS4__
45#include <sys/resource.h>
46#endif
47#include <assert.h>
48#ifdef SYS_BEOS
49#  define socklen_t uint32_t
50#endif
51#ifdef BEOS_NETSERVER
52#  define in_port_t uint16_t
53#else
54#  include <arpa/inet.h>
55#endif
56
57#define TR_NAME                 "Transmission"
58
59#ifndef INADDR_NONE
60#define INADDR_NONE             0xffffffff
61#endif
62
63#ifdef __GNUC__
64#  define UNUSED __attribute__((unused))
65#  define PRINTF( fmt, args ) __attribute__((format (printf, fmt, args)))
66#else
67#  define UNUSED
68#  define PRINTF( fmt, args )
69#endif
70
71/* We use OpenSSL whenever possible, since it is likely to be more
72   optimized and it is ok to use it with a MIT-licensed application.
73   Otherwise, we use the included implementation by vi@nwr.jp. */
74#ifdef HAVE_OPENSSL
75#  undef SHA_DIGEST_LENGTH
76#  include <openssl/sha.h>
77#else
78#  include "sha1.h"
79#  define SHA1(p,i,h) \
80   { \
81     sha1_state_s pms; \
82     sha1_init( &pms ); \
83     sha1_update( &pms, (sha1_byte_t *) p, i ); \
84     sha1_finish( &pms, (sha1_byte_t *) h ); \
85   }
86#endif
87
88#define TR_MAX_PEER_COUNT 60
89
90typedef struct tr_completion_s tr_completion_t;
91typedef struct tr_shared_s tr_shared_t;
92
93typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
94
95#include "platform.h"
96#include "tracker.h"
97#include "peer.h"
98#include "inout.h"
99#include "ratecontrol.h"
100
101#ifndef TRUE
102#define TRUE 1
103#endif
104#ifndef FALSE
105#define FALSE 0
106#endif
107
108void tr_peerIdNew ( char* buf, int buflen );
109
110void tr_torrentResetTransferStats( tr_torrent_t * );
111
112int tr_torrentAddCompact( tr_torrent_t * tor, int from,
113                           uint8_t * buf, int count );
114int tr_torrentAttachPeer( tr_torrent_t * tor, tr_peer_t * peer );
115
116void tr_torrentSetHasPiece( tr_torrent_t * tor, int pieceIndex, int has );
117
118void tr_torrentReaderLock    ( const tr_torrent_t * );
119void tr_torrentReaderUnlock  ( const tr_torrent_t * );
120void tr_torrentWriterLock    ( tr_torrent_t * );
121void tr_torrentWriterUnlock  ( tr_torrent_t * );
122
123#define tr_blockPiece(a) _tr_blockPiece(tor,a)
124int _tr_blockPiece( const tr_torrent_t * tor, int block );
125
126#define tr_blockSize(a) _tr_blockSize(tor,a)
127int _tr_blockSize( const tr_torrent_t * tor, int block );
128
129#define tr_blockPosInPiece(a) _tr_blockPosInPiece(tor,a)
130int _tr_blockPosInPiece( const tr_torrent_t * tor, int block );
131
132#define tr_pieceCountBlocks(a) _tr_pieceCountBlocks(tor,a)
133int _tr_pieceCountBlocks( const tr_torrent_t * tor, int piece );
134
135#define tr_pieceStartBlock(a) _tr_pieceStartBlock(tor,a)
136int _tr_pieceStartBlock( const tr_torrent_t * tor, int piece );
137
138#define tr_pieceSize(a) _tr_pieceSize(tor,a)
139int _tr_pieceSize( const tr_torrent_t * tor, int piece );
140
141#define tr_block(a,b) _tr_block(tor,a,b)
142int _tr_block( const tr_torrent_t * tor, int index, int begin );
143
144
145typedef enum
146{
147    TR_RUN_CHECKING           = (1<<0), /* checking files' checksums */
148    TR_RUN_RUNNING            = (1<<1), /* seeding or leeching */
149    TR_RUN_STOPPING           = (1<<2), /* stopping */
150    TR_RUN_STOPPING_NET_WAIT  = (1<<3), /* waiting on network -- we're
151                                           telling tracker we've stopped */
152    TR_RUN_STOPPED            = (1<<4)  /* stopped */
153}
154run_status_t;
155
156#define TR_ID_LEN               20
157#define TR_KEY_LEN              20
158
159struct tr_torrent_s
160{
161    tr_handle_t * handle;
162    tr_info_t info;
163
164    tr_speedlimit_t    uploadLimitMode;
165    tr_speedlimit_t    downloadLimitMode;
166    tr_ratecontrol_t * upload;
167    tr_ratecontrol_t * download;
168    tr_ratecontrol_t * swarmspeed;
169
170    int               error;
171    char              errorString[128];
172    int               hasChangedState;
173
174    char              peer_id[TR_ID_LEN+1];
175    char            * key;
176    uint8_t         * azId;
177    int               publicPort;
178
179    /* An escaped string used to include the hash in HTTP queries */
180    char              escapedHashString[3*SHA_DIGEST_LENGTH+1];
181
182    /* Where to download */
183    char            * destination;
184   
185    /* How many bytes we ask for per request */
186    int               blockSize;
187    int               blockCount;
188   
189    tr_completion_t * completion;
190
191    volatile char     dieFlag;
192    volatile char     recheckFlag;
193    run_status_t      runStatus;
194    cp_status_t       cpStatus;
195    tr_thread_t       thread;
196    tr_rwlock_t       lock;
197
198    tr_tracker_t    * tracker;
199    tr_io_t         * io;
200    uint64_t          startDate;
201    uint64_t          stopDate;
202    char              ioLoaded;
203    char              fastResumeDirty;
204
205    int               peerCount;
206    tr_peer_t       * peers[TR_MAX_PEER_COUNT];
207
208    uint64_t          downloadedCur;
209    uint64_t          downloadedPrev;
210    uint64_t          uploadedCur;
211    uint64_t          uploadedPrev;
212    uint64_t          activityDate;
213
214    uint8_t           pexDisabled;
215
216    int8_t            statCur;
217    tr_stat_t         stats[2];
218
219    tr_torrent_t    * next;
220};
221
222#include "utils.h"
223#include "completion.h"
224
225struct tr_handle_s
226{
227    int                torrentCount;
228    tr_torrent_t     * torrentList;
229
230    char             * tag;
231    int                isPortSet;
232
233    tr_ratecontrol_t * upload;
234    tr_ratecontrol_t * download;
235
236    tr_shared_t      * shared;
237
238    char           key[TR_KEY_LEN+1];
239
240    tr_handle_status_t stats[2];
241    int                statCur;
242#define TR_AZ_ID_LEN            20
243    uint8_t        azId[TR_AZ_ID_LEN];
244};
245
246#endif
Note: See TracBrowser for help on using the repository browser.