diff options
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Block.hs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/Network/BitTorrent/Exchange/Block.hs b/src/Network/BitTorrent/Exchange/Block.hs index 8e3ef91f..ca126acb 100644 --- a/src/Network/BitTorrent/Exchange/Block.hs +++ b/src/Network/BitTorrent/Exchange/Block.hs | |||
@@ -34,9 +34,7 @@ module Network.BitTorrent.Exchange.Block | |||
34 | import Control.Applicative | 34 | import Control.Applicative |
35 | import Data.Aeson.TH | 35 | import Data.Aeson.TH |
36 | import Data.ByteString.Lazy as BL | 36 | import Data.ByteString.Lazy as BL |
37 | import Data.Char | ||
38 | import Data.Default | 37 | import Data.Default |
39 | import Data.List as L | ||
40 | import Data.Serialize as S | 38 | import Data.Serialize as S |
41 | import Data.Typeable | 39 | import Data.Typeable |
42 | import Text.PrettyPrint | 40 | import Text.PrettyPrint |
@@ -121,9 +119,9 @@ instance Pretty BlockIx where | |||
121 | 119 | ||
122 | -- | Get location of payload bytes in the torrent content. | 120 | -- | Get location of payload bytes in the torrent content. |
123 | blockIxRange :: (Num a, Integral a) => PieceSize -> BlockIx -> (a, a) | 121 | blockIxRange :: (Num a, Integral a) => PieceSize -> BlockIx -> (a, a) |
124 | blockIxRange pieceSize BlockIx {..} = (offset, offset + len) | 122 | blockIxRange piSize BlockIx {..} = (offset, offset + len) |
125 | where | 123 | where |
126 | offset = fromIntegral pieceSize * fromIntegral ixPiece | 124 | offset = fromIntegral piSize * fromIntegral ixPiece |
127 | + fromIntegral ixOffset | 125 | + fromIntegral ixOffset |
128 | len = fromIntegral ixLength | 126 | len = fromIntegral ixLength |
129 | {-# INLINE blockIxRange #-} | 127 | {-# INLINE blockIxRange #-} |
@@ -158,8 +156,9 @@ blockIx :: Block BL.ByteString -> BlockIx | |||
158 | blockIx = BlockIx <$> blkPiece <*> blkOffset <*> blockSize | 156 | blockIx = BlockIx <$> blkPiece <*> blkOffset <*> blockSize |
159 | 157 | ||
160 | -- | Get location of payload bytes in the torrent content. | 158 | -- | Get location of payload bytes in the torrent content. |
161 | blockRange :: (Num a, Integral a) => PieceSize -> Block BL.ByteString -> (a, a) | 159 | blockRange :: (Num a, Integral a) |
162 | blockRange pieceSize = blockIxRange pieceSize . blockIx | 160 | => PieceSize -> Block BL.ByteString -> (a, a) |
161 | blockRange piSize = blockIxRange piSize . blockIx | ||
163 | {-# INLINE blockRange #-} | 162 | {-# INLINE blockRange #-} |
164 | 163 | ||
165 | -- | Test if a block can be safely turned into a piece. | 164 | -- | Test if a block can be safely turned into a piece. |