From 6b264121bee3b5c08af388f20c5273ef8956bc5e Mon Sep 17 00:00:00 2001 From: James Crayne Date: Sat, 3 Nov 2018 03:00:58 -0400 Subject: addDestroySessionHook --- src/Network/Tox/Crypto/Handlers.hs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/Network/Tox/Crypto/Handlers.hs') diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index f0332df0..50224178 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs @@ -360,6 +360,15 @@ type NewSessionHook = IOHook (Maybe NoSpam) NetCryptoSession addNewSessionHook :: NetCryptoSessions -> NewSessionHook -> STM () addNewSessionHook allsessions@(NCSessions { announceNewSessionHooks }) hook = modifyTVar announceNewSessionHooks (hook:) +addDestroySessionHook :: NetCryptoSession -> (Maybe Int) -> (NetCryptoSession -> IO ()) -> STM Int +addDestroySessionHook netcrypto mbkey hook = do + modifyTVar (ncDestoryHooks netcrypto) $ \hooklist -> + case mbkey of + Just key -> ((key,hook):filter ((/=key) . fst) hooklist) + Nothing -> let maxkey = maximum (map fst hooklist) + in if null hooklist then [(0,hook)] else (maxkey+1,hook):hooklist + fst . head <$> readTVar (ncDestoryHooks netcrypto) + forgetCrypto :: TransportCrypto -> NetCryptoSessions -> NetCryptoSession -> STM () forgetCrypto crypto (NCSessions {netCryptoSessions,netCryptoSessionsByKey}) session = do let HaveDHTKey addr = ncSockAddr session -- cgit v1.2.3