diff options
Diffstat (limited to 'dht/examples')
-rw-r--r-- | dht/examples/dhtd.hs | 26 | ||||
-rw-r--r-- | dht/examples/testTox.hs | 8 |
2 files changed, 20 insertions, 14 deletions
diff --git a/dht/examples/dhtd.hs b/dht/examples/dhtd.hs index adfe0d69..9c03a4f9 100644 --- a/dht/examples/dhtd.hs +++ b/dht/examples/dhtd.hs | |||
@@ -706,7 +706,7 @@ clientSession s@Session{..} sock cnum h = do | |||
706 | tcp_spill <- readTVar (TCP.probeSpill $ tcpProber onionRouter) | 706 | tcp_spill <- readTVar (TCP.probeSpill $ tcpProber onionRouter) |
707 | tcp_cache <- readTVar (TCP.probeCache $ tcpProber onionRouter) | 707 | tcp_cache <- readTVar (TCP.probeCache $ tcpProber onionRouter) |
708 | tcp_queue <- readTVar (TCP.probeQueue $ tcpProber onionRouter) | 708 | tcp_queue <- readTVar (TCP.probeQueue $ tcpProber onionRouter) |
709 | tcpmode <- readTVar (tcpMode onionRouter) | 709 | tcpmode <- requestTCPModeSTM onionRouter Nothing |
710 | tcps <- readTVar (TCP.lru $ tcpProberState onionRouter) | 710 | tcps <- readTVar (TCP.lru $ tcpProberState onionRouter) |
711 | let showRecord :: Int -> Int -> [String] | 711 | let showRecord :: Int -> Int -> [String] |
712 | showRecord n wanted_ver | 712 | showRecord n wanted_ver |
@@ -734,13 +734,13 @@ clientSession s@Session{..} sock cnum h = do | |||
734 | 734 | ||
735 | ("onion", s) | "udp" <- strp $ map toLower s | 735 | ("onion", s) | "udp" <- strp $ map toLower s |
736 | -> cmd0 $ do | 736 | -> cmd0 $ do |
737 | atomically $ writeTVar (tcpMode onionRouter) False | 737 | tcpm <- requestTCPMode onionRouter (Just False) |
738 | hPutClient h "Onion routes: UDP." | 738 | hPutClient h $ "Onion routes: " ++ if tcpm then "TCP." else "UDP." |
739 | 739 | ||
740 | ("onion", s) | "tcp" <- strp $ map toLower s | 740 | ("onion", s) | "tcp" <- strp $ map toLower s |
741 | -> cmd0 $ do | 741 | -> cmd0 $ do |
742 | atomically $ writeTVar (tcpMode onionRouter) True | 742 | tcpm <- requestTCPMode onionRouter (Just True) |
743 | hPutClient h "Onion routes: TCP." | 743 | hPutClient h $ "Onion routes: " ++ if tcpm then "TCP." else "UDP." |
744 | 744 | ||
745 | ("g", s) | Just DHT{..} <- Map.lookup netname dhts | 745 | ("g", s) | Just DHT{..} <- Map.lookup netname dhts |
746 | -> cmd0 $ do | 746 | -> cmd0 $ do |
@@ -1119,6 +1119,7 @@ data Options = Options | |||
1119 | , verbosity :: Int | 1119 | , verbosity :: Int |
1120 | , verboseTags :: [DebugTag] | 1120 | , verboseTags :: [DebugTag] |
1121 | , advertiseOnAvahi :: Bool | 1121 | , advertiseOnAvahi :: Bool |
1122 | , enableTCPDHT :: Bool | ||
1122 | } | 1123 | } |
1123 | deriving (Eq,Show) | 1124 | deriving (Eq,Show) |
1124 | 1125 | ||
@@ -1134,6 +1135,7 @@ sensibleDefaults = Options | |||
1134 | , verbosity = 2 | 1135 | , verbosity = 2 |
1135 | , verboseTags = [XUnexpected, XUnused] | 1136 | , verboseTags = [XUnexpected, XUnused] |
1136 | , advertiseOnAvahi = True | 1137 | , advertiseOnAvahi = True |
1138 | , enableTCPDHT = True | ||
1137 | } | 1139 | } |
1138 | 1140 | ||
1139 | data ShowHelp = ShowHelp | 1141 | data ShowHelp = ShowHelp |
@@ -1145,6 +1147,7 @@ usage ShowHelp | |||
1145 | ,["--dht-key ",dhtkey]],["Use ",dhtkey," as the dht key"]) | 1147 | ,["--dht-key ",dhtkey]],["Use ",dhtkey," as the dht key"]) |
1146 | , ([["-4"]] ,["Use IPv4 only"]) | 1148 | , ([["-4"]] ,["Use IPv4 only"]) |
1147 | , ([["--noavahi"]] ,["Disable avahi advertising on LAN"]) | 1149 | , ([["--noavahi"]] ,["Disable avahi advertising on LAN"]) |
1150 | , ([["--notcp"]] ,["Disable TCP-relay server and client-based DHT"]) | ||
1148 | , ([["-v ",tags]] ,["Enable or disable specified DebugTags.\n DebugTags = ", listDebugTags]) | 1151 | , ([["-v ",tags]] ,["Enable or disable specified DebugTags.\n DebugTags = ", listDebugTags]) |
1149 | ] ; | 1152 | ] ; |
1150 | dhtkey ="<dhtkey>" ; | 1153 | dhtkey ="<dhtkey>" ; |
@@ -1165,6 +1168,7 @@ parseArgs :: [String] -> Options -> Either ShowHelp Options | |||
1165 | parseArgs [] opts = Right opts | 1168 | parseArgs [] opts = Right opts |
1166 | parseArgs ("--help":args) opts = Left ShowHelp | 1169 | parseArgs ("--help":args) opts = Left ShowHelp |
1167 | parseArgs ("--noavahi":args) opts = parseArgs args opts { advertiseOnAvahi = False } | 1170 | parseArgs ("--noavahi":args) opts = parseArgs args opts { advertiseOnAvahi = False } |
1171 | parseArgs ("--notcp":args) opts = parseArgs args opts { enableTCPDHT = False } | ||
1168 | parseArgs ("--dhtkey":k:args) opts = parseArgs args opts | 1172 | parseArgs ("--dhtkey":k:args) opts = parseArgs args opts |
1169 | { dhtkey = decodeSecret $ B.pack k } | 1173 | { dhtkey = decodeSecret $ B.pack k } |
1170 | parseArgs ("--dht-key":k:args) opts = parseArgs args opts | 1174 | parseArgs ("--dht-key":k:args) opts = parseArgs args opts |
@@ -1384,9 +1388,9 @@ initTox opts ssvar keysdb mbxmpp invc = case porttox opts of | |||
1384 | Nothing -> \_ _ _ -> return () | 1388 | Nothing -> \_ _ _ -> return () |
1385 | Just xmpp -> onNewToxSession xmpp ssvar invc) | 1389 | Just xmpp -> onNewToxSession xmpp ssvar invc) |
1386 | crypto | 1390 | crypto |
1387 | (\_ _ -> return ()) -- TODO: TCP relay send | 1391 | (enableTCPDHT opts) |
1388 | -- addrTox <- getBindAddress toxport (ip6tox opts) | 1392 | -- addrTox <- getBindAddress toxport (ip6tox opts) |
1389 | (quitTox, toxStrap4, toxStrap6) <- Tox.forkTox tox (advertiseOnAvahi opts) | 1393 | (quitTox, toxStrap4, toxStrap6) <- Tox.forkTox tox (advertiseOnAvahi opts) (enableTCPDHT opts) |
1390 | 1394 | ||
1391 | toxSearches <- atomically $ newTVar Map.empty | 1395 | toxSearches <- atomically $ newTVar Map.empty |
1392 | 1396 | ||
@@ -1592,9 +1596,11 @@ initTox opts ssvar keysdb mbxmpp invc = case porttox opts of | |||
1592 | dhts = Map.fromList $ | 1596 | dhts = Map.fromList $ |
1593 | ("tox4", toxDHT Tox.routing4 Want_IP4) | 1597 | ("tox4", toxDHT Tox.routing4 Want_IP4) |
1594 | : (if ip6tox opts | 1598 | : (if ip6tox opts |
1595 | then [ ("tox6", toxDHT Tox.routing6 Want_IP6) ] | 1599 | then ( ("tox6", toxDHT Tox.routing6 Want_IP6) :) |
1600 | else id) | ||
1601 | (if enableTCPDHT opts | ||
1602 | then [ ("toxtcp", tcpDHT) ] | ||
1596 | else []) | 1603 | else []) |
1597 | ++ [("toxtcp", tcpDHT)] | ||
1598 | ips :: IO [SockAddr] | 1604 | ips :: IO [SockAddr] |
1599 | ips = readExternals Tox.nodeAddr [ Tox.routing4 $ Tox.toxRouting tox | 1605 | ips = readExternals Tox.nodeAddr [ Tox.routing4 $ Tox.toxRouting tox |
1600 | , Tox.routing6 $ Tox.toxRouting tox ] | 1606 | , Tox.routing6 $ Tox.toxRouting tox ] |
@@ -1777,7 +1783,7 @@ main = do | |||
1777 | let defaultToxData = do | 1783 | let defaultToxData = do |
1778 | rster <- Tox.newContactInfo | 1784 | rster <- Tox.newContactInfo |
1779 | crypto <- newCrypto | 1785 | crypto <- newCrypto |
1780 | (orouter,_) <- newOnionRouter crypto (dput XMisc) | 1786 | (orouter,_) <- newOnionRouter crypto (dput XMisc) (enableTCPDHT opts) |
1781 | return (rster, orouter) | 1787 | return (rster, orouter) |
1782 | (rstr,orouter) <- fromMaybe defaultToxData $ do | 1788 | (rstr,orouter) <- fromMaybe defaultToxData $ do |
1783 | tox <- mbtox | 1789 | tox <- mbtox |
diff --git a/dht/examples/testTox.hs b/dht/examples/testTox.hs index 57601422..6db977be 100644 --- a/dht/examples/testTox.hs +++ b/dht/examples/testTox.hs | |||
@@ -48,7 +48,7 @@ makeToxNode udp sec onSessionF = do | |||
48 | onSessionF | 48 | onSessionF |
49 | crypto | 49 | crypto |
50 | udp | 50 | udp |
51 | (\_ _ -> return ()) | 51 | Nothing |
52 | 52 | ||
53 | 53 | ||
54 | setToxID :: Tox () -> Maybe SecretKey -> IO () | 54 | setToxID :: Tox () -> Maybe SecretKey -> IO () |
@@ -113,8 +113,8 @@ main = do | |||
113 | 113 | ||
114 | -- b_sessions <- sessionChan b_OM7znaPMYkTbm'9GcZJAdnDATXmZxZ9fnaSTP3qNCZk | 114 | -- b_sessions <- sessionChan b_OM7znaPMYkTbm'9GcZJAdnDATXmZxZ9fnaSTP3qNCZk |
115 | 115 | ||
116 | (a_quit,_,_) <- forkTox a_Ct7g5azVcJ8KnvxzbXs9GqeqcjrP7VdZXIC'uHeTlRf False | 116 | (a_quit,_,_) <- forkTox a_Ct7g5azVcJ8KnvxzbXs9GqeqcjrP7VdZXIC'uHeTlRf False False |
117 | (b_quit,_,_) <- forkTox b_OM7znaPMYkTbm'9GcZJAdnDATXmZxZ9fnaSTP3qNCZk False | 117 | (b_quit,_,_) <- forkTox b_OM7znaPMYkTbm'9GcZJAdnDATXmZxZ9fnaSTP3qNCZk False False |
118 | 118 | ||
119 | threadReport False >>= putStrLn | 119 | threadReport False >>= putStrLn |
120 | 120 | ||
@@ -149,7 +149,7 @@ main = do | |||
149 | 149 | ||
150 | -- sendMessage (toxHandshakes a_Ct7g5azVcJ8KnvxzbXs9GqeqcjrP7VdZXIC'uHeTlRf) (nodeAddr b) hs | 150 | -- sendMessage (toxHandshakes a_Ct7g5azVcJ8KnvxzbXs9GqeqcjrP7VdZXIC'uHeTlRf) (nodeAddr b) hs |
151 | 151 | ||
152 | (b_quit,_,_) <- forkTox b_OM7znaPMYkTbm'9GcZJAdnDATXmZxZ9fnaSTP3qNCZk False | 152 | (b_quit,_,_) <- forkTox b_OM7znaPMYkTbm'9GcZJAdnDATXmZxZ9fnaSTP3qNCZk False False |
153 | 153 | ||
154 | forkIO $ do | 154 | forkIO $ do |
155 | tid <- myThreadId | 155 | tid <- myThreadId |