summaryrefslogtreecommitdiff
path: root/dht/src/Network/Tox/TCP.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2020-01-28 17:23:02 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-28 17:26:25 -0500
commit1e16567904a147b842070c1d98c83dc3e9c00c98 (patch)
treed3435b1b6ed89de751770b70da38a0e93a13950f /dht/src/Network/Tox/TCP.hs
parentd1eef43fde09b670dfedad9742a70224fcdc941f (diff)
Kill tcp session on exception.HEADmaster
Diffstat (limited to 'dht/src/Network/Tox/TCP.hs')
-rw-r--r--dht/src/Network/Tox/TCP.hs16
1 files changed, 6 insertions, 10 deletions
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
146 dput XTCP $ "TCP exception: " ++ show e 146 dput XTCP $ "TCP exception: " ++ show e
147 return Nothing 147 return Nothing
148 , streamEncode = \y -> do 148 , streamEncode = \y -> do
149 -- dput XTCP $ "TCP(acquire nonce):" ++ show addr ++ " <-- " ++ show y 149 -- We need this to throw so the tcp session state can be cleaned up elsewhere.
150 n24 <- takeMVar nsend 150 bracket (takeMVar nsend) (putMVar nsend . incrementNonce24)
151 -- dput XTCP $ "TCP(got nonce):" ++ show addr ++ " <-- " ++ show y 151 $ \n24 -> do
152 let bs = encode $ encrypt (noncef' n24) $ encodePlain y 152 let bs = encode $ encrypt (noncef' n24) $ encodePlain y
153 ($ h) -- bracket (takeMVar hvar) (putMVar hvar) 153 hPut h (encode (fromIntegral $ Data.ByteString.length bs :: Word16) <> bs)
154 $ \h -> hPut h (encode (fromIntegral $ Data.ByteString.length bs :: Word16) <> bs) 154 dput XTCP $ "TCP: " ++ show addr ++ " <-- " ++ show y
155 `catchIOError` \e -> dput XTCP $ "TCP write exception: " ++ show e
156 -- dput XTCP $ "TCP(incrementing nonce): " ++ show addr ++ " <-- " ++ show y
157 putMVar nsend (incrementNonce24 n24)
158 dput XTCP $ "TCP: " ++ show addr ++ " <-- " ++ show y
159 } 155 }
160 , streamAddr = nodeAddr 156 , streamAddr = nodeAddr
161 } 157 }