From 74ba73f2923a3b4f49bff2333a5769386eedc5e4 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sun, 22 Dec 2019 11:54:17 -0500 Subject: Convert zbase32 tox node-id to hex. --- dht/examples/dhtd.hs | 7 +++++-- dht/src/Network/Tox/NodeId.hs | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/dht/examples/dhtd.hs b/dht/examples/dhtd.hs index 35b0d07b..71be24eb 100644 --- a/dht/examples/dhtd.hs +++ b/dht/examples/dhtd.hs @@ -533,7 +533,7 @@ 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 + ("nid", s) | Just DHT{dhtParseId,dhtShowHexId} <- Map.lookup netname dhts -> cmd0 $ do hPutClient h $ case dhtParseId s of Left e -> @@ -550,7 +550,7 @@ clientSession s@Session{..} sock cnum h = do jid = readMaybe $ '0':'x':nspam ++ "@" ++ show nid ++ ".tox" in unlines [ maybe "" show jid , show nid ++ " nospam:" ++ nspam ] - Right nid -> show nid + Right nid -> maybe (show nid) (\shwhex -> unlines [show nid, shwhex nid]) dhtShowHexId ("lan", _) -> cmd0 $ do announceToLan @@ -1615,6 +1615,7 @@ initTox opts ssvar keysdb mbxmpp invc = case porttox opts of , dhtBootstrap = case wantip of Want_IP4 -> toxStrap4 Want_IP6 -> toxStrap6 + , dhtShowHexId = Just $ Tox.showHexId } tcpprober = tcpProber $ Tox.toxOnionRoutes tox tcpclient = tcpKademliaClient $ Tox.toxOnionRoutes tox @@ -1642,6 +1643,7 @@ initTox opts ssvar keysdb mbxmpp invc = case porttox opts of , dhtSearches = tcpSearches , dhtFallbackNodes = return [] , dhtBootstrap = bootstrap tcpRefresher + , dhtShowHexId = Just Tox.showHexId } dhts = Map.fromList $ ("tox4", toxDHT Tox.routing4 Want_IP4) @@ -1797,6 +1799,7 @@ main = do , dhtBootstrap = case wantip of Want_IP4 -> btBootstrap4 Want_IP6 -> btBootstrap6 + , dhtShowHexId = Nothing } dhts = Map.fromList $ ("bt4", mainlineDHT Mainline.routing4 Want_IP4) diff --git a/dht/src/Network/Tox/NodeId.hs b/dht/src/Network/Tox/NodeId.hs index a3ddd617..d05e3697 100644 --- a/dht/src/Network/Tox/NodeId.hs +++ b/dht/src/Network/Tox/NodeId.hs @@ -41,6 +41,7 @@ module Network.Tox.NodeId , showToken32 , show32Token32 , nodeInfoFromJSON + , showHexId ) where import Control.Applicative @@ -174,6 +175,9 @@ instance S.Serialize NodeId where get = key2id <$> getPublicKey put nid = putPublicKey $ id2key nid +showHexId :: NodeId -> String +showHexId nid = C8.unpack $ Base16.encode $ BA.convert $ id2key nid + instance Hashable NodeId where hashWithSalt salt (NodeId ws _) = hashWithSalt salt (head ws) -- cgit v1.2.3