libktorrent  2.2.0
Public Types | Public Member Functions | List of all members
bt::Chunk Class Reference

Keep track of a piece of the file. More...

#include <chunk.h>

Public Types

enum  Status { ON_DISK, NOT_DOWNLOADED }
 

Public Member Functions

 Chunk (Uint32 index, Uint32 size, Cache *cache)
 
bool checkHash (const SHA1Hash &h)
 
Uint32 getIndex () const
 Get the chunk's index.
 
PieceData::Ptr getPiece (Uint32 off, Uint32 len, bool read_only)
 
Priority getPriority () const
 get chunk priority
 
Uint32 getSize () const
 Get the chunk's size.
 
Status getStatus () const
 Get the chunks status.
 
bool isExcluded () const
 Is chunk excluded.
 
bool isExcludedForDownloading () const
 Is this a seed only chunk.
 
bool readPiece (Uint32 off, Uint32 len, Uint8 *data)
 
void savePiece (PieceData::Ptr piece)
 
void setExclude (bool yes)
 In/Exclude chunk.
 
void setPriority (Priority newpriority=NORMAL_PRIORITY)
 set chunk priority
 
void setStatus (Status s)
 

Detailed Description

Author
Joris Guisson

Keeps track of a piece of the file. The Chunk has 3 possible states :

Definition at line 45 of file chunk.h.

Member Function Documentation

◆ checkHash()

bool bt::Chunk::checkHash ( const SHA1Hash h)

Check wehter the chunk matches it's hash.

Parameters
hThe hash
Returns
true if the data matches the hash

◆ getPiece()

PieceData::Ptr bt::Chunk::getPiece ( Uint32  off,
Uint32  len,
bool  read_only 
)

Get a pointer to the data of a piece. If it isn't loaded, it will be loaded.

Parameters
offOffset of the piece
lenLength of the piece
read_onlyIs this for reading the piece or for writing
Returns
Pointer to the PieceData

◆ readPiece()

bool bt::Chunk::readPiece ( Uint32  off,
Uint32  len,
Uint8 *  data 
)

Read a piece from the chunk

Parameters
offThe offset of the chunk
lenThe length of the chunk
dataThe data, should be big enough to hold len bytes

◆ savePiece()

void bt::Chunk::savePiece ( PieceData::Ptr  piece)

Save a piece

Parameters
offOffset of the piece
lenLength of the piece

◆ setStatus()

void bt::Chunk::setStatus ( Status  s)
inline

Set the chunks status

Parameters
s

Definition at line 89 of file chunk.h.


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