summaryrefslogtreecommitdiff
path: root/src/Network/Tox
diff options
context:
space:
mode:
authorjim@bo <jim@bo>2018-06-24 18:50:44 -0400
committerjim@bo <jim@bo>2018-06-24 18:50:44 -0400
commit47637306b8c19b0b7363f9a2642c7190470a2c93 (patch)
tree070565ea9211ef7f782b736458ba1acc129493ea /src/Network/Tox
parenta5fad52f1e1ca6d8ebfcbb448f19014225368777 (diff)
call setTerminated from destroySession
Diffstat (limited to 'src/Network/Tox')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs
index 2e00d61b..85e6192a 100644
--- a/src/Network/Tox/Crypto/Handlers.hs
+++ b/src/Network/Tox/Crypto/Handlers.hs
@@ -326,6 +326,7 @@ data NetCryptoSession = NCrypto
326 TVar 326 TVar
327 , ncUnrecognizedHook :: TVar (MessageType -> NetCryptoHook) 327 , ncUnrecognizedHook :: TVar (MessageType -> NetCryptoHook)
328 , ncIdleEventHooks :: TVar [(Int,NetCryptoSession -> IO ())] 328 , ncIdleEventHooks :: TVar [(Int,NetCryptoSession -> IO ())]
329 , ncDestoryHooks :: TVar [(Int,NetCryptoSession -> IO ())]
329 , ncIncomingTypeArray :: TVar MsgTypeArray 330 , ncIncomingTypeArray :: TVar MsgTypeArray
330 -- ^ This array maps 255 Id bytes to MessageType 331 -- ^ This array maps 255 Id bytes to MessageType
331 -- It should contain all messages this session understands. 332 -- It should contain all messages this session understands.
@@ -412,6 +413,7 @@ data NetCryptoSessions = NCSessions
412 , defaultHooks :: Map.Map MessageType [NetCryptoHook] 413 , defaultHooks :: Map.Map MessageType [NetCryptoHook]
413 , defaultUnrecognizedHook :: MessageType -> NetCryptoHook 414 , defaultUnrecognizedHook :: MessageType -> NetCryptoHook
414 , defaultIdleEventHooks :: [(Int,NetCryptoSession -> IO ())] 415 , defaultIdleEventHooks :: [(Int,NetCryptoSession -> IO ())]
416 , defaultDestroyHook :: [(Int,NetCryptoSession -> IO ())]
415 , sessionView :: SessionView 417 , sessionView :: SessionView
416 , msgTypeArray :: MsgTypeArray 418 , msgTypeArray :: MsgTypeArray
417 , inboundQueueCapacity :: Word32 419 , inboundQueueCapacity :: Word32
@@ -445,10 +447,11 @@ forgetCrypto crypto (NCSessions {netCryptoSessions,netCryptoSessionsByKey}) sess
445 ys -> Just ys) sPubKey) 447 ys -> Just ys) sPubKey)
446 448
447newSessionsState :: TransportCrypto 449newSessionsState :: TransportCrypto
450 -> (NetCryptoSession -> IO ()) -- ^ default destroy hook
448 -> (MessageType -> NetCryptoHook) -- ^ default hook 451 -> (MessageType -> NetCryptoHook) -- ^ default hook
449 -> Map.Map MessageType [NetCryptoHook] -- ^ all hooks, can be empty to start 452 -> Map.Map MessageType [NetCryptoHook] -- ^ all hooks, can be empty to start
450 -> IO NetCryptoSessions 453 -> IO NetCryptoSessions
451newSessionsState crypto unrechook hooks = do 454newSessionsState crypto destroyHook unrechook hooks = do
452 x <- atomically $ newTVar Map.empty 455 x <- atomically $ newTVar Map.empty
453 x2 <- atomically $ newTVar Map.empty 456 x2 <- atomically $ newTVar Map.empty
454 nick <- atomically $ newTVar B.empty 457 nick <- atomically $ newTVar B.empty
@@ -479,6 +482,7 @@ newSessionsState crypto unrechook hooks = do
479 , defaultHooks = hooks 482 , defaultHooks = hooks
480 , defaultUnrecognizedHook = unrechook 483 , defaultUnrecognizedHook = unrechook
481 , defaultIdleEventHooks = [(0,handleRequestsOutOfOrder)] 484 , defaultIdleEventHooks = [(0,handleRequestsOutOfOrder)]
485 , defaultDestroyHook = [(0,destroyHook)]
482 , sessionView = SessionView 486 , sessionView = SessionView
483 { svNick = nick 487 { svNick = nick
484 , svStatus = status 488 , svStatus = status
@@ -609,6 +613,7 @@ freshCryptoSession sessions
609 ncHooks0 <- newTVar (defaultHooks sessions) 613 ncHooks0 <- newTVar (defaultHooks sessions)
610 ncUnrecognizedHook0 <- newTVar (defaultUnrecognizedHook sessions) 614 ncUnrecognizedHook0 <- newTVar (defaultUnrecognizedHook sessions)
611 ncIdleEventHooks0 <- newTVar (defaultIdleEventHooks sessions) 615 ncIdleEventHooks0 <- newTVar (defaultIdleEventHooks sessions)
616 ncDestoryHooks0 <- newTVar (defaultDestroyHook sessions)
612 ncIncomingTypeArray0 <- newTVar (msgTypeArray sessions) 617 ncIncomingTypeArray0 <- newTVar (msgTypeArray sessions)
613 let idMap = foldl (\mp (x,y) -> W64.insert x y mp) W64.empty (zip [0..255] [0..255]) 618 let idMap = foldl (\mp (x,y) -> W64.insert x y mp) W64.empty (zip [0..255] [0..255])
614 (ncOutgoingIdMap0,lossyEscapeIdMap,losslessEscapeIdMap,ncOutHooks0) <- do 619 (ncOutgoingIdMap0,lossyEscapeIdMap,losslessEscapeIdMap,ncOutHooks0) <- do
@@ -684,6 +689,7 @@ freshCryptoSession sessions
684 , ncOutHooks = ncOutHooks0 689 , ncOutHooks = ncOutHooks0
685 , ncUnrecognizedHook = ncUnrecognizedHook0 690 , ncUnrecognizedHook = ncUnrecognizedHook0
686 , ncIdleEventHooks = ncIdleEventHooks0 691 , ncIdleEventHooks = ncIdleEventHooks0
692 , ncDestoryHooks = ncDestoryHooks0
687 , ncAllSessions = sessions 693 , ncAllSessions = sessions
688 , ncIncomingTypeArray = ncIncomingTypeArray0 694 , ncIncomingTypeArray = ncIncomingTypeArray0
689 , ncOutgoingIdMap = ncOutgoingIdMap0 695 , ncOutgoingIdMap = ncOutgoingIdMap0
@@ -892,6 +898,10 @@ runUponHandshake netCryptoSession0 addr pktoq = do
892 898
893destroySession :: NetCryptoSession -> IO () 899destroySession :: NetCryptoSession -> IO ()
894destroySession session = do 900destroySession session = do
901 -- first run all destory hooks
902 hooks <- atomically (readTVar (ncDestoryHooks session))
903 forM_ hooks $ \(key,hook) -> hook session
904 -- now clean up threads
895 let allsessions = ncAllSessions session 905 let allsessions = ncAllSessions session
896 sid = ncSessionId session 906 sid = ncSessionId session
897 stopThread :: TVar (Maybe ThreadId) -> IO () 907 stopThread :: TVar (Maybe ThreadId) -> IO ()