source: trunk/libtransmission/internal.h @ 3147

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