summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-12-02 22:19:37 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-01 23:22:52 -0500
commit457fec85e4b5e707d578df267ce5f5331b126a7f (patch)
tree9d3f1fb387006aa141091babe66df49a3838e1b9
parent2e9253a8e49606e7c4c538e030ee6d7ef6893c52 (diff)
Command 'r' to generate random node ids.
-rw-r--r--dht/dht-client.cabal1
-rw-r--r--dht/examples/dhtd.hs14
2 files changed, 15 insertions, 0 deletions
diff --git a/dht/dht-client.cabal b/dht/dht-client.cabal
index a2a86b95..feaf2ed4 100644
--- a/dht/dht-client.cabal
+++ b/dht/dht-client.cabal
@@ -334,6 +334,7 @@ executable dhtd
334 , filepath 334 , filepath
335 , process 335 , process
336 , cereal-conduit >= 0.7.3 336 , cereal-conduit >= 0.7.3
337 , cryptonite
337 338
338 if flag(thread-debug) 339 if flag(thread-debug)
339 build-depends: time 340 build-depends: time
diff --git a/dht/examples/dhtd.hs b/dht/examples/dhtd.hs
index 9c03a4f9..d028a308 100644
--- a/dht/examples/dhtd.hs
+++ b/dht/examples/dhtd.hs
@@ -28,6 +28,7 @@ import Control.Concurrent.STM.TMChan
28import Control.Exception 28import Control.Exception
29import Control.Monad 29import Control.Monad
30import Control.Monad.IO.Class (liftIO) 30import Control.Monad.IO.Class (liftIO)
31import Crypto.Random (getRandomBytes)
31import Data.Array.MArray (getAssocs) 32import Data.Array.MArray (getAssocs)
32import Data.Bool 33import Data.Bool
33import Data.Bits (xor) 34import Data.Bits (xor)
@@ -400,6 +401,7 @@ clientSession s@Session{..} sock cnum h = do
400 , ["nid"] 401 , ["nid"]
401 , ["lan"] 402 , ["lan"]
402 , ["ls"] 403 , ["ls"]
404 , ["r"]
403 , ["k"] 405 , ["k"]
404 , ["roster"] 406 , ["roster"]
405 , ["sessions"] 407 , ["sessions"]
@@ -553,6 +555,18 @@ clientSession s@Session{..} sock cnum h = do
553 , ("node-id", show $ thisNode bkts) 555 , ("node-id", show $ thisNode bkts)
554 , ("network", netname) ] 556 , ("network", netname) ]
555 557
558 ("r", s) | Just DHT{dhtQuery,dhtBuckets} <- Map.lookup netname dhts
559 , Just DHTQuery{qsearch} <- Map.lookup "node" dhtQuery
560 -> cmd0 $ do
561 ni <- atomically $ thisNode <$> readTVar dhtBuckets
562 let kad = searchSpace qsearch
563 nid = kademliaLocation kad ni
564 b = case readMaybe $ strp s of
565 Nothing -> bucketRange 0 True
566 Just n -> bucketRange n False
567 rnid <- kademliaSample kad getRandomBytes nid b
568 hPutClient h $ show rnid
569
556 -- TODO: online documentation. 570 -- TODO: online documentation.
557 -- 571 --
558 -- k - manage key-pairs 572 -- k - manage key-pairs