summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-11-23 02:14:13 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-11-23 02:14:13 +0400
commit41f229b5746501738800d721fb19083e32516f8c (patch)
tree8a469cf08a3d5d377fb8679bba759393cc7d8ef2
parent923abc9ee7576f2d3e1b7e2b2d5a32ed5d2f21c9 (diff)
Remove ClientVersion newtype
-rw-r--r--src/Data/Torrent/Client.hs30
-rw-r--r--src/Network/BitTorrent/Core/PeerId.hs2
-rw-r--r--tests/Data/Torrent/ClientSpec.hs4
3 files changed, 13 insertions, 23 deletions
diff --git a/src/Data/Torrent/Client.hs b/src/Data/Torrent/Client.hs
index 0246e29a..a7e94513 100644
--- a/src/Data/Torrent/Client.hs
+++ b/src/Data/Torrent/Client.hs
@@ -21,15 +21,9 @@
21-- done using 'Network.BitTorrent.Extension'! 21-- done using 'Network.BitTorrent.Extension'!
22-- 22--
23module Data.Torrent.Client 23module Data.Torrent.Client
24 ( -- * Client implementation 24 ( ClientImpl (..)
25 ClientImpl (..)
26 , ppClientImpl 25 , ppClientImpl
27 26 , ppVersion
28 -- * Client version
29 , ClientVersion (..)
30 , ppClientVersion
31
32 -- * Client information
33 , ClientInfo (..) 27 , ClientInfo (..)
34 , ppClientInfo 28 , ppClientInfo
35 , libClientInfo 29 , libClientInfo
@@ -122,23 +116,19 @@ instance Default ClientImpl where
122ppClientImpl :: ClientImpl -> Doc 116ppClientImpl :: ClientImpl -> Doc
123ppClientImpl = text . L.tail . show 117ppClientImpl = text . L.tail . show
124 118
125-- | Version of client software, normally extracted from peer id.
126newtype ClientVersion = ClientVersion { getClientVersion :: Version }
127 deriving (Show, Eq, Ord)
128
129-- | Just the '0' version. 119-- | Just the '0' version.
130instance Default ClientVersion where 120instance Default Version where
131 def = ClientVersion $ Version [0] [] 121 def = Version [0] []
132 122
133-- | Format client implementation version in human-readable form. 123-- | Format client implementation version in human-readable form.
134ppClientVersion :: ClientVersion -> Doc 124ppVersion :: Version -> Doc
135ppClientVersion = text . showVersion . getClientVersion 125ppVersion = text . showVersion
136 126
137-- | The all sensible infomation that can be obtained from a peer 127-- | The all sensible infomation that can be obtained from a peer
138-- identifier or torrent /createdBy/ field. 128-- identifier or torrent /createdBy/ field.
139data ClientInfo = ClientInfo { 129data ClientInfo = ClientInfo {
140 ciImpl :: ClientImpl 130 ciImpl :: ClientImpl
141 , ciVersion :: ClientVersion 131 , ciVersion :: Version
142 } deriving (Show, Eq, Ord) 132 } deriving (Show, Eq, Ord)
143 133
144-- | Unrecognized client implementation. 134-- | Unrecognized client implementation.
@@ -148,14 +138,14 @@ instance Default ClientInfo where
148-- | Format client info in human-readable form. 138-- | Format client info in human-readable form.
149ppClientInfo :: ClientInfo -> Doc 139ppClientInfo :: ClientInfo -> Doc
150ppClientInfo ClientInfo {..} = 140ppClientInfo ClientInfo {..} =
151 ppClientImpl ciImpl <+> "version" <+> ppClientVersion ciVersion 141 ppClientImpl ciImpl <+> "version" <+> ppVersion ciVersion
152 142
153-- | Client info of this (the bittorrent library) package. Normally, 143-- | Client info of this (the bittorrent library) package. Normally,
154-- applications should introduce its own idenitifiers, otherwise they 144-- applications should introduce its own idenitifiers, otherwise they
155-- can use 'libClientInfo' value. 145-- can use 'libClientInfo' value.
156-- 146--
157libClientInfo :: ClientInfo 147libClientInfo :: ClientInfo
158libClientInfo = ClientInfo IlibHSbittorrent (ClientVersion version) 148libClientInfo = ClientInfo IlibHSbittorrent version
159 149
160{----------------------------------------------------------------------- 150{-----------------------------------------------------------------------
161-- For torrent file 151-- For torrent file
@@ -164,7 +154,7 @@ libClientInfo = ClientInfo IlibHSbittorrent (ClientVersion version)
164renderImpl :: ClientImpl -> Text 154renderImpl :: ClientImpl -> Text
165renderImpl = T.pack . L.tail . show 155renderImpl = T.pack . L.tail . show
166 156
167renderVersion :: ClientVersion -> Text 157renderVersion :: Version -> Text
168renderVersion = undefined 158renderVersion = undefined
169 159
170renderClientInfo :: ClientInfo -> Text 160renderClientInfo :: ClientInfo -> Text
diff --git a/src/Network/BitTorrent/Core/PeerId.hs b/src/Network/BitTorrent/Core/PeerId.hs
index 8883656b..a212df3d 100644
--- a/src/Network/BitTorrent/Core/PeerId.hs
+++ b/src/Network/BitTorrent/Core/PeerId.hs
@@ -285,4 +285,4 @@ clientInfo pid = either (const def) id $ runGet getCI (getPeerId pid)
285 getClientImpl = parseImpl <$> getByteString 2 285 getClientImpl = parseImpl <$> getByteString 2
286 getClientVersion = mkVer <$> getByteString 4 286 getClientVersion = mkVer <$> getByteString 4
287 where 287 where
288 mkVer bs = ClientVersion $ Version [fromMaybe 0 $ readMaybe $ BC.unpack bs] [] 288 mkVer bs = Version [fromMaybe 0 $ readMaybe $ BC.unpack bs] []
diff --git a/tests/Data/Torrent/ClientSpec.hs b/tests/Data/Torrent/ClientSpec.hs
index f02a3b1f..85ace5e0 100644
--- a/tests/Data/Torrent/ClientSpec.hs
+++ b/tests/Data/Torrent/ClientSpec.hs
@@ -11,6 +11,6 @@ spec = do
11 describe "client info" $ do 11 describe "client info" $ do
12 it "decode azureus encoded peer id" $ do 12 it "decode azureus encoded peer id" $ do
13 clientInfo "-AZ2060-xxxxxxxxxxxx" `shouldBe` 13 clientInfo "-AZ2060-xxxxxxxxxxxx" `shouldBe`
14 ClientInfo IAzureus (ClientVersion (Version [2060] [])) 14 ClientInfo IAzureus (Version [2060] [])
15 clientInfo "-BS0000-xxxxxxxxxxxx" `shouldBe` 15 clientInfo "-BS0000-xxxxxxxxxxxx" `shouldBe`
16 ClientInfo IBTSlave (ClientVersion (Version [0] [])) 16 ClientInfo IBTSlave (Version [0] [])