From 2171aef0c2ffbae3ff407c4f91a33a1b0414c76a Mon Sep 17 00:00:00 2001 From: James Crayne Date: Thu, 24 May 2018 22:53:13 +0000 Subject: PerSession, queue of handled/unhandled cryptomessages --- examples/dhtd.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/dhtd.hs b/examples/dhtd.hs index f25792ac..2f903d5f 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs @@ -1215,6 +1215,11 @@ announceToxJabberPeer echan laddr saddr pingflag tsrc tsnk #endif +data PerSession = PerSession { perSessionMsgs :: PacketQueue (Bool{-Handled?-},Tox.CryptoMessage) + , perSessionPublicKey :: PublicKey + , perSessionAddr :: SockAddr + } + main :: IO () main = runResourceT $ liftBaseWith $ \resT -> do args <- getArgs @@ -1322,6 +1327,7 @@ main = runResourceT $ liftBaseWith $ \resT -> do crypto <- Tox.newCrypto netCryptoSessionsState <- Tox.newSessionsState crypto Tox.defaultUnRecHook Tox.defaultCryptoDataHooks + sessions <- atomically (newTVar []) :: IO (TVar [PerSession]) (mbtox,quitTox,toxdhts,toxips,taddrs) <- case porttox opts of "" -> return (Nothing,return (), Map.empty, return [],[]) toxport -> do @@ -1544,12 +1550,12 @@ main = runResourceT $ liftBaseWith $ \resT -> do announceToxJabberPeer (xmppEventChannel sv) addrTox (Tox.ncSockAddr netcrypto) pingflag xmppSrc xmppSink -- TODO: Update toxContactInfo, connected. #endif - let handleIncoming typ session cd | any ($ typ) [Tox.isKillPacket, Tox.isOFFLINE] = atomically $ do + let handleIncoming typ session cm | any ($ typ) [Tox.isKillPacket, Tox.isOFFLINE] = atomically $ do closeTMChan tmchan Tox.forgetCrypto crypto netCryptoSessionsState netcrypto return Nothing - handleIncoming mTyp session cd = do - atomically $ writeTMChan tmchan (Tox.bufferData cd) + handleIncoming mTyp session cm = do + atomically $ writeTMChan tmchan cm -- (Tox.bufferData cd) return Nothing atomically $ writeTVar (Tox.ncUnrecognizedHook netcrypto) handleIncoming return Nothing -- cgit v1.2.3