From f4ef80c5f921ee7f659c3bd4b6c8162ae0b4ccb8 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Thu, 31 May 2018 17:00:59 +0000 Subject: yet more debug prints --- src/Network/Tox/Crypto/Handlers.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') 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 pktoq <- PQ.newOutGoing pktq ncToWire toWireIO 0 (outboundQueueCapacity sessions) 0 return (HaveHandshake pktoq) --- | add this session to the lookup maps, unless its already in them +-- | add this session to the lookup maps, overwrite if its already in them addSessionToMapIfNotThere :: NetCryptoSessions -> SockAddr -> NetCryptoSession -> STM () addSessionToMapIfNotThere sessions addr netCryptoSession = do let dmsg msg = trace msg (return ()) @@ -620,11 +620,17 @@ addSessionToMapIfNotThere sessions addr netCryptoSession = do allsessions = netCryptoSessions sessions allsessionsByKey= netCryptoSessionsByKey sessions byAddrResult <- readTVar allsessions >>= return . Map.lookup addr + mp <- readTVar allsessions case byAddrResult of Just (NCrypto { ncSessionId = staleId }) -> do + dmsg $ "addSessionToMapIfNotThere: addr(" ++ show addr ++") already in map(" ++ show (map (second ncSessionId) (Map.assocs mp)) ++ ")" + dmsg $ "addSessionToMapIfNotThere: considering it stale(staleId=" ++ show staleId ++") and removing it from the by-key map, so remove it from by-key map." + dmsg $ "addSessionToMapIfNotThere: leave it in the by-addr map, and overwrite it shortly." -- manually remove the stale session from the by-key map modifyTVar allsessionsByKey (Map.map (filter ((/=staleId) . ncSessionId))) - Nothing -> return () -- nothing to remove + Nothing -> -- nothing to remove + dmsg $ "addSessionToMapIfNotThere: addr(" ++ show addr ++") not yet in map(" ++ show (map (second ncSessionId) (Map.assocs mp)) ++ ")" + dmsg $ "addSessionToMapIfNotThere: Inserting addr(" ++ show addr ++") into map(" ++ show (map (second ncSessionId) (Map.assocs mp)) ++ ")" -- write session to by-addr map regardless of whether one is in there, -- it should overwrite on match modifyTVar allsessions (Map.insert addr netCryptoSession) @@ -815,7 +821,7 @@ handshakeH sessions addr hshake@(Handshake (Cookie n24 ecookie) nonce24 encrypte sessionsmap <- readTVar allsessions case Map.lookup addr sessionsmap of Nothing -> do - dmsg "sockaddr not in session map, so freshCryptoSession" + dmsg $ "sockaddr(" ++ show addr ++ ") not in session map(" ++ show (map (second ncSessionId) (Map.assocs sessionsmap)) ++ "), so freshCryptoSession" freshCryptoSession sessions addr newsession timestamp hp -- create new session Just session -> do dmsg "sockaddr ALREADY in session map, so updateCryptoSession" -- cgit v1.2.3