summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2018-05-29 05:10:40 +0000
committerJames Crayne <jim.crayne@gmail.com>2018-05-29 05:10:40 +0000
commitf6ac09e60cb38c181b44c6bf51a3d58bdd75e7bc (patch)
treeaa9628dae1ba674492d07280a48cea2a29763c4d
parent15a8a7270fc35f0a7e77b09d82c1aaded8d44885 (diff)
testcookie program wip
-rw-r--r--dht-client.cabal5
-rw-r--r--examples/testcookie.hs40
2 files changed, 45 insertions, 0 deletions
diff --git a/dht-client.cabal b/dht-client.cabal
index 77ea1736..81521e05 100644
--- a/dht-client.cabal
+++ b/dht-client.cabal
@@ -285,3 +285,8 @@ executable dhtd
285 cpp-options: -DXMPP 285 cpp-options: -DXMPP
286 ghc-options: -rtsopts -fdefer-typed-holes -threaded 286 ghc-options: -rtsopts -fdefer-typed-holes -threaded
287 287
288executable testcookie
289 hs-source-dirs: examples
290 main-is: testcookie.hs
291 default-language: Haskell2010
292 build-depends: base, bytestring, cereal, dht-client, stm
diff --git a/examples/testcookie.hs b/examples/testcookie.hs
new file mode 100644
index 00000000..c4974125
--- /dev/null
+++ b/examples/testcookie.hs
@@ -0,0 +1,40 @@
1
2
3import System.Exit
4
5import Control.Concurrent.STM
6import Crypto.Tox
7import Network.Tox
8import Network.Tox.DHT.Handlers
9import Network.Tox.Crypto.Handlers
10
11import Data.Serialize as S
12
13--
14-- Some relevant functions:
15--
16-- src/Network/Tox.hs
17-- newCrypto :: IO TransportCrypto
18--
19-- src/Network/Tox/DHT/Handlers.hs
20-- createCookie :: TransportCrypto -> NodeInfo -> PublicKey -> IO Cookie
21--
22-- src/Crypto/Tox.hs
23-- decryptSymmetric :: SymmetricKey -> Nonce24 -> Encrypted a -> Either String (Plain s a)
24--
25--src/Network/Tox/NodeId.hs
26--nodeInfo :: NodeId -> SockAddr -> Either String NodeInfo
27--
28
29main = do
30 crypto <- newCrypto
31 n24 <- atomically $ transportNewNonce crypto
32 putStrLn $ "n24 = " ++ show n24
33 let e24 = S.encode n24
34 case (S.decode e24) of
35 Left e -> do
36 putStrLn $ "serialize Failure:" ++ show e
37 exitFailure
38 Right n24' -> do
39 putStrLn $ "n24' = " ++ show n24'
40 if n24' == n24 then exitSuccess else exitFailure