summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-01-24 05:54:58 -0500
committerjoe <joe@jerkface.net>2017-01-24 05:54:58 -0500
commit804499c370068febee47b3e2b7441e2c742f7b9a (patch)
tree2a26af8de0e785fe8052edb14364a134aa05c322 /examples
parentc0256fa5a3bb7374eb5aade5f46b0a586c8d314a (diff)
dhtd "ping" command
Diffstat (limited to 'examples')
-rw-r--r--examples/dhtd.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index 1790d10a..f8ca8575 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -30,6 +30,9 @@ import System.Posix.Process (getProcessID)
30import Data.Torrent (InfoHash) 30import Data.Torrent (InfoHash)
31import Network.BitTorrent.Address 31import Network.BitTorrent.Address
32import Network.BitTorrent.DHT 32import Network.BitTorrent.DHT
33import Network.BitTorrent.DHT.Query
34import Network.KRPC.Manager (QueryFailure(..))
35import Network.KRPC.Message (ReflectedIP(..))
33import qualified Network.BitTorrent.DHT.Routing as R 36import qualified Network.BitTorrent.DHT.Routing as R
34import Network.BitTorrent.DHT.Session 37import Network.BitTorrent.DHT.Session
35import Network.SocketLike 38import Network.SocketLike
@@ -201,10 +204,25 @@ clientSession st signalQuit sock n h = do
201 hPutClient h $ unlines $ map (showEnry . (flip (,) 0)) nodes 204 hPutClient h $ unlines $ map (showEnry . (flip (,) 0)) nodes
202 Left er -> return $ hPutClient h er 205 Left er -> return $ hPutClient h er
203 206
207 ("ping", s) -> cmd $ do
208 case readEither s of
209 Right addr -> do result <- try $ pingQ addr
210 let rs = either (pure . showQueryFail) reportPong result
211 return $ do
212 hPutClient h $ unlines rs
213 Left er -> return $ hPutClient h er
214
204 _ -> cmd0 $ hPutClient h "error." 215 _ -> cmd0 $ hPutClient h "error."
205 216
206defaultPort = error "TODO defaultPort" 217defaultPort = error "TODO defaultPort"
207 218
219showQueryFail :: QueryFailure -> String
220showQueryFail e = show e
221
222reportPong (info,myip) = maybe id consip myip [show $ pPrint info]
223 where
224 consip (ReflectedIP ip) xs = ("(external-ip " ++ show ip ++ ")") : xs
225
208main :: IO () 226main :: IO ()
209main = do 227main = do
210 args <- getArgs 228 args <- getArgs