source: trunk/libtransmission/internal.h @ 3105

Last change on this file since 3105 was 3105, checked in by livings124, 15 years ago

merge encryption branch to trunk (xcode project is still out of date)

  • Property svn:keywords set to Date Rev Author Id
File size: 6.4 KB
Line 
1/******************************************************************************
2 * $Id: internal.h 3105 2007-09-20 16:32:01Z livings124 $
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 *, int port );
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    int                        publicPort;
124
125    /* Where to download */
126    char                     * destination;
127   
128    /* How many bytes we ask for per request */
129    int                        blockSize;
130    int                        blockCount;
131
132    int                        lastBlockSize;
133    int                        lastPieceSize;
134
135    int                        blockCountInPiece;
136    int                        blockCountInLastPiece;
137   
138    struct tr_completion     * completion;
139
140    volatile char              dieFlag;
141    struct tr_bitfield       * uncheckedPieces;
142    run_status_t               runStatus;
143    run_status_t               runStatusToSave;
144    char                       runStatusToSaveIsSet;
145    cp_status_t                cpStatus;
146    struct tr_lock           * lock;
147
148    struct tr_tracker        * tracker;
149    struct tr_publisher_tag  * trackerSubscription;
150    uint64_t                   startDate;
151    uint64_t                   stopDate;
152
153    uint64_t                   downloadedCur;
154    uint64_t                   downloadedPrev;
155    uint64_t                   uploadedCur;
156    uint64_t                   uploadedPrev;
157    uint64_t                   corruptCur;
158    uint64_t                   corruptPrev;
159    uint64_t                   activityDate;
160
161    uint8_t                    pexDisabled;
162
163    int8_t                     statCur;
164    tr_stat                    stats[2];
165
166    tr_torrent               * next;
167};
168
169struct tr_handle
170{
171    tr_encryption_mode         encryptionMode;
172
173    struct tr_event_handle   * events;
174
175    int                        torrentCount;
176    tr_torrent               * torrentList;
177
178    char                     * tag;
179    int                        isPortSet;
180
181    char                       useUploadLimit;
182    char                       useDownloadLimit;
183    struct tr_ratecontrol    * upload;
184    struct tr_ratecontrol    * download;
185
186    struct tr_peerMgr        * peerMgr;
187    struct tr_shared         * shared;
188
189    tr_handle_status           stats[2];
190    int                        statCur;
191
192    uint8_t                    isClosed;
193
194#define TR_AZ_ID_LEN 20
195    uint8_t                    azId[TR_AZ_ID_LEN];
196};
197
198#endif
Note: See TracBrowser for help on using the repository browser.