diff options
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index 722d8507..1aaee998 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs | |||
@@ -611,7 +611,7 @@ createNetCryptoOutQueue sessions newsession theirSessionKey pktq ncMyPacketNonce | |||
611 | pktoq <- PQ.newOutGoing pktq ncToWire toWireIO 0 (outboundQueueCapacity sessions) 0 | 611 | pktoq <- PQ.newOutGoing pktq ncToWire toWireIO 0 (outboundQueueCapacity sessions) 0 |
612 | return (HaveHandshake pktoq) | 612 | return (HaveHandshake pktoq) |
613 | 613 | ||
614 | -- | add this session to the lookup maps, unless its already in them | 614 | -- | add this session to the lookup maps, overwrite if its already in them |
615 | addSessionToMapIfNotThere :: NetCryptoSessions -> SockAddr -> NetCryptoSession -> STM () | 615 | addSessionToMapIfNotThere :: NetCryptoSessions -> SockAddr -> NetCryptoSession -> STM () |
616 | addSessionToMapIfNotThere sessions addr netCryptoSession = do | 616 | addSessionToMapIfNotThere sessions addr netCryptoSession = do |
617 | let dmsg msg = trace msg (return ()) | 617 | let dmsg msg = trace msg (return ()) |
@@ -620,11 +620,17 @@ addSessionToMapIfNotThere sessions addr netCryptoSession = do | |||
620 | allsessions = netCryptoSessions sessions | 620 | allsessions = netCryptoSessions sessions |
621 | allsessionsByKey= netCryptoSessionsByKey sessions | 621 | allsessionsByKey= netCryptoSessionsByKey sessions |
622 | byAddrResult <- readTVar allsessions >>= return . Map.lookup addr | 622 | byAddrResult <- readTVar allsessions >>= return . Map.lookup addr |
623 | mp <- readTVar allsessions | ||
623 | case byAddrResult of | 624 | case byAddrResult of |
624 | Just (NCrypto { ncSessionId = staleId }) -> do | 625 | Just (NCrypto { ncSessionId = staleId }) -> do |
626 | dmsg $ "addSessionToMapIfNotThere: addr(" ++ show addr ++") already in map(" ++ show (map (second ncSessionId) (Map.assocs mp)) ++ ")" | ||
627 | dmsg $ "addSessionToMapIfNotThere: considering it stale(staleId=" ++ show staleId ++") and removing it from the by-key map, so remove it from by-key map." | ||
628 | dmsg $ "addSessionToMapIfNotThere: leave it in the by-addr map, and overwrite it shortly." | ||
625 | -- manually remove the stale session from the by-key map | 629 | -- manually remove the stale session from the by-key map |
626 | modifyTVar allsessionsByKey (Map.map (filter ((/=staleId) . ncSessionId))) | 630 | modifyTVar allsessionsByKey (Map.map (filter ((/=staleId) . ncSessionId))) |
627 | Nothing -> return () -- nothing to remove | 631 | Nothing -> -- nothing to remove |
632 | dmsg $ "addSessionToMapIfNotThere: addr(" ++ show addr ++") not yet in map(" ++ show (map (second ncSessionId) (Map.assocs mp)) ++ ")" | ||
633 | dmsg $ "addSessionToMapIfNotThere: Inserting addr(" ++ show addr ++") into map(" ++ show (map (second ncSessionId) (Map.assocs mp)) ++ ")" | ||
628 | -- write session to by-addr map regardless of whether one is in there, | 634 | -- write session to by-addr map regardless of whether one is in there, |
629 | -- it should overwrite on match | 635 | -- it should overwrite on match |
630 | modifyTVar allsessions (Map.insert addr netCryptoSession) | 636 | modifyTVar allsessions (Map.insert addr netCryptoSession) |
@@ -815,7 +821,7 @@ handshakeH sessions addr hshake@(Handshake (Cookie n24 ecookie) nonce24 encrypte | |||
815 | sessionsmap <- readTVar allsessions | 821 | sessionsmap <- readTVar allsessions |
816 | case Map.lookup addr sessionsmap of | 822 | case Map.lookup addr sessionsmap of |
817 | Nothing -> do | 823 | Nothing -> do |
818 | dmsg "sockaddr not in session map, so freshCryptoSession" | 824 | dmsg $ "sockaddr(" ++ show addr ++ ") not in session map(" ++ show (map (second ncSessionId) (Map.assocs sessionsmap)) ++ "), so freshCryptoSession" |
819 | freshCryptoSession sessions addr newsession timestamp hp -- create new session | 825 | freshCryptoSession sessions addr newsession timestamp hp -- create new session |
820 | Just session -> do | 826 | Just session -> do |
821 | dmsg "sockaddr ALREADY in session map, so updateCryptoSession" | 827 | dmsg "sockaddr ALREADY in session map, so updateCryptoSession" |