From 1e16567904a147b842070c1d98c83dc3e9c00c98 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Tue, 28 Jan 2020 17:23:02 -0500 Subject: Kill tcp session on exception. --- dht/src/Network/Tox/TCP.hs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'dht/src/Network/Tox') diff --git a/dht/src/Network/Tox/TCP.hs b/dht/src/Network/Tox/TCP.hs index 36289e19..e3780675 100644 --- a/dht/src/Network/Tox/TCP.hs +++ b/dht/src/Network/Tox/TCP.hs @@ -146,16 +146,12 @@ tcpStream crypto mkst = StreamHandshake dput XTCP $ "TCP exception: " ++ show e return Nothing , streamEncode = \y -> do - -- dput XTCP $ "TCP(acquire nonce):" ++ show addr ++ " <-- " ++ show y - n24 <- takeMVar nsend - -- dput XTCP $ "TCP(got nonce):" ++ show addr ++ " <-- " ++ show y - let bs = encode $ encrypt (noncef' n24) $ encodePlain y - ($ h) -- bracket (takeMVar hvar) (putMVar hvar) - $ \h -> hPut h (encode (fromIntegral $ Data.ByteString.length bs :: Word16) <> bs) - `catchIOError` \e -> dput XTCP $ "TCP write exception: " ++ show e - -- dput XTCP $ "TCP(incrementing nonce): " ++ show addr ++ " <-- " ++ show y - putMVar nsend (incrementNonce24 n24) - dput XTCP $ "TCP: " ++ show addr ++ " <-- " ++ show y + -- We need this to throw so the tcp session state can be cleaned up elsewhere. + bracket (takeMVar nsend) (putMVar nsend . incrementNonce24) + $ \n24 -> do + let bs = encode $ encrypt (noncef' n24) $ encodePlain y + hPut h (encode (fromIntegral $ Data.ByteString.length bs :: Word16) <> bs) + dput XTCP $ "TCP: " ++ show addr ++ " <-- " ++ show y } , streamAddr = nodeAddr } -- cgit v1.2.3