~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): Andrew Starr-Bochicchio, Andrew Starr-Bochicchio, Martin Pitt
  • Date: 2009-02-26 11:55:50 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20090226115550-3rnhgt9qhe3y6g74
Tags: 1.50-1ubuntu1
[ Andrew Starr-Bochicchio ]
* Merge from debian unstable (LP: #329161), remaining changes:
 - debian/control: 
  + Added replaces & provides clutch (now included as part of transmission).
  + Build-depends on quilt.
 - debian/rules: 
  + Uncommented "include /usr/share/quilt/quilt.make".
  + Added patch/unpatch targets for Quilt.
  + Create a PO template during package build.
 - 20_add_X-Ubuntu-Gettext-Domain.diff: Add X-Ubuntu-Gettext-Domain 
   to .desktop file.

[ Martin Pitt ]
* Add 01_check_notification_actions.diff: Check if notification
  agent supports actions, and do not use actions if not. (LP: #334252)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************************************
2
 
 * $Id: torrent.h 7365 2008-12-13 22:52:13Z charles $
3
 
 *
4
 
 * Copyright (c) 2005-2008 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
 
 *****************************************************************************/
 
1
/*
 
2
 * This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com>
 
3
 *
 
4
 * This file is licensed by the GPL version 2.  Works owned by the
 
5
 * Transmission project are granted a special exemption to clause 2(b)
 
6
 * so that the bulk of its code can remain under the MIT license. 
 
7
 * This exemption does not extend to derived works not owned by
 
8
 * the Transmission project.
 
9
 *
 
10
 * $Id: torrent.h 7813 2009-01-29 18:18:24Z charles $
 
11
 */
24
12
 
25
13
#ifndef __TRANSMISSION__
26
 
#error only libtransmission should #include this header.
 
14
 #error only libtransmission should #include this header.
27
15
#endif
28
16
 
29
17
#ifndef TR_TORRENT_H
30
18
#define TR_TORRENT_H 1
31
19
 
 
20
#include "completion.h" /* tr_completion */
 
21
#include "ratecontrol.h" /* tr_ratecontrol */
 
22
#include "session.h" /* tr_globalLock(), tr_globalUnlock() */
 
23
#include "utils.h" /* tr_bitfield */
 
24
 
32
25
struct tr_bandwidth;
33
26
struct tr_ratecontrol;
 
27
struct tr_torrent_peers;
34
28
 
35
29
/**
36
30
***  Package-visible ctor API
37
31
**/
38
32
 
39
33
void        tr_ctorSetSave( tr_ctor * ctor,
40
 
                            int       saveMetadataInOurTorrentsDir );
 
34
                            tr_bool   saveMetadataInOurTorrentsDir );
41
35
 
42
36
int         tr_ctorGetSave( const tr_ctor * ctor );
43
37
 
49
43
void        tr_torrentInitFileDLs( tr_torrent *      tor,
50
44
                                   tr_file_index_t * files,
51
45
                                   tr_file_index_t   fileCount,
52
 
                                   int               do_download );
53
 
 
54
 
int         tr_torrentIsPrivate( const tr_torrent * );
 
46
                                   tr_bool           do_download );
55
47
 
56
48
void        tr_torrentRecheckCompleteness( tr_torrent * );
57
49
 
59
51
 
60
52
void        tr_torrentSetHasPiece( tr_torrent *     tor,
61
53
                                   tr_piece_index_t pieceIndex,
62
 
                                   int              has );
63
 
 
64
 
void        tr_torrentLock( const tr_torrent * session );
65
 
 
66
 
void        tr_torrentUnlock( const tr_torrent * session );
67
 
 
68
 
int         tr_torrentIsSeed( const tr_torrent * session );
 
54
                                   tr_bool          has );
69
55
 
70
56
void        tr_torrentChangeMyPort( tr_torrent * session );
71
57
 
72
 
int         tr_torrentExists( const tr_session * session,
73
 
                              const uint8_t    * hash );
74
 
 
75
58
tr_torrent* tr_torrentFindFromId( tr_session * session,
76
59
                                  int          id );
77
60
 
84
67
tr_torrent* tr_torrentFindFromObfuscatedHash( tr_session    * session,
85
68
                                              const uint8_t * hash );
86
69
 
87
 
int         tr_torrentAllowsPex( const tr_torrent * );
88
 
 
89
70
tr_bool     tr_torrentIsPieceTransferAllowed( const tr_torrent * torrent,
90
71
                                              tr_direction       direction );
91
72
 
92
 
/* get the index of this piece's first block */
93
 
#define tr_torPieceFirstBlock( tor, piece ) ( ( piece ) *\
94
 
                                             ( tor )->blockCountInPiece )
95
 
 
96
 
/* what piece index is this block in? */
97
 
#define tr_torBlockPiece( tor, block ) ( ( block ) /\
98
 
                                        ( tor )->blockCountInPiece )
99
 
 
100
 
/* how many blocks are in this piece? */
101
 
#define tr_torPieceCountBlocks( tor, piece ) \
102
 
    ( ( ( piece ) ==\
103
 
       ( ( tor )->info.pieceCount - \
104
 
        1 ) ) ? ( tor )->blockCountInLastPiece : ( tor )->blockCountInPiece )
105
 
 
106
 
/* how many bytes are in this piece? */
107
 
#define tr_torPieceCountBytes( tor, piece ) \
108
 
    ( ( ( piece ) ==\
109
 
       ( ( tor )->info.pieceCount - \
110
 
        1 ) ) ? ( tor )->lastPieceSize : ( tor )->info.pieceSize )
111
 
 
112
 
/* how many bytes are in this block? */
113
 
#define tr_torBlockCountBytes( tor, block ) \
114
 
    ( ( ( block ) ==\
115
 
       ( ( tor )->blockCount - \
116
 
        1 ) ) ? ( tor )->lastBlockSize : ( tor )->blockSize )
117
73
 
118
74
#define tr_block( a, b ) _tr_block( tor, a, b )
119
75
tr_block_index_t _tr_block( const tr_torrent * tor,
120
76
                            tr_piece_index_t   index,
121
77
                            uint32_t           offset );
122
78
 
123
 
int              tr_torrentReqIsValid( const tr_torrent * tor,
 
79
tr_bool          tr_torrentReqIsValid( const tr_torrent * tor,
124
80
                                       tr_piece_index_t   index,
125
81
                                       uint32_t           offset,
126
82
                                       uint32_t           length );
137
93
 
138
94
int              tr_torrentCountUncheckedPieces( const tr_torrent * );
139
95
 
140
 
int              tr_torrentIsPieceChecked( const tr_torrent  * tor,
141
 
                                           tr_piece_index_t    piece );
142
 
 
143
 
int              tr_torrentIsFileChecked( const tr_torrent  * tor,
 
96
tr_bool          tr_torrentIsFileChecked( const tr_torrent  * tor,
144
97
                                          tr_file_index_t     file );
145
98
 
146
99
void             tr_torrentSetPieceChecked( tr_torrent       * tor,
147
100
                                            tr_piece_index_t   piece,
148
 
                                            int                isChecked );
 
101
                                            tr_bool            isChecked );
149
102
 
150
103
void             tr_torrentSetFileChecked( tr_torrent       * tor,
151
104
                                           tr_file_index_t    file,
152
 
                                           int                isChecked );
 
105
                                           tr_bool            isChecked );
153
106
 
154
107
void             tr_torrentUncheck( tr_torrent * tor );
155
108
 
159
112
time_t*          tr_torrentGetMTimes( const tr_torrent  * tor,
160
113
                                      size_t            * setmeCount );
161
114
 
 
115
tr_torrent*      tr_torrentNext( tr_session  * session,
 
116
                                 tr_torrent  * current );
 
117
 
 
118
 
162
119
typedef enum
163
120
{
164
121
    TR_VERIFY_NONE,
174
131
 
175
132
    tr_speedlimit            speedLimitMode[2];
176
133
 
177
 
    struct tr_ratecontrol *  swarmSpeed;
 
134
    struct tr_ratecontrol    swarmSpeed;
 
135
 
 
136
    int                      magicNumber;
178
137
 
179
138
    int                      error;
180
139
    char                     errorString[128];
203
162
    uint32_t                   blockCountInPiece;
204
163
    uint32_t                   blockCountInLastPiece;
205
164
 
206
 
    struct tr_completion *     completion;
 
165
    struct tr_completion       completion;
207
166
 
208
 
    struct tr_bitfield *       checkedPieces;
 
167
    struct tr_bitfield         checkedPieces;
209
168
    tr_completeness            completeness;
210
169
 
211
170
    struct tr_tracker *        tracker;
241
200
    int                        uniqueId;
242
201
 
243
202
    struct tr_bandwidth      * bandwidth;
244
 
};
 
203
 
 
204
    struct tr_torrent_peers  * torrentPeers;
 
205
};
 
206
 
 
207
/* get the index of this piece's first block */
 
208
static TR_INLINE tr_block_index_t
 
209
tr_torPieceFirstBlock( const tr_torrent * tor, const tr_piece_index_t piece )
 
210
{
 
211
    return piece * tor->blockCountInPiece;
 
212
}
 
213
 
 
214
/* what piece index is this block in? */
 
215
static TR_INLINE tr_piece_index_t
 
216
tr_torBlockPiece( const tr_torrent * tor, const tr_block_index_t block )
 
217
{
 
218
    return block / tor->blockCountInPiece;
 
219
}
 
220
 
 
221
/* how many blocks are in this piece? */
 
222
static TR_INLINE uint32_t
 
223
tr_torPieceCountBlocks( const tr_torrent * tor, const tr_piece_index_t piece )
 
224
{
 
225
    return piece == tor->info.pieceCount - 1 ? tor->blockCountInLastPiece
 
226
                                             : tor->blockCountInPiece;
 
227
}
 
228
 
 
229
/* how many bytes are in this piece? */
 
230
static TR_INLINE uint32_t
 
231
tr_torPieceCountBytes( const tr_torrent * tor, const tr_piece_index_t piece )
 
232
{
 
233
    return piece == tor->info.pieceCount - 1 ? tor->lastPieceSize
 
234
                                             : tor->info.pieceSize;
 
235
}
 
236
 
 
237
/* how many bytes are in this block? */
 
238
static TR_INLINE uint32_t
 
239
tr_torBlockCountBytes( const tr_torrent * tor, const tr_block_index_t block )
 
240
{
 
241
    return block == tor->blockCount - 1 ? tor->lastBlockSize
 
242
                                        : tor->blockSize;
 
243
}
 
244
 
 
245
static TR_INLINE void tr_torrentLock( const tr_torrent * tor )
 
246
{
 
247
    tr_globalLock( tor->session );
 
248
}
 
249
 
 
250
static TR_INLINE void tr_torrentUnlock( const tr_torrent * tor )
 
251
{
 
252
    tr_globalUnlock( tor->session );
 
253
}
 
254
 
 
255
static TR_INLINE tr_bool
 
256
tr_torrentExists( const tr_session * session, const uint8_t *   torrentHash )
 
257
{
 
258
    return tr_torrentFindFromHash( (tr_session*)session, torrentHash ) != NULL;
 
259
}
 
260
 
 
261
static TR_INLINE tr_bool
 
262
tr_torrentIsSeed( const tr_torrent * tor )
 
263
{
 
264
    return tor->completeness != TR_LEECH;
 
265
}
 
266
 
 
267
static TR_INLINE tr_bool tr_torrentIsPrivate( const tr_torrent * tor )
 
268
{
 
269
    return ( tor != NULL ) && tor->info.isPrivate;
 
270
}
 
271
 
 
272
static TR_INLINE tr_bool tr_torrentAllowsPex( const tr_torrent * tor )
 
273
{
 
274
    return ( tor != NULL  ) && tor->session->isPexEnabled && !tr_torrentIsPrivate( tor );
 
275
}
 
276
 
 
277
static TR_INLINE tr_bool tr_torrentIsPieceChecked( const tr_torrent  * tor, tr_piece_index_t i )
 
278
{
 
279
    return tr_bitfieldHas( &tor->checkedPieces, i );
 
280
}
 
281
 
 
282
/***
 
283
****
 
284
***/
 
285
 
 
286
enum
 
287
{
 
288
    TORRENT_MAGIC_NUMBER = 95549
 
289
};
 
290
 
 
291
static inline tr_bool tr_isTorrent( const tr_torrent * tor )
 
292
{
 
293
    return ( tor != NULL )
 
294
        && ( tor->magicNumber == TORRENT_MAGIC_NUMBER )
 
295
        && ( tr_isSession( tor->session ) );
 
296
}
245
297
 
246
298
#endif