source: trunk/libtransmission/internal.h @ 3225

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

remove obsolete MAX_PEERS in internal.h

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