source: trunk/libtransmission/internal.h @ 3119

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

slightly less broken handling of cases where we can't bind to our listening port.

  • Property svn:keywords set to Date Rev Author Id
File size: 6.3 KB
Line 
1/******************************************************************************
2 * $Id: internal.h 3119 2007-09-21 05:31:29Z 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#define TR_NAME "Transmission"
29
30#ifdef __GNUC__
31#define UNUSED __attribute__((unused))
32#else
33#define UNUSED
34#endif
35
36#define TR_MAX_PEER_COUNT 60
37
38typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
39
40#ifndef TRUE
41#define TRUE 1
42#endif
43
44#ifndef FALSE
45#define FALSE 0
46#endif
47
48int tr_trackerInfoInit( struct tr_tracker_info  * info,
49                        const char              * address,
50                        int                       address_len );
51
52void tr_trackerInfoClear( struct tr_tracker_info * info );
53
54void tr_peerIdNew ( char* buf, int buflen );
55
56void tr_torrentResetTransferStats( tr_torrent * );
57
58void tr_torrentSetHasPiece( tr_torrent * tor, int pieceIndex, int has );
59
60void tr_torrentLock    ( const tr_torrent * );
61void tr_torrentUnlock  ( const tr_torrent * );
62
63void tr_torrentChangeMyPort  ( tr_torrent * );
64
65int tr_torrentExists( tr_handle *, const uint8_t * );
66tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * );
67tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* );
68
69/* get the index of this piece's first block */
70#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
71
72/* what piece index is this block in? */
73#define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece )
74
75/* how many blocks are in this piece? */
76#define tr_torPieceCountBlocks(tor,piece) \
77    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece )
78
79/* how many bytes are in this piece? */
80#define tr_torPieceCountBytes(tor,piece) \
81    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize )
82
83/* how many bytes are in this block? */
84#define tr_torBlockCountBytes(tor,block) \
85    ( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize )
86
87#define tr_block(a,b) _tr_block(tor,a,b)
88int _tr_block( const tr_torrent * tor, int index, int begin );
89
90
91typedef enum
92{
93    TR_RUN_CHECKING_WAIT      = (1<<0), /* waiting to be checked */
94    TR_RUN_CHECKING           = (1<<1), /* checking files' checksums */
95    TR_RUN_RUNNING            = (1<<2), /* seeding or leeching */
96    TR_RUN_STOPPING           = (1<<3), /* waiting for acknowledgment from tracker */
97    TR_RUN_STOPPED            = (1<<4)  /* stopped */
98}
99run_status_t;
100
101#define TR_ID_LEN  20
102
103struct tr_torrent
104{
105    tr_handle                 * handle;
106    tr_info                     info;
107
108    tr_speedlimit               uploadLimitMode;
109    tr_speedlimit               downloadLimitMode;
110    struct tr_ratecontrol     * upload;
111    struct tr_ratecontrol     * download;
112    struct tr_ratecontrol     * swarmspeed;
113
114    struct tr_timer           * saveTimer;
115
116    int                        error;
117    char                       errorString[128];
118    int                        hasChangedState;
119
120    uint8_t                    obfuscatedHash[SHA_DIGEST_LENGTH];
121
122    uint8_t                  * azId;
123
124    /* Where to download */
125    char                     * destination;
126   
127    /* How many bytes we ask for per request */
128    int                        blockSize;
129    int                        blockCount;
130
131    int                        lastBlockSize;
132    int                        lastPieceSize;
133
134    int                        blockCountInPiece;
135    int                        blockCountInLastPiece;
136   
137    struct tr_completion     * completion;
138
139    volatile char              dieFlag;
140    struct tr_bitfield       * uncheckedPieces;
141    run_status_t               runStatus;
142    run_status_t               runStatusToSave;
143    char                       runStatusToSaveIsSet;
144    cp_status_t                cpStatus;
145    struct tr_lock           * lock;
146
147    struct tr_tracker        * tracker;
148    struct tr_publisher_tag  * trackerSubscription;
149    uint64_t                   startDate;
150    uint64_t                   stopDate;
151
152    uint64_t                   downloadedCur;
153    uint64_t                   downloadedPrev;
154    uint64_t                   uploadedCur;
155    uint64_t                   uploadedPrev;
156    uint64_t                   corruptCur;
157    uint64_t                   corruptPrev;
158    uint64_t                   activityDate;
159
160    uint8_t                    pexDisabled;
161
162    int8_t                     statCur;
163    tr_stat                    stats[2];
164
165    tr_torrent               * next;
166};
167
168struct tr_handle
169{
170    tr_encryption_mode         encryptionMode;
171
172    struct tr_event_handle   * events;
173
174    int                        torrentCount;
175    tr_torrent               * torrentList;
176
177    char                     * tag;
178    int                        isPortSet;
179
180    char                       useUploadLimit;
181    char                       useDownloadLimit;
182    struct tr_ratecontrol    * upload;
183    struct tr_ratecontrol    * download;
184
185    struct tr_peerMgr        * peerMgr;
186    struct tr_shared         * shared;
187
188    tr_handle_status           stats[2];
189    int                        statCur;
190
191    uint8_t                    isClosed;
192
193#define TR_AZ_ID_LEN 20
194    uint8_t                    azId[TR_AZ_ID_LEN];
195};
196
197#endif
Note: See TracBrowser for help on using the repository browser.