source: trunk/libtransmission/internal.h @ 2891

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

added support for `corrupt' announce tag s.t. corrupted bytes don't count towards your download ratio

  • Property svn:keywords set to Date Rev Author Id
File size: 6.6 KB
Line 
1/******************************************************************************
2 * $Id: internal.h 2891 2007-08-21 15:17:02Z 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_s  * info,
49                        const char                * address,
50                        int                         address_len );
51
52void tr_trackerInfoClear( struct tr_tracker_info_s * info );
53
54struct tr_peer_s;
55
56void tr_peerIdNew ( char* buf, int buflen );
57
58void tr_torrentResetTransferStats( tr_torrent_t * );
59
60int tr_torrentAddCompact( tr_torrent_t * tor, int from,
61                           const uint8_t * buf, int count );
62int tr_torrentAttachPeer( tr_torrent_t * tor, struct tr_peer_s * );
63
64void tr_torrentSetHasPiece( tr_torrent_t * tor, int pieceIndex, int has );
65
66void tr_torrentReaderLock    ( const tr_torrent_t * );
67void tr_torrentReaderUnlock  ( const tr_torrent_t * );
68void tr_torrentWriterLock    ( tr_torrent_t * );
69void tr_torrentWriterUnlock  ( tr_torrent_t * );
70
71void tr_torrentChangeMyPort  ( tr_torrent_t *, int port );
72
73/* get the index of this piece's first block */
74#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
75
76/* what piece index is this block in? */
77#define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece )
78
79/* how many blocks are in this piece? */
80#define tr_torPieceCountBlocks(tor,piece) \
81    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece )
82
83/* how many bytes are in this piece? */
84#define tr_torPieceCountBytes(tor,piece) \
85    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize )
86
87/* how many bytes are in this block? */
88#define tr_torBlockCountBytes(tor,block) \
89    ( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize )
90
91#define tr_block(a,b) _tr_block(tor,a,b)
92int _tr_block( const tr_torrent_t * tor, int index, int begin );
93
94
95typedef enum
96{
97    TR_RUN_CHECKING           = (1<<0), /* checking files' checksums */
98    TR_RUN_RUNNING            = (1<<1), /* seeding or leeching */
99    TR_RUN_STOPPING           = (1<<2), /* stopping */
100    TR_RUN_STOPPING_NET_WAIT  = (1<<3), /* waiting on network -- we're
101                                           telling tracker we've stopped */
102    TR_RUN_STOPPED            = (1<<4)  /* stopped */
103}
104run_status_t;
105
106#define TR_ID_LEN  20
107
108struct tr_torrent_s
109{
110    tr_handle_t               * handle;
111    tr_info_t                   info;
112
113    tr_speedlimit_t             uploadLimitMode;
114    tr_speedlimit_t             downloadLimitMode;
115    struct tr_ratecontrol_s   * upload;
116    struct tr_ratecontrol_s   * download;
117    struct tr_ratecontrol_s   * swarmspeed;
118
119    int                        error;
120    char                       errorString[128];
121    int                        hasChangedState;
122
123    uint8_t                  * azId;
124    int                        publicPort;
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_s   * completion;
140
141    volatile char              dieFlag;
142    struct tr_bitfield_s     * uncheckedPieces;
143    run_status_t               runStatus;
144    run_status_t               runStatusToSave;
145    char                       runStatusToSaveIsSet;
146    cp_status_t                cpStatus;
147    struct tr_thread_s       * thread;
148    struct tr_rwlock_s       * lock;
149
150    struct tr_tracker_s      * tracker;
151    struct tr_publisher_tag  * trackerSubscription;
152    struct tr_io_s           * io;
153    uint64_t                   startDate;
154    uint64_t                   stopDate;
155    char                       ioLoaded;
156    char                       fastResumeDirty;
157
158    int                        peerCount;
159    struct tr_peer_s *         peers[TR_MAX_PEER_COUNT];
160
161    uint64_t                   downloadedCur;
162    uint64_t                   downloadedPrev;
163    uint64_t                   uploadedCur;
164    uint64_t                   uploadedPrev;
165    uint64_t                   corruptCur;
166    uint64_t                   corruptPrev;
167    uint64_t                   activityDate;
168
169    uint8_t                    pexDisabled;
170
171    int8_t                     statCur;
172    tr_stat_t                  stats[2];
173
174    tr_torrent_t             * next;
175};
176
177struct tr_handle_s
178{
179    struct tr_event_handle_s * events;
180
181    int                        torrentCount;
182    tr_torrent_t             * torrentList;
183
184    char                     * tag;
185    int                        isPortSet;
186
187    char                       useUploadLimit;
188    char                       useDownloadLimit;
189    struct tr_ratecontrol_s  * upload;
190    struct tr_ratecontrol_s  * download;
191
192    struct tr_shared_s       * shared;
193
194    tr_handle_status_t         stats[2];
195    int                        statCur;
196
197#define TR_AZ_ID_LEN 20
198    uint8_t                    azId[TR_AZ_ID_LEN];
199};
200
201#endif
Note: See TracBrowser for help on using the repository browser.