diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-07 23:10:27 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-07 23:10:27 +0400 |
commit | 1ae7d4877a2a30131babbee54bc0c24651eaba90 (patch) | |
tree | 1d2b6835d70a546859569933d0a34037b029d7c5 /src/Network | |
parent | 44fc77ee51b5aef9d43e3d384845d73646ea1d0e (diff) |
Move JSON options to separate module
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/BitTorrent/Core/PeerAddr.hs | 3 | ||||
-rw-r--r-- | src/Network/BitTorrent/Exchange/Block.hs | 3 | ||||
-rw-r--r-- | src/Network/BitTorrent/Exchange/Status.hs | 7 | ||||
-rw-r--r-- | src/Network/BitTorrent/Tracker/Message.hs | 12 |
4 files changed, 16 insertions, 9 deletions
diff --git a/src/Network/BitTorrent/Core/PeerAddr.hs b/src/Network/BitTorrent/Core/PeerAddr.hs index 846a14f9..e7a4ea61 100644 --- a/src/Network/BitTorrent/Core/PeerAddr.hs +++ b/src/Network/BitTorrent/Core/PeerAddr.hs | |||
@@ -41,6 +41,7 @@ import Text.PrettyPrint.Class | |||
41 | import Text.Read (readMaybe) | 41 | import Text.Read (readMaybe) |
42 | import System.IO.Unsafe | 42 | import System.IO.Unsafe |
43 | 43 | ||
44 | import Data.Torrent.JSON | ||
44 | import Network.BitTorrent.Core.PeerId | 45 | import Network.BitTorrent.Core.PeerId |
45 | 46 | ||
46 | 47 | ||
@@ -68,7 +69,7 @@ data PeerAddr = PeerAddr | |||
68 | , peerPort :: {-# UNPACK #-} !PortNumber | 69 | , peerPort :: {-# UNPACK #-} !PortNumber |
69 | } deriving (Show, Eq, Ord, Typeable) | 70 | } deriving (Show, Eq, Ord, Typeable) |
70 | 71 | ||
71 | $(deriveJSON defaultOptions { fieldLabelModifier = (L.map toLower . L.dropWhile isLower) } ''PeerAddr) | 72 | $(deriveJSON omitRecordPrefix ''PeerAddr) |
72 | 73 | ||
73 | peer_id_key, peer_ip_key, peer_port_key :: BKey | 74 | peer_id_key, peer_ip_key, peer_port_key :: BKey |
74 | peer_id_key = "peer id" | 75 | peer_id_key = "peer id" |
diff --git a/src/Network/BitTorrent/Exchange/Block.hs b/src/Network/BitTorrent/Exchange/Block.hs index 5ab73b65..d06fe727 100644 --- a/src/Network/BitTorrent/Exchange/Block.hs +++ b/src/Network/BitTorrent/Exchange/Block.hs | |||
@@ -41,6 +41,7 @@ import Data.Typeable | |||
41 | import Text.PrettyPrint | 41 | import Text.PrettyPrint |
42 | import Text.PrettyPrint.Class | 42 | import Text.PrettyPrint.Class |
43 | 43 | ||
44 | import Data.Torrent.JSON | ||
44 | import Data.Torrent.Piece | 45 | import Data.Torrent.Piece |
45 | 46 | ||
46 | {----------------------------------------------------------------------- | 47 | {----------------------------------------------------------------------- |
@@ -84,7 +85,7 @@ data BlockIx = BlockIx { | |||
84 | , ixLength :: {-# UNPACK #-} !BlockSize | 85 | , ixLength :: {-# UNPACK #-} !BlockSize |
85 | } deriving (Show, Eq, Typeable) | 86 | } deriving (Show, Eq, Typeable) |
86 | 87 | ||
87 | $(deriveJSON defaultOptions { fieldLabelModifier = (L.map toLower . L.dropWhile isLower) } ''BlockIx) | 88 | $(deriveJSON omitRecordPrefix ''BlockIx) |
88 | 89 | ||
89 | getInt :: S.Get Int | 90 | getInt :: S.Get Int |
90 | getInt = fromIntegral <$> S.getWord32be | 91 | getInt = fromIntegral <$> S.getWord32be |
diff --git a/src/Network/BitTorrent/Exchange/Status.hs b/src/Network/BitTorrent/Exchange/Status.hs index 42766428..8472e575 100644 --- a/src/Network/BitTorrent/Exchange/Status.hs +++ b/src/Network/BitTorrent/Exchange/Status.hs | |||
@@ -36,14 +36,15 @@ module Network.BitTorrent.Exchange.Status | |||
36 | import Control.Lens | 36 | import Control.Lens |
37 | import Data.Aeson.TH | 37 | import Data.Aeson.TH |
38 | import Data.Default | 38 | import Data.Default |
39 | import Data.List as L | ||
40 | import Data.Maybe | 39 | import Data.Maybe |
41 | import Data.Monoid | 40 | import Data.Monoid |
42 | import Text.PrettyPrint as PP hiding ((<>)) | 41 | import Text.PrettyPrint as PP hiding ((<>)) |
43 | import Text.PrettyPrint.Class | 42 | import Text.PrettyPrint.Class |
44 | 43 | ||
44 | import Data.Torrent.JSON | ||
45 | import Network.BitTorrent.Exchange.Message | 45 | import Network.BitTorrent.Exchange.Message |
46 | 46 | ||
47 | |||
47 | {----------------------------------------------------------------------- | 48 | {----------------------------------------------------------------------- |
48 | -- Peer status | 49 | -- Peer status |
49 | -----------------------------------------------------------------------} | 50 | -----------------------------------------------------------------------} |
@@ -60,7 +61,7 @@ data PeerStatus = PeerStatus | |||
60 | } deriving (Show, Eq, Ord) | 61 | } deriving (Show, Eq, Ord) |
61 | 62 | ||
62 | $(makeLenses ''PeerStatus) | 63 | $(makeLenses ''PeerStatus) |
63 | $(deriveJSON defaultOptions { fieldLabelModifier = L.tail } ''PeerStatus) | 64 | $(deriveJSON omitLensPrefix ''PeerStatus) |
64 | 65 | ||
65 | instance Pretty PeerStatus where | 66 | instance Pretty PeerStatus where |
66 | pretty PeerStatus {..} = | 67 | pretty PeerStatus {..} = |
@@ -103,7 +104,7 @@ data SessionStatus = SessionStatus | |||
103 | } deriving (Show, Eq) | 104 | } deriving (Show, Eq) |
104 | 105 | ||
105 | $(makeLenses ''SessionStatus) | 106 | $(makeLenses ''SessionStatus) |
106 | $(deriveJSON defaultOptions { fieldLabelModifier = L.tail } ''SessionStatus) | 107 | $(deriveJSON omitRecordPrefix ''SessionStatus) |
107 | 108 | ||
108 | instance Pretty SessionStatus where | 109 | instance Pretty SessionStatus where |
109 | pretty SessionStatus {..} = | 110 | pretty SessionStatus {..} = |
diff --git a/src/Network/BitTorrent/Tracker/Message.hs b/src/Network/BitTorrent/Tracker/Message.hs index 212181b9..943c3af5 100644 --- a/src/Network/BitTorrent/Tracker/Message.hs +++ b/src/Network/BitTorrent/Tracker/Message.hs | |||
@@ -34,6 +34,9 @@ module Network.BitTorrent.Tracker.Message | |||
34 | 34 | ||
35 | -- ** Request | 35 | -- ** Request |
36 | , AnnounceQueryExt (..) | 36 | , AnnounceQueryExt (..) |
37 | , renderAnnounceQueryExt | ||
38 | , parseAnnounceQueryExt | ||
39 | |||
37 | , AnnounceRequest (..) | 40 | , AnnounceRequest (..) |
38 | , parseAnnounceRequest | 41 | , parseAnnounceRequest |
39 | , renderAnnounceRequest | 42 | , renderAnnounceRequest |
@@ -87,6 +90,7 @@ import Network.Socket | |||
87 | import Text.Read (readMaybe) | 90 | import Text.Read (readMaybe) |
88 | 91 | ||
89 | import Data.Torrent.InfoHash | 92 | import Data.Torrent.InfoHash |
93 | import Data.Torrent.JSON | ||
90 | import Data.Torrent.Progress | 94 | import Data.Torrent.Progress |
91 | import Network.BitTorrent.Core | 95 | import Network.BitTorrent.Core |
92 | 96 | ||
@@ -104,7 +108,7 @@ data Event = Started | |||
104 | -- ^ To be sent when the peer completes a download. | 108 | -- ^ To be sent when the peer completes a download. |
105 | deriving (Show, Read, Eq, Ord, Enum, Bounded, Typeable) | 109 | deriving (Show, Read, Eq, Ord, Enum, Bounded, Typeable) |
106 | 110 | ||
107 | $(deriveJSON defaultOptions { fieldLabelModifier = (L.map toLower . L.dropWhile isLower) } ''Event) | 111 | $(deriveJSON omitRecordPrefix ''Event) |
108 | 112 | ||
109 | -- | HTTP tracker protocol compatible encoding. | 113 | -- | HTTP tracker protocol compatible encoding. |
110 | instance QueryValueLike Event where | 114 | instance QueryValueLike Event where |
@@ -174,7 +178,7 @@ data AnnounceQuery = AnnounceQuery | |||
174 | , reqEvent :: Maybe Event | 178 | , reqEvent :: Maybe Event |
175 | } deriving (Show, Eq, Typeable) | 179 | } deriving (Show, Eq, Typeable) |
176 | 180 | ||
177 | $(deriveJSON defaultOptions { fieldLabelModifier = (L.map toLower . L.dropWhile isLower) } ''AnnounceQuery) | 181 | $(deriveJSON omitRecordPrefix ''AnnounceQuery) |
178 | 182 | ||
179 | -- | UDP tracker protocol compatible encoding. | 183 | -- | UDP tracker protocol compatible encoding. |
180 | instance Serialize AnnounceQuery where | 184 | instance Serialize AnnounceQuery where |
@@ -480,7 +484,7 @@ data AnnounceInfo = | |||
480 | , respWarning :: !(Maybe Text) | 484 | , respWarning :: !(Maybe Text) |
481 | } deriving (Show, Typeable) | 485 | } deriving (Show, Typeable) |
482 | 486 | ||
483 | $(deriveJSON defaultOptions { fieldLabelModifier = (L.map toLower . L.dropWhile isLower) } ''AnnounceInfo) | 487 | $(deriveJSON omitRecordPrefix ''AnnounceInfo) |
484 | 488 | ||
485 | -- | HTTP tracker protocol compatible encoding. | 489 | -- | HTTP tracker protocol compatible encoding. |
486 | instance BEncode AnnounceInfo where | 490 | instance BEncode AnnounceInfo where |
@@ -630,7 +634,7 @@ data ScrapeEntry = ScrapeEntry { | |||
630 | , siName :: !(Maybe Text) | 634 | , siName :: !(Maybe Text) |
631 | } deriving (Show, Eq, Typeable) | 635 | } deriving (Show, Eq, Typeable) |
632 | 636 | ||
633 | $(deriveJSON defaultOptions { fieldLabelModifier = (L.map toLower . L.dropWhile isLower) } ''ScrapeEntry) | 637 | $(deriveJSON omitRecordPrefix ''ScrapeEntry) |
634 | 638 | ||
635 | -- | HTTP tracker protocol compatible encoding. | 639 | -- | HTTP tracker protocol compatible encoding. |
636 | instance BEncode ScrapeEntry where | 640 | instance BEncode ScrapeEntry where |