libktorrent  2.2.0
Signals | Public Member Functions | Static Public Member Functions | List of all members
bt::ChunkManager Class Reference

#include <chunkmanager.h>

Inheritance diagram for bt::ChunkManager:
Inheritance graph
[legend]

Signals

void corrupted (Uint32 chunk)
 
void excluded (Uint32 from, Uint32 to)
 
void included (Uint32 from, Uint32 to)
 
void updateStats ()
 

Public Member Functions

 ChunkManager (Torrent &tor, const QString &tmpdir, const QString &datadir, bool custom_output_name, CacheFactory *fac)
 
Uint64 bytesExcluded () const
 
Uint64 bytesLeft () const
 
Uint64 bytesLeftToDownload () const
 
void changeDataDir (const QString &data_dir)
 
void changeOutputPath (const QString &output_path)
 
void checkMemoryUsage ()
 Remove obsolete chunks.
 
void chunkDownloaded (unsigned int i)
 
Uint32 chunksDownloaded () const
 
Uint32 chunksExcluded () const
 
Uint32 chunksLeft () const
 
bool completed () const
 Are all not deselected chunks downloaded.
 
void createFiles (bool check_priority=false)
 
void dataChecked (const BitSet &ok_chunks, Uint32 from, Uint32 to)
 
void debugPrintMemUsage ()
 Print memory usage to log file.
 
JobdeleteDataFiles ()
 Delete all data files.
 
Uint64 diskUsage ()
 Get the current disk usage of all the files in this torrent.
 
void dndMissingFiles ()
 Set missing files as do not download.
 
void downloadPriorityChanged (TorrentFile *tf, Priority newpriority, Priority oldpriority)
 The download priority of a file has changed.
 
void exclude (Uint32 from, Uint32 to)
 
const BitSetgetBitSet () const
 
ChunkgetChunk (unsigned int i)
 
QString getDataDir () const
 Get the data dir.
 
const BitSetgetExcludedBitSet () const
 
Uint32 getNumChunks () const
 Get the number of chunks into the file.
 
const BitSetgetOnlySeedBitSet () const
 
QString getOutputPath () const
 Get the actual output path.
 
const TorrentgetTorrent () const
 Get the torrent.
 
bool hasExistingFiles () const
 Test if the torrent has existing files, only works the first time a torrent is loaded.
 
bool hasMissingFiles (QStringList &sl)
 
bool haveAllChunks () const
 
void include (Uint32 from, Uint32 to)
 
bool isStorageMounted (QStringList &missing)
 Is the storage mounted ?
 
void loadIndexFile ()
 
void markExistingFilesAsDownloaded ()
 Mark all existing files as downloaded.
 
JobmoveDataFiles (const QMap< TorrentFileInterface *, QString > &files)
 
JobmoveDataFiles (const QString &ndir)
 
void moveDataFilesFinished (const QMap< TorrentFileInterface *, QString > &files, Job *job)
 
void moveDataFilesFinished (Job *job)
 
Uint32 onlySeedChunks () const
 
void preparePreallocation (PreallocationThread *prealloc)
 
Uint32 previewChunkRangeSize () const
 Get the size in chunks of the preview range for a single file torrent.
 
Uint32 previewChunkRangeSize (const TorrentFile &tf) const
 Get the size in chunks of the preview range of a file of the torrent.
 
void prioritise (Uint32 from, Uint32 to, Priority priority)
 
void recreateMissingFiles ()
 Recreates missing files.
 
void resetChunk (unsigned int i)
 
void start ()
 
void stop ()
 

Static Public Member Functions

static void setPreviewSizes (Uint32 audio, Uint32 video)
 Set the preview sizes for audio and video files.
 

Detailed Description

Author
Joris Guisson

Manages all Chunk's and the cache file, where all the chunk's are stored. It also manages a separate index file, where the position of each piece in the cache file is stored.

The chunks are stored in the cache file in the correct order. Eliminating the need for a file reconstruction algorithm for single files.

Definition at line 60 of file chunkmanager.h.

Member Function Documentation

◆ bytesExcluded()

Uint64 bt::ChunkManager::bytesExcluded ( ) const

Calculates the number of bytes which have been excluded.

Returns
The number of bytes excluded

◆ bytesLeft()

Uint64 bt::ChunkManager::bytesLeft ( ) const

Calculates the number of bytes left for the tracker. Does include excluded chunks (this should be used for the tracker).

Returns
The number of bytes to download + the number of bytes excluded

◆ bytesLeftToDownload()

Uint64 bt::ChunkManager::bytesLeftToDownload ( ) const

Calculates the number of bytes left to download.

◆ changeDataDir()

void bt::ChunkManager::changeDataDir ( const QString &  data_dir)

Change the data dir.

Parameters
data_dir

◆ chunkDownloaded()

void bt::ChunkManager::chunkDownloaded ( unsigned int  i)

Mark a chunk as downloaded.

Parameters
iThe Chunk's index

◆ chunksDownloaded()

Uint32 bt::ChunkManager::chunksDownloaded ( ) const

Get the number of downloaded chunks

Returns

◆ chunksExcluded()

Uint32 bt::ChunkManager::chunksExcluded ( ) const

Get the number of chunks which have been excluded.

Returns
The number of excluded chunks

◆ chunksLeft()

Uint32 bt::ChunkManager::chunksLeft ( ) const

Calculates the number of chunks left to download. Does not include excluded chunks.

Returns
The number of chunks to download

◆ corrupted

void bt::ChunkManager::corrupted ( Uint32  chunk)
signal

A corrupted chunk has been found during uploading.

Parameters
chunkThe chunk

◆ createFiles()

void bt::ChunkManager::createFiles ( bool  check_priority = false)

Create the cache file, and index files.

Parameters
check_priorityCheck if priority of chunk matches that of files
Exceptions
ErrorWhen it can be created

◆ dataChecked()

void bt::ChunkManager::dataChecked ( const BitSet ok_chunks,
Uint32  from,
Uint32  to 
)

Data has been checked, and these chunks are OK. The ChunkManager will update it's internal structures

Parameters
ok_chunksThe ok_chunks
fromFirst chunk of the check
toLast chunk of the check

◆ exclude()

void bt::ChunkManager::exclude ( Uint32  from,
Uint32  to 
)

Make sure that a range will not be downloaded.

Parameters
fromFirst chunk in range
toLast chunk in range

◆ excluded

void bt::ChunkManager::excluded ( Uint32  from,
Uint32  to 
)
signal

Emitted when a range of chunks has been excluded

Parameters
fromFirst chunk in range
toLast chunk in range

◆ getBitSet()

const BitSet& bt::ChunkManager::getBitSet ( ) const
inline

Get a BitSet of the status of all Chunks

Definition at line 226 of file chunkmanager.h.

◆ getChunk()

Chunk* bt::ChunkManager::getChunk ( unsigned int  i)

Get's the i'th Chunk.

Parameters
iThe Chunk's index
Returns
The Chunk, or 0 when i is out of bounds

◆ getExcludedBitSet()

const BitSet& bt::ChunkManager::getExcludedBitSet ( ) const
inline

Get the excluded bitset

Definition at line 234 of file chunkmanager.h.

◆ getOnlySeedBitSet()

const BitSet& bt::ChunkManager::getOnlySeedBitSet ( ) const
inline

Get the only seed bitset.

Definition at line 242 of file chunkmanager.h.

◆ hasMissingFiles()

bool bt::ChunkManager::hasMissingFiles ( QStringList &  sl)

Test all files and see if they are not missing. If so put them in a list

◆ haveAllChunks()

bool bt::ChunkManager::haveAllChunks ( ) const

Check if we have all chunks, this is not the same as chunksLeft() == 0, it does not look at excluded chunks.

Returns
true if all chunks have been downloaded

◆ include()

void bt::ChunkManager::include ( Uint32  from,
Uint32  to 
)

Make sure that a range will be downloaded. Does the opposite of exclude.

Parameters
fromFirst chunk in range
toLast chunk in range

◆ included

void bt::ChunkManager::included ( Uint32  from,
Uint32  to 
)
signal

Emitted when a range of chunks has been included back.

Parameters
fromFirst chunk in range
toLast chunk in range

◆ loadIndexFile()

void bt::ChunkManager::loadIndexFile ( )

Loads the index file.

Exceptions
ErrorWhen it can be loaded

◆ moveDataFiles() [1/2]

Job* bt::ChunkManager::moveDataFiles ( const QMap< TorrentFileInterface *, QString > &  files)

Move some data files to a new location

Parameters
filesMap of files and their new location

◆ moveDataFiles() [2/2]

Job* bt::ChunkManager::moveDataFiles ( const QString &  ndir)

Move the data files of the torrent.

Parameters
ndirThe new directory

◆ moveDataFilesFinished() [1/2]

void bt::ChunkManager::moveDataFilesFinished ( const QMap< TorrentFileInterface *, QString > &  files,
Job job 
)

A move of data files with the map has finished

Parameters
filesMap of files and their new location
jobThe job doing the move

◆ moveDataFilesFinished() [2/2]

void bt::ChunkManager::moveDataFilesFinished ( Job job)

A move of data files has finished

Parameters
jobThe job doing the move

◆ onlySeedChunks()

Uint32 bt::ChunkManager::onlySeedChunks ( ) const

Get the number of only seed chunks.

◆ preparePreallocation()

void bt::ChunkManager::preparePreallocation ( PreallocationThread prealloc)

Prepare diskspace preallocation

Parameters
preallocThe thread going to do the preallocation

◆ prioritise()

void bt::ChunkManager::prioritise ( Uint32  from,
Uint32  to,
Priority  priority 
)

Make sure that a range will get priority over other chunks.

Parameters
fromFirst chunk in range
toLast chunk in range

◆ resetChunk()

void bt::ChunkManager::resetChunk ( unsigned int  i)

Reset a chunk as if it were never downloaded.

Parameters
iThe chunk

◆ start()

void bt::ChunkManager::start ( )

Open the necessary files when the download gets started.

◆ stop()

void bt::ChunkManager::stop ( )

Closes files when the download gets stopped.

◆ updateStats

void bt::ChunkManager::updateStats ( )
signal

Emitted when chunks get excluded or included, so that the statistics can be updated.


The documentation for this class was generated from the following file: