summaryrefslogtreecommitdiff
path: root/dht/examples
diff options
context:
space:
mode:
Diffstat (limited to 'dht/examples')
-rw-r--r--dht/examples/dhtd.hs8
-rw-r--r--dht/examples/testTox.hs3
-rw-r--r--dht/examples/toxrelay.hs12
3 files changed, 17 insertions, 6 deletions
diff --git a/dht/examples/dhtd.hs b/dht/examples/dhtd.hs
index 68c847c5..5f0eead8 100644
--- a/dht/examples/dhtd.hs
+++ b/dht/examples/dhtd.hs
@@ -698,7 +698,7 @@ clientSession s@Session{..} sock cnum h = do
698 tcnt <- readTVar $ setCount t 698 tcnt <- readTVar $ setCount t
699 icnt <- HashMap.size <$> readTVar (setIDs t) 699 icnt <- HashMap.size <$> readTVar (setIDs t)
700 return (ts,tcnt,icnt) 700 return (ts,tcnt,icnt)
701 (ts,tcnt,icnt) <- trampstate (trampolinesUDP onionRouter) 701 (uts,tcnt,icnt) <- trampstate (trampolinesUDP onionRouter)
702 (tts,ttcnt,ticnt) <- trampstate (trampolinesTCP onionRouter) 702 (tts,ttcnt,ticnt) <- trampstate (trampolinesTCP onionRouter)
703 rs <- getAssocs (pendingRoutes onionRouter) 703 rs <- getAssocs (pendingRoutes onionRouter)
704 pqs <- readTVar (pendingQueries onionRouter) 704 pqs <- readTVar (pendingQueries onionRouter)
@@ -718,9 +718,10 @@ clientSession s@Session{..} sock cnum h = do
718 then show routeVersion 718 then show routeVersion
719 else show routeVersion ++ "(pending)" ] 719 else show routeVersion ++ "(pending)" ]
720 | otherwise = [show n, "error!","","",""] 720 | otherwise = [show n, "error!","","",""]
721 -- otherwise = [show n, "error!",show (IntMap.lookup n rm),show (IntMap.null rm),""]
721 r = map (uncurry showRecord) rs 722 r = map (uncurry showRecord) rs
722 return $ do 723 return $ do
723 hPutClientChunk h $ unlines [ "trampolines(UDP): " ++ show (IntMap.size ts,tcnt,icnt) 724 hPutClientChunk h $ unlines [ "trampolines(UDP): " ++ show (IntMap.size uts,tcnt,icnt)
724 ++ if tcpmode then "" else " *" 725 ++ if tcpmode then "" else " *"
725 , "trampolines(TCP): " ++ show (IntMap.size tts,ttcnt,ticnt) 726 , "trampolines(TCP): " ++ show (IntMap.size tts,ttcnt,ticnt)
726 ++ if tcpmode then " *" else "" 727 ++ if tcpmode then " *" else ""
@@ -1377,12 +1378,13 @@ initTox opts ssvar keysdb mbxmpp invc = case porttox opts of
1377 [""] -> return (Nothing,return (), Map.empty, return [],[]) 1378 [""] -> return (Nothing,return (), Map.empty, return [],[])
1378 toxport -> do 1379 toxport -> do
1379 dput XMisc $ "Supplied key: " ++ show (fmap (Tox.key2id . toPublic) (dhtkey opts)) 1380 dput XMisc $ "Supplied key: " ++ show (fmap (Tox.key2id . toPublic) (dhtkey opts))
1381 crypto <- Tox.newToxCrypto (dhtkey opts)
1380 tox <- Tox.newTox keysdb 1382 tox <- Tox.newTox keysdb
1381 toxport 1383 toxport
1382 (case mbxmpp of 1384 (case mbxmpp of
1383 Nothing -> \_ _ _ -> return () 1385 Nothing -> \_ _ _ -> return ()
1384 Just xmpp -> onNewToxSession xmpp ssvar invc) 1386 Just xmpp -> onNewToxSession xmpp ssvar invc)
1385 (dhtkey opts) 1387 crypto
1386 (\_ _ -> return ()) -- TODO: TCP relay send 1388 (\_ _ -> return ()) -- TODO: TCP relay send
1387 -- addrTox <- getBindAddress toxport (ip6tox opts) 1389 -- addrTox <- getBindAddress toxport (ip6tox opts)
1388 (quitTox, toxStrap4, toxStrap6) <- Tox.forkTox tox (advertiseOnAvahi opts) 1390 (quitTox, toxStrap4, toxStrap6) <- Tox.forkTox tox (advertiseOnAvahi opts)
diff --git a/dht/examples/testTox.hs b/dht/examples/testTox.hs
index 67c4daef..57601422 100644
--- a/dht/examples/testTox.hs
+++ b/dht/examples/testTox.hs
@@ -42,10 +42,11 @@ makeToxNode :: UDPTransport -> Maybe SecretKey
42 -> IO (Tox extra) 42 -> IO (Tox extra)
43makeToxNode udp sec onSessionF = do 43makeToxNode udp sec onSessionF = do
44 keysdb <- newKeysDatabase 44 keysdb <- newKeysDatabase
45 crypto <- newToxCrypto sec
45 newToxOverTransport keysdb 46 newToxOverTransport keysdb
46 (SockAddrInet 0 0) 47 (SockAddrInet 0 0)
47 onSessionF 48 onSessionF
48 sec 49 crypto
49 udp 50 udp
50 (\_ _ -> return ()) 51 (\_ _ -> return ())
51 52
diff --git a/dht/examples/toxrelay.hs b/dht/examples/toxrelay.hs
index af08e8d7..d6b0da17 100644
--- a/dht/examples/toxrelay.hs
+++ b/dht/examples/toxrelay.hs
@@ -1,15 +1,23 @@
1import Network.Address (getBindAddress) 1import Network.Address (getBindAddress,sockAddrPort)
2import Network.SocketLike 2import Network.SocketLike
3import Network.StreamServer 3import Network.StreamServer
4import Network.Tox.Onion.Transport hiding (encrypt,decrypt) 4import Network.Tox.Onion.Transport hiding (encrypt,decrypt)
5import Network.Tox.Relay 5import Network.Tox.Relay
6import Crypto.Tox
7
8import DPut
9import DebugTag
10
11socketPort s = sockAddrPort <$> getSocketName s
6 12
7main :: IO () 13main :: IO ()
8main = do 14main = do
9 udp_addr <- getBindAddress "33445" True 15 udp_addr <- getBindAddress "33445" True
10 let sendOnion :: SockAddr -> OnionRequest N1 -> IO () 16 let sendOnion :: SockAddr -> OnionRequest N1 -> IO ()
11 sendOnion _ _ = return () 17 sendOnion _ _ = return ()
12 (h,sendTCP) <- tcpRelay udp_addr sendOnion 18 setVerbose XNetCrypto
19 crypto <- newCrypto
20 (h,sendTCP) <- tcpRelay crypto udp_addr sendOnion
13 boundPort <- socketPort $ listenSocket h 21 boundPort <- socketPort $ listenSocket h
14 putStrLn $ "Listening on port: " ++ show boundPort 22 putStrLn $ "Listening on port: " ++ show boundPort
15 23