source: trunk/libtransmission/internal.h @ 2544

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

this looks bug but it's not: just janitorial cleanup, moving #includes from headers into source file

  • Property svn:keywords set to Date Rev Author Id
File size: 7.1 KB
Line 
1/******************************************************************************
2 * $Id: internal.h 2544 2007-07-29 18:11:21Z 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
29#ifdef SYS_BEOS
30/* BeOS doesn't declare vasprintf in its headers, but actually
31 * implements it */
32extern int vasprintf( char **, const char *, va_list );
33#endif
34
35#ifndef __AMIGAOS4__
36#include <sys/resource.h>
37#endif
38
39#ifdef SYS_BEOS
40#  define socklen_t uint32_t
41#endif
42
43#ifdef BEOS_NETSERVER
44#  define in_port_t uint16_t
45#else
46#  include <arpa/inet.h>
47#endif
48
49#define TR_NAME "Transmission"
50
51#ifndef INADDR_NONE
52#define INADDR_NONE 0xffffffff
53#endif
54
55#ifdef __GNUC__
56#  define UNUSED __attribute__((unused))
57#  define PRINTF( fmt, args ) __attribute__((format (printf, fmt, args)))
58#else
59#  define UNUSED
60#  define PRINTF( fmt, args )
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#if defined(HAVE_OPENSSL) || defined(HAVE_LIBSSL)
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#define TR_MAX_PEER_COUNT 60
81
82typedef struct tr_completion_s tr_completion_t;
83typedef struct tr_shared_s tr_shared_t;
84
85typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
86
87#include "platform.h"
88#include "tracker.h"
89#include "peer.h"
90#include "inout.h"
91#include "ratecontrol.h"
92#include "utils.h"
93
94#ifndef TRUE
95#define TRUE 1
96#endif
97#ifndef FALSE
98#define FALSE 0
99#endif
100
101void tr_peerIdNew ( char* buf, int buflen );
102
103void tr_torrentResetTransferStats( tr_torrent_t * );
104
105int tr_torrentAddCompact( tr_torrent_t * tor, int from,
106                           uint8_t * buf, int count );
107int tr_torrentAttachPeer( tr_torrent_t * tor, tr_peer_t * peer );
108
109void tr_torrentSetHasPiece( tr_torrent_t * tor, int pieceIndex, int has );
110
111void tr_torrentReaderLock    ( const tr_torrent_t * );
112void tr_torrentReaderUnlock  ( const tr_torrent_t * );
113void tr_torrentWriterLock    ( tr_torrent_t * );
114void tr_torrentWriterUnlock  ( tr_torrent_t * );
115
116/* get the index of this piece's first block */
117#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
118
119/* what piece index is this block in? */
120#define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece )
121
122/* how many blocks are in this piece? */
123#define tr_torPieceCountBlocks(tor,piece) \
124    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece )
125
126/* how many bytes are in this piece? */
127#define tr_torPieceCountBytes(tor,piece) \
128    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize )
129
130/* how many bytes are in this block? */
131#define tr_torBlockCountBytes(tor,block) \
132    ( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize )
133
134#define tr_block(a,b) _tr_block(tor,a,b)
135int _tr_block( const tr_torrent_t * tor, int index, int begin );
136
137
138typedef enum
139{
140    TR_RUN_CHECKING           = (1<<0), /* checking files' checksums */
141    TR_RUN_RUNNING            = (1<<1), /* seeding or leeching */
142    TR_RUN_STOPPING           = (1<<2), /* stopping */
143    TR_RUN_STOPPING_NET_WAIT  = (1<<3), /* waiting on network -- we're
144                                           telling tracker we've stopped */
145    TR_RUN_STOPPED            = (1<<4)  /* stopped */
146}
147run_status_t;
148
149#define TR_ID_LEN               20
150#define TR_KEY_LEN              20
151
152struct tr_torrent_s
153{
154    tr_handle_t * handle;
155    tr_info_t info;
156
157    tr_speedlimit_t    uploadLimitMode;
158    tr_speedlimit_t    downloadLimitMode;
159    tr_ratecontrol_t * upload;
160    tr_ratecontrol_t * download;
161    tr_ratecontrol_t * swarmspeed;
162
163    int               error;
164    char              errorString[128];
165    int               hasChangedState;
166
167    char              peer_id[TR_ID_LEN+1];
168    char            * key;
169    uint8_t         * azId;
170    int               publicPort;
171
172    /* An escaped string used to include the hash in HTTP queries */
173    char              escapedHashString[3*SHA_DIGEST_LENGTH+1];
174
175    /* Where to download */
176    char            * destination;
177   
178    /* How many bytes we ask for per request */
179    int               blockSize;
180    int               blockCount;
181
182    int               lastBlockSize;
183    int               lastPieceSize;
184
185    int               blockCountInPiece;
186    int               blockCountInLastPiece;
187   
188    tr_completion_t * completion;
189
190    volatile char     dieFlag;
191    tr_bitfield_t   * uncheckedPieces;
192    run_status_t      runStatus;
193    cp_status_t       cpStatus;
194    tr_thread_t       thread;
195    tr_rwlock_t       lock;
196
197    tr_tracker_t    * tracker;
198    tr_io_t         * io;
199    uint64_t          startDate;
200    uint64_t          stopDate;
201    char              ioLoaded;
202    char              fastResumeDirty;
203
204    int               peerCount;
205    tr_peer_t       * peers[TR_MAX_PEER_COUNT];
206
207    uint64_t          downloadedCur;
208    uint64_t          downloadedPrev;
209    uint64_t          uploadedCur;
210    uint64_t          uploadedPrev;
211    uint64_t          activityDate;
212
213    uint8_t           pexDisabled;
214
215    int8_t            statCur;
216    tr_stat_t         stats[2];
217
218    tr_torrent_t    * next;
219};
220
221#include "utils.h"
222#include "completion.h"
223
224struct tr_handle_s
225{
226    int                torrentCount;
227    tr_torrent_t     * torrentList;
228
229    char             * tag;
230    int                isPortSet;
231
232    char               useUploadLimit;
233    tr_ratecontrol_t * upload;
234    char               useDownloadLimit;
235    tr_ratecontrol_t * download;
236
237    tr_shared_t      * shared;
238
239    char           key[TR_KEY_LEN+1];
240
241    tr_handle_status_t stats[2];
242    int                statCur;
243#define TR_AZ_ID_LEN            20
244    uint8_t        azId[TR_AZ_ID_LEN];
245};
246
247#endif
Note: See TracBrowser for help on using the repository browser.