From 4f707645d5a47f2f88ffcbd926a7dd5f18ec8591 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Tue, 31 Oct 2017 20:54:02 +0000 Subject: allow hooks to be passed in to newTox --- src/Network/Tox.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/Network/Tox.hs') diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index 70962844..f73de4e9 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs @@ -89,7 +89,7 @@ import Crypto.Tox import Data.Word64Map (fitsInInt) import qualified Data.Word64Map (empty) import Network.Tox.Crypto.Transport (NetCrypto) -import Network.Tox.Crypto.Handlers (newSessionsState, cryptoNetHandler, defaultCryptoDataHooks) +import Network.Tox.Crypto.Handlers (cryptoNetHandler, newSessionsState, defaultUnRecHook, defaultCryptoDataHooks, NetCryptoSessions(..)) import qualified Network.Tox.DHT.Handlers as DHT import qualified Network.Tox.DHT.Transport as DHT import Network.Tox.NodeId @@ -281,10 +281,15 @@ getOnionAlias crypto dhtself remoteNode = atomically $ do return $ Onion.OnionDestination Onion.SearchingAlias alias Nothing -newTox :: TVar Onion.AnnouncedKeys -> SockAddr -> IO Tox -newTox keydb addr = do +newTox :: TVar Onion.AnnouncedKeys -> SockAddr -> Maybe NetCryptoSessions -> IO Tox +newTox keydb addr mbSessionsState = do udp <- addVerbosity <$> udpTransport addr - crypto <- newCrypto + (crypto,sessionsState) <- case mbSessionsState of + Nothing -> do + crypto <- newCrypto + sessionsState <- newSessionsState crypto defaultUnRecHook defaultCryptoDataHooks + return (crypto,sessionsState) + Just s -> return (transportCrypto s, s) drg <- drgNew let lookupClose _ = return Nothing @@ -309,7 +314,6 @@ newTox keydb addr = do (const id) roster <- newRoster - sessionsState <- newSessionsState crypto defaultCryptoDataHooks return Tox { toxDHT = dhtclient , toxOnion = onionclient -- cgit v1.2.3