summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network')
-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