summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/dhtd.hs50
1 files changed, 46 insertions, 4 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index ede203bf..623b03c5 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -375,7 +375,36 @@ clientSession s@Session{..} sock cnum h = do
375 let mkrow :: (SecretKey, PublicKey) -> (String,String) 375 let mkrow :: (SecretKey, PublicKey) -> (String,String)
376 mkrow (a,b) | Just x <- encodeSecret a= (B.unpack x, show (Tox.key2id b)) 376 mkrow (a,b) | Just x <- encodeSecret a= (B.unpack x, show (Tox.key2id b))
377 mkrow _ = error (concat ["Assertion fail in 'mkrow' function at ", __FILE__, ":", show __LINE__]) 377 mkrow _ = error (concat ["Assertion fail in 'mkrow' function at ", __FILE__, ":", show __LINE__])
378 sessionCommands :: [[String]]
379 sessionCommands =
380 [ ["stop"]
381 , ["quit"]
382 , ["pid"]
383 , ["external-ip"]
384 , ["threads"]
385 , ["mem"]
386 , ["ls"]
387 , ["k"]
388 , ["roster"]
389 , ["g"]
390 , ["p"]
391 , ["a"]
392 , ["s"]
393 , ["x"]
394 , ["save"]
395 , ["load"]
396 , ["swarms"]
397 , ["peers"]
398 , ["toxids"]
399 , ["c"]
400 , ["help"]
401 ]
378 case (map toLower c,args) of 402 case (map toLower c,args) of
403 (n, _) | n `elem` Map.keys dhts -> switchNetwork n
404 (x,_) | not (null (strp x))
405 , x `notElem` map head sessionCommands -> cmd0 $ do
406 hPutClient h $ "error."
407
379 ("stop", _) -> do hPutClient h "Terminating DHT Daemon." 408 ("stop", _) -> do hPutClient h "Terminating DHT Daemon."
380 hClose h 409 hClose h
381 putMVar signalQuit () 410 putMVar signalQuit ()
@@ -690,9 +719,9 @@ clientSession s@Session{..} sock cnum h = do
690 -> case (Map.lookup (head ws) combinedLinkMap) of 719 -> case (Map.lookup (head ws) combinedLinkMap) of
691 Nothing -> return . Left $ "I don't know a '" ++ head ws ++ "' link type." 720 Nothing -> return . Left $ "I don't know a '" ++ head ws ++ "' link type."
692 Just l@(DHTLink 721 Just l@(DHTLink
693 { linkInit {- :: params -> IO (Either String status) -} 722 { linkInit {- :: params -> IO (Either String status) -}
694 , linkParamParser {- :: [String] -> Either String params -} 723 , linkParamParser {- :: [String] -> Either String params -}
695 , showLinkStatus {- :: status -> String -} 724 , showLinkStatus {- :: status -> String -}
696 }) -> case linkParamParser rest of 725 }) -> case linkParamParser rest of
697 Left er -> return $ Left er 726 Left er -> return $ Left er
698 Right params -> fmap showLinkStatus <$> linkInit params 727 Right params -> fmap showLinkStatus <$> linkInit params
@@ -700,7 +729,20 @@ clientSession s@Session{..} sock cnum h = do
700 case result of 729 case result of
701 Left er -> hPutClient h er 730 Left er -> hPutClient h er
702 Right statusstr -> hPutClient h statusstr 731 Right statusstr -> hPutClient h statusstr
703 (n, _) | n `elem` Map.keys dhts -> switchNetwork n 732
733 ("help", s) | Just DHT{..} <- Map.lookup netname dhts
734 -> cmd0 $ do
735 let tolist :: a -> [a]
736 tolist = (:[])
737
738 dhtkeys, announcables, links, ks, allcommands :: [[String]]
739 dhtkeys = map tolist $ Map.keys dhts
740 announcables = map (tolist . ("s "++)) $ Map.keys dhtAnnouncables
741 links = map (tolist . ("c "++)) $ Map.keys dhtLinks
742 ks = [["k gen"],["k public"],["k secret"]]
743 allcommands = sortBy (comparing head) $ concat [sessionCommands, dhtkeys, announcables, links, ks]
744
745 hPutClient h ("Available commands:\n" ++ showColumns allcommands)
704 746
705 _ -> cmd0 $ hPutClient h "error." 747 _ -> cmd0 $ hPutClient h "error."
706 748