summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Data/Torrent/Client.hs46
1 files changed, 31 insertions, 15 deletions
diff --git a/src/Data/Torrent/Client.hs b/src/Data/Torrent/Client.hs
index b6649e04..0246e29a 100644
--- a/src/Data/Torrent/Client.hs
+++ b/src/Data/Torrent/Client.hs
@@ -9,20 +9,27 @@
9-- version which also contained in 'Peer'. For exsample first 6 9-- version which also contained in 'Peer'. For exsample first 6
10-- bytes of peer id of this this library are @-HS0100-@ while for 10-- bytes of peer id of this this library are @-HS0100-@ while for
11-- mainline we have @M4-3-6--@. We could extract this info and 11-- mainline we have @M4-3-6--@. We could extract this info and
12-- print in human frienly form: this is useful for debugging and 12-- print in human-friendly form: this is useful for debugging and
13-- logging. For more information see: 13-- logging.
14-- <http://bittorrent.org/beps/bep_0020.html> NOTE: Do _not_ use 14--
15-- this information to control client capabilities (such as 15-- For more information see:
16-- supported enchancements), this should be done using 16-- <http://bittorrent.org/beps/bep_0020.html>
17-- 'Network.BitTorrent.Extension'! 17--
18--
19-- NOTE: Do _not_ use this information to control client
20-- capabilities (such as supported enchancements), this should be
21-- done using 'Network.BitTorrent.Extension'!
18-- 22--
19module Data.Torrent.Client 23module Data.Torrent.Client
20 ( ClientImpl (..) 24 ( -- * Client implementation
25 ClientImpl (..)
21 , ppClientImpl 26 , ppClientImpl
22 27
28 -- * Client version
23 , ClientVersion (..) 29 , ClientVersion (..)
24 , ppClientVersion 30 , ppClientVersion
25 31
32 -- * Client information
26 , ClientInfo (..) 33 , ClientInfo (..)
27 , ppClientInfo 34 , ppClientInfo
28 , libClientInfo 35 , libClientInfo
@@ -40,7 +47,11 @@ import Text.PrettyPrint hiding ((<>))
40import Paths_bittorrent (version) 47import Paths_bittorrent (version)
41 48
42 49
43-- | All known client versions. 50-- | List of registered client versions + IlibHSbittorrent (this
51-- package) + Unknown (for not recognized software). All names are
52-- prefixed by "I" because some of them starts from lowercase letter
53-- but that is not a valid Haskell constructor name.
54--
44data ClientImpl = 55data ClientImpl =
45 IUnknown 56 IUnknown
46 | IAres 57 | IAres
@@ -103,27 +114,28 @@ data ClientImpl =
103 | IZipTorrent 114 | IZipTorrent
104 deriving (Show, Eq, Ord, Enum, Bounded) 115 deriving (Show, Eq, Ord, Enum, Bounded)
105 116
106-- | Used to represent not recognized implementation 117-- | Used to represent a not recognized implementation
107instance Default ClientImpl where 118instance Default ClientImpl where
108 def = IUnknown 119 def = IUnknown
109 120
110-- | Format client implementation info in human readable form. 121-- | Format client implementation info in human-readable form.
111ppClientImpl :: ClientImpl -> Doc 122ppClientImpl :: ClientImpl -> Doc
112ppClientImpl = text . L.tail . show 123ppClientImpl = text . L.tail . show
113 124
114-- | Raw version of client, normally extracted from peer id. 125-- | Version of client software, normally extracted from peer id.
115newtype ClientVersion = ClientVersion { getClientVersion :: Version } 126newtype ClientVersion = ClientVersion { getClientVersion :: Version }
116 deriving (Show, Eq, Ord) 127 deriving (Show, Eq, Ord)
117 128
129-- | Just the '0' version.
118instance Default ClientVersion where 130instance Default ClientVersion where
119 def = ClientVersion $ Version [0] [] 131 def = ClientVersion $ Version [0] []
120 132
121-- | Format client implementation version in human readable form. 133-- | Format client implementation version in human-readable form.
122ppClientVersion :: ClientVersion -> Doc 134ppClientVersion :: ClientVersion -> Doc
123ppClientVersion = text . showVersion . getClientVersion 135ppClientVersion = text . showVersion . getClientVersion
124 136
125-- | All useful infomation that can be obtained from a peer 137-- | The all sensible infomation that can be obtained from a peer
126-- identifier. 138-- identifier or torrent /createdBy/ field.
127data ClientInfo = ClientInfo { 139data ClientInfo = ClientInfo {
128 ciImpl :: ClientImpl 140 ciImpl :: ClientImpl
129 , ciVersion :: ClientVersion 141 , ciVersion :: ClientVersion
@@ -133,11 +145,15 @@ data ClientInfo = ClientInfo {
133instance Default ClientInfo where 145instance Default ClientInfo where
134 def = ClientInfo def def 146 def = ClientInfo def def
135 147
136-- | Format client implementation in human readable form. 148-- | Format client info in human-readable form.
137ppClientInfo :: ClientInfo -> Doc 149ppClientInfo :: ClientInfo -> Doc
138ppClientInfo ClientInfo {..} = 150ppClientInfo ClientInfo {..} =
139 ppClientImpl ciImpl <+> "version" <+> ppClientVersion ciVersion 151 ppClientImpl ciImpl <+> "version" <+> ppClientVersion ciVersion
140 152
153-- | Client info of this (the bittorrent library) package. Normally,
154-- applications should introduce its own idenitifiers, otherwise they
155-- can use 'libClientInfo' value.
156--
141libClientInfo :: ClientInfo 157libClientInfo :: ClientInfo
142libClientInfo = ClientInfo IlibHSbittorrent (ClientVersion version) 158libClientInfo = ClientInfo IlibHSbittorrent (ClientVersion version)
143 159