diff options
-rw-r--r-- | dht-client.cabal | 4 | ||||
-rw-r--r-- | examples/testTox.hs | 35 |
2 files changed, 37 insertions, 2 deletions
diff --git a/dht-client.cabal b/dht-client.cabal index bcce1609..08670b9d 100644 --- a/dht-client.cabal +++ b/dht-client.cabal | |||
@@ -321,9 +321,13 @@ executable testTox | |||
321 | , dht-client | 321 | , dht-client |
322 | , stm | 322 | , stm |
323 | , stm-chans | 323 | , stm-chans |
324 | , time | ||
324 | , concurrent-supply | 325 | , concurrent-supply |
325 | , containers | 326 | , containers |
326 | , network | 327 | , network |
328 | , unordered-containers | ||
329 | if flag(thread-debug) | ||
330 | cpp-options: -DTHREAD_DEBUG | ||
327 | 331 | ||
328 | executable atox | 332 | executable atox |
329 | hs-source-dirs: examples | 333 | hs-source-dirs: examples |
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 |