diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Data/Torrent.hs | 20 | ||||
-rw-r--r-- | src/Data/Torrent/InfoHash.hs | 10 | ||||
-rw-r--r-- | src/Data/Torrent/JSON.hs | 56 | ||||
-rw-r--r-- | src/Data/Torrent/Layout.hs | 10 | ||||
-rw-r--r-- | src/Data/Torrent/Piece.hs | 16 | ||||
-rw-r--r-- | src/Data/Torrent/Progress.hs | 4 | ||||
-rw-r--r-- | src/Network/BitTorrent/Core/NodeInfo.hs | 9 | ||||
-rw-r--r-- | src/Network/BitTorrent/Core/PeerAddr.hs | 8 | ||||
-rw-r--r-- | src/Network/BitTorrent/Core/PeerId.hs | 4 | ||||
-rw-r--r-- | src/Network/BitTorrent/Exchange/Block.hs | 4 | ||||
-rw-r--r-- | src/Network/BitTorrent/Exchange/Connection/Status.hs | 4 | ||||
-rw-r--r-- | src/Network/BitTorrent/Internal/Cache.hs | 25 | ||||
-rw-r--r-- | src/Network/BitTorrent/Tracker/Message.hs | 8 | ||||
-rw-r--r-- | src/Network/BitTorrent/Tracker/Session.hs | 12 |
14 files changed, 2 insertions, 188 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs index ccd5e666..b233937b 100644 --- a/src/Data/Torrent.hs +++ b/src/Data/Torrent.hs | |||
@@ -71,8 +71,6 @@ import qualified Crypto.Hash.SHA1 as C | |||
71 | import Control.DeepSeq | 71 | import Control.DeepSeq |
72 | import Control.Exception | 72 | import Control.Exception |
73 | import Control.Lens | 73 | import Control.Lens |
74 | import Data.Aeson.Types (ToJSON(..), FromJSON(..), Value(..), withText) | ||
75 | import Data.Aeson.TH | ||
76 | import Data.BEncode as BE | 74 | import Data.BEncode as BE |
77 | import Data.BEncode.Types as BE | 75 | import Data.BEncode.Types as BE |
78 | import Data.ByteString as BS | 76 | import Data.ByteString as BS |
@@ -93,7 +91,6 @@ import Text.PrettyPrint.Class | |||
93 | import System.FilePath | 91 | import System.FilePath |
94 | 92 | ||
95 | import Data.Torrent.InfoHash as IH | 93 | import Data.Torrent.InfoHash as IH |
96 | import Data.Torrent.JSON | ||
97 | import Data.Torrent.Layout | 94 | import Data.Torrent.Layout |
98 | import Data.Torrent.Piece | 95 | import Data.Torrent.Piece |
99 | import Network.BitTorrent.Core.NodeInfo | 96 | import Network.BitTorrent.Core.NodeInfo |
@@ -125,8 +122,6 @@ data InfoDict = InfoDict | |||
125 | -- BEP 27: <http://www.bittorrent.org/beps/bep_0027.html> | 122 | -- BEP 27: <http://www.bittorrent.org/beps/bep_0027.html> |
126 | } deriving (Show, Read, Eq, Typeable) | 123 | } deriving (Show, Read, Eq, Typeable) |
127 | 124 | ||
128 | $(deriveJSON omitRecordPrefix ''InfoDict) | ||
129 | |||
130 | makeLensesFor | 125 | makeLensesFor |
131 | [ ("idInfoHash" , "infohash" ) | 126 | [ ("idInfoHash" , "infohash" ) |
132 | , ("idLayoutInfo", "layoutInfo") | 127 | , ("idLayoutInfo", "layoutInfo") |
@@ -242,21 +237,6 @@ data Torrent = Torrent | |||
242 | -- encrypted SHA-1 hash of the info dictionary). | 237 | -- encrypted SHA-1 hash of the info dictionary). |
243 | } deriving (Show, Eq, Typeable) | 238 | } deriving (Show, Eq, Typeable) |
244 | 239 | ||
245 | instance FromJSON URI where | ||
246 | parseJSON = withText "URI" $ | ||
247 | maybe (fail "could not parse URI") pure . parseURI . T.unpack | ||
248 | |||
249 | instance ToJSON URI where | ||
250 | toJSON = String . T.pack . show | ||
251 | |||
252 | instance ToJSON NominalDiffTime where | ||
253 | toJSON = toJSON . posixSecondsToUTCTime | ||
254 | |||
255 | instance FromJSON NominalDiffTime where | ||
256 | parseJSON v = utcTimeToPOSIXSeconds <$> parseJSON v | ||
257 | |||
258 | $(deriveJSON omitRecordPrefix ''Torrent) | ||
259 | |||
260 | makeLensesFor | 240 | makeLensesFor |
261 | [ ("tAnnounce" , "announce" ) | 241 | [ ("tAnnounce" , "announce" ) |
262 | , ("tAnnounceList", "announceList") | 242 | , ("tAnnounceList", "announceList") |
diff --git a/src/Data/Torrent/InfoHash.hs b/src/Data/Torrent/InfoHash.hs index 9eec631c..f322ac6f 100644 --- a/src/Data/Torrent/InfoHash.hs +++ b/src/Data/Torrent/InfoHash.hs | |||
@@ -24,7 +24,6 @@ module Data.Torrent.InfoHash | |||
24 | 24 | ||
25 | import Control.Applicative | 25 | import Control.Applicative |
26 | import Control.Monad | 26 | import Control.Monad |
27 | import Data.Aeson | ||
28 | import Data.BEncode | 27 | import Data.BEncode |
29 | import Data.ByteString as BS | 28 | import Data.ByteString as BS |
30 | import Data.ByteString.Char8 as BC | 29 | import Data.ByteString.Char8 as BC |
@@ -146,15 +145,6 @@ instance Convertible Text InfoHash where | |||
146 | instance IsString InfoHash where | 145 | instance IsString InfoHash where |
147 | fromString = either (error . prettyConvertError) id . safeConvert . T.pack | 146 | fromString = either (error . prettyConvertError) id . safeConvert . T.pack |
148 | 147 | ||
149 | -- | Convert to base16 encoded JSON string. | ||
150 | instance ToJSON InfoHash where | ||
151 | toJSON (InfoHash ih) = String $ T.decodeUtf8 $ Base16.encode ih | ||
152 | |||
153 | -- | Convert from base16\/base32\/base64 encoded JSON string. | ||
154 | instance FromJSON InfoHash where | ||
155 | parseJSON = withText "InfoHash" $ | ||
156 | either (fail . prettyConvertError) pure . safeConvert | ||
157 | |||
158 | ignoreErrorMsg :: Either a b -> Maybe b | 148 | ignoreErrorMsg :: Either a b -> Maybe b |
159 | ignoreErrorMsg = either (const Nothing) Just | 149 | ignoreErrorMsg = either (const Nothing) Just |
160 | 150 | ||
diff --git a/src/Data/Torrent/JSON.hs b/src/Data/Torrent/JSON.hs deleted file mode 100644 index 845b288a..00000000 --- a/src/Data/Torrent/JSON.hs +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | {-# OPTIONS_GHC -fno-warn-orphans #-} | ||
2 | module Data.Torrent.JSON | ||
3 | ( omitLensPrefix | ||
4 | , omitRecordPrefix | ||
5 | ) where | ||
6 | |||
7 | import Control.Applicative | ||
8 | import Data.Aeson.TH | ||
9 | import Data.Aeson.Types | ||
10 | import Data.ByteString as BS | ||
11 | import Data.ByteString.Base16 as Base16 | ||
12 | import Data.Char | ||
13 | import Data.IP | ||
14 | import Data.List as L | ||
15 | import Data.Text.Encoding as T | ||
16 | |||
17 | |||
18 | -- | Ignore '_' prefix. | ||
19 | omitLensPrefix :: Options | ||
20 | omitLensPrefix = defaultOptions | ||
21 | { fieldLabelModifier = L.dropWhile (== '_') | ||
22 | , constructorTagModifier = id | ||
23 | , allNullaryToStringTag = True | ||
24 | , omitNothingFields = True | ||
25 | } | ||
26 | |||
27 | mapWhile :: (a -> Bool) -> (a -> a) -> [a] -> [a] | ||
28 | mapWhile p f = go | ||
29 | where | ||
30 | go [] = [] | ||
31 | go (x : xs) | ||
32 | | p x = f x : go xs | ||
33 | | otherwise = x : xs | ||
34 | |||
35 | omitRecordPrefix :: Options | ||
36 | omitRecordPrefix = omitLensPrefix | ||
37 | { fieldLabelModifier = mapWhile isUpper toLower . L.dropWhile isLower | ||
38 | } | ||
39 | |||
40 | instance ToJSON ByteString where | ||
41 | toJSON = String . T.decodeUtf8 . Base16.encode | ||
42 | |||
43 | instance FromJSON ByteString where | ||
44 | parseJSON v = do | ||
45 | (ok, bad) <- (Base16.decode . T.encodeUtf8) <$> parseJSON v | ||
46 | if BS.null bad | ||
47 | then return ok | ||
48 | else fail "parseJSON: unable to decode ByteString" | ||
49 | |||
50 | instance ToJSON IP where | ||
51 | toJSON = toJSON . show | ||
52 | |||
53 | instance FromJSON IP where | ||
54 | parseJSON v = do | ||
55 | str <- parseJSON v | ||
56 | return $ read str | ||
diff --git a/src/Data/Torrent/Layout.hs b/src/Data/Torrent/Layout.hs index ef8d45eb..cc529840 100644 --- a/src/Data/Torrent/Layout.hs +++ b/src/Data/Torrent/Layout.hs | |||
@@ -64,8 +64,6 @@ module Data.Torrent.Layout | |||
64 | import Control.Applicative | 64 | import Control.Applicative |
65 | import Control.DeepSeq | 65 | import Control.DeepSeq |
66 | import Control.Lens | 66 | import Control.Lens |
67 | import Data.Aeson.TH | ||
68 | import Data.Aeson.Types (FromJSON, ToJSON) | ||
69 | import Data.BEncode | 67 | import Data.BEncode |
70 | import Data.BEncode.Types | 68 | import Data.BEncode.Types |
71 | import Data.ByteString as BS | 69 | import Data.ByteString as BS |
@@ -82,8 +80,6 @@ import Text.PrettyPrint.Class | |||
82 | import System.FilePath | 80 | import System.FilePath |
83 | import System.Posix.Types | 81 | import System.Posix.Types |
84 | 82 | ||
85 | import Data.Torrent.JSON | ||
86 | |||
87 | {----------------------------------------------------------------------- | 83 | {----------------------------------------------------------------------- |
88 | -- File attribytes | 84 | -- File attribytes |
89 | -----------------------------------------------------------------------} | 85 | -----------------------------------------------------------------------} |
@@ -91,8 +87,6 @@ import Data.Torrent.JSON | |||
91 | -- | Size of a file in bytes. | 87 | -- | Size of a file in bytes. |
92 | type FileSize = FileOffset | 88 | type FileSize = FileOffset |
93 | 89 | ||
94 | deriving instance FromJSON FileOffset | ||
95 | deriving instance ToJSON FileOffset | ||
96 | deriving instance BEncode FileOffset | 90 | deriving instance BEncode FileOffset |
97 | 91 | ||
98 | {----------------------------------------------------------------------- | 92 | {----------------------------------------------------------------------- |
@@ -125,8 +119,6 @@ data FileInfo a = FileInfo { | |||
125 | , Functor, Foldable | 119 | , Functor, Foldable |
126 | ) | 120 | ) |
127 | 121 | ||
128 | $(deriveJSON omitRecordPrefix ''FileInfo) | ||
129 | |||
130 | makeLensesFor | 122 | makeLensesFor |
131 | [ ("fiLength", "fileLength") | 123 | [ ("fiLength", "fileLength") |
132 | , ("fiMD5Sum", "fileMD5Sum") | 124 | , ("fiMD5Sum", "fileMD5Sum") |
@@ -210,8 +202,6 @@ data LayoutInfo | |||
210 | , liDirName :: !ByteString | 202 | , liDirName :: !ByteString |
211 | } deriving (Show, Read, Eq, Typeable) | 203 | } deriving (Show, Read, Eq, Typeable) |
212 | 204 | ||
213 | $(deriveJSON omitRecordPrefix ''LayoutInfo) | ||
214 | |||
215 | makeLensesFor | 205 | makeLensesFor |
216 | [ ("liFile" , "singleFile" ) | 206 | [ ("liFile" , "singleFile" ) |
217 | , ("liFiles" , "multiFile" ) | 207 | , ("liFiles" , "multiFile" ) |
diff --git a/src/Data/Torrent/Piece.hs b/src/Data/Torrent/Piece.hs index 03335819..d4b2c399 100644 --- a/src/Data/Torrent/Piece.hs +++ b/src/Data/Torrent/Piece.hs | |||
@@ -47,8 +47,6 @@ module Data.Torrent.Piece | |||
47 | import Control.DeepSeq | 47 | import Control.DeepSeq |
48 | import Control.Lens | 48 | import Control.Lens |
49 | import qualified Crypto.Hash.SHA1 as SHA1 | 49 | import qualified Crypto.Hash.SHA1 as SHA1 |
50 | import Data.Aeson (ToJSON(..), FromJSON(..), Value(..), withText) | ||
51 | import Data.Aeson.TH | ||
52 | import Data.BEncode | 50 | import Data.BEncode |
53 | import Data.BEncode.Types | 51 | import Data.BEncode.Types |
54 | import Data.Bits | 52 | import Data.Bits |
@@ -63,8 +61,6 @@ import Data.Typeable | |||
63 | import Text.PrettyPrint | 61 | import Text.PrettyPrint |
64 | import Text.PrettyPrint.Class | 62 | import Text.PrettyPrint.Class |
65 | 63 | ||
66 | import Data.Torrent.JSON | ||
67 | |||
68 | 64 | ||
69 | -- TODO add torrent file validation | 65 | -- TODO add torrent file validation |
70 | class Lint a where | 66 | class Lint a where |
@@ -139,8 +135,6 @@ data Piece a = Piece | |||
139 | , pieceData :: !a | 135 | , pieceData :: !a |
140 | } deriving (Show, Read, Eq, Functor, Typeable) | 136 | } deriving (Show, Read, Eq, Functor, Typeable) |
141 | 137 | ||
142 | $(deriveJSON omitRecordPrefix ''Piece) | ||
143 | |||
144 | instance NFData (Piece a) | 138 | instance NFData (Piece a) |
145 | 139 | ||
146 | -- | Payload bytes are omitted. | 140 | -- | Payload bytes are omitted. |
@@ -163,14 +157,6 @@ hashPiece Piece {..} = SHA1.hashlazy pieceData | |||
163 | newtype HashList = HashList { unHashList :: ByteString } | 157 | newtype HashList = HashList { unHashList :: ByteString } |
164 | deriving (Show, Read, Eq, BEncode, Typeable) | 158 | deriving (Show, Read, Eq, BEncode, Typeable) |
165 | 159 | ||
166 | -- | Represented as base64 encoded JSON string. | ||
167 | instance ToJSON HashList where | ||
168 | toJSON (HashList bs) = String $ T.decodeUtf8 $ Base64.encode bs | ||
169 | |||
170 | instance FromJSON HashList where | ||
171 | parseJSON = withText "HashArray" $ | ||
172 | either fail (return . HashList) . Base64.decode . T.encodeUtf8 | ||
173 | |||
174 | -- | Empty hash list. | 160 | -- | Empty hash list. |
175 | instance Default HashList where | 161 | instance Default HashList where |
176 | def = HashList "" | 162 | def = HashList "" |
@@ -184,8 +170,6 @@ data PieceInfo = PieceInfo | |||
184 | -- ^ Concatenation of all 20-byte SHA1 hash values. | 170 | -- ^ Concatenation of all 20-byte SHA1 hash values. |
185 | } deriving (Show, Read, Eq, Typeable) | 171 | } deriving (Show, Read, Eq, Typeable) |
186 | 172 | ||
187 | $(deriveJSON omitRecordPrefix ''PieceInfo) | ||
188 | |||
189 | -- | Number of bytes in each piece. | 173 | -- | Number of bytes in each piece. |
190 | makeLensesFor [("piPieceLength", "pieceLength")] ''PieceInfo | 174 | makeLensesFor [("piPieceLength", "pieceLength")] ''PieceInfo |
191 | 175 | ||
diff --git a/src/Data/Torrent/Progress.hs b/src/Data/Torrent/Progress.hs index ffcbf2aa..4719020a 100644 --- a/src/Data/Torrent/Progress.hs +++ b/src/Data/Torrent/Progress.hs | |||
@@ -36,7 +36,6 @@ module Data.Torrent.Progress | |||
36 | 36 | ||
37 | import Control.Applicative | 37 | import Control.Applicative |
38 | import Control.Lens hiding ((%=)) | 38 | import Control.Lens hiding ((%=)) |
39 | import Data.Aeson.TH | ||
40 | import Data.ByteString.Lazy.Builder as BS | 39 | import Data.ByteString.Lazy.Builder as BS |
41 | import Data.ByteString.Lazy.Builder.ASCII as BS | 40 | import Data.ByteString.Lazy.Builder.ASCII as BS |
42 | import Data.Default | 41 | import Data.Default |
@@ -49,8 +48,6 @@ import Network.HTTP.Types.QueryLike | |||
49 | import Text.PrettyPrint as PP | 48 | import Text.PrettyPrint as PP |
50 | import Text.PrettyPrint.Class | 49 | import Text.PrettyPrint.Class |
51 | 50 | ||
52 | import Data.Torrent.JSON | ||
53 | |||
54 | 51 | ||
55 | -- | Progress data is considered as dynamic within one client | 52 | -- | Progress data is considered as dynamic within one client |
56 | -- session. This data also should be shared across client application | 53 | -- session. This data also should be shared across client application |
@@ -64,7 +61,6 @@ data Progress = Progress | |||
64 | } deriving (Show, Read, Eq) | 61 | } deriving (Show, Read, Eq) |
65 | 62 | ||
66 | $(makeLenses ''Progress) | 63 | $(makeLenses ''Progress) |
67 | $(deriveJSON omitLensPrefix ''Progress) | ||
68 | 64 | ||
69 | -- | UDP tracker compatible encoding. | 65 | -- | UDP tracker compatible encoding. |
70 | instance Serialize Progress where | 66 | instance Serialize Progress where |
diff --git a/src/Network/BitTorrent/Core/NodeInfo.hs b/src/Network/BitTorrent/Core/NodeInfo.hs index fa20caf5..fe17c097 100644 --- a/src/Network/BitTorrent/Core/NodeInfo.hs +++ b/src/Network/BitTorrent/Core/NodeInfo.hs | |||
@@ -39,8 +39,6 @@ module Network.BitTorrent.Core.NodeInfo | |||
39 | ) where | 39 | ) where |
40 | 40 | ||
41 | import Control.Applicative | 41 | import Control.Applicative |
42 | import Data.Aeson (ToJSON, FromJSON) | ||
43 | import Data.Aeson.TH | ||
44 | import Data.Bits | 42 | import Data.Bits |
45 | import Data.ByteString as BS | 43 | import Data.ByteString as BS |
46 | import Data.ByteString.Char8 as BC | 44 | import Data.ByteString.Char8 as BC |
@@ -62,7 +60,6 @@ import System.Entropy | |||
62 | import Text.PrettyPrint as PP hiding ((<>)) | 60 | import Text.PrettyPrint as PP hiding ((<>)) |
63 | import Text.PrettyPrint.Class | 61 | import Text.PrettyPrint.Class |
64 | 62 | ||
65 | import Data.Torrent.JSON | ||
66 | import Network.BitTorrent.Core.PeerAddr (PeerAddr (..)) | 63 | import Network.BitTorrent.Core.PeerAddr (PeerAddr (..)) |
67 | 64 | ||
68 | {----------------------------------------------------------------------- | 65 | {----------------------------------------------------------------------- |
@@ -76,7 +73,7 @@ import Network.BitTorrent.Core.PeerAddr (PeerAddr (..)) | |||
76 | -- Normally, /this/ node id should be saved between invocations | 73 | -- Normally, /this/ node id should be saved between invocations |
77 | -- of the client software. | 74 | -- of the client software. |
78 | newtype NodeId = NodeId ByteString | 75 | newtype NodeId = NodeId ByteString |
79 | deriving (Show, Eq, Ord, BEncode, FromJSON, ToJSON, Typeable) | 76 | deriving (Show, Eq, Ord, BEncode, Typeable) |
80 | 77 | ||
81 | nodeIdSize :: Int | 78 | nodeIdSize :: Int |
82 | nodeIdSize = 20 | 79 | nodeIdSize = 20 |
@@ -146,8 +143,6 @@ data NodeAddr a = NodeAddr | |||
146 | , nodePort :: {-# UNPACK #-} !PortNumber | 143 | , nodePort :: {-# UNPACK #-} !PortNumber |
147 | } deriving (Eq, Typeable, Functor) | 144 | } deriving (Eq, Typeable, Functor) |
148 | 145 | ||
149 | $(deriveJSON omitRecordPrefix ''NodeAddr) | ||
150 | |||
151 | instance Show a => Show (NodeAddr a) where | 146 | instance Show a => Show (NodeAddr a) where |
152 | showsPrec i NodeAddr {..} | 147 | showsPrec i NodeAddr {..} |
153 | = showsPrec i nodeHost <> showString ":" <> showsPrec i nodePort | 148 | = showsPrec i nodeHost <> showString ":" <> showsPrec i nodePort |
@@ -202,8 +197,6 @@ data NodeInfo a = NodeInfo | |||
202 | , nodeAddr :: !(NodeAddr a) | 197 | , nodeAddr :: !(NodeAddr a) |
203 | } deriving (Show, Eq, Functor) | 198 | } deriving (Show, Eq, Functor) |
204 | 199 | ||
205 | $(deriveJSON omitRecordPrefix ''NodeInfo) | ||
206 | |||
207 | instance Eq a => Ord (NodeInfo a) where | 200 | instance Eq a => Ord (NodeInfo a) where |
208 | compare = comparing nodeId | 201 | compare = comparing nodeId |
209 | 202 | ||
diff --git a/src/Network/BitTorrent/Core/PeerAddr.hs b/src/Network/BitTorrent/Core/PeerAddr.hs index adf64c7f..92fb83a7 100644 --- a/src/Network/BitTorrent/Core/PeerAddr.hs +++ b/src/Network/BitTorrent/Core/PeerAddr.hs | |||
@@ -33,8 +33,6 @@ module Network.BitTorrent.Core.PeerAddr | |||
33 | 33 | ||
34 | import Control.Applicative | 34 | import Control.Applicative |
35 | import Control.Monad | 35 | import Control.Monad |
36 | import Data.Aeson (ToJSON, FromJSON) | ||
37 | import Data.Aeson.TH | ||
38 | import Data.BEncode as BS | 36 | import Data.BEncode as BS |
39 | import Data.BEncode.BDict (BKey) | 37 | import Data.BEncode.BDict (BKey) |
40 | import Data.ByteString.Char8 as BS8 | 38 | import Data.ByteString.Char8 as BS8 |
@@ -58,7 +56,6 @@ import Text.Read (readMaybe) | |||
58 | import qualified Text.ParserCombinators.ReadP as RP | 56 | import qualified Text.ParserCombinators.ReadP as RP |
59 | 57 | ||
60 | import Data.Torrent.InfoHash | 58 | import Data.Torrent.InfoHash |
61 | import Data.Torrent.JSON | ||
62 | import Network.BitTorrent.Core.PeerId | 59 | import Network.BitTorrent.Core.PeerId |
63 | 60 | ||
64 | 61 | ||
@@ -66,9 +63,6 @@ import Network.BitTorrent.Core.PeerId | |||
66 | -- Port number | 63 | -- Port number |
67 | -----------------------------------------------------------------------} | 64 | -----------------------------------------------------------------------} |
68 | 65 | ||
69 | deriving instance ToJSON PortNumber | ||
70 | deriving instance FromJSON PortNumber | ||
71 | |||
72 | instance BEncode PortNumber where | 66 | instance BEncode PortNumber where |
73 | toBEncode = toBEncode . fromEnum | 67 | toBEncode = toBEncode . fromEnum |
74 | fromBEncode = fromBEncode >=> portNumber | 68 | fromBEncode = fromBEncode >=> portNumber |
@@ -208,8 +202,6 @@ data PeerAddr a = PeerAddr | |||
208 | , peerPort :: {-# UNPACK #-} !PortNumber | 202 | , peerPort :: {-# UNPACK #-} !PortNumber |
209 | } deriving (Show, Eq, Ord, Typeable, Functor) | 203 | } deriving (Show, Eq, Ord, Typeable, Functor) |
210 | 204 | ||
211 | $(deriveJSON omitRecordPrefix ''PeerAddr) | ||
212 | |||
213 | peer_ip_key, peer_id_key, peer_port_key :: BKey | 205 | peer_ip_key, peer_id_key, peer_port_key :: BKey |
214 | peer_ip_key = "ip" | 206 | peer_ip_key = "ip" |
215 | peer_id_key = "peer id" | 207 | peer_id_key = "peer id" |
diff --git a/src/Network/BitTorrent/Core/PeerId.hs b/src/Network/BitTorrent/Core/PeerId.hs index f8d69e8b..a180ff30 100644 --- a/src/Network/BitTorrent/Core/PeerId.hs +++ b/src/Network/BitTorrent/Core/PeerId.hs | |||
@@ -34,7 +34,6 @@ module Network.BitTorrent.Core.PeerId | |||
34 | ) where | 34 | ) where |
35 | 35 | ||
36 | import Control.Applicative | 36 | import Control.Applicative |
37 | import Data.Aeson | ||
38 | import Data.BEncode as BE | 37 | import Data.BEncode as BE |
39 | import Data.ByteString as BS | 38 | import Data.ByteString as BS |
40 | import Data.ByteString.Internal as BS | 39 | import Data.ByteString.Internal as BS |
@@ -62,14 +61,13 @@ import Text.PrettyPrint hiding ((<>)) | |||
62 | import Text.PrettyPrint.Class | 61 | import Text.PrettyPrint.Class |
63 | import Text.Read (readMaybe) | 62 | import Text.Read (readMaybe) |
64 | 63 | ||
65 | import Data.Torrent.JSON () | ||
66 | import Network.BitTorrent.Core.Fingerprint | 64 | import Network.BitTorrent.Core.Fingerprint |
67 | 65 | ||
68 | -- TODO use unpacked Word160 form (length is known statically) | 66 | -- TODO use unpacked Word160 form (length is known statically) |
69 | 67 | ||
70 | -- | Peer identifier is exactly 20 bytes long bytestring. | 68 | -- | Peer identifier is exactly 20 bytes long bytestring. |
71 | newtype PeerId = PeerId { getPeerId :: ByteString } | 69 | newtype PeerId = PeerId { getPeerId :: ByteString } |
72 | deriving (Show, Eq, Ord, BEncode, ToJSON, FromJSON, Typeable) | 70 | deriving (Show, Eq, Ord, BEncode, Typeable) |
73 | 71 | ||
74 | peerIdLen :: Int | 72 | peerIdLen :: Int |
75 | peerIdLen = 20 | 73 | peerIdLen = 20 |
diff --git a/src/Network/BitTorrent/Exchange/Block.hs b/src/Network/BitTorrent/Exchange/Block.hs index 6e5b960a..16c124e9 100644 --- a/src/Network/BitTorrent/Exchange/Block.hs +++ b/src/Network/BitTorrent/Exchange/Block.hs | |||
@@ -57,7 +57,6 @@ module Network.BitTorrent.Exchange.Block | |||
57 | 57 | ||
58 | import Prelude hiding (span) | 58 | import Prelude hiding (span) |
59 | import Control.Applicative | 59 | import Control.Applicative |
60 | import Data.Aeson.TH | ||
61 | import Data.ByteString as BS hiding (span) | 60 | import Data.ByteString as BS hiding (span) |
62 | import Data.ByteString.Lazy as BL hiding (span) | 61 | import Data.ByteString.Lazy as BL hiding (span) |
63 | import Data.ByteString.Lazy.Builder as BS | 62 | import Data.ByteString.Lazy.Builder as BS |
@@ -70,7 +69,6 @@ import Numeric | |||
70 | import Text.PrettyPrint as PP hiding ((<>)) | 69 | import Text.PrettyPrint as PP hiding ((<>)) |
71 | import Text.PrettyPrint.Class | 70 | import Text.PrettyPrint.Class |
72 | 71 | ||
73 | import Data.Torrent.JSON | ||
74 | import Data.Torrent.Piece | 72 | import Data.Torrent.Piece |
75 | 73 | ||
76 | {----------------------------------------------------------------------- | 74 | {----------------------------------------------------------------------- |
@@ -114,8 +112,6 @@ data BlockIx = BlockIx { | |||
114 | , ixLength :: {-# UNPACK #-} !BlockSize | 112 | , ixLength :: {-# UNPACK #-} !BlockSize |
115 | } deriving (Show, Eq, Typeable) | 113 | } deriving (Show, Eq, Typeable) |
116 | 114 | ||
117 | $(deriveJSON omitRecordPrefix ''BlockIx) | ||
118 | |||
119 | -- | First block in torrent. Useful for debugging. | 115 | -- | First block in torrent. Useful for debugging. |
120 | instance Default BlockIx where | 116 | instance Default BlockIx where |
121 | def = BlockIx 0 0 defaultTransferSize | 117 | def = BlockIx 0 0 defaultTransferSize |
diff --git a/src/Network/BitTorrent/Exchange/Connection/Status.hs b/src/Network/BitTorrent/Exchange/Connection/Status.hs index b4b10371..f6abc580 100644 --- a/src/Network/BitTorrent/Exchange/Connection/Status.hs +++ b/src/Network/BitTorrent/Exchange/Connection/Status.hs | |||
@@ -34,14 +34,12 @@ module Network.BitTorrent.Exchange.Connection.Status | |||
34 | ) where | 34 | ) where |
35 | 35 | ||
36 | import Control.Lens | 36 | import Control.Lens |
37 | import Data.Aeson.TH | ||
38 | import Data.Default | 37 | import Data.Default |
39 | import Data.Maybe | 38 | import Data.Maybe |
40 | import Data.Monoid | 39 | import Data.Monoid |
41 | import Text.PrettyPrint as PP hiding ((<>)) | 40 | import Text.PrettyPrint as PP hiding ((<>)) |
42 | import Text.PrettyPrint.Class | 41 | import Text.PrettyPrint.Class |
43 | 42 | ||
44 | import Data.Torrent.JSON | ||
45 | import Network.BitTorrent.Exchange.Message | 43 | import Network.BitTorrent.Exchange.Message |
46 | 44 | ||
47 | 45 | ||
@@ -61,7 +59,6 @@ data PeerStatus = PeerStatus | |||
61 | } deriving (Show, Eq, Ord) | 59 | } deriving (Show, Eq, Ord) |
62 | 60 | ||
63 | $(makeLenses ''PeerStatus) | 61 | $(makeLenses ''PeerStatus) |
64 | $(deriveJSON omitLensPrefix ''PeerStatus) | ||
65 | 62 | ||
66 | instance Pretty PeerStatus where | 63 | instance Pretty PeerStatus where |
67 | pretty PeerStatus {..} = | 64 | pretty PeerStatus {..} = |
@@ -104,7 +101,6 @@ data ConnectionStatus = ConnectionStatus | |||
104 | } deriving (Show, Eq) | 101 | } deriving (Show, Eq) |
105 | 102 | ||
106 | $(makeLenses ''ConnectionStatus) | 103 | $(makeLenses ''ConnectionStatus) |
107 | $(deriveJSON omitRecordPrefix ''ConnectionStatus) | ||
108 | 104 | ||
109 | instance Pretty ConnectionStatus where | 105 | instance Pretty ConnectionStatus where |
110 | pretty ConnectionStatus {..} = | 106 | pretty ConnectionStatus {..} = |
diff --git a/src/Network/BitTorrent/Internal/Cache.hs b/src/Network/BitTorrent/Internal/Cache.hs index 5c3f379b..8c74467a 100644 --- a/src/Network/BitTorrent/Internal/Cache.hs +++ b/src/Network/BitTorrent/Internal/Cache.hs | |||
@@ -32,7 +32,6 @@ module Network.BitTorrent.Internal.Cache | |||
32 | ) where | 32 | ) where |
33 | 33 | ||
34 | import Control.Applicative | 34 | import Control.Applicative |
35 | import Data.Aeson | ||
36 | import Data.Monoid | 35 | import Data.Monoid |
37 | import Data.Default | 36 | import Data.Default |
38 | import Data.Time | 37 | import Data.Time |
@@ -56,30 +55,6 @@ data Cached a = Cached | |||
56 | 55 | ||
57 | -- INVARIANT: minUpdateInterval <= updateInterval | 56 | -- INVARIANT: minUpdateInterval <= updateInterval |
58 | 57 | ||
59 | -- | Examples: | ||
60 | -- | ||
61 | -- { data: "some string", | ||
62 | -- observed: "2014-03-20T19:49:39.505Z", | ||
63 | -- expires: "2014-03-20T19:50:10.881Z" } | ||
64 | -- | ||
65 | -- or: | ||
66 | -- | ||
67 | -- { expired: "2014-03-20T19:50:10.881Z" } | ||
68 | -- | ||
69 | instance ToJSON a => ToJSON (Cached a) where | ||
70 | toJSON Cached {..} | ||
71 | | currentTime < expireTime = object | ||
72 | [ "observed" .= posixSecondsToUTCTime lastUpdated | ||
73 | , "expires" .= posixSecondsToUTCTime expireTime | ||
74 | , "data" .= cachedData | ||
75 | ] | ||
76 | | otherwise = object | ||
77 | [ "expired" .= posixSecondsToUTCTime expireTime | ||
78 | ] | ||
79 | where | ||
80 | expireTime = currentTime + updateInterval | ||
81 | currentTime = unsafePerformIO getPOSIXTime | ||
82 | |||
83 | instance Default (Cached a) where | 58 | instance Default (Cached a) where |
84 | def = mempty | 59 | def = mempty |
85 | 60 | ||
diff --git a/src/Network/BitTorrent/Tracker/Message.hs b/src/Network/BitTorrent/Tracker/Message.hs index ffe36c82..cdc07af8 100644 --- a/src/Network/BitTorrent/Tracker/Message.hs +++ b/src/Network/BitTorrent/Tracker/Message.hs | |||
@@ -97,7 +97,6 @@ module Network.BitTorrent.Tracker.Message | |||
97 | 97 | ||
98 | import Control.Applicative | 98 | import Control.Applicative |
99 | import Control.Monad | 99 | import Control.Monad |
100 | import Data.Aeson.TH | ||
101 | import Data.BEncode as BE hiding (Result) | 100 | import Data.BEncode as BE hiding (Result) |
102 | import Data.BEncode.BDict as BE | 101 | import Data.BEncode.BDict as BE |
103 | import Data.ByteString as BS | 102 | import Data.ByteString as BS |
@@ -126,7 +125,6 @@ import System.Entropy | |||
126 | import Text.Read (readMaybe) | 125 | import Text.Read (readMaybe) |
127 | 126 | ||
128 | import Data.Torrent.InfoHash | 127 | import Data.Torrent.InfoHash |
129 | import Data.Torrent.JSON | ||
130 | import Data.Torrent.Progress | 128 | import Data.Torrent.Progress |
131 | import Network.BitTorrent.Core | 129 | import Network.BitTorrent.Core |
132 | 130 | ||
@@ -150,8 +148,6 @@ data AnnounceEvent | |||
150 | | Completed | 148 | | Completed |
151 | deriving (Show, Read, Eq, Ord, Enum, Bounded, Typeable) | 149 | deriving (Show, Read, Eq, Ord, Enum, Bounded, Typeable) |
152 | 150 | ||
153 | $(deriveJSON omitRecordPrefix ''AnnounceEvent) | ||
154 | |||
155 | -- | HTTP tracker protocol compatible encoding. | 151 | -- | HTTP tracker protocol compatible encoding. |
156 | instance QueryValueLike AnnounceEvent where | 152 | instance QueryValueLike AnnounceEvent where |
157 | toQueryValue e = toQueryValue (Char.toLower x : xs) | 153 | toQueryValue e = toQueryValue (Char.toLower x : xs) |
@@ -224,8 +220,6 @@ data AnnounceQuery = AnnounceQuery | |||
224 | , reqEvent :: Maybe AnnounceEvent | 220 | , reqEvent :: Maybe AnnounceEvent |
225 | } deriving (Show, Eq, Typeable) | 221 | } deriving (Show, Eq, Typeable) |
226 | 222 | ||
227 | $(deriveJSON omitRecordPrefix ''AnnounceQuery) | ||
228 | |||
229 | -- | UDP tracker protocol compatible encoding. | 223 | -- | UDP tracker protocol compatible encoding. |
230 | instance Serialize AnnounceQuery where | 224 | instance Serialize AnnounceQuery where |
231 | put AnnounceQuery {..} = do | 225 | put AnnounceQuery {..} = do |
@@ -636,8 +630,6 @@ data ScrapeEntry = ScrapeEntry { | |||
636 | , siName :: !(Maybe Text) | 630 | , siName :: !(Maybe Text) |
637 | } deriving (Show, Eq, Typeable) | 631 | } deriving (Show, Eq, Typeable) |
638 | 632 | ||
639 | $(deriveJSON omitRecordPrefix ''ScrapeEntry) | ||
640 | |||
641 | -- | HTTP tracker protocol compatible encoding. | 633 | -- | HTTP tracker protocol compatible encoding. |
642 | instance BEncode ScrapeEntry where | 634 | instance BEncode ScrapeEntry where |
643 | toBEncode ScrapeEntry {..} = toDict $ | 635 | toBEncode ScrapeEntry {..} = toDict $ |
diff --git a/src/Network/BitTorrent/Tracker/Session.hs b/src/Network/BitTorrent/Tracker/Session.hs index 5aa9c0eb..560acf84 100644 --- a/src/Network/BitTorrent/Tracker/Session.hs +++ b/src/Network/BitTorrent/Tracker/Session.hs | |||
@@ -47,8 +47,6 @@ import Control.Exception | |||
47 | import Control.Concurrent | 47 | import Control.Concurrent |
48 | import Control.Concurrent.Chan.Split as CS | 48 | import Control.Concurrent.Chan.Split as CS |
49 | import Control.Monad | 49 | import Control.Monad |
50 | import Data.Aeson | ||
51 | import Data.Aeson.TH | ||
52 | import Data.Default | 50 | import Data.Default |
53 | import Data.Fixed | 51 | import Data.Fixed |
54 | import Data.Foldable as F | 52 | import Data.Foldable as F |
@@ -60,7 +58,6 @@ import Data.Traversable | |||
60 | import Network.URI | 58 | import Network.URI |
61 | 59 | ||
62 | import Data.Torrent.InfoHash | 60 | import Data.Torrent.InfoHash |
63 | import Data.Torrent.JSON | ||
64 | import Network.BitTorrent.Core | 61 | import Network.BitTorrent.Core |
65 | import Network.BitTorrent.Internal.Cache | 62 | import Network.BitTorrent.Internal.Cache |
66 | import Network.BitTorrent.Internal.Types | 63 | import Network.BitTorrent.Internal.Types |
@@ -95,8 +92,6 @@ data LastScrape = LastScrape | |||
95 | , scrapeSeeders :: Maybe Int | 92 | , scrapeSeeders :: Maybe Int |
96 | } deriving (Show, Eq) | 93 | } deriving (Show, Eq) |
97 | 94 | ||
98 | $(deriveJSON omitRecordPrefix ''LastScrape) | ||
99 | |||
100 | -- | Single tracker session. | 95 | -- | Single tracker session. |
101 | data TrackerSession = TrackerSession | 96 | data TrackerSession = TrackerSession |
102 | { -- | Used to notify 'Stopped' and 'Completed' events. | 97 | { -- | Used to notify 'Stopped' and 'Completed' events. |
@@ -109,13 +104,6 @@ data TrackerSession = TrackerSession | |||
109 | , trackerScrape :: Cached LastScrape | 104 | , trackerScrape :: Cached LastScrape |
110 | } | 105 | } |
111 | 106 | ||
112 | instance ToJSON (TierEntry TrackerSession) where | ||
113 | toJSON (uri, TrackerSession {..}) = object | ||
114 | [ "uri" .= uri | ||
115 | , "peers" .= trackerPeers | ||
116 | , "scrape" .= trackerScrape | ||
117 | ] | ||
118 | |||
119 | -- | Not contacted. | 107 | -- | Not contacted. |
120 | instance Default TrackerSession where | 108 | instance Default TrackerSession where |
121 | def = TrackerSession Nothing def def | 109 | def = TrackerSession Nothing def def |