From 8a8e67099fd1e0182b096778682b2e8c4af8085f Mon Sep 17 00:00:00 2001 From: Sam T Date: Thu, 25 Apr 2013 00:03:16 +0400 Subject: ~ Add handshake info hash check. --- src/Network/BitTorrent/PeerWire/Handshake.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/Network/BitTorrent/PeerWire/Handshake.hs') 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 defaultHandshake = Handshake defaultBTProtocol defaultReserved --- TODO check if hash the same -- | Handshaking with a peer specified by the second argument. -- handshake :: Socket -> Handshake -> IO (Either String Handshake) handshake sock hs = do - sendAll sock (S.encode hs) - r <- recv sock handshakeMaxSize - return (S.decode r) + sendAll sock (S.encode hs) + r <- recv sock handshakeMaxSize + return (checkIH (S.decode r)) + where + checkIH (Right hs') + | hsInfoHash hs /= hsInfoHash hs' = Left "Handshake info hash do not match." + checkIH x = x -- cgit v1.2.3