summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Crypto/Handlers.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox/Crypto/Handlers.hs')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs9
1 files changed, 9 insertions, 0 deletions
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
360addNewSessionHook :: NetCryptoSessions -> NewSessionHook -> STM () 360addNewSessionHook :: NetCryptoSessions -> NewSessionHook -> STM ()
361addNewSessionHook allsessions@(NCSessions { announceNewSessionHooks }) hook = modifyTVar announceNewSessionHooks (hook:) 361addNewSessionHook allsessions@(NCSessions { announceNewSessionHooks }) hook = modifyTVar announceNewSessionHooks (hook:)
362 362
363addDestroySessionHook :: NetCryptoSession -> (Maybe Int) -> (NetCryptoSession -> IO ()) -> STM Int
364addDestroySessionHook netcrypto mbkey hook = do
365 modifyTVar (ncDestoryHooks netcrypto) $ \hooklist ->
366 case mbkey of
367 Just key -> ((key,hook):filter ((/=key) . fst) hooklist)
368 Nothing -> let maxkey = maximum (map fst hooklist)
369 in if null hooklist then [(0,hook)] else (maxkey+1,hook):hooklist
370 fst . head <$> readTVar (ncDestoryHooks netcrypto)
371
363forgetCrypto :: TransportCrypto -> NetCryptoSessions -> NetCryptoSession -> STM () 372forgetCrypto :: TransportCrypto -> NetCryptoSessions -> NetCryptoSession -> STM ()
364forgetCrypto crypto (NCSessions {netCryptoSessions,netCryptoSessionsByKey}) session = do 373forgetCrypto crypto (NCSessions {netCryptoSessions,netCryptoSessionsByKey}) session = do
365 let HaveDHTKey addr = ncSockAddr session 374 let HaveDHTKey addr = ncSockAddr session