diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-21 00:54:48 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-21 00:54:48 +0400 |
commit | 1d251b08f470363a0e3de3894b21c5ada797113d (patch) | |
tree | 8c0613c2b58326e0a3eba29d8c6ca04837ad3994 /src/Data | |
parent | 2b7044a4c1034e36e1762905fa6ca1a515afc0bf (diff) |
Prettify Client module documentation
Diffstat (limited to 'src/Data')
-rw-r--r-- | src/Data/Torrent/Client.hs | 46 |
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 | -- |
19 | module Data.Torrent.Client | 23 | module 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 ((<>)) | |||
40 | import Paths_bittorrent (version) | 47 | import 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 | -- | ||
44 | data ClientImpl = | 55 | data 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 |
107 | instance Default ClientImpl where | 118 | instance 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. |
111 | ppClientImpl :: ClientImpl -> Doc | 122 | ppClientImpl :: ClientImpl -> Doc |
112 | ppClientImpl = text . L.tail . show | 123 | ppClientImpl = 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. |
115 | newtype ClientVersion = ClientVersion { getClientVersion :: Version } | 126 | newtype ClientVersion = ClientVersion { getClientVersion :: Version } |
116 | deriving (Show, Eq, Ord) | 127 | deriving (Show, Eq, Ord) |
117 | 128 | ||
129 | -- | Just the '0' version. | ||
118 | instance Default ClientVersion where | 130 | instance 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. |
122 | ppClientVersion :: ClientVersion -> Doc | 134 | ppClientVersion :: ClientVersion -> Doc |
123 | ppClientVersion = text . showVersion . getClientVersion | 135 | ppClientVersion = 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. |
127 | data ClientInfo = ClientInfo { | 139 | data ClientInfo = ClientInfo { |
128 | ciImpl :: ClientImpl | 140 | ciImpl :: ClientImpl |
129 | , ciVersion :: ClientVersion | 141 | , ciVersion :: ClientVersion |
@@ -133,11 +145,15 @@ data ClientInfo = ClientInfo { | |||
133 | instance Default ClientInfo where | 145 | instance 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. |
137 | ppClientInfo :: ClientInfo -> Doc | 149 | ppClientInfo :: ClientInfo -> Doc |
138 | ppClientInfo ClientInfo {..} = | 150 | ppClientInfo 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 | -- | ||
141 | libClientInfo :: ClientInfo | 157 | libClientInfo :: ClientInfo |
142 | libClientInfo = ClientInfo IlibHSbittorrent (ClientVersion version) | 158 | libClientInfo = ClientInfo IlibHSbittorrent (ClientVersion version) |
143 | 159 | ||