summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/PeerWire/Handshake.hs
diff options
context:
space:
mode:
authorSam T <sta.cs.vsu@gmail.com>2013-04-25 00:03:16 +0400
committerSam T <sta.cs.vsu@gmail.com>2013-04-25 00:03:16 +0400
commit8a8e67099fd1e0182b096778682b2e8c4af8085f (patch)
treef02acf055e98679e4f50882fab465fb87eeef6c0 /src/Network/BitTorrent/PeerWire/Handshake.hs
parent82bea85b66304a550df074e700078c0c0c5d602a (diff)
~ Add handshake info hash check.
Diffstat (limited to 'src/Network/BitTorrent/PeerWire/Handshake.hs')
-rw-r--r--src/Network/BitTorrent/PeerWire/Handshake.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/Network/BitTorrent/PeerWire/Handshake.hs b/src/Network/BitTorrent/PeerWire/Handshake.hs
index a80728aa..a05ecc33 100644
--- a/src/Network/BitTorrent/PeerWire/Handshake.hs
+++ b/src/Network/BitTorrent/PeerWire/Handshake.hs
@@ -91,11 +91,14 @@ defaultHandshake :: InfoHash -> PeerID -> Handshake
91defaultHandshake = Handshake defaultBTProtocol defaultReserved 91defaultHandshake = Handshake defaultBTProtocol defaultReserved
92 92
93 93
94-- TODO check if hash the same
95-- | Handshaking with a peer specified by the second argument. 94-- | Handshaking with a peer specified by the second argument.
96-- 95--
97handshake :: Socket -> Handshake -> IO (Either String Handshake) 96handshake :: Socket -> Handshake -> IO (Either String Handshake)
98handshake sock hs = do 97handshake sock hs = do
99 sendAll sock (S.encode hs) 98 sendAll sock (S.encode hs)
100 r <- recv sock handshakeMaxSize 99 r <- recv sock handshakeMaxSize
101 return (S.decode r) 100 return (checkIH (S.decode r))
101 where
102 checkIH (Right hs')
103 | hsInfoHash hs /= hsInfoHash hs' = Left "Handshake info hash do not match."
104 checkIH x = x