summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-11-25 09:04:35 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-11-25 09:04:35 +0400
commite241ad38fad792424d711a5bd775c9841b3e6a5f (patch)
tree7ba179aeca01c45f79ca01b874c38f0d85361d8c
parent5c8b0cc9fcfc0fc6e029ac240ab4aedf0ba7f325 (diff)
Fix documentation markup in PeerId module
-rw-r--r--bittorrent.cabal6
-rw-r--r--src/Network/BitTorrent/Core/PeerId.hs27
2 files changed, 16 insertions, 17 deletions
diff --git a/bittorrent.cabal b/bittorrent.cabal
index be888bf5..9f966428 100644
--- a/bittorrent.cabal
+++ b/bittorrent.cabal
@@ -98,7 +98,7 @@ library
98 , containers >= 0.4 98 , containers >= 0.4
99 , data-default 99 , data-default
100 , IntervalMap 100 , IntervalMap
101 , intset 101-- , intset
102 , split 102 , split
103 , text >= 0.11.0 103 , text >= 0.11.0
104 , unordered-containers 104 , unordered-containers
@@ -111,7 +111,7 @@ library
111 -- Codecs & Serialization 111 -- Codecs & Serialization
112 , aeson 112 , aeson
113 , base16-bytestring 113 , base16-bytestring
114 , base32-bytestring 114 , base32-bytestring == 0.1.1.0
115 , base64-bytestring 115 , base64-bytestring
116 , bencoding >= 0.4 116 , bencoding >= 0.4
117 , binary 117 , binary
@@ -125,7 +125,7 @@ library
125 -- Network 125 -- Network
126 , network >= 2.4 126 , network >= 2.4
127 , HTTP >= 4000.2 127 , HTTP >= 4000.2
128 , krpc >= 0.3 128-- , krpc >= 0.3
129 129
130 -- System 130 -- System
131 , directory >= 1 131 , directory >= 1
diff --git a/src/Network/BitTorrent/Core/PeerId.hs b/src/Network/BitTorrent/Core/PeerId.hs
index b8780a96..beec7408 100644
--- a/src/Network/BitTorrent/Core/PeerId.hs
+++ b/src/Network/BitTorrent/Core/PeerId.hs
@@ -8,9 +8,8 @@
8-- 'PeerID' represent self assigned peer identificator. Ideally each 8-- 'PeerID' represent self assigned peer identificator. Ideally each
9-- host in the network should have unique peer id to avoid 9-- host in the network should have unique peer id to avoid
10-- collisions, therefore for peer ID generation we use good entropy 10-- collisions, therefore for peer ID generation we use good entropy
11-- source. (FIX not really) Peer ID is sent in /tracker request/, 11-- source. Peer ID is sent in /tracker request/, sent and received in
12-- sent and received in /peer handshakes/ and used in /distributed 12-- /peer handshakes/ and used in DHT queries.
13-- hash table/ queries.
14-- 13--
15{-# LANGUAGE GeneralizedNewtypeDeriving #-} 14{-# LANGUAGE GeneralizedNewtypeDeriving #-}
16module Network.BitTorrent.Core.PeerId 15module Network.BitTorrent.Core.PeerId
@@ -29,7 +28,7 @@ module Network.BitTorrent.Core.PeerId
29 -- * Decoding 28 -- * Decoding
30 , clientInfo 29 , clientInfo
31 30
32 -- ** Extra 31 -- * Extra
33 , byteStringPadded 32 , byteStringPadded
34 , defaultClientId 33 , defaultClientId
35 , defaultVersionNumber 34 , defaultVersionNumber
@@ -155,12 +154,12 @@ shadowStyle cid ver rnd = PeerId $ BL.toStrict $ BS.toLazyByteString $
155 byteStringPadded rnd 15 '0' 154 byteStringPadded rnd 15 '0'
156 155
157 156
158-- | "HS" - 2 bytes long client identifier. 157-- | 'HS'- 2 bytes long client identifier.
159defaultClientId :: ByteString 158defaultClientId :: ByteString
160defaultClientId = "HS" 159defaultClientId = "HS"
161 160
162-- | Gives exactly 4 bytes long version number for any version of the 161-- | Gives exactly 4 bytes long version number for any version of the
163-- package. Version is taken from .cabal. 162-- package. Version is taken from .cabal file.
164defaultVersionNumber :: ByteString 163defaultVersionNumber :: ByteString
165defaultVersionNumber = BS.take 4 $ BC.pack $ foldMap show $ 164defaultVersionNumber = BS.take 4 $ BC.pack $ foldMap show $
166 versionBranch version 165 versionBranch version
@@ -173,14 +172,13 @@ defaultVersionNumber = BS.take 4 $ BC.pack $ foldMap show $
173-- 172--
174-- * 6 bytes : first 6 characters from picoseconds obtained with %q. 173-- * 6 bytes : first 6 characters from picoseconds obtained with %q.
175-- 174--
176-- * 1 bytes : character '.' for readability. 175-- * 1 byte : character \'.\' for readability.
177-- 176--
178-- * 9..* bytes: number of whole seconds since the Unix epoch 177-- * 9..* bytes: number of whole seconds since the Unix epoch
179-- (!)REVERSED. 178-- (!)REVERSED.
180-- 179--
181-- Can be used both with shadow and azureus style encoding. This 180-- Can be used both with shadow and azureus style encoding. This
182-- format is used to make the ID's readable(for debugging) and more 181-- format is used to make the ID's readable for debugging purposes.
183-- or less random.
184-- 182--
185timestamp :: IO ByteString 183timestamp :: IO ByteString
186timestamp = (BC.pack . format) <$> getCurrentTime 184timestamp = (BC.pack . format) <$> getCurrentTime
@@ -189,19 +187,20 @@ timestamp = (BC.pack . format) <$> getCurrentTime
189 L.take 9 (L.reverse (formatTime defaultTimeLocale "%s" t)) 187 L.take 9 (L.reverse (formatTime defaultTimeLocale "%s" t))
190 188
191-- | Gives 15 character long random bytestring. This is more robust 189-- | Gives 15 character long random bytestring. This is more robust
192-- method for generation of random part of peer ID than timestamp. 190-- method for generation of random part of peer ID than 'timestamp'.
193entropy :: IO ByteString 191entropy :: IO ByteString
194entropy = getEntropy 15 192entropy = getEntropy 15
195 193
196-- NOTE: entropy generates incorrrect peer id 194-- NOTE: entropy generates incorrrect peer id
197 195
198-- | Here we use Azureus-style encoding with the following args: 196-- | Here we use 'azureusStyle' encoding with the following args:
199-- 197--
200-- * 'HS' for the client id. 198-- * 'HS' for the client id; ('defaultClientId')
201-- 199--
202-- * Version of the package for the version number 200-- * Version of the package for the version number;
201-- ('defaultVersionNumber')
203-- 202--
204-- * UTC time day ++ day time for the random number. 203-- * UTC time day ++ day time for the random number. ('timestamp')
205-- 204--
206genPeerId :: IO PeerId 205genPeerId :: IO PeerId
207genPeerId = azureusStyle defaultClientId defaultVersionNumber <$> timestamp 206genPeerId = azureusStyle defaultClientId defaultVersionNumber <$> timestamp