summaryrefslogtreecommitdiff
path: root/src/Network/Torrent/PeerWire
diff options
context:
space:
mode:
authorSam T <sta.cs.vsu@gmail.com>2013-04-08 02:59:45 +0400
committerSam T <sta.cs.vsu@gmail.com>2013-04-08 02:59:45 +0400
commitd6c53fd0af4c395459f89a4e3fa9c5988c27ec32 (patch)
treeb291b42f9248d3e96cced7185eabf2e1be6dcd1a /src/Network/Torrent/PeerWire
parent4296031c4c1b004ec2271c0028ab603c3f6c4e8a (diff)
+ mk newtype for info hash
Diffstat (limited to 'src/Network/Torrent/PeerWire')
-rw-r--r--src/Network/Torrent/PeerWire/Handshake.hs12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/Network/Torrent/PeerWire/Handshake.hs b/src/Network/Torrent/PeerWire/Handshake.hs
index 7bdb7fef..ab255c14 100644
--- a/src/Network/Torrent/PeerWire/Handshake.hs
+++ b/src/Network/Torrent/PeerWire/Handshake.hs
@@ -9,7 +9,7 @@ import Data.Word
9import Data.ByteString (ByteString) 9import Data.ByteString (ByteString)
10import qualified Data.ByteString as B 10import qualified Data.ByteString as B
11import Data.Serialize 11import Data.Serialize
12 12import Data.Torrent.InfoHash
13import Network.Torrent.PeerID 13import Network.Torrent.PeerID
14 14
15-- | In order to establish the connection between peers we should send 'Handshake' 15-- | In order to establish the connection between peers we should send 'Handshake'
@@ -18,7 +18,7 @@ import Network.Torrent.PeerID
18data Handshake = Handshake { 18data Handshake = Handshake {
19 hsProtocol :: ByteString -- ^ Identifier of the protocol. 19 hsProtocol :: ByteString -- ^ Identifier of the protocol.
20 , hsReserved :: Word64 -- ^ Reserved bytes, rarely used. 20 , hsReserved :: Word64 -- ^ Reserved bytes, rarely used.
21 , hsInfoHash :: ByteString -- ^ Hash from the metainfo file. 21 , hsInfoHash :: InfoHash -- ^ Hash from the metainfo file.
22 -- This /should be/ same hash that is transmitted in tracker requests. 22 -- This /should be/ same hash that is transmitted in tracker requests.
23 , hsPeerID :: PeerID -- ^ Peer id of the initiator. 23 , hsPeerID :: PeerID -- ^ Peer id of the initiator.
24 -- This is /usually the same peer id that is transmitted in tracker requests. 24 -- This is /usually the same peer id that is transmitted in tracker requests.
@@ -29,14 +29,14 @@ instance Serialize Handshake where
29 putWord8 (fromIntegral (B.length (hsProtocol hs))) 29 putWord8 (fromIntegral (B.length (hsProtocol hs)))
30 putByteString (hsProtocol hs) 30 putByteString (hsProtocol hs)
31 putWord64be (hsReserved hs) 31 putWord64be (hsReserved hs)
32 putByteString (hsInfoHash hs) 32 put (hsInfoHash hs)
33 put (hsPeerID hs) 33 put (hsPeerID hs)
34 34
35 get = do 35 get = do
36 len <- getWord8 36 len <- getWord8
37 Handshake <$> getBytes (fromIntegral len) 37 Handshake <$> getBytes (fromIntegral len)
38 <*> getWord64be 38 <*> getWord64be
39 <*> getBytes 20 39 <*> get
40 <*> get 40 <*> get
41 41
42-- | Default protocol string "BitTorrent protocol" as is. 42-- | Default protocol string "BitTorrent protocol" as is.
@@ -48,7 +48,5 @@ defaultReserved :: Word64
48defaultReserved = 0 48defaultReserved = 0
49 49
50-- | Length of info hash and peer id is unchecked, so it /should/ be equal 20. 50-- | Length of info hash and peer id is unchecked, so it /should/ be equal 20.
51defaultHandshake :: ByteString -- ^ Info hash string. 51defaultHandshake :: InfoHash -> PeerID -> Handshake
52 -> PeerID
53 -> Handshake
54defaultHandshake hash pid = Handshake defaultProtocol defaultReserved hash pid \ No newline at end of file 52defaultHandshake hash pid = Handshake defaultProtocol defaultReserved hash pid \ No newline at end of file