summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Crypto/Handlers.hs
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2018-05-31 14:24:43 +0000
committerJames Crayne <jim.crayne@gmail.com>2018-05-31 14:24:43 +0000
commit9045835b429e88e8cbcca2b41c126f664b53d471 (patch)
treea8095fdf749f143685cb190018a9b167d5eb25cf /src/Network/Tox/Crypto/Handlers.hs
parent3d8aa4dd86eb805dc0ab285be679f4a52bdae3c3 (diff)
debug prints and clean up stale sessions
Diffstat (limited to 'src/Network/Tox/Crypto/Handlers.hs')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs
index b47aeac1..eabbc9b0 100644
--- a/src/Network/Tox/Crypto/Handlers.hs
+++ b/src/Network/Tox/Crypto/Handlers.hs
@@ -619,15 +619,27 @@ createNetCryptoOutQueue sessions newsession theirSessionKey pktq ncMyPacketNonce
619-- | add this session to the lookup maps, unless its already in them 619-- | add this session to the lookup maps, unless its already in them
620addSessionToMapIfNotThere :: NetCryptoSessions -> SockAddr -> NetCryptoSession -> IO () 620addSessionToMapIfNotThere :: NetCryptoSessions -> SockAddr -> NetCryptoSession -> IO ()
621addSessionToMapIfNotThere sessions addr netCryptoSession = do 621addSessionToMapIfNotThere sessions addr netCryptoSession = do
622 dput XNetCrypto $ "addSessionToMapIfNotThere sockaddr = " ++ show addr ++ ", sessionid = " ++ show (ncSessionId netCryptoSession)
622 atomically $ do 623 atomically $ do
623 let remotePublicKey = ncTheirPublicKey netCryptoSession 624 let remotePublicKey = ncTheirPublicKey netCryptoSession
624 allsessions = netCryptoSessions sessions 625 allsessions = netCryptoSessions sessions
625 allsessionsByKey= netCryptoSessionsByKey sessions 626 allsessionsByKey= netCryptoSessionsByKey sessions
627 byAddrResult <- readTVar allsessions >>= return . Map.lookup addr
628 case byAddrResult of
629 Just (NCrypto { ncSessionId = staleId }) -> do
630 -- manually remove the stale session from the by-key map
631 modifyTVar allsessionsByKey (Map.map (filter ((/=staleId) . ncSessionId)))
632 Nothing -> return () -- nothing to remove
633 -- write session to by-addr map regardless of whether one is in there,
634 -- it should overwrite on match
626 modifyTVar allsessions (Map.insert addr netCryptoSession) 635 modifyTVar allsessions (Map.insert addr netCryptoSession)
636 -- Now insert new session into by-key map
627 byKeyResult <- readTVar allsessionsByKey >>= return . Map.lookup remotePublicKey 637 byKeyResult <- readTVar allsessionsByKey >>= return . Map.lookup remotePublicKey
628 case byKeyResult of 638 case byKeyResult of
629 Nothing -> modifyTVar allsessionsByKey (Map.insert remotePublicKey [netCryptoSession]) 639 Nothing -> modifyTVar allsessionsByKey (Map.insert remotePublicKey [netCryptoSession])
630 Just xs -> modifyTVar allsessionsByKey (Map.insert remotePublicKey (netCryptoSession:xs)) 640 Just xs -> do
641 -- in case we're using the same long term key on different IPs ...
642 modifyTVar allsessionsByKey (Map.insert remotePublicKey (netCryptoSession:xs))
631 643
632runUponHandshake :: NetCryptoSession -> SockAddr -> NetCryptoOutQueue -> IO () 644runUponHandshake :: NetCryptoSession -> SockAddr -> NetCryptoOutQueue -> IO ()
633runUponHandshake netCryptoSession0 addr pktoq = do 645runUponHandshake netCryptoSession0 addr pktoq = do