~ubuntu-branches/ubuntu/hardy/transmission/hardy-updates

« back to all changes in this revision

Viewing changes to libtransmission/internal.h

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Benner
  • Date: 2007-10-26 16:02:39 UTC
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20071026160239-2c0agn7q1ken0xsp
Tags: upstream-0.90.dfsg
ImportĀ upstreamĀ versionĀ 0.90.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: internal.h 2607 2007-08-03 16:28:32Z charles $
 
2
 * $Id: internal.h 3492 2007-10-21 15:47:26Z charles $
3
3
 *
4
4
 * Copyright (c) 2005-2007 Transmission authors and contributors
5
5
 *
33
33
#define UNUSED
34
34
#endif
35
35
 
36
 
#define TR_MAX_PEER_COUNT 60
37
 
 
38
36
typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
39
37
 
40
38
#ifndef TRUE
45
43
#define FALSE 0
46
44
#endif
47
45
 
48
 
struct tr_peer_s;
 
46
 
 
47
void tr_torrentRecheckCompleteness( tr_torrent * );
 
48
 
 
49
int tr_trackerInfoInit( struct tr_tracker_info  * info,
 
50
                        const char              * address,
 
51
                        int                       address_len );
 
52
 
 
53
void tr_trackerInfoClear( struct tr_tracker_info * info );
49
54
 
50
55
void tr_peerIdNew ( char* buf, int buflen );
51
56
 
52
 
void tr_torrentResetTransferStats( tr_torrent_t * );
53
 
 
54
 
int tr_torrentAddCompact( tr_torrent_t * tor, int from,
55
 
                           uint8_t * buf, int count );
56
 
int tr_torrentAttachPeer( tr_torrent_t * tor, struct tr_peer_s * );
57
 
 
58
 
void tr_torrentSetHasPiece( tr_torrent_t * tor, int pieceIndex, int has );
59
 
 
60
 
void tr_torrentReaderLock    ( const tr_torrent_t * );
61
 
void tr_torrentReaderUnlock  ( const tr_torrent_t * );
62
 
void tr_torrentWriterLock    ( tr_torrent_t * );
63
 
void tr_torrentWriterUnlock  ( tr_torrent_t * );
 
57
void tr_torrentResetTransferStats( tr_torrent * );
 
58
 
 
59
void tr_torrentSetHasPiece( tr_torrent * tor, int pieceIndex, int has );
 
60
 
 
61
void tr_torrentLock    ( const tr_torrent * );
 
62
void tr_torrentUnlock  ( const tr_torrent * );
 
63
 
 
64
int  tr_torrentIsSeed  ( const tr_torrent * );
 
65
 
 
66
void tr_torrentChangeMyPort  ( tr_torrent * );
 
67
 
 
68
int tr_torrentExists( tr_handle *, const uint8_t * );
 
69
tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * );
 
70
tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* );
 
71
 
 
72
void tr_torrentGetRates( const tr_torrent *, float * toClient, float * toPeer );
64
73
 
65
74
/* get the index of this piece's first block */
66
75
#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
81
90
    ( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize )
82
91
 
83
92
#define tr_block(a,b) _tr_block(tor,a,b)
84
 
int _tr_block( const tr_torrent_t * tor, int index, int begin );
 
93
int _tr_block( const tr_torrent * tor, int index, int begin );
85
94
 
 
95
uint64_t tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length );
86
96
 
87
97
typedef enum
88
98
{
89
 
    TR_RUN_CHECKING           = (1<<0), /* checking files' checksums */
90
 
    TR_RUN_RUNNING            = (1<<1), /* seeding or leeching */
91
 
    TR_RUN_STOPPING           = (1<<2), /* stopping */
92
 
    TR_RUN_STOPPING_NET_WAIT  = (1<<3), /* waiting on network -- we're
93
 
                                           telling tracker we've stopped */
94
 
    TR_RUN_STOPPED            = (1<<4)  /* stopped */
 
99
   TR_RECHECK_NONE,
 
100
   TR_RECHECK_WAIT,
 
101
   TR_RECHECK_NOW
95
102
}
96
 
run_status_t;
97
 
 
98
 
#define TR_ID_LEN               20
99
 
#define TR_KEY_LEN              20
100
 
 
101
 
struct tr_torrent_s
 
103
tr_recheck_state;
 
104
 
 
105
#define TR_ID_LEN  20
 
106
 
 
107
struct tr_torrent
102
108
{
103
 
    tr_handle_t * handle;
104
 
    tr_info_t info;
105
 
 
106
 
    tr_speedlimit_t    uploadLimitMode;
107
 
    tr_speedlimit_t    downloadLimitMode;
108
 
    struct tr_ratecontrol_s * upload;
109
 
    struct tr_ratecontrol_s * download;
110
 
    struct tr_ratecontrol_s * swarmspeed;
111
 
 
112
 
    int               error;
113
 
    char              errorString[128];
114
 
    int               hasChangedState;
115
 
 
116
 
    char              peer_id[TR_ID_LEN+1];
117
 
    char            * key;
118
 
    uint8_t         * azId;
119
 
    int               publicPort;
120
 
 
121
 
    /* An escaped string used to include the hash in HTTP queries */
122
 
    char              escapedHashString[3*SHA_DIGEST_LENGTH+1];
 
109
    tr_handle                 * handle;
 
110
    tr_info                     info;
 
111
 
 
112
    tr_speedlimit               uploadLimitMode;
 
113
    tr_speedlimit               downloadLimitMode;
 
114
    struct tr_ratecontrol     * upload;
 
115
    struct tr_ratecontrol     * download;
 
116
    struct tr_ratecontrol     * swarmspeed;
 
117
 
 
118
    int                        error;
 
119
    char                       errorString[128];
 
120
 
 
121
    uint8_t                    obfuscatedHash[SHA_DIGEST_LENGTH];
123
122
 
124
123
    /* Where to download */
125
 
    char            * destination;
 
124
    char                     * destination;
126
125
    
127
126
    /* 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;
 
127
    int                        blockSize;
 
128
    int                        blockCount;
 
129
 
 
130
    int                        lastBlockSize;
 
131
    int                        lastPieceSize;
 
132
 
 
133
    int                        blockCountInPiece;
 
134
    int                        blockCountInLastPiece;
136
135
    
137
 
    struct tr_completion_s * completion;
138
 
 
139
 
    volatile char     dieFlag;
140
 
    struct tr_bitfield_s   * uncheckedPieces;
141
 
    run_status_t      runStatus;
142
 
    cp_status_t       cpStatus;
143
 
    struct tr_thread_s     * thread;
144
 
    struct tr_rwlock_s     * lock;
145
 
 
146
 
    struct tr_tracker_s    * tracker;
147
 
    struct tr_io_s         * io;
148
 
    uint64_t          startDate;
149
 
    uint64_t          stopDate;
150
 
    char              ioLoaded;
151
 
    char              fastResumeDirty;
152
 
 
153
 
    int               peerCount;
154
 
    struct tr_peer_s * peers[TR_MAX_PEER_COUNT];
155
 
 
156
 
    uint64_t          downloadedCur;
157
 
    uint64_t          downloadedPrev;
158
 
    uint64_t          uploadedCur;
159
 
    uint64_t          uploadedPrev;
160
 
    uint64_t          activityDate;
161
 
 
162
 
    uint8_t           pexDisabled;
163
 
 
164
 
    int8_t            statCur;
165
 
    tr_stat_t         stats[2];
166
 
 
167
 
    tr_torrent_t    * next;
 
136
    struct tr_completion     * completion;
 
137
 
 
138
    struct tr_bitfield       * uncheckedPieces;
 
139
    cp_status_t                cpStatus;
 
140
 
 
141
    struct tr_tracker        * tracker;
 
142
    struct tr_publisher_tag  * trackerSubscription;
 
143
 
 
144
    uint64_t                   downloadedCur;
 
145
    uint64_t                   downloadedPrev;
 
146
    uint64_t                   uploadedCur;
 
147
    uint64_t                   uploadedPrev;
 
148
    uint64_t                   corruptCur;
 
149
    uint64_t                   corruptPrev;
 
150
 
 
151
    uint64_t                   startDate;
 
152
    uint64_t                   stopDate;
 
153
    uint64_t                   activityDate;
 
154
 
 
155
    tr_torrent_status_func   * status_func;
 
156
    void                     * status_func_user_data;
 
157
 
 
158
    unsigned int               pexDisabled : 1;
 
159
    unsigned int               statCur : 1;
 
160
    unsigned int               isRunning : 1;
 
161
 
 
162
    tr_recheck_state           recheckState;
 
163
 
 
164
    tr_stat                    stats[2];
 
165
 
 
166
    tr_torrent               * next;
168
167
};
169
168
 
170
 
struct tr_handle_s
 
169
struct tr_handle
171
170
{
172
 
    int                torrentCount;
173
 
    tr_torrent_t     * torrentList;
174
 
 
175
 
    char             * tag;
176
 
    int                isPortSet;
177
 
 
178
 
    char               useUploadLimit;
179
 
    char               useDownloadLimit;
180
 
    struct tr_ratecontrol_s * upload;
181
 
    struct tr_ratecontrol_s * download;
182
 
 
183
 
    struct tr_shared_s      * shared;
184
 
 
185
 
    char           key[TR_KEY_LEN+1];
186
 
 
187
 
    tr_handle_status_t stats[2];
188
 
    int                statCur;
189
 
#define TR_AZ_ID_LEN            20
190
 
    uint8_t        azId[TR_AZ_ID_LEN];
 
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
    struct tr_lock           * lock;
 
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];
191
198
};
192
199
 
 
200
void tr_globalLock       ( struct tr_handle * );
 
201
void tr_globalUnlock     ( struct tr_handle * );
 
202
int  tr_globalIsLocked   ( const struct tr_handle * );
 
203
 
 
204
 
193
205
#endif