diff options
Diffstat (limited to 'src/Network/Tox/Crypto/Handlers.hs')
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 9 |
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 | |||
360 | addNewSessionHook :: NetCryptoSessions -> NewSessionHook -> STM () | 360 | addNewSessionHook :: NetCryptoSessions -> NewSessionHook -> STM () |
361 | addNewSessionHook allsessions@(NCSessions { announceNewSessionHooks }) hook = modifyTVar announceNewSessionHooks (hook:) | 361 | addNewSessionHook allsessions@(NCSessions { announceNewSessionHooks }) hook = modifyTVar announceNewSessionHooks (hook:) |
362 | 362 | ||
363 | addDestroySessionHook :: NetCryptoSession -> (Maybe Int) -> (NetCryptoSession -> IO ()) -> STM Int | ||
364 | addDestroySessionHook 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 | |||
363 | forgetCrypto :: TransportCrypto -> NetCryptoSessions -> NetCryptoSession -> STM () | 372 | forgetCrypto :: TransportCrypto -> NetCryptoSessions -> NetCryptoSession -> STM () |
364 | forgetCrypto crypto (NCSessions {netCryptoSessions,netCryptoSessionsByKey}) session = do | 373 | forgetCrypto crypto (NCSessions {netCryptoSessions,netCryptoSessionsByKey}) session = do |
365 | let HaveDHTKey addr = ncSockAddr session | 374 | let HaveDHTKey addr = ncSockAddr session |