source: trunk/libtransmission/internal.h @ 2555

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

add portability wrapper for in_port_t...

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