diff options
author | joe <joe@jerkface.net> | 2017-01-22 22:49:46 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-01-22 22:49:46 -0500 |
commit | a41dc208af6180d307553c504d3f7d47dd9b9f0a (patch) | |
tree | 5e68969008e923247e847584e44126dba5a63a66 | |
parent | be0436e4d5c301fa643799cc41b204459d696f17 (diff) |
dhtd command: external-ip
-rw-r--r-- | examples/dhtd.hs | 18 |
1 files changed, 14 insertions, 4 deletions
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 | |||
96 | godht :: forall b. (NodeAddr IPv4 -> NodeId -> DHT IPv4 b) -> IO b | 96 | godht :: forall b. (NodeAddr IPv4 -> NodeId -> DHT IPv4 b) -> IO b |
97 | godht f = do | 97 | godht f = do |
98 | a <- btBindAddr "8008" False | 98 | a <- btBindAddr "8008" False |
99 | dht def { optTimeout = 5 } a (const $ const True) $ do | 99 | dht def { optTimeout = 5 } a noDebugPrints $ do |
100 | me0 <- asks tentativeNodeId | 100 | me0 <- asks tentativeNodeId |
101 | printReport [("tentative node-id",show $ pPrint me0) | 101 | printReport [("tentative node-id",show $ pPrint me0) |
102 | ,("listen-address", show a) | 102 | ,("listen-address", show a) |
@@ -116,7 +116,7 @@ clientSession st signalQuit sock n h = do | |||
116 | cmd action = cmd0 $ join $ runDHT st action | 116 | cmd action = cmd0 $ join $ runDHT st action |
117 | case line of | 117 | case line of |
118 | 118 | ||
119 | "quit" -> hPutClient h "goodbye." >> hClose h | 119 | "quit" -> hPutClient h "" >> hClose h |
120 | 120 | ||
121 | "stop" -> do hPutClient h "Terminating DHT Daemon." | 121 | "stop" -> do hPutClient h "Terminating DHT Daemon." |
122 | hClose h | 122 | hClose h |
@@ -135,9 +135,19 @@ clientSession st signalQuit sock n h = do | |||
135 | , ("internet address", show ip) | 135 | , ("internet address", show ip) |
136 | , ("buckets", show $ R.shape tbl)] | 136 | , ("buckets", show $ R.shape tbl)] |
137 | ] | 137 | ] |
138 | "swarms" -> cmd $ do | 138 | "external-ip" -> cmd $ do |
139 | ip <- routableAddress | ||
140 | return $ do | ||
141 | hPutClient h $ maybe "" (takeWhile (/=':') . show) ip | ||
142 | |||
143 | s | s=="swarms" || "swarms " `isPrefixOf` s -> cmd $ do | ||
144 | let fltr = case dropWhile isSpace (drop 7 s) of | ||
145 | ('-':'v':cs) | all isSpace (take 1 cs) | ||
146 | -> const True | ||
147 | _ -> (\(h,c,n) -> c/=0 ) | ||
139 | ss <- getSwarms | 148 | ss <- getSwarms |
140 | let r = map (\(h,c,n) -> (unwords [show h,show c], maybe "" show n)) ss | 149 | let r = map (\(h,c,n) -> (unwords [show h,show c], maybe "" show n)) |
150 | $ filter fltr ss | ||
141 | return $ do | 151 | return $ do |
142 | hPutClient h $ showReport r | 152 | hPutClient h $ showReport r |
143 | 153 | ||