~ubuntu-branches/ubuntu/jaunty/transmission/jaunty-security

« back to all changes in this revision

Viewing changes to libtransmission/torrent.h

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2008-11-28 15:33:48 UTC
  • mfrom: (1.1.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20081128153348-it70trfnxiroblmc
Tags: 1.40-0ubuntu1
* New upstream release (LP: #302672)
  - Tracker communication uses fewer resources
  - More accurate bandwidth limits
  - Reduce disk fragmentation by preallocating files (LP: #287726)
  - Stability, security and performance improvements to the RPC /
    Web UI server (closes LP: #290423)
  - Support compression when serving Web UI and RPC responses
  - Simplify the RPC whitelist
  - Fix bug that prevented handshakes with encrypted BitComet peers
  - Fix 1.3x bug that could re-download some data unnecessarily
    (LP: #295040)
  - Option to automatically update the blocklist weekly
  - Added off-hour bandwidth scheduling
  - Simplify file/priority selection in the details dialog
  - Fix a couple of crashes
  - New / updated translations
  - Don't inhibit hibernation by default (LP: #292929)
  - Use "close" animation when sending to notification area (LP: #130811)
  - Fix resize problems (LP: #269872)
  - Support "--version" option when launching from command line
    (LP: #292011)
  - Correctly parse announce URLs that have leading or trailing
    spaces (LP: #262411)
  - Display an error when "Open Torrent" fails (LP: #281463)
* Dropped 10_fix_crasher_from_upstream.dpatch: Fix is in this
  upstream release.
* debian/control: Don't just build-depend on libcurl-dev, which is
  a virtual package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: torrent.h 6016 2008-06-03 19:16:12Z charles $
 
2
 * $Id: torrent.h 7069 2008-11-08 02:49:04Z charles $
3
3
 *
4
4
 * Copyright (c) 2005-2008 Transmission authors and contributors
5
5
 *
25
25
#ifndef TR_TORRENT_H
26
26
#define TR_TORRENT_H 1
27
27
 
 
28
struct tr_ratecontrol;
 
29
 
 
30
/**
 
31
***  Package-visible ctor API
 
32
**/
 
33
 
 
34
void        tr_ctorSetSave( tr_ctor * ctor,
 
35
                            int       saveMetadataInOurTorrentsDir );
 
36
 
 
37
int         tr_ctorGetSave( const tr_ctor * ctor );
 
38
 
 
39
/**
 
40
***
 
41
**/
 
42
 
28
43
/* just like tr_torrentSetFileDLs but doesn't trigger a fastresume save */
29
 
void tr_torrentInitFileDLs( tr_torrent       * tor,
30
 
                            tr_file_index_t  * files,
31
 
                            tr_file_index_t    fileCount,
32
 
                            int                do_download );
33
 
 
34
 
int tr_torrentIsPrivate( const tr_torrent * );
35
 
 
36
 
void tr_torrentRecheckCompleteness( tr_torrent * );
37
 
 
38
 
void tr_torrentResetTransferStats( tr_torrent * );
39
 
 
40
 
void tr_torrentSetHasPiece( tr_torrent       * tor,
41
 
                            tr_piece_index_t   pieceIndex,
42
 
                            int                has );
43
 
 
44
 
void tr_torrentLock    ( const tr_torrent * );
45
 
void tr_torrentUnlock  ( const tr_torrent * );
46
 
 
47
 
int  tr_torrentIsSeed  ( const tr_torrent * );
48
 
 
49
 
void tr_torrentChangeMyPort  ( tr_torrent * );
50
 
 
51
 
int tr_torrentExists( const tr_handle *, const uint8_t * );
52
 
tr_torrent* tr_torrentFindFromId( tr_handle *, int id );
53
 
tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * );
54
 
tr_torrent* tr_torrentFindFromHashString( tr_handle *, const char * );
55
 
tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* );
56
 
 
57
 
void tr_torrentGetRates( const tr_torrent *, float * toClient, float * toPeer );
58
 
 
59
 
int tr_torrentAllowsPex( const tr_torrent * );
 
44
void        tr_torrentInitFileDLs( tr_torrent *      tor,
 
45
                                   tr_file_index_t * files,
 
46
                                   tr_file_index_t   fileCount,
 
47
                                   int               do_download );
 
48
 
 
49
int         tr_torrentIsPrivate( const tr_torrent * );
 
50
 
 
51
void        tr_torrentRecheckCompleteness( tr_torrent * );
 
52
 
 
53
void        tr_torrentResetTransferStats( tr_torrent * );
 
54
 
 
55
void        tr_torrentSetHasPiece( tr_torrent *     tor,
 
56
                                   tr_piece_index_t pieceIndex,
 
57
                                   int              has );
 
58
 
 
59
void        tr_torrentLock( const tr_torrent * session );
 
60
 
 
61
void        tr_torrentUnlock( const tr_torrent * session );
 
62
 
 
63
int         tr_torrentIsSeed( const tr_torrent * session );
 
64
 
 
65
void        tr_torrentChangeMyPort( tr_torrent * session );
 
66
 
 
67
int         tr_torrentExists( const tr_session * session,
 
68
                              const uint8_t    * hash );
 
69
 
 
70
tr_torrent* tr_torrentFindFromId( tr_session * session,
 
71
                                  int          id );
 
72
 
 
73
tr_torrent* tr_torrentFindFromHash( tr_session *    session,
 
74
                                    const uint8_t * hash );
 
75
 
 
76
tr_torrent* tr_torrentFindFromHashString( tr_session * session,
 
77
                                          const char * hashString );
 
78
 
 
79
tr_torrent* tr_torrentFindFromObfuscatedHash( tr_session    * session,
 
80
                                              const uint8_t * hash );
 
81
 
 
82
int         tr_torrentAllowsPex( const tr_torrent * );
 
83
 
 
84
int         tr_torrentIsPieceTransferAllowed( const tr_torrent * torrent,
 
85
                                              tr_direction       direction );
60
86
 
61
87
/* get the index of this piece's first block */
62
 
#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
 
88
#define tr_torPieceFirstBlock( tor, piece ) ( ( piece ) *\
 
89
                                             ( tor )->blockCountInPiece )
63
90
 
64
91
/* what piece index is this block in? */
65
 
#define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece )
 
92
#define tr_torBlockPiece( tor, block ) ( ( block ) /\
 
93
                                        ( tor )->blockCountInPiece )
66
94
 
67
95
/* how many blocks are in this piece? */
68
 
#define tr_torPieceCountBlocks(tor,piece) \
69
 
    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece )
 
96
#define tr_torPieceCountBlocks( tor, piece ) \
 
97
    ( ( ( piece ) ==\
 
98
       ( ( tor )->info.pieceCount - \
 
99
        1 ) ) ? ( tor )->blockCountInLastPiece : ( tor )->blockCountInPiece )
70
100
 
71
101
/* how many bytes are in this piece? */
72
 
#define tr_torPieceCountBytes(tor,piece) \
73
 
    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize )
 
102
#define tr_torPieceCountBytes( tor, piece ) \
 
103
    ( ( ( piece ) ==\
 
104
       ( ( tor )->info.pieceCount - \
 
105
        1 ) ) ? ( tor )->lastPieceSize : ( tor )->info.pieceSize )
74
106
 
75
107
/* how many bytes are in this block? */
76
 
#define tr_torBlockCountBytes(tor,block) \
77
 
    ( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize )
 
108
#define tr_torBlockCountBytes( tor, block ) \
 
109
    ( ( ( block ) ==\
 
110
       ( ( tor )->blockCount - \
 
111
        1 ) ) ? ( tor )->lastBlockSize : ( tor )->blockSize )
78
112
 
79
 
#define tr_block(a,b) _tr_block(tor,a,b)
 
113
#define tr_block( a, b ) _tr_block( tor, a, b )
80
114
tr_block_index_t _tr_block( const tr_torrent * tor,
81
115
                            tr_piece_index_t   index,
82
116
                            uint32_t           offset );
83
117
 
84
 
int tr_torrentReqIsValid( const tr_torrent * tor,
85
 
                          tr_piece_index_t   index,
86
 
                          uint32_t           offset,
87
 
                          uint32_t           length );
88
 
 
89
 
uint64_t tr_pieceOffset( const tr_torrent * tor,
90
 
                         tr_piece_index_t   index,
91
 
                         uint32_t           offset,
92
 
                         uint32_t           length );
93
 
 
94
 
void tr_torrentInitFilePriority( tr_torrent       * tor,
95
 
                                 tr_file_index_t    fileIndex,
96
 
                                 tr_priority_t      priority );
97
 
 
98
 
 
99
 
int  tr_torrentCountUncheckedPieces( const tr_torrent * );
100
 
int  tr_torrentIsPieceChecked      ( const tr_torrent *, tr_piece_index_t piece );
101
 
int  tr_torrentIsFileChecked       ( const tr_torrent *, tr_file_index_t file );
102
 
void tr_torrentSetPieceChecked     ( tr_torrent *, tr_piece_index_t piece, int isChecked );
103
 
void tr_torrentSetFileChecked      ( tr_torrent *, tr_file_index_t file, int isChecked );
104
 
void tr_torrentUncheck             ( tr_torrent * );
105
 
 
106
 
int tr_torrentPromoteTracker       ( tr_torrent *, int trackerIndex );
107
 
 
108
 
time_t* tr_torrentGetMTimes        ( const tr_torrent *, int * setmeCount );
 
118
int              tr_torrentReqIsValid( const tr_torrent * tor,
 
119
                                       tr_piece_index_t   index,
 
120
                                       uint32_t           offset,
 
121
                                       uint32_t           length );
 
122
 
 
123
uint64_t         tr_pieceOffset( const tr_torrent * tor,
 
124
                                 tr_piece_index_t   index,
 
125
                                 uint32_t           offset,
 
126
                                 uint32_t           length );
 
127
 
 
128
void             tr_torrentInitFilePriority( tr_torrent       * tor,
 
129
                                             tr_file_index_t    fileIndex,
 
130
                                             tr_priority_t      priority );
 
131
 
 
132
 
 
133
int              tr_torrentCountUncheckedPieces( const tr_torrent * );
 
134
 
 
135
int              tr_torrentIsPieceChecked( const tr_torrent  * tor,
 
136
                                           tr_piece_index_t    piece );
 
137
 
 
138
int              tr_torrentIsFileChecked( const tr_torrent  * tor,
 
139
                                          tr_file_index_t     file );
 
140
 
 
141
void             tr_torrentSetPieceChecked( tr_torrent       * tor,
 
142
                                            tr_piece_index_t   piece,
 
143
                                            int                isChecked );
 
144
 
 
145
void             tr_torrentSetFileChecked( tr_torrent       * tor,
 
146
                                           tr_file_index_t    file,
 
147
                                           int                isChecked );
 
148
 
 
149
void             tr_torrentUncheck( tr_torrent * tor );
 
150
 
 
151
int              tr_torrentPromoteTracker( tr_torrent   * tor,
 
152
                                           int            trackerIndex );
 
153
 
 
154
time_t*          tr_torrentGetMTimes( const tr_torrent  * tor,
 
155
                                      size_t            * setmeCount );
109
156
 
110
157
typedef enum
111
158
{
112
 
   TR_VERIFY_NONE,
113
 
   TR_VERIFY_WAIT,
114
 
   TR_VERIFY_NOW
 
159
    TR_VERIFY_NONE,
 
160
    TR_VERIFY_WAIT,
 
161
    TR_VERIFY_NOW
115
162
}
116
163
tr_verify_state;
117
164
 
118
165
struct tr_torrent
119
166
{
120
 
    tr_handle                * handle;
121
 
    tr_info                    info;
122
 
 
123
 
    tr_speedlimit              uploadLimitMode;
124
 
    tr_speedlimit              downloadLimitMode;
125
 
    struct tr_ratecontrol    * upload;
126
 
    struct tr_ratecontrol    * download;
127
 
    struct tr_ratecontrol    * swarmSpeed;
128
 
 
129
 
    int                        error;
130
 
    char                       errorString[128];
131
 
 
132
 
    uint8_t                    obfuscatedHash[SHA_DIGEST_LENGTH];
 
167
    tr_session *             session;
 
168
    tr_info                  info;
 
169
 
 
170
    int                      uploadLimit;
 
171
    tr_speedlimit            uploadLimitMode;
 
172
    int                      downloadLimit;
 
173
    tr_speedlimit            downloadLimitMode;
 
174
 
 
175
    struct tr_ratecontrol *  swarmSpeed;
 
176
 
 
177
    int                      error;
 
178
    char                     errorString[128];
 
179
 
 
180
    uint8_t                  obfuscatedHash[SHA_DIGEST_LENGTH];
133
181
 
134
182
    /* Where to download */
135
 
    char                     * downloadDir;
136
 
    
 
183
    char *  downloadDir;
 
184
 
137
185
    /* How many bytes we ask for per request */
138
186
    uint32_t                   blockSize;
139
187
    tr_block_index_t           blockCount;
143
191
 
144
192
    uint32_t                   blockCountInPiece;
145
193
    uint32_t                   blockCountInLastPiece;
146
 
    
147
 
    struct tr_completion     * completion;
148
 
 
149
 
    struct tr_bitfield       * checkedPieces;
150
 
    cp_status_t                cpStatus;
151
 
 
152
 
    struct tr_tracker        * tracker;
153
 
    struct tr_publisher_tag  * trackerSubscription;
 
194
 
 
195
    struct tr_completion *     completion;
 
196
 
 
197
    struct tr_bitfield *       checkedPieces;
 
198
    tr_completeness            completeness;
 
199
 
 
200
    struct tr_tracker *        tracker;
 
201
    struct tr_publisher_tag *  trackerSubscription;
154
202
 
155
203
    uint64_t                   downloadedCur;
156
204
    uint64_t                   downloadedPrev;
164
212
    time_t                     doneDate;
165
213
    time_t                     startDate;
166
214
 
167
 
    tr_torrent_status_func   * status_func;
168
 
    void                     * status_func_user_data;
 
215
    tr_torrent_completeness_func *   completeness_func;
 
216
    void *                     completeness_func_user_data;
169
217
 
170
 
    unsigned int               isRunning : 1;
 
218
    unsigned int               isRunning  : 1;
171
219
    unsigned int               isDeleting : 1;
172
220
 
173
221
    uint16_t                   maxConnectedPeers;
177
225
    time_t                     lastStatTime;
178
226
    tr_stat                    stats;
179
227
 
180
 
    tr_torrent               * next;
 
228
    tr_torrent *               next;
181
229
 
182
230
    int                        uniqueId;
 
231
 
 
232
    /* the rate at which pieces are being transferred between client and
 
233
     * its peers.  protocol overhead is NOT included; only the piece data */
 
234
    struct tr_ratecontrol    * pieceSpeed[2];
 
235
 
 
236
    /* the rate at which bytes are being sent between client and peers */
 
237
    struct tr_ratecontrol    * rawSpeed[2];
183
238
};
184
239
 
185
240
#endif