summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2018-05-24 22:53:13 +0000
committerJames Crayne <jim.crayne@gmail.com>2018-05-24 22:53:13 +0000
commit2171aef0c2ffbae3ff407c4f91a33a1b0414c76a (patch)
treeb14f959710a9ef8b1411c73f9aafb0365ba3726f /examples
parentde92c277aafcb8c85ff5f0824ad062ca560eefdd (diff)
PerSession, queue of handled/unhandled cryptomessages
Diffstat (limited to 'examples')
-rw-r--r--examples/dhtd.hs12
1 files changed, 9 insertions, 3 deletions
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
1215 1215
1216#endif 1216#endif
1217 1217
1218data PerSession = PerSession { perSessionMsgs :: PacketQueue (Bool{-Handled?-},Tox.CryptoMessage)
1219 , perSessionPublicKey :: PublicKey
1220 , perSessionAddr :: SockAddr
1221 }
1222
1218main :: IO () 1223main :: IO ()
1219main = runResourceT $ liftBaseWith $ \resT -> do 1224main = runResourceT $ liftBaseWith $ \resT -> do
1220 args <- getArgs 1225 args <- getArgs
@@ -1322,6 +1327,7 @@ main = runResourceT $ liftBaseWith $ \resT -> do
1322 1327
1323 crypto <- Tox.newCrypto 1328 crypto <- Tox.newCrypto
1324 netCryptoSessionsState <- Tox.newSessionsState crypto Tox.defaultUnRecHook Tox.defaultCryptoDataHooks 1329 netCryptoSessionsState <- Tox.newSessionsState crypto Tox.defaultUnRecHook Tox.defaultCryptoDataHooks
1330 sessions <- atomically (newTVar []) :: IO (TVar [PerSession])
1325 (mbtox,quitTox,toxdhts,toxips,taddrs) <- case porttox opts of 1331 (mbtox,quitTox,toxdhts,toxips,taddrs) <- case porttox opts of
1326 "" -> return (Nothing,return (), Map.empty, return [],[]) 1332 "" -> return (Nothing,return (), Map.empty, return [],[])
1327 toxport -> do 1333 toxport -> do
@@ -1544,12 +1550,12 @@ main = runResourceT $ liftBaseWith $ \resT -> do
1544 announceToxJabberPeer (xmppEventChannel sv) addrTox (Tox.ncSockAddr netcrypto) pingflag xmppSrc xmppSink 1550 announceToxJabberPeer (xmppEventChannel sv) addrTox (Tox.ncSockAddr netcrypto) pingflag xmppSrc xmppSink
1545 -- TODO: Update toxContactInfo, connected. 1551 -- TODO: Update toxContactInfo, connected.
1546#endif 1552#endif
1547 let handleIncoming typ session cd | any ($ typ) [Tox.isKillPacket, Tox.isOFFLINE] = atomically $ do 1553 let handleIncoming typ session cm | any ($ typ) [Tox.isKillPacket, Tox.isOFFLINE] = atomically $ do
1548 closeTMChan tmchan 1554 closeTMChan tmchan
1549 Tox.forgetCrypto crypto netCryptoSessionsState netcrypto 1555 Tox.forgetCrypto crypto netCryptoSessionsState netcrypto
1550 return Nothing 1556 return Nothing
1551 handleIncoming mTyp session cd = do 1557 handleIncoming mTyp session cm = do
1552 atomically $ writeTMChan tmchan (Tox.bufferData cd) 1558 atomically $ writeTMChan tmchan cm -- (Tox.bufferData cd)
1553 return Nothing 1559 return Nothing
1554 atomically $ writeTVar (Tox.ncUnrecognizedHook netcrypto) handleIncoming 1560 atomically $ writeTVar (Tox.ncUnrecognizedHook netcrypto) handleIncoming
1555 return Nothing 1561 return Nothing