summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-12-07 23:10:27 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-07 23:10:27 +0400
commit1ae7d4877a2a30131babbee54bc0c24651eaba90 (patch)
tree1d2b6835d70a546859569933d0a34037b029d7c5 /src/Network
parent44fc77ee51b5aef9d43e3d384845d73646ea1d0e (diff)
Move JSON options to separate module
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent/Core/PeerAddr.hs3
-rw-r--r--src/Network/BitTorrent/Exchange/Block.hs3
-rw-r--r--src/Network/BitTorrent/Exchange/Status.hs7
-rw-r--r--src/Network/BitTorrent/Tracker/Message.hs12
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
41import Text.Read (readMaybe) 41import Text.Read (readMaybe)
42import System.IO.Unsafe 42import System.IO.Unsafe
43 43
44import Data.Torrent.JSON
44import Network.BitTorrent.Core.PeerId 45import 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
73peer_id_key, peer_ip_key, peer_port_key :: BKey 74peer_id_key, peer_ip_key, peer_port_key :: BKey
74peer_id_key = "peer id" 75peer_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
41import Text.PrettyPrint 41import Text.PrettyPrint
42import Text.PrettyPrint.Class 42import Text.PrettyPrint.Class
43 43
44import Data.Torrent.JSON
44import Data.Torrent.Piece 45import 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
89getInt :: S.Get Int 90getInt :: S.Get Int
90getInt = fromIntegral <$> S.getWord32be 91getInt = 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
36import Control.Lens 36import Control.Lens
37import Data.Aeson.TH 37import Data.Aeson.TH
38import Data.Default 38import Data.Default
39import Data.List as L
40import Data.Maybe 39import Data.Maybe
41import Data.Monoid 40import Data.Monoid
42import Text.PrettyPrint as PP hiding ((<>)) 41import Text.PrettyPrint as PP hiding ((<>))
43import Text.PrettyPrint.Class 42import Text.PrettyPrint.Class
44 43
44import Data.Torrent.JSON
45import Network.BitTorrent.Exchange.Message 45import 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
65instance Pretty PeerStatus where 66instance 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
108instance Pretty SessionStatus where 109instance 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
87import Text.Read (readMaybe) 90import Text.Read (readMaybe)
88 91
89import Data.Torrent.InfoHash 92import Data.Torrent.InfoHash
93import Data.Torrent.JSON
90import Data.Torrent.Progress 94import Data.Torrent.Progress
91import Network.BitTorrent.Core 95import 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.
110instance QueryValueLike Event where 114instance 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.
180instance Serialize AnnounceQuery where 184instance 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.
486instance BEncode AnnounceInfo where 490instance 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.
636instance BEncode ScrapeEntry where 640instance BEncode ScrapeEntry where