From b88601d78aeae15c75aa584afa51d1666595b7d8 Mon Sep 17 00:00:00 2001 From: "jim@bo" Date: Sun, 24 Jun 2018 00:27:49 -0400 Subject: fix index-bounds error & improve efficiency --- src/Network/Tox/Crypto/Handlers.hs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/Network/Tox') diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index d8ba19eb..82aa8f12 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs @@ -623,13 +623,19 @@ freshCryptoSession sessions lossyEsc <- newTVar $ U.listArray (0,255) [0 .. 255] losslessEsc <- newTVar $ U.listArray (0,255) [0 .. 255] outHooks <- emptySTMRangeMap - mapM_ ($ outHooks) -- TODO: combine into larger ranges for faster lookup - [ insertWhereItGoes (A.listArray (2,2) [sendKillHook]) - , insertWhereItGoes (A.listArray (16,16) [sendLossless{-Ping-}]) - , insertWhereItGoes (A.listArray (24,25) [sendOnlineHook,sendLossless{-Offline-}]) - , insertWhereItGoes (A.listArray (48,51) [sendNickHook,sendStatusMsgHook,sendStatusHook,sendTypingHook]) - , insertWhereItGoes (A.listArray (63,64) [sendMessageHook, sendMessageHook]) - ] + let doNothingHook crypto session msg = return (Left "unsupported") + assignHook 2 = (2,sendKillHook) + assignHook 16 = (16,sendLossless{-Ping-}) + assignHook 24 = (24,sendOnlineHook) + assignHook 25 = (25,sendLossless{-Offline-}) + assignHook 48 = (48,sendNickHook) + assignHook 49 = (49,sendStatusMsgHook) + assignHook 50 = (50,sendStatusHook) + assignHook 51 = (51,sendTypingHook) + assignHook 63 = (63,sendMessageHook) + assignHook 64 = (64,sendMessageHook{-ACTION-}) + assignHook other = (other,doNothingHook) + insertArrayAt outHooks 0 (A.array (0,64) (map assignHook [0..64])) return (idmap,lossyEsc,losslessEsc,outHooks) ncView0 <- newTVar (sessionView sessions) pktq <- PQ.new (inboundQueueCapacity sessions) 0 -- cgit v1.2.3