diff options
author | James Crayne <jim.crayne@gmail.com> | 2018-06-27 03:31:02 +0000 |
---|---|---|
committer | James Crayne <jim.crayne@gmail.com> | 2018-06-27 03:31:02 +0000 |
commit | af9a5df9b6c5fff2820cdeae6ac34a0206051c98 (patch) | |
tree | b47cc444870c26bf5aa32977363fc015247e3b6a /examples | |
parent | 23528f18e72dd18efec00a644e7d3e62ca85ae5b (diff) |
testTox now simulates netCrypto session
Diffstat (limited to 'examples')
-rw-r--r-- | examples/testTox.hs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/examples/testTox.hs b/examples/testTox.hs index 531841be..a58c1fa0 100644 --- a/examples/testTox.hs +++ b/examples/testTox.hs | |||
@@ -1,10 +1,16 @@ | |||
1 | {-# LANGUAGE NamedFieldPuns #-} | 1 | {-# LANGUAGE NamedFieldPuns #-} |
2 | {-# LANGUAGE CPP #-} | ||
2 | {-# LANGUAGE OverloadedStrings #-} | 3 | {-# LANGUAGE OverloadedStrings #-} |
3 | import Control.Concurrent (threadDelay) | 4 | #ifdef THREAD_DEBUG |
5 | import Control.Concurrent.Lifted.Instrument | ||
6 | #else | ||
7 | import Control.Concurrent.Lifted | ||
8 | #endif | ||
4 | import Control.Concurrent.STM.TChan | 9 | import Control.Concurrent.STM.TChan |
5 | import Control.Concurrent.STM.TMChan | 10 | import Control.Concurrent.STM.TMChan |
6 | import Control.Concurrent.STM.TVar | 11 | import Control.Concurrent.STM.TVar |
7 | import Control.Concurrent.Supply | 12 | import Control.Concurrent.Supply |
13 | import Control.Monad | ||
8 | import Control.Monad.STM | 14 | import Control.Monad.STM |
9 | import Crypto.Tox | 15 | import Crypto.Tox |
10 | import qualified Data.IntMap.Strict as IntMap | 16 | import qualified Data.IntMap.Strict as IntMap |
@@ -19,6 +25,11 @@ import Network.Tox.Crypto.Transport | |||
19 | import Network.Tox.DHT.Handlers as DHT | 25 | import Network.Tox.DHT.Handlers as DHT |
20 | import Network.Tox.DHT.Transport | 26 | import Network.Tox.DHT.Transport |
21 | import Network.Tox.Onion.Transport | 27 | import Network.Tox.Onion.Transport |
28 | import Connection | ||
29 | import qualified Data.HashMap.Strict as HashMap | ||
30 | ;import Data.HashMap.Strict (HashMap) | ||
31 | import Data.Time.Clock.POSIX | ||
32 | import System.Exit | ||
22 | 33 | ||
23 | 34 | ||
24 | makeToxNode :: UDPTransport -> Maybe SecretKey -> IO (Tox extra) | 35 | makeToxNode :: UDPTransport -> Maybe SecretKey -> IO (Tox extra) |
@@ -77,6 +88,21 @@ main = do | |||
77 | 88 | ||
78 | threadReport False >>= putStrLn | 89 | threadReport False >>= putStrLn |
79 | 90 | ||
91 | [(a_secret,a_public)] <- atomically (userKeys (toxCryptoKeys a_Ct7g5azVcJ8KnvxzbXs9GqeqcjrP7VdZXIC'uHeTlRf)) | ||
92 | [(_,b_public)] <- atomically (userKeys (toxCryptoKeys b_OM7znaPMYkTbm'9GcZJAdnDATXmZxZ9fnaSTP3qNCZk)) | ||
93 | mbAccount <- atomically $ do | ||
94 | accs <- readTVar (accounts $ toxContactInfo a_Ct7g5azVcJ8KnvxzbXs9GqeqcjrP7VdZXIC'uHeTlRf) | ||
95 | return $ HashMap.lookup (key2id a_public) accs | ||
96 | now <- getPOSIXTime | ||
97 | case mbAccount of | ||
98 | Just account -> atomically $ do | ||
99 | setContactPolicy b_public TryingToConnect account | ||
100 | setContactAddr now b_public b account | ||
101 | Nothing -> dput XUnused "MISSING Account!" | ||
102 | |||
103 | dput XUnused $ "a_public = " ++ show (key2id a_public) | ||
104 | dput XUnused $ "BDD... = " ++ show (read "BDDj3maMmK8hR3mTpju29wmtE2YJ5cf8NlNEWi1dXlI":: NodeId) | ||
105 | |||
80 | -- Tell /a/ about /b/'s DHT-key. | 106 | -- Tell /a/ about /b/'s DHT-key. |
81 | updateContactInfo (toxContactInfo a_Ct7g5azVcJ8KnvxzbXs9GqeqcjrP7VdZXIC'uHeTlRf) | 107 | updateContactInfo (toxContactInfo a_Ct7g5azVcJ8KnvxzbXs9GqeqcjrP7VdZXIC'uHeTlRf) |
82 | (AnnouncedRendezvous (id2key $ read "AvETKhO-YqnNRopZrj8K3xUpGtGbX0sLhZZjh2VufJB") -- b toxid | 108 | (AnnouncedRendezvous (id2key $ read "AvETKhO-YqnNRopZrj8K3xUpGtGbX0sLhZZjh2VufJB") -- b toxid |
@@ -91,9 +117,14 @@ main = do | |||
91 | 117 | ||
92 | DHT.ping (toxDHT a_Ct7g5azVcJ8KnvxzbXs9GqeqcjrP7VdZXIC'uHeTlRf) b | 118 | DHT.ping (toxDHT a_Ct7g5azVcJ8KnvxzbXs9GqeqcjrP7VdZXIC'uHeTlRf) b |
93 | 119 | ||
94 | |||
95 | -- sendMessage (toxHandshakes a_Ct7g5azVcJ8KnvxzbXs9GqeqcjrP7VdZXIC'uHeTlRf) (nodeAddr b) hs | 120 | -- sendMessage (toxHandshakes a_Ct7g5azVcJ8KnvxzbXs9GqeqcjrP7VdZXIC'uHeTlRf) (nodeAddr b) hs |
96 | 121 | ||
122 | (b_quit,_,_) <- forkTox b_OM7znaPMYkTbm'9GcZJAdnDATXmZxZ9fnaSTP3qNCZk False | ||
123 | |||
124 | forkIO $ do | ||
125 | tid <- myThreadId | ||
126 | labelThread tid "testToxLaunch" | ||
127 | void $ netCrypto a_Ct7g5azVcJ8KnvxzbXs9GqeqcjrP7VdZXIC'uHeTlRf a_secret b_public | ||
97 | 128 | ||
98 | putStrLn "Type Enter to quit..." | 129 | putStrLn "Type Enter to quit..." |
99 | getLine | 130 | getLine |