diff options
author | Joe Crayne <joe@jerkface.net> | 2019-12-02 22:19:37 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-01 23:22:52 -0500 |
commit | 457fec85e4b5e707d578df267ce5f5331b126a7f (patch) | |
tree | 9d3f1fb387006aa141091babe66df49a3838e1b9 /dht | |
parent | 2e9253a8e49606e7c4c538e030ee6d7ef6893c52 (diff) |
Command 'r' to generate random node ids.
Diffstat (limited to 'dht')
-rw-r--r-- | dht/dht-client.cabal | 1 | ||||
-rw-r--r-- | dht/examples/dhtd.hs | 14 |
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 | |||
28 | import Control.Exception | 28 | import Control.Exception |
29 | import Control.Monad | 29 | import Control.Monad |
30 | import Control.Monad.IO.Class (liftIO) | 30 | import Control.Monad.IO.Class (liftIO) |
31 | import Crypto.Random (getRandomBytes) | ||
31 | import Data.Array.MArray (getAssocs) | 32 | import Data.Array.MArray (getAssocs) |
32 | import Data.Bool | 33 | import Data.Bool |
33 | import Data.Bits (xor) | 34 | import 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 |