diff options
author | Joe Crayne <joe@jerkface.net> | 2018-12-16 13:51:02 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-12-16 14:08:27 -0500 |
commit | 688450c2d9998db7b4389dc9642d219774c23857 (patch) | |
tree | 69933330ad0baba2eb115d70d1e63cb085664ea1 /examples/dhtd.hs | |
parent | 8a72757ae66f6ec013b8f3443aea6f3266a2ab26 (diff) |
More TCP work.
Diffstat (limited to 'examples/dhtd.hs')
-rw-r--r-- | examples/dhtd.hs | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs index d014a611..96cfbe0e 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs | |||
@@ -264,7 +264,7 @@ forkSearch :: | |||
264 | -> TVar (Maybe (IO ())) | 264 | -> TVar (Maybe (IO ())) |
265 | -> STM () | 265 | -> STM () |
266 | forkSearch method nid DHTQuery{qsearch,qshowTok,qshowR} dhtSearches dhtBuckets tid kvar = do | 266 | forkSearch method nid DHTQuery{qsearch,qshowTok,qshowR} dhtSearches dhtBuckets tid kvar = do |
267 | ns <- R.kclosest (searchSpace qsearch) searchK nid <$> readTVar dhtBuckets | 267 | ns <- R.kclosest (searchSpace qsearch) (searchK qsearch) nid <$> readTVar dhtBuckets |
268 | st <- newSearch qsearch nid ns | 268 | st <- newSearch qsearch nid ns |
269 | results <- newTVar Set.empty | 269 | results <- newTVar Set.empty |
270 | let storeResult r = modifyTVar' results (Set.insert (qshowR r)) | 270 | let storeResult r = modifyTVar' results (Set.insert (qshowR r)) |
@@ -674,7 +674,8 @@ clientSession s@Session{..} sock cnum h = do | |||
674 | hPutClient h $ "Showing " ++ show tag ++ " messages." | 674 | hPutClient h $ "Showing " ++ show tag ++ " messages." |
675 | 675 | ||
676 | 676 | ||
677 | ("onion", s) -> cmd0 $ do | 677 | ("onion", s) | "" <- strp $ map toLower s |
678 | -> cmd0 $ do | ||
678 | now <- getPOSIXTime | 679 | now <- getPOSIXTime |
679 | join $ atomically $ do | 680 | join $ atomically $ do |
680 | rm <- IntMap.fromList . catMaybes . map (\(i,m) -> fmap (i,) m) <$> getAssocs (routeMap onionRouter) | 681 | rm <- IntMap.fromList . catMaybes . map (\(i,m) -> fmap (i,) m) <$> getAssocs (routeMap onionRouter) |
@@ -690,10 +691,14 @@ clientSession s@Session{..} sock cnum h = do | |||
690 | tcp_spill <- readTVar (TCP.probeSpill $ tcpProber onionRouter) | 691 | tcp_spill <- readTVar (TCP.probeSpill $ tcpProber onionRouter) |
691 | tcp_cache <- readTVar (TCP.probeCache $ tcpProber onionRouter) | 692 | tcp_cache <- readTVar (TCP.probeCache $ tcpProber onionRouter) |
692 | tcp_queue <- readTVar (TCP.probeQueue $ tcpProber onionRouter) | 693 | tcp_queue <- readTVar (TCP.probeQueue $ tcpProber onionRouter) |
694 | tcpmode <- readTVar (tcpMode onionRouter) | ||
693 | let showRecord :: Int -> Int -> [String] | 695 | let showRecord :: Int -> Int -> [String] |
694 | showRecord n wanted_ver | 696 | showRecord n wanted_ver |
695 | | Just RouteRecord{responseCount,timeoutCount,routeVersion,routeBirthTime} <- IntMap.lookup n rm | 697 | | Just RouteRecord{responseCount,timeoutCount,routeVersion,routeBirthTime |
696 | = [ show n, show responseCount, show timeoutCount, show (now-routeBirthTime) | 698 | ,storedRoute=Tox.OnionRoute{routeRelayPort}} <- IntMap.lookup n rm |
699 | = [ show n, show responseCount, show timeoutCount | ||
700 | , maybe "" show routeRelayPort | ||
701 | , show (now - routeBirthTime) | ||
697 | , if routeVersion >= wanted_ver | 702 | , if routeVersion >= wanted_ver |
698 | then show routeVersion | 703 | then show routeVersion |
699 | else show routeVersion ++ "(pending)" ] | 704 | else show routeVersion ++ "(pending)" ] |
@@ -701,11 +706,23 @@ clientSession s@Session{..} sock cnum h = do | |||
701 | r = map (uncurry showRecord) rs | 706 | r = map (uncurry showRecord) rs |
702 | return $ do | 707 | return $ do |
703 | hPutClientChunk h $ unlines [ "trampolines(UDP): " ++ show (IntMap.size ts,tcnt,icnt) | 708 | hPutClientChunk h $ unlines [ "trampolines(UDP): " ++ show (IntMap.size ts,tcnt,icnt) |
709 | ++ if tcpmode then "" else " *" | ||
704 | , "trampolines(TCP): " ++ show (IntMap.size tts,ttcnt,ticnt) | 710 | , "trampolines(TCP): " ++ show (IntMap.size tts,ttcnt,ticnt) |
711 | ++ if tcpmode then " *" else "" | ||
705 | , "pending: " ++ show (W64.size pqs) | 712 | , "pending: " ++ show (W64.size pqs) |
706 | , "TCP spill,cache,queue: " | 713 | , "TCP spill,cache,queue: " |
707 | ++ show (PSQ.size tcp_spill, PSQ.size tcp_cache, PSQ.size tcp_queue)] | 714 | ++ show (PSQ.size tcp_spill, PSQ.size tcp_cache, PSQ.size tcp_queue)] |
708 | hPutClient h $ showColumns $ ["","responses","timeouts", "age", "version"]:r | 715 | hPutClient h $ showColumns $ ["","responses","timeouts", "tcp", "age", "version"]:r |
716 | |||
717 | ("onion", s) | "udp" <- strp $ map toLower s | ||
718 | -> cmd0 $ do | ||
719 | atomically $ writeTVar (tcpMode onionRouter) False | ||
720 | hPutClient h "Onion routes: UDP." | ||
721 | |||
722 | ("onion", s) | "tcp" <- strp $ map toLower s | ||
723 | -> cmd0 $ do | ||
724 | atomically $ writeTVar (tcpMode onionRouter) True | ||
725 | hPutClient h "Onion routes: TCP." | ||
709 | 726 | ||
710 | ("g", s) | Just DHT{..} <- Map.lookup netname dhts | 727 | ("g", s) | Just DHT{..} <- Map.lookup netname dhts |
711 | -> cmd0 $ do | 728 | -> cmd0 $ do |
@@ -884,7 +901,7 @@ clientSession s@Session{..} sock cnum h = do | |||
884 | akey | 901 | akey |
885 | (AnnounceMethod qsearch asend | 902 | (AnnounceMethod qsearch asend |
886 | (\nid -> R.kclosest (searchSpace qsearch) | 903 | (\nid -> R.kclosest (searchSpace qsearch) |
887 | searchK | 904 | (searchK qsearch) |
888 | nid | 905 | nid |
889 | <$> readTVar dhtBuckets) | 906 | <$> readTVar dhtBuckets) |
890 | (announceTarget dta) | 907 | (announceTarget dta) |
@@ -910,7 +927,7 @@ clientSession s@Session{..} sock cnum h = do | |||
910 | akey | 927 | akey |
911 | (SearchMethod qsearch (asend pub) | 928 | (SearchMethod qsearch (asend pub) |
912 | (\nid -> R.kclosest (searchSpace qsearch) | 929 | (\nid -> R.kclosest (searchSpace qsearch) |
913 | searchK | 930 | (searchK qsearch) |
914 | nid | 931 | nid |
915 | <$> readTVar dhtBuckets) | 932 | <$> readTVar dhtBuckets) |
916 | (announceTarget dta) | 933 | (announceTarget dta) |
@@ -1514,7 +1531,9 @@ initTox opts ssvar keysdb mbxmpp invc = case porttox opts of | |||
1514 | , dhtQuery = Map.singleton "node" DHTQuery | 1531 | , dhtQuery = Map.singleton "node" DHTQuery |
1515 | { qsearch = TCP.nodeSearch tcpprober tcpclient | 1532 | { qsearch = TCP.nodeSearch tcpprober tcpclient |
1516 | , qhandler = \ni nid -> do | 1533 | , qhandler = \ni nid -> do |
1517 | ns <- R.kclosest (searchSpace $ TCP.nodeSearch tcpprober tcpclient) searchK nid | 1534 | ns <- R.kclosest (searchSpace $ TCP.nodeSearch tcpprober tcpclient) |
1535 | (searchK $ TCP.nodeSearch tcpprober tcpclient) | ||
1536 | nid | ||
1518 | <$> atomically (readTVar $ refreshBuckets tcpRefresher) | 1537 | <$> atomically (readTVar $ refreshBuckets tcpRefresher) |
1519 | return (ns,ns,Just ()) | 1538 | return (ns,ns,Just ()) |
1520 | , qshowR = show -- TCP.NodeInfo | 1539 | , qshowR = show -- TCP.NodeInfo |