bittorrent-0.0.0.3: Bittorrent protocol implementation.

Portabilityportable
Stabilityexperimental
Maintainerpxqr.sta@gmail.com
Safe HaskellNone

Data.Torrent.Block

Contents

Description

Blocks are used to transfer pieces.

Synopsis

Piece attributes

type PieceIx = IntSource

Zero-based index of piece in torrent content.

type PieceSize = IntSource

Size of piece in bytes. Should be a power of 2.

NOTE: Have max and min size constrained to wide used semi-standard values. This bounds should be used to make decision about piece size for new torrents.

Block attributes

type BlockOffset = IntSource

Offset of a block in a piece in bytes. Should be multiple of the choosen block size.

type BlockCount = IntSource

Number of block in a piece of a torrent. Used to distinguish block count from piece count.

type BlockSize = IntSource

Size of a block in bytes. Should be power of 2.

Normally block size is equal to defaultTransferSize.

defaultTransferSize :: BlockSizeSource

Widely used semi-official block size. Some clients can ignore if block size of BlockIx in Request message is not equal to this value.

Block index

data BlockIx Source

BlockIx correspond.

Constructors

BlockIx 

Fields

ixPiece :: !PieceIx

Zero-based piece index.

ixOffset :: !BlockOffset

Zero-based byte offset within the piece.

ixLength :: !BlockSize

Block size starting from offset.

blockIxRange :: (Num a, Integral a) => PieceSize -> BlockIx -> (a, a)Source

Get location of payload bytes in the torrent content.

Block data

data Block payload Source

Constructors

Block 

Fields

blkPiece :: !PieceIx

Zero-based piece index.

blkOffset :: !BlockOffset

Zero-based byte offset within the piece.

blkData :: !payload

Payload bytes.

Instances

Eq payload => Eq (Block payload) 
Show payload => Show (Block payload) 
Pretty (Block Lazy.ByteString)

Payload is ommitted.

blockIx :: Block Lazy.ByteString -> BlockIxSource

Get block index of a block.

blockSize :: Block Lazy.ByteString -> BlockSizeSource

Get size of block payload in bytes.

blockRange :: (Num a, Integral a) => PieceSize -> Block Lazy.ByteString -> (a, a)Source

Get location of payload bytes in the torrent content.