summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-13 17:54:30 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-13 17:54:30 +0400
commitab374fe7ca82b2e03bc692d4cc03cf9a9e0da4cf (patch)
tree4bdf6dfe17e907b115dab9d32c9396061b131007
parente7f07c7e57527f60ee093c04419c99663526a372 (diff)
Add leadingBlock function
-rw-r--r--src/Network/BitTorrent/Exchange/Block.hs10
1 files changed, 10 insertions, 0 deletions
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
30 , blockSize 30 , blockSize
31 , blockRange 31 , blockRange
32 , isPiece 32 , isPiece
33 , leadingBlock
33 34
34 -- * Block bucket 35 -- * Block bucket
35 , Bucket 36 , Bucket
@@ -194,6 +195,15 @@ isPiece pieceLen blk @ (Block i offset _) =
194 offset == 0 && blockSize blk == pieceLen && i >= 0 195 offset == 0 && blockSize blk == pieceLen && i >= 0
195{-# INLINE isPiece #-} 196{-# INLINE isPiece #-}
196 197
198-- | First block in the piece.
199leadingBlock :: PieceIx -> BlockSize -> BlockIx
200leadingBlock pix blockSize = BlockIx
201 { ixPiece = pix
202 , ixOffset = 0
203 , ixLength = blockSize
204 }
205{-# INLINE leadingBlock #-}
206
197{----------------------------------------------------------------------- 207{-----------------------------------------------------------------------
198-- Bucket 208-- Bucket
199-----------------------------------------------------------------------} 209-----------------------------------------------------------------------}