From 8e442fb2a71ec85d47127d90319b1bf2c2767fda Mon Sep 17 00:00:00 2001 From: joe Date: Sat, 28 Oct 2017 19:22:38 -0400 Subject: Expose DHT secret key in the "secrets" method output. --- examples/dhtd.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/dhtd.hs b/examples/dhtd.hs index 4de735bc..ebc8b69e 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs @@ -145,6 +145,7 @@ data DHT = forall nid ni. ( Show ni ) => DHT { dhtBuckets :: TVar (BucketList ni) + , dhtSecretKey :: STM (Maybe SecretKey) , dhtPing :: Map.Map String (DHTPing ni) , dhtQuery :: Map.Map String (DHTQuery nid ni) , dhtAnnouncables :: Map.Map String DHTAnnouncable @@ -435,7 +436,11 @@ clientSession s@Session{..} sock cnum h = do ++ [mappend " *" . show . Tox.key2id $ pubkey] | "secrets" <- strp s -> cmd0 $ do ks <- atomically $ readTVar userkeys - hPutClient h . showReport $ map mkrow ks + skey <- maybe (return Nothing) (atomically . dhtSecretKey) + $ Map.lookup netname dhts + hPutClient h . showReport $ map mkrow ks ++ case skey >>= encodeSecret of + Just x -> [("",""),("dht-key:",B.unpack x)] + Nothing -> [] | ("add":secs) <- words s , mbSecs <- map (decodeSecret . B.pack) secs , all isJust mbSecs -> cmd0 $ do @@ -713,6 +718,7 @@ main = do Just _ -> return Nothing })] + , dhtSecretKey = return Nothing } dhts = Map.fromList $ ("bt4", mainlineDHT Mainline.routing4 Want_IP4) @@ -836,6 +842,7 @@ main = do Right (pubkey :: PublicKey, nospam) return r })] + , dhtSecretKey = return $ Just $ transportSecret (Tox.toxCryptoKeys tox) } dhts = Map.fromList $ ("tox4", toxDHT Tox.routing4) @@ -873,9 +880,9 @@ main = do forM_ (Map.toList dhts) $ \(netname, dht@DHT { dhtBuckets = bkts - , dhtQuery = qrys - , dhtPing = pings - , dhtFallbackNodes = getBootstrapNodes }) -> do + , dhtQuery = qrys + , dhtPing = pings + , dhtFallbackNodes = getBootstrapNodes }) -> do btSaved <- loadNodes netname -- :: IO [Mainline.NodeInfo] putStrLn $ "Loaded "++show (length btSaved)++" nodes for "++netname++"." fallbackNodes <- getBootstrapNodes -- cgit v1.2.3