summaryrefslogtreecommitdiff
path: root/examples/dhtd.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-20 01:04:28 -0400
committerjoe <joe@jerkface.net>2018-06-20 01:04:28 -0400
commit14585ca1eb3ec1d73c4907dcd05676b5b0272a5b (patch)
treef3947de64cb4454d7629ad4c7389bb0616696644 /examples/dhtd.hs
parent1844a59b6abb02017eef7be00b1efb6bbc681f4b (diff)
Keep track of age of onion routes.
Diffstat (limited to 'examples/dhtd.hs')
-rw-r--r--examples/dhtd.hs17
1 files changed, 10 insertions, 7 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index 6437e94f..36a9fa68 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -813,7 +813,9 @@ clientSession s@Session{..} sock cnum h = do
813 Tox.sendChatMsg (Tox.toxCryptoKeys tox) session (B.pack msg) 813 Tox.sendChatMsg (Tox.toxCryptoKeys tox) session (B.pack msg)
814 hPutClient h "sent MESSAGE" 814 hPutClient h "sent MESSAGE"
815 815
816 ("onion", s) -> cmd0 $ join $ atomically $ do 816 ("onion", s) -> cmd0 $ do
817 now <- getPOSIXTime
818 join $ atomically $ do
817 rm <- readTVar $ routeMap onionRouter 819 rm <- readTVar $ routeMap onionRouter
818 ts <- readTVar $ trampolineNodes onionRouter 820 ts <- readTVar $ trampolineNodes onionRouter
819 tcnt <- readTVar $ trampolineCount onionRouter 821 tcnt <- readTVar $ trampolineCount onionRouter
@@ -822,16 +824,17 @@ clientSession s@Session{..} sock cnum h = do
822 pqs <- readTVar (pendingQueries onionRouter) 824 pqs <- readTVar (pendingQueries onionRouter)
823 let showRecord :: Int -> Int -> [String] 825 let showRecord :: Int -> Int -> [String]
824 showRecord n wanted_ver 826 showRecord n wanted_ver
825 | Just RouteRecord{responseCount,timeoutCount,routeVersion} <- IntMap.lookup n rm 827 | Just RouteRecord{responseCount,timeoutCount,routeVersion,routeBirthTime} <- IntMap.lookup n rm
826 = if routeVersion >= wanted_ver 828 = [ show n, show responseCount, show timeoutCount, show (now-routeBirthTime)
827 then [show n, show responseCount, show timeoutCount, show (routeVersion,wanted_ver) ] 829 , if routeVersion >= wanted_ver
828 else [show n, show responseCount, show timeoutCount, show (routeVersion,wanted_ver) ++ "(pending)" ] 830 then show routeVersion
829 | otherwise = [show n, "error!",""] 831 else show routeVersion ++ "(pending)" ]
832 | otherwise = [show n, "error!","","",""]
830 r = map (uncurry showRecord) $ IntMap.toAscList rs 833 r = map (uncurry showRecord) $ IntMap.toAscList rs
831 return $ do 834 return $ do
832 hPutClientChunk h $ unlines [ "trampolines: " ++ show (IntMap.size ts,tcnt,icnt) 835 hPutClientChunk h $ unlines [ "trampolines: " ++ show (IntMap.size ts,tcnt,icnt)
833 , "pending: " ++ show (W64.size pqs) ] 836 , "pending: " ++ show (W64.size pqs) ]
834 hPutClient h $ showColumns $ ["","responses","timeouts", "version"]:r 837 hPutClient h $ showColumns $ ["","responses","timeouts", "age", "version"]:r
835 838
836 -- necrypto <FRIEND-TOXID> 839 -- necrypto <FRIEND-TOXID>
837 -- establish a netcrypto session with specified person 840 -- establish a netcrypto session with specified person