import System.Exit import Control.Concurrent.STM import Crypto.Tox import Network.Tox import Network.Tox.DHT.Handlers import Network.Tox.Crypto.Handlers import Network.Tox.DHT.Transport (Cookie(..)) import Data.Serialize as S import Network.Tox.Crypto.Transport import Data.Word -- -- Some relevant functions: -- -- src/Network/Tox.hs -- newCrypto :: IO TransportCrypto -- -- src/Network/Tox/DHT/Handlers.hs -- createCookie :: TransportCrypto -> NodeInfo -> PublicKey -> IO Cookie -- -- src/Crypto/Tox.hs -- decryptSymmetric :: SymmetricKey -> Nonce24 -> Encrypted a -> Either String (Plain s a) -- --src/Network/Tox/NodeId.hs --nodeInfo :: NodeId -> SockAddr -> Either String NodeInfo -- main = do crypto <- newCrypto secUser <- generateSecretKey let pubUser = toPublic secUser node = read "Ivr3mkGriCmv5FeF91UPZbkirDfpIagXcfvo6ozUCRp@92.99.99.99:33412" ecookie@(Cookie cookieNonce eCookieData) <- createCookie crypto node pubUser let bs = encode ecookie print $ (decode bs :: Either String Cookie) sym <- atomically $ transportSymmetric crypto print $ decryptSymmetric sym cookieNonce eCookieData >>= decodePlain n24 <- atomically $ transportNewNonce crypto putStrLn $ "n24 = " ++ show n24 let e24 = S.encode n24 case (S.decode e24) of Left e -> do putStrLn $ "serialize Failure:" ++ show e exitFailure Right n24' -> do putStrLn $ "n24' = " ++ show n24' if n24' == n24 then doContinue else exitFailure doContinue = do let allmsgids = [Padding .. Messenger255] allgrpmsgids = [Ping .. MessageName0xff] allmsgs = map Msg allmsgids ++ concatMap (\x -> [GrpMsg KnownLossless x,GrpMsg KnownLossy x]) allgrpmsgids typmap :: [(MessageType,Word64)] typmap = map (\x -> (x, toWord64 x)) allmsgs mapM_ print typmap