Portability | portable |
---|---|
Stability | experimental |
Maintainer | pxqr.sta@gmail.com |
Safe Haskell | None |
Pieces are used to validate torrent content.
- type PieceIx = Int
- type PieceCount = Int
- type PieceSize = Int
- minPieceSize :: Int
- maxPieceSize :: Int
- defaultPieceSize :: Int64 -> Int
- data Piece a = Piece {
- pieceIndex :: !PieceIx
- pieceData :: !a
- pieceSize :: Piece BL.ByteString -> PieceSize
- isPiece :: PieceSize -> Block BL.ByteString -> Bool
- newtype HashArray = HashArray {}
- data PieceInfo = PieceInfo {}
- pieceCount :: PieceInfo -> PieceCount
- pieceLength :: Lens' PieceInfo PieceSize
- pieceHashes :: Lens' PieceInfo HashArray
- pieceHash :: PieceInfo -> PieceIx -> BS.ByteString
- checkPieceLazy :: PieceInfo -> Piece BL.ByteString -> Bool
- getPieceInfo :: Get PieceInfo
- putPieceInfo :: PieceInfo -> BDict -> BDict
Piece attributes
type PieceCount = IntSource
Number of pieces in torrent or a part of torrent.
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.
Piece size should not be less than this value.
To prevent transfer degradation piece size should not exceed this value.
defaultPieceSize :: Int64 -> IntSource
Find the optimal piece size for a given torrent size.
Piece data
Piece payload should be strict or lazy bytestring.
Piece | |
|
pieceSize :: Piece BL.ByteString -> PieceSizeSource
Get size of piece in bytes.
isPiece :: PieceSize -> Block BL.ByteString -> BoolSource
Test if a block can be safely turned into a piece.
Piece control
A flat array of SHA1 sums of each piece.
Part of torrent file used for torrent content validation.
PieceInfo | |
|
pieceCount :: PieceInfo -> PieceCountSource
Find count of pieces in the torrent. If torrent size is not a multiple of piece size then the count is rounded up.
Lens
pieceLength :: Lens' PieceInfo PieceSizeSource
Number of bytes in each piece.
pieceHashes :: Lens' PieceInfo HashArraySource
Concatenation of all 20-byte SHA1 hash values.
Validation
pieceHash :: PieceInfo -> PieceIx -> BS.ByteStringSource
Extract validation hash by specified piece index.
checkPieceLazy :: PieceInfo -> Piece BL.ByteString -> BoolSource
Validate piece with metainfo hash.
Internal
getPieceInfo :: Get PieceInfoSource
putPieceInfo :: PieceInfo -> BDict -> BDictSource