diff options
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 14 |
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 |
620 | addSessionToMapIfNotThere :: NetCryptoSessions -> SockAddr -> NetCryptoSession -> IO () | 620 | addSessionToMapIfNotThere :: NetCryptoSessions -> SockAddr -> NetCryptoSession -> IO () |
621 | addSessionToMapIfNotThere sessions addr netCryptoSession = do | 621 | addSessionToMapIfNotThere 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 | ||
632 | runUponHandshake :: NetCryptoSession -> SockAddr -> NetCryptoOutQueue -> IO () | 644 | runUponHandshake :: NetCryptoSession -> SockAddr -> NetCryptoOutQueue -> IO () |
633 | runUponHandshake netCryptoSession0 addr pktoq = do | 645 | runUponHandshake netCryptoSession0 addr pktoq = do |