From ab374fe7ca82b2e03bc692d4cc03cf9a9e0da4cf Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Thu, 13 Feb 2014 17:54:30 +0400 Subject: Add leadingBlock function --- src/Network/BitTorrent/Exchange/Block.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Network/BitTorrent/Exchange') diff --git a/src/Network/BitTorrent/Exchange/Block.hs b/src/Network/BitTorrent/Exchange/Block.hs index c910a716..32e4f99f 100644 --- a/src/Network/BitTorrent/Exchange/Block.hs +++ b/src/Network/BitTorrent/Exchange/Block.hs @@ -30,6 +30,7 @@ module Network.BitTorrent.Exchange.Block , blockSize , blockRange , isPiece + , leadingBlock -- * Block bucket , Bucket @@ -194,6 +195,15 @@ isPiece pieceLen blk @ (Block i offset _) = offset == 0 && blockSize blk == pieceLen && i >= 0 {-# INLINE isPiece #-} +-- | First block in the piece. +leadingBlock :: PieceIx -> BlockSize -> BlockIx +leadingBlock pix blockSize = BlockIx + { ixPiece = pix + , ixOffset = 0 + , ixLength = blockSize + } +{-# INLINE leadingBlock #-} + {----------------------------------------------------------------------- -- Bucket -----------------------------------------------------------------------} -- cgit v1.2.3