summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-12-22 11:54:17 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-01 23:28:00 -0500
commit74ba73f2923a3b4f49bff2333a5769386eedc5e4 (patch)
tree7b5e6196273ac75a1bfce8540c7b8a18cc29ee2a
parent57f909d36869dee02849bbc95cdc3216081fef32 (diff)
Convert zbase32 tox node-id to hex.
-rw-r--r--dht/examples/dhtd.hs7
-rw-r--r--dht/src/Network/Tox/NodeId.hs4
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
533 else hPutClient h "Run with +RTS -T to obtain live memory-usage information." 533 else hPutClient h "Run with +RTS -T to obtain live memory-usage information."
534 _ -> hPutClient h "error." 534 _ -> hPutClient h "error."
535 535
536 ("nid", s) | Just DHT{dhtParseId} <- Map.lookup netname dhts 536 ("nid", s) | Just DHT{dhtParseId,dhtShowHexId} <- Map.lookup netname dhts
537 -> cmd0 $ do 537 -> cmd0 $ do
538 hPutClient h $ case dhtParseId s of 538 hPutClient h $ case dhtParseId s of
539 Left e -> 539 Left e ->
@@ -550,7 +550,7 @@ clientSession s@Session{..} sock cnum h = do
550 jid = readMaybe $ '0':'x':nspam ++ "@" ++ show nid ++ ".tox" 550 jid = readMaybe $ '0':'x':nspam ++ "@" ++ show nid ++ ".tox"
551 in unlines [ maybe "" show jid 551 in unlines [ maybe "" show jid
552 , show nid ++ " nospam:" ++ nspam ] 552 , show nid ++ " nospam:" ++ nspam ]
553 Right nid -> show nid 553 Right nid -> maybe (show nid) (\shwhex -> unlines [show nid, shwhex nid]) dhtShowHexId
554 554
555 ("lan", _) -> cmd0 $ do 555 ("lan", _) -> cmd0 $ do
556 announceToLan 556 announceToLan
@@ -1615,6 +1615,7 @@ initTox opts ssvar keysdb mbxmpp invc = case porttox opts of
1615 , dhtBootstrap = case wantip of 1615 , dhtBootstrap = case wantip of
1616 Want_IP4 -> toxStrap4 1616 Want_IP4 -> toxStrap4
1617 Want_IP6 -> toxStrap6 1617 Want_IP6 -> toxStrap6
1618 , dhtShowHexId = Just $ Tox.showHexId
1618 } 1619 }
1619 tcpprober = tcpProber $ Tox.toxOnionRoutes tox 1620 tcpprober = tcpProber $ Tox.toxOnionRoutes tox
1620 tcpclient = tcpKademliaClient $ Tox.toxOnionRoutes tox 1621 tcpclient = tcpKademliaClient $ Tox.toxOnionRoutes tox
@@ -1642,6 +1643,7 @@ initTox opts ssvar keysdb mbxmpp invc = case porttox opts of
1642 , dhtSearches = tcpSearches 1643 , dhtSearches = tcpSearches
1643 , dhtFallbackNodes = return [] 1644 , dhtFallbackNodes = return []
1644 , dhtBootstrap = bootstrap tcpRefresher 1645 , dhtBootstrap = bootstrap tcpRefresher
1646 , dhtShowHexId = Just Tox.showHexId
1645 } 1647 }
1646 dhts = Map.fromList $ 1648 dhts = Map.fromList $
1647 ("tox4", toxDHT Tox.routing4 Want_IP4) 1649 ("tox4", toxDHT Tox.routing4 Want_IP4)
@@ -1797,6 +1799,7 @@ main = do
1797 , dhtBootstrap = case wantip of 1799 , dhtBootstrap = case wantip of
1798 Want_IP4 -> btBootstrap4 1800 Want_IP4 -> btBootstrap4
1799 Want_IP6 -> btBootstrap6 1801 Want_IP6 -> btBootstrap6
1802 , dhtShowHexId = Nothing
1800 } 1803 }
1801 dhts = Map.fromList $ 1804 dhts = Map.fromList $
1802 ("bt4", mainlineDHT Mainline.routing4 Want_IP4) 1805 ("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
41 , showToken32 41 , showToken32
42 , show32Token32 42 , show32Token32
43 , nodeInfoFromJSON 43 , nodeInfoFromJSON
44 , showHexId
44 ) where 45 ) where
45 46
46import Control.Applicative 47import Control.Applicative
@@ -174,6 +175,9 @@ instance S.Serialize NodeId where
174 get = key2id <$> getPublicKey 175 get = key2id <$> getPublicKey
175 put nid = putPublicKey $ id2key nid 176 put nid = putPublicKey $ id2key nid
176 177
178showHexId :: NodeId -> String
179showHexId nid = C8.unpack $ Base16.encode $ BA.convert $ id2key nid
180
177instance Hashable NodeId where 181instance Hashable NodeId where
178 hashWithSalt salt (NodeId ws _) = hashWithSalt salt (head ws) 182 hashWithSalt salt (NodeId ws _) = hashWithSalt salt (head ws)
179 183