diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-05-01 09:07:54 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-05-01 09:07:54 +0400 |
commit | c80221283ceb618195eb7fde5174f362aea0a27a (patch) | |
tree | 7d29769f51aa84cc2c4f070c51d73645edf1b16e /src/Network/BitTorrent | |
parent | b705ef2baa0930aff3c43c31f3ea29caf969512b (diff) |
~ Add documentation to client info.
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/PeerWire/ClientInfo.hs | 25 | ||||
-rw-r--r-- | src/Network/BitTorrent/PeerWire/Handshake.hs | 8 |
2 files changed, 22 insertions, 11 deletions
diff --git a/src/Network/BitTorrent/PeerWire/ClientInfo.hs b/src/Network/BitTorrent/PeerWire/ClientInfo.hs index e2da4d3b..629c883f 100644 --- a/src/Network/BitTorrent/PeerWire/ClientInfo.hs +++ b/src/Network/BitTorrent/PeerWire/ClientInfo.hs | |||
@@ -9,13 +9,14 @@ | |||
9 | -- implementation that can be later printed in human frienly | 9 | -- implementation that can be later printed in human frienly |
10 | -- form. Useful for debugging and logging. | 10 | -- form. Useful for debugging and logging. |
11 | -- | 11 | -- |
12 | -- See http://bittorrent.org/beps/bep_0020.html for more information. | 12 | -- > See http://bittorrent.org/beps/bep_0020.html for more information. |
13 | -- | 13 | -- |
14 | {-# LANGUAGE OverloadedStrings #-} | 14 | {-# LANGUAGE OverloadedStrings #-} |
15 | module Network.BitTorrent.PeerWire.ClientInfo | 15 | module Network.BitTorrent.PeerWire.ClientInfo |
16 | ( ClientInfo(..), ClientVersion, ClientImpl | 16 | ( ClientInfo(..), clientInfo, ppClientInfo, unknownClient |
17 | , clientInfo | 17 | |
18 | , ppClientInfo, ppClientVersion, ppClientImpl | 18 | , ClientVersion, ppClientVersion |
19 | , ClientImpl(..), ppClientImpl | ||
19 | 20 | ||
20 | -- , mkEnumTyDef, mkPars, nameMap | 21 | -- , mkEnumTyDef, mkPars, nameMap |
21 | ) where | 22 | ) where |
@@ -29,6 +30,7 @@ import Data.Serialize.Get | |||
29 | import Network.BitTorrent.PeerID | 30 | import Network.BitTorrent.PeerID |
30 | 31 | ||
31 | 32 | ||
33 | -- | All known client versions. | ||
32 | data ClientImpl = | 34 | data ClientImpl = |
33 | IUnknown | 35 | IUnknown |
34 | | IAres | 36 | | IAres |
@@ -89,7 +91,7 @@ data ClientImpl = | |||
89 | | IXanTorrent | 91 | | IXanTorrent |
90 | | IXtorrent | 92 | | IXtorrent |
91 | | IZipTorrent | 93 | | IZipTorrent |
92 | deriving Show | 94 | deriving (Show, Eq, Ord) |
93 | 95 | ||
94 | parseImpl :: ByteString -> ClientImpl | 96 | parseImpl :: ByteString -> ClientImpl |
95 | parseImpl = f . BC.unpack | 97 | parseImpl = f . BC.unpack |
@@ -156,6 +158,7 @@ parseImpl = f . BC.unpack | |||
156 | f "ZT" = IZipTorrent | 158 | f "ZT" = IZipTorrent |
157 | f _ = IUnknown | 159 | f _ = IUnknown |
158 | 160 | ||
161 | -- | Format client implementation info in human readable form. | ||
159 | ppClientImpl :: ClientImpl -> String | 162 | ppClientImpl :: ClientImpl -> String |
160 | ppClientImpl = tail . show | 163 | ppClientImpl = tail . show |
161 | 164 | ||
@@ -166,6 +169,7 @@ unknownImpl = IUnknown | |||
166 | 169 | ||
167 | type ClientVersion = ByteString | 170 | type ClientVersion = ByteString |
168 | 171 | ||
172 | -- | Format client implementation version in human readable form. | ||
169 | ppClientVersion :: ClientVersion -> String | 173 | ppClientVersion :: ClientVersion -> String |
170 | ppClientVersion = BC.unpack | 174 | ppClientVersion = BC.unpack |
171 | 175 | ||
@@ -173,19 +177,26 @@ unknownVersion :: ClientVersion | |||
173 | unknownVersion = "0000" | 177 | unknownVersion = "0000" |
174 | 178 | ||
175 | 179 | ||
176 | 180 | -- | All useful infomation that can be obtained from a peer | |
181 | -- identifier. | ||
177 | data ClientInfo = ClientInfo { | 182 | data ClientInfo = ClientInfo { |
178 | ciImpl :: ClientImpl | 183 | ciImpl :: ClientImpl |
179 | , ciVersion :: ClientVersion | 184 | , ciVersion :: ClientVersion |
180 | } deriving Show | 185 | } deriving (Show, Eq, Ord) |
181 | 186 | ||
187 | -- | Format client implementation in human readable form. | ||
182 | ppClientInfo :: ClientInfo -> String | 188 | ppClientInfo :: ClientInfo -> String |
183 | ppClientInfo ci = ppClientImpl (ciImpl ci) ++ " version " | 189 | ppClientInfo ci = ppClientImpl (ciImpl ci) ++ " version " |
184 | ++ ppClientVersion (ciVersion ci) | 190 | ++ ppClientVersion (ciVersion ci) |
185 | 191 | ||
192 | -- | Unrecognized client implementation. | ||
186 | unknownClient :: ClientInfo | 193 | unknownClient :: ClientInfo |
187 | unknownClient = ClientInfo unknownImpl unknownVersion | 194 | unknownClient = ClientInfo unknownImpl unknownVersion |
188 | 195 | ||
196 | -- | Tries to extract meaningful information from peer ID bytes. If | ||
197 | -- peer id uses unknown coding style then client info returned is | ||
198 | -- 'unknownClient'. | ||
199 | -- | ||
189 | clientInfo :: PeerID -> ClientInfo | 200 | clientInfo :: PeerID -> ClientInfo |
190 | clientInfo pid = either (const unknownClient) id $ runGet getCI (getPeerID pid) | 201 | clientInfo pid = either (const unknownClient) id $ runGet getCI (getPeerID pid) |
191 | where -- TODO other styles | 202 | where -- TODO other styles |
diff --git a/src/Network/BitTorrent/PeerWire/Handshake.hs b/src/Network/BitTorrent/PeerWire/Handshake.hs index a05ecc33..7a250782 100644 --- a/src/Network/BitTorrent/PeerWire/Handshake.hs +++ b/src/Network/BitTorrent/PeerWire/Handshake.hs | |||
@@ -34,20 +34,20 @@ import Network.BitTorrent.PeerWire.ClientInfo | |||
34 | -- peer. | 34 | -- peer. |
35 | -- | 35 | -- |
36 | data Handshake = Handshake { | 36 | data Handshake = Handshake { |
37 | -- ^ Identifier of the protocol. | 37 | -- | Identifier of the protocol. |
38 | hsProtocol :: ByteString | 38 | hsProtocol :: ByteString |
39 | 39 | ||
40 | -- ^ Reserved bytes used to specify supported BEP's. | 40 | -- | Reserved bytes used to specify supported BEP's. |
41 | , hsReserved :: Word64 | 41 | , hsReserved :: Word64 |
42 | 42 | ||
43 | -- ^ Info hash of the info part of the metainfo file. that is | 43 | -- | Info hash of the info part of the metainfo file. that is |
44 | -- transmitted in tracker requests. Info hash of the initiator | 44 | -- transmitted in tracker requests. Info hash of the initiator |
45 | -- handshake and response handshake should match, otherwise | 45 | -- handshake and response handshake should match, otherwise |
46 | -- initiator should break the connection. | 46 | -- initiator should break the connection. |
47 | -- | 47 | -- |
48 | , hsInfoHash :: InfoHash | 48 | , hsInfoHash :: InfoHash |
49 | 49 | ||
50 | -- ^ Peer id of the initiator. This is usually the same peer id | 50 | -- | Peer id of the initiator. This is usually the same peer id |
51 | -- that is transmitted in tracker requests. | 51 | -- that is transmitted in tracker requests. |
52 | -- | 52 | -- |
53 | , hsPeerID :: PeerID | 53 | , hsPeerID :: PeerID |