From a41dc208af6180d307553c504d3f7d47dd9b9f0a Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 22 Jan 2017 22:49:46 -0500 Subject: dhtd command: external-ip --- examples/dhtd.hs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/dhtd.hs b/examples/dhtd.hs index bc5e9eda..3df77190 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs @@ -96,7 +96,7 @@ resume = do godht :: forall b. (NodeAddr IPv4 -> NodeId -> DHT IPv4 b) -> IO b godht f = do a <- btBindAddr "8008" False - dht def { optTimeout = 5 } a (const $ const True) $ do + dht def { optTimeout = 5 } a noDebugPrints $ do me0 <- asks tentativeNodeId printReport [("tentative node-id",show $ pPrint me0) ,("listen-address", show a) @@ -116,7 +116,7 @@ clientSession st signalQuit sock n h = do cmd action = cmd0 $ join $ runDHT st action case line of - "quit" -> hPutClient h "goodbye." >> hClose h + "quit" -> hPutClient h "" >> hClose h "stop" -> do hPutClient h "Terminating DHT Daemon." hClose h @@ -135,9 +135,19 @@ clientSession st signalQuit sock n h = do , ("internet address", show ip) , ("buckets", show $ R.shape tbl)] ] - "swarms" -> cmd $ do + "external-ip" -> cmd $ do + ip <- routableAddress + return $ do + hPutClient h $ maybe "" (takeWhile (/=':') . show) ip + + s | s=="swarms" || "swarms " `isPrefixOf` s -> cmd $ do + let fltr = case dropWhile isSpace (drop 7 s) of + ('-':'v':cs) | all isSpace (take 1 cs) + -> const True + _ -> (\(h,c,n) -> c/=0 ) ss <- getSwarms - let r = map (\(h,c,n) -> (unwords [show h,show c], maybe "" show n)) ss + let r = map (\(h,c,n) -> (unwords [show h,show c], maybe "" show n)) + $ filter fltr ss return $ do hPutClient h $ showReport r -- cgit v1.2.3