/usr/include/libktorrent/torrent/torrent.h is in libktorrent-dev 1.3.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | /***************************************************************************
* Copyright (C) 2005 by *
* Joris Guisson <joris.guisson@gmail.com> *
* Ivan Vasic <ivasic@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef BTTORRENT_H
#define BTTORRENT_H
#include <kurl.h>
#include <QVector>
#include <QList>
#include <util/sha1hash.h>
#include <util/constants.h>
#include <interfaces/torrentinterface.h>
#include <peer/peerid.h>
#include <ktorrent_export.h>
#include "torrentfile.h"
class QTextCodec;
namespace bt
{
class BNode;
class BDictNode;
class BListNode;
struct TrackerTier
{
KUrl::List urls;
TrackerTier* next;
TrackerTier() : next(0)
{}
~TrackerTier()
{
delete next;
}
};
/**
* @author Joris Guisson
*
* Listener base class, to get notified when the priority of a file changes.
*/
class KTORRENT_EXPORT FilePriorityListener
{
public:
virtual ~FilePriorityListener() {}
virtual void downloadPriorityChanged(TorrentFile* tf,Priority newpriority,Priority oldpriority) = 0;
};
/**
* @author Joris Guisson
* @brief Loads a .torrent file
*
* Loads a torrent file and calculates some miscelanious other data,
* like the info_hash and the peer_id.
*/
class KTORRENT_EXPORT Torrent
{
public:
Torrent();
Torrent(const bt::SHA1Hash & hash);
virtual ~Torrent();
/**
* Set the FilePriorityListener
* @param l THe listener
*/
void setFilePriorityListener(FilePriorityListener* l) {file_prio_listener = l;}
/**
* Called by TorrentFile when the priority changes
* @param tf The file
* @param newpriority The old priority
* @param oldpriority The new priority
*/
void downloadPriorityChanged(TorrentFile* tf,Priority newpriority,Priority oldpriority);
/**
* Called by TorrentFile when the percentage changes
* @param tf The file
* @param perc The percentage
*/
void filePercentageChanged(TorrentFile* tf,float perc);
/**
* Called by TorrentFile when the preview state changes
* @param tf The file
* @param preview Whether preview is possible or not
*/
void filePreviewChanged(TorrentFile* tf,bool preview);
/**
* Load a .torrent file.
* @param file The file
* @param verbose Whether to print information to the log
* @throw Error if something goes wrong
*/
void load(const QString & file,bool verbose);
/**
* Load a .torrent file.
* @param data The data
* @param verbose Whether to print information to the log
* @throw Error if something goes wrong
*/
void load(const QByteArray & data,bool verbose);
void debugPrintInfo();
/// Return the comments in the torrent
QString getComments() const {return comments;}
/// Get the number of chunks.
Uint32 getNumChunks() const {return hash_pieces.size();}
/// Get the size of a chunk.
Uint64 getChunkSize() const {return chunk_size;}
/// Get the size of the last chunk
Uint64 getLastChunkSize() const {return last_chunk_size;}
/// Get the info_hash.
const SHA1Hash & getInfoHash() const {return info_hash;}
/// Get our peer_id.
const PeerID & getPeerID() const {return peer_id;}
/// Get the file size in number of bytes.
Uint64 getTotalSize() const {return total_size;}
/// Get the suggested name.
QString getNameSuggestion() const {return name_suggestion;}
/**
* Verify whether a hash matches the hash
* of a Chunk
* @param h The hash
* @param index The index of the chunk
* @return true if they match
*/
bool verifyHash(const SHA1Hash & h,Uint32 index);
/// Get the number of tracker URL's
unsigned int getNumTrackerURLs() const;
/**
* Get the hash of a Chunk. Throws an Error
* if idx is out of bounds.
* @param idx Index of Chunk
* @return The SHA1 hash of the chunk
*/
const SHA1Hash & getHash(Uint32 idx) const;
/// See if we have a multi file torrent.
bool isMultiFile() const {return files.count() > 0;}
/// Get the number of files in a multi file torrent.
/// If we have a single file torrent, this will return 0.
Uint32 getNumFiles() const {return files.count();}
/**
* Get a TorrentFile. If the index is out of range, or
* we have a single file torrent we return a null TorrentFile.
* @param idx Index of the file
* @param A reference to the file
*/
TorrentFile & getFile(Uint32 idx);
/**
* Get a TorrentFile. If the index is out of range, or
* we have a single file torrent we return a null TorrentFile.
* @param idx Index of the file
* @param A reference to the file
*/
const TorrentFile & getFile(Uint32 idx) const;
/**
* Calculate in which file(s) a Chunk lies. A list will
* get filled with the indices of all the files. The list gets cleared at
* the beginning. If something is wrong only the list will
* get cleared.
* @param chunk The index of the chunk
* @param file_list This list will be filled with all the indices
*/
void calcChunkPos(Uint32 chunk,QList<Uint32> & file_list) const;
/**
* Checks if torrent file is audio or video.
**/
bool isMultimedia() const;
/// See if the torrent is private
bool isPrivate() const {return priv_torrent;}
/// Is the torrent loaded
bool isLoaded() const {return loaded;}
///Gets a pointer to AnnounceList
const TrackerTier* getTrackerList() const { return trackers; }
/// Get the number of initial DHT nodes
Uint32 getNumDHTNodes() const {return nodes.count();}
/// Get a DHT node
const DHTNode & getDHTNode(Uint32 i) {return nodes[i];}
/**
* Update the percentage of all files.
* @param cman The ChunkManager
*/
void updateFilePercentage(ChunkManager & cman);
/**
* Update the percentage of a all files which have a particular chunk.
* @param cman The ChunkManager
*/
void updateFilePercentage(Uint32 chunk,ChunkManager & cman);
/**
* Get the list with web seed URL's
*/
const KUrl::List & getWebSeeds() const {return web_seeds;}
/// Change the text codec
void changeTextCodec(QTextCodec* codec);
/// Get the text codec
const QTextCodec* getTextCodec() {return text_codec;}
/// Set the monitor
void setMonitor(MonitorInterface* m) {tmon = m;}
/// Get the metadata
const QByteArray & getMetaData() const {return metadata;}
private:
void loadInfo(BDictNode* node);
void loadTrackerURL(const QString & s);
void loadHash(BDictNode* dict);
void loadFiles(BListNode* node);
void loadNodes(BListNode* node);
void loadAnnounceList(BNode* node);
void loadWebSeeds(BListNode* node);
bool checkPathForDirectoryTraversal(const QString & p);
private:
TrackerTier* trackers;
QString name_suggestion;
QByteArray unencoded_name;
Uint64 chunk_size;
Uint64 last_chunk_size;
Uint64 total_size;
SHA1Hash info_hash;
PeerID peer_id;
QVector<SHA1Hash> hash_pieces;
QVector<TorrentFile> files;
QVector<DHTNode> nodes;
QTextCodec* text_codec;
bool priv_torrent;
KUrl::List web_seeds;
FilePriorityListener* file_prio_listener;
mutable Uint32 pos_cache_chunk;
mutable Uint32 pos_cache_file;
MonitorInterface* tmon;
QString comments;
QByteArray metadata;
bool loaded;
};
}
#endif
|