summaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data')
-rw-r--r--src/Data/Torrent/Piece.hs17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/Data/Torrent/Piece.hs b/src/Data/Torrent/Piece.hs
index a7ea4700..74a2469a 100644
--- a/src/Data/Torrent/Piece.hs
+++ b/src/Data/Torrent/Piece.hs
@@ -24,6 +24,7 @@ module Data.Torrent.Piece
24 -- * Piece data 24 -- * Piece data
25 , Piece (..) 25 , Piece (..)
26 , pieceSize 26 , pieceSize
27 , hashPiece
27 28
28 -- * Piece control 29 -- * Piece control
29 , HashList (..) 30 , HashList (..)
@@ -121,6 +122,12 @@ defaultPieceSize x = max minPieceSize $ min maxPieceSize $ toPow2 pc
121-- Piece data 122-- Piece data
122-----------------------------------------------------------------------} 123-----------------------------------------------------------------------}
123 124
125type PieceHash = ByteString
126
127hashsize :: Int
128hashsize = 20
129{-# INLINE hashsize #-}
130
124-- TODO check if pieceLength is power of 2 131-- TODO check if pieceLength is power of 2
125-- | Piece payload should be strict or lazy bytestring. 132-- | Piece payload should be strict or lazy bytestring.
126data Piece a = Piece 133data Piece a = Piece
@@ -143,16 +150,14 @@ instance Pretty (Piece a) where
143pieceSize :: Piece BL.ByteString -> PieceSize 150pieceSize :: Piece BL.ByteString -> PieceSize
144pieceSize Piece {..} = fromIntegral (BL.length pieceData) 151pieceSize Piece {..} = fromIntegral (BL.length pieceData)
145 152
153-- | Get piece hash.
154hashPiece :: Piece BL.ByteString -> PieceHash
155hashPiece Piece {..} = SHA1.hashlazy pieceData
156
146{----------------------------------------------------------------------- 157{-----------------------------------------------------------------------
147-- Piece control 158-- Piece control
148-----------------------------------------------------------------------} 159-----------------------------------------------------------------------}
149 160
150type PieceHash = ByteString
151
152hashsize :: Int
153hashsize = 20
154{-# INLINE hashsize #-}
155
156-- | A flat array of SHA1 hash for each piece. 161-- | A flat array of SHA1 hash for each piece.
157newtype HashList = HashList { unHashList :: ByteString } 162newtype HashList = HashList { unHashList :: ByteString }
158 deriving (Show, Read, Eq, BEncode, Typeable) 163 deriving (Show, Read, Eq, BEncode, Typeable)