summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/PeerWire
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-05-01 09:07:54 +0400
committerSam T <pxqr.sta@gmail.com>2013-05-01 09:07:54 +0400
commitc80221283ceb618195eb7fde5174f362aea0a27a (patch)
tree7d29769f51aa84cc2c4f070c51d73645edf1b16e /src/Network/BitTorrent/PeerWire
parentb705ef2baa0930aff3c43c31f3ea29caf969512b (diff)
~ Add documentation to client info.
Diffstat (limited to 'src/Network/BitTorrent/PeerWire')
-rw-r--r--src/Network/BitTorrent/PeerWire/ClientInfo.hs25
-rw-r--r--src/Network/BitTorrent/PeerWire/Handshake.hs8
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 #-}
15module Network.BitTorrent.PeerWire.ClientInfo 15module 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
29import Network.BitTorrent.PeerID 30import Network.BitTorrent.PeerID
30 31
31 32
33-- | All known client versions.
32data ClientImpl = 34data 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
94parseImpl :: ByteString -> ClientImpl 96parseImpl :: ByteString -> ClientImpl
95parseImpl = f . BC.unpack 97parseImpl = 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.
159ppClientImpl :: ClientImpl -> String 162ppClientImpl :: ClientImpl -> String
160ppClientImpl = tail . show 163ppClientImpl = tail . show
161 164
@@ -166,6 +169,7 @@ unknownImpl = IUnknown
166 169
167type ClientVersion = ByteString 170type ClientVersion = ByteString
168 171
172-- | Format client implementation version in human readable form.
169ppClientVersion :: ClientVersion -> String 173ppClientVersion :: ClientVersion -> String
170ppClientVersion = BC.unpack 174ppClientVersion = BC.unpack
171 175
@@ -173,19 +177,26 @@ unknownVersion :: ClientVersion
173unknownVersion = "0000" 177unknownVersion = "0000"
174 178
175 179
176 180-- | All useful infomation that can be obtained from a peer
181-- identifier.
177data ClientInfo = ClientInfo { 182data 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.
182ppClientInfo :: ClientInfo -> String 188ppClientInfo :: ClientInfo -> String
183ppClientInfo ci = ppClientImpl (ciImpl ci) ++ " version " 189ppClientInfo ci = ppClientImpl (ciImpl ci) ++ " version "
184 ++ ppClientVersion (ciVersion ci) 190 ++ ppClientVersion (ciVersion ci)
185 191
192-- | Unrecognized client implementation.
186unknownClient :: ClientInfo 193unknownClient :: ClientInfo
187unknownClient = ClientInfo unknownImpl unknownVersion 194unknownClient = 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--
189clientInfo :: PeerID -> ClientInfo 200clientInfo :: PeerID -> ClientInfo
190clientInfo pid = either (const unknownClient) id $ runGet getCI (getPeerID pid) 201clientInfo 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--
36data Handshake = Handshake { 36data 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