From 06cb3e9cfd146610892957381df1d8b50eb5eeae Mon Sep 17 00:00:00 2001 From: joe Date: Tue, 21 Nov 2017 12:34:51 -0500 Subject: Fleshed out some stubs, added comments. --- examples/dhtd.hs | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/examples/dhtd.hs b/examples/dhtd.hs index fbfca86f..8fd1402d 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs @@ -23,6 +23,7 @@ import Control.Applicative import Control.Concurrent.STM import Control.Exception import Control.Monad +import Control.Monad.IO.Class (liftIO) import Control.Monad.Trans.Control import Control.Monad.Trans.Resource (runResourceT) import Data.Bool @@ -988,11 +989,17 @@ noArgPing :: (x -> IO (Maybe r)) -> [String] -> x -> IO (Maybe r) noArgPing f [] x = f x noArgPing _ _ _ = return Nothing -newXmmpSource :: Tox.NetCryptoSession -> IO (C.Source IO Tox.CryptoMessage) -newXmmpSource = _todo +newXmmpSource :: Tox.NetCryptoSession -> C.Source IO Tox.CryptoMessage +newXmmpSource sessions = do + v <- liftIO $ _todo sessions {- receive a fucking message -} + case v of + Nothing -> return () -- Nothing indicates EOF. + Just cryptomessage -> do C.yield cryptomessage + newXmmpSource sessions -newXmmpSink :: Tox.NetCryptoSession -> IO (C.Sink (Flush Tox.CryptoMessage) IO ()) -newXmmpSink = _todo +newXmmpSink :: Tox.NetCryptoSession -> C.Sink (Flush Tox.CryptoMessage) IO () +newXmmpSink sessions = C.awaitForever $ \flush_cyptomessage -> do + liftIO $ (_todo sessions {- send the fucking message -}) flush_cyptomessage -- | TODO -- @@ -1000,9 +1007,20 @@ newXmmpSink = _todo -- XMPP roster. toxman :: Tox.Tox -> ToxManager k toxman tox = ToxManager - { activateAccount = \k pubname seckey -> return () - , deactivateAccount = \k pubname -> return () - , setToxConnectionPolicy = \me them policy -> return () + { activateAccount = \k pubname seckey -> do + -- Schedule recuring announce. + -- Schedule recuring search for all non-connected contacts. + return () + , deactivateAccount = \k pubname -> do + -- If /k/ is the last reference: + -- Stop recuring announce. + -- If this is the last reference to a non-connected contact: + -- Stop the recuring search for that contact + return () + , setToxConnectionPolicy = \me them policy -> + case policy of + TryingToConnect -> return () -- Add a contact. + _ -> return () -- Remove contact. } @@ -1325,9 +1343,9 @@ main = runResourceT $ liftBaseWith $ \resT -> do forM_ (take 1 taddrs) $ \addrTox -> do atomically $ Tox.addNewSessionHook netCryptoSessionsState $ \mbNoSpam netcrypto -> do let Just pingMachine = Tox.ncPingMachine netcrypto - pingflag = readTVar (pingFlag pingMachine) - xmppSrc <- newXmmpSource netcrypto - xmppSink <- newXmmpSink netcrypto + pingflag = readTVar (pingFlag pingMachine) + xmppSrc = newXmmpSource netcrypto + xmppSink = newXmmpSink netcrypto announceToxXMPPClients (xmppEventChannel sv) addrTox (Tox.ncSockAddr netcrypto) pingflag xmppSrc xmppSink let dhts = Map.union btdhts toxdhts -- cgit v1.2.3