summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dht-client.cabal4
-rw-r--r--examples/testTox.hs35
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
328executable atox 332executable 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 #-}
3import Control.Concurrent (threadDelay) 4#ifdef THREAD_DEBUG
5import Control.Concurrent.Lifted.Instrument
6#else
7import Control.Concurrent.Lifted
8#endif
4import Control.Concurrent.STM.TChan 9import Control.Concurrent.STM.TChan
5import Control.Concurrent.STM.TMChan 10import Control.Concurrent.STM.TMChan
6import Control.Concurrent.STM.TVar 11import Control.Concurrent.STM.TVar
7import Control.Concurrent.Supply 12import Control.Concurrent.Supply
13import Control.Monad
8import Control.Monad.STM 14import Control.Monad.STM
9import Crypto.Tox 15import Crypto.Tox
10import qualified Data.IntMap.Strict as IntMap 16import qualified Data.IntMap.Strict as IntMap
@@ -19,6 +25,11 @@ import Network.Tox.Crypto.Transport
19import Network.Tox.DHT.Handlers as DHT 25import Network.Tox.DHT.Handlers as DHT
20import Network.Tox.DHT.Transport 26import Network.Tox.DHT.Transport
21import Network.Tox.Onion.Transport 27import Network.Tox.Onion.Transport
28import Connection
29import qualified Data.HashMap.Strict as HashMap
30 ;import Data.HashMap.Strict (HashMap)
31import Data.Time.Clock.POSIX
32import System.Exit
22 33
23 34
24makeToxNode :: UDPTransport -> Maybe SecretKey -> IO (Tox extra) 35makeToxNode :: 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