From d1ce5a1dad8faca6cab13ca4c2612c1208d52850 Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 20 May 2018 00:17:35 -0400 Subject: Implemented "nid" command to convert hex toxid. --- examples/dhtd.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/dhtd.hs b/examples/dhtd.hs index b3c60015..918df327 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs @@ -449,12 +449,16 @@ clientSession s@Session{..} sock cnum h = do mkrow _ = error (concat ["Assertion fail in 'mkrow' function at ", __FILE__, ":", show __LINE__]) sessionCommands :: [[String]] sessionCommands = - [ ["stop"] + [ ["ping"] -- pinglike + , ["cookie"] -- pinglike + , ["stop"] + , ["throw"] , ["quit"] , ["pid"] , ["external-ip"] , ["threads"] , ["mem"] + , ["nid"] , ["ls"] , ["k"] , ["roster"] @@ -471,7 +475,6 @@ clientSession s@Session{..} sock cnum h = do , ["toxids"] , ["c"] , ["help"] - , ["throw"] ] case (map toLower c,args) of (n, _) | n `elem` Map.keys dhts -> switchNetwork n @@ -550,6 +553,16 @@ clientSession s@Session{..} sock cnum h = do else hPutClient h "Run with +RTS -T to obtain live memory-usage information." _ -> hPutClient h "error." + ("nid", s) | Just DHT{dhtParseId} <- Map.lookup netname dhts + -> cmd0 $ do + hPutClient h $ case dhtParseId s of + Left e -> + -- HACK: split nospam from hex toxid + case dhtParseId (take 64 s) of + Left e -> "Error: " ++ e + Right nid -> show nid ++ " nospam:" ++ drop 64 s + Right nid -> show nid + ("ls", _) | Just DHT{dhtBuckets} <- Map.lookup netname dhts -> cmd0 $ do bkts <- atomically $ readTVar dhtBuckets -- cgit v1.2.3