summaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-11-25 07:56:51 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-11-25 07:56:51 +0400
commit2a4d3e941320c489d7359cde725031432ea96765 (patch)
tree5952cfb979110447d339cfbafccc29bdf9a03881 /src/Data
parent087e3435877445c5776e035ec08a26edefb3f7a1 (diff)
Fix test
Diffstat (limited to 'src/Data')
-rw-r--r--src/Data/Torrent.hs15
-rw-r--r--src/Data/Torrent/Piece.hs2
2 files changed, 15 insertions, 2 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index fc0cb10b..4d6461af 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -26,6 +26,7 @@
26module Data.Torrent 26module Data.Torrent
27 ( -- * Info dictionary 27 ( -- * Info dictionary
28 InfoDict (..) 28 InfoDict (..)
29 , infoDictionary
29 30
30 -- ** Lenses 31 -- ** Lenses
31 , infohash 32 , infohash
@@ -131,6 +132,13 @@ instance Hashable InfoDict where
131 hash = Hashable.hash . idInfoHash 132 hash = Hashable.hash . idInfoHash
132 {-# INLINE hash #-} 133 {-# INLINE hash #-}
133 134
135-- | Smart constructor: add a info hash to info dictionary.
136infoDictionary :: LayoutInfo -> PieceInfo -> Bool -> InfoDict
137infoDictionary li pinfo private = InfoDict ih li pinfo private
138 where
139 ih = IH.hashlazy $ encode $ InfoDict fake_ih li pinfo private
140 fake_ih = InfoHash ""
141
134getPrivate :: Get Bool 142getPrivate :: Get Bool
135getPrivate = (Just True ==) <$>? "private" 143getPrivate = (Just True ==) <$>? "private"
136 144
@@ -155,8 +163,8 @@ instance BEncode InfoDict where
155ppPrivacy :: Bool -> Doc 163ppPrivacy :: Bool -> Doc
156ppPrivacy privacy = "Privacy: " <> if privacy then "private" else "public" 164ppPrivacy privacy = "Privacy: " <> if privacy then "private" else "public"
157 165
158ppAdditionalInfo :: InfoDict -> Doc 166--ppAdditionalInfo :: InfoDict -> Doc
159ppAdditionalInfo layout = PP.empty 167--ppAdditionalInfo layout = PP.empty
160 168
161instance Pretty InfoDict where 169instance Pretty InfoDict where
162 pretty InfoDict {..} = 170 pretty InfoDict {..} =
@@ -246,6 +254,9 @@ instance BEncode URI where
246 fromBEncode b = decodingError $ "url <" ++ show b ++ ">" 254 fromBEncode b = decodingError $ "url <" ++ show b ++ ">"
247 {-# INLINE fromBEncode #-} 255 {-# INLINE fromBEncode #-}
248 256
257--pico2uni :: Pico -> Uni
258--pico2uni = undefined
259
249-- TODO move to bencoding 260-- TODO move to bencoding
250instance BEncode POSIXTime where 261instance BEncode POSIXTime where
251 toBEncode pt = toBEncode (floor pt :: Integer) 262 toBEncode pt = toBEncode (floor pt :: Integer)
diff --git a/src/Data/Torrent/Piece.hs b/src/Data/Torrent/Piece.hs
index 6cff53d6..7eb4e3d5 100644
--- a/src/Data/Torrent/Piece.hs
+++ b/src/Data/Torrent/Piece.hs
@@ -25,6 +25,7 @@ module Data.Torrent.Piece
25 , isPiece 25 , isPiece
26 26
27 -- * Piece control 27 -- * Piece control
28 , HashArray (..)
28 , PieceInfo (..) 29 , PieceInfo (..)
29 , pieceCount 30 , pieceCount
30 31
@@ -138,6 +139,7 @@ isPiece pieceLen blk @ (Block i offset _) =
138-- Piece control 139-- Piece control
139-----------------------------------------------------------------------} 140-----------------------------------------------------------------------}
140 141
142-- | A flat array of SHA1 sums of each piece.
141newtype HashArray = HashArray { unHashArray :: ByteString } 143newtype HashArray = HashArray { unHashArray :: ByteString }
142 deriving (Show, Read, Eq, BEncode) 144 deriving (Show, Read, Eq, BEncode)
143 145