diff options
Diffstat (limited to 'src/Data')
-rw-r--r-- | src/Data/Torrent.hs | 4 | ||||
-rw-r--r-- | src/Data/Torrent/Progress.hs | 24 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs index e4b17c2b..d6227b6f 100644 --- a/src/Data/Torrent.hs +++ b/src/Data/Torrent.hs | |||
@@ -78,6 +78,7 @@ import Data.ByteString as BS | |||
78 | import qualified Data.ByteString.Char8 as BC (pack, unpack) | 78 | import qualified Data.ByteString.Char8 as BC (pack, unpack) |
79 | import qualified Data.ByteString.Lazy as BL | 79 | import qualified Data.ByteString.Lazy as BL |
80 | import Data.Char as Char | 80 | import Data.Char as Char |
81 | import Data.Default | ||
81 | import Data.Hashable as Hashable | 82 | import Data.Hashable as Hashable |
82 | import qualified Data.List as L | 83 | import qualified Data.List as L |
83 | import Data.Maybe | 84 | import Data.Maybe |
@@ -143,8 +144,7 @@ instance Hashable InfoDict where | |||
143 | infoDictionary :: LayoutInfo -> PieceInfo -> Bool -> InfoDict | 144 | infoDictionary :: LayoutInfo -> PieceInfo -> Bool -> InfoDict |
144 | infoDictionary li pinfo private = InfoDict ih li pinfo private | 145 | infoDictionary li pinfo private = InfoDict ih li pinfo private |
145 | where | 146 | where |
146 | ih = hashLazyIH $ encode $ InfoDict fake_ih li pinfo private | 147 | ih = hashLazyIH $ encode $ InfoDict def li pinfo private |
147 | fake_ih = "0123456789012345678901234567890123456789" | ||
148 | 148 | ||
149 | getPrivate :: Get Bool | 149 | getPrivate :: Get Bool |
150 | getPrivate = (Just True ==) <$>? "private" | 150 | getPrivate = (Just True ==) <$>? "private" |
diff --git a/src/Data/Torrent/Progress.hs b/src/Data/Torrent/Progress.hs index d0aa75c6..1a4a68e2 100644 --- a/src/Data/Torrent/Progress.hs +++ b/src/Data/Torrent/Progress.hs | |||
@@ -12,6 +12,7 @@ | |||
12 | -- | 12 | -- |
13 | {-# LANGUAGE TemplateHaskell #-} | 13 | {-# LANGUAGE TemplateHaskell #-} |
14 | {-# LANGUAGE ViewPatterns #-} | 14 | {-# LANGUAGE ViewPatterns #-} |
15 | {-# OPTIONS -fno-warn-orphans #-} | ||
15 | module Data.Torrent.Progress | 16 | module Data.Torrent.Progress |
16 | ( -- * Progress | 17 | ( -- * Progress |
17 | Progress (..) | 18 | Progress (..) |
@@ -36,13 +37,15 @@ module Data.Torrent.Progress | |||
36 | import Control.Applicative | 37 | import Control.Applicative |
37 | import Control.Lens hiding ((%=)) | 38 | import Control.Lens hiding ((%=)) |
38 | import Data.Aeson.TH | 39 | import Data.Aeson.TH |
40 | import Data.ByteString.Lazy.Builder as BS | ||
41 | import Data.ByteString.Lazy.Builder.ASCII as BS | ||
39 | import Data.Default | 42 | import Data.Default |
40 | import Data.List as L | 43 | import Data.List as L |
41 | import Data.Monoid | 44 | import Data.Monoid |
42 | import Data.Serialize as S | 45 | import Data.Serialize as S |
43 | import Data.Ratio | 46 | import Data.Ratio |
44 | import Data.URLEncoded | ||
45 | import Data.Word | 47 | import Data.Word |
48 | import Network.HTTP.Types.QueryLike | ||
46 | import Text.PrettyPrint as PP | 49 | import Text.PrettyPrint as PP |
47 | import Text.PrettyPrint.Class | 50 | import Text.PrettyPrint.Class |
48 | 51 | ||
@@ -89,18 +92,19 @@ instance Monoid Progress where | |||
89 | } | 92 | } |
90 | {-# INLINE mappend #-} | 93 | {-# INLINE mappend #-} |
91 | 94 | ||
92 | instance URLShow Word64 where | 95 | instance QueryValueLike Builder where |
93 | urlShow = show | 96 | toQueryValue = toQueryValue . BS.toLazyByteString |
94 | {-# INLINE urlShow #-} | 97 | |
98 | instance QueryValueLike Word64 where | ||
99 | toQueryValue = toQueryValue . BS.word64Dec | ||
95 | 100 | ||
96 | -- | HTTP Tracker protocol compatible encoding. | 101 | -- | HTTP Tracker protocol compatible encoding. |
97 | instance URLEncode Progress where | 102 | instance QueryLike Progress where |
98 | urlEncode Progress {..} = mconcat | 103 | toQuery Progress {..} = |
99 | [ s "uploaded" %= _uploaded | 104 | [ ("uploaded" , toQueryValue _uploaded) |
100 | , s "left" %= _left | 105 | , ("left" , toQueryValue _left) |
101 | , s "downloaded" %= _downloaded | 106 | , ("downloaded", toQueryValue _downloaded) |
102 | ] | 107 | ] |
103 | where s :: String -> String; s = id; {-# INLINE s #-} | ||
104 | 108 | ||
105 | instance Pretty Progress where | 109 | instance Pretty Progress where |
106 | pretty Progress {..} = | 110 | pretty Progress {..} = |