From 921f845e56033b959247dc0347083e287963f677 Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 6 Sep 2017 01:27:36 -0400 Subject: Removed Data.Bits requirement for Kademlia node id. --- Kademlia.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'Kademlia.hs') diff --git a/Kademlia.hs b/Kademlia.hs index f2288642..2620948d 100644 --- a/Kademlia.hs +++ b/Kademlia.hs @@ -30,6 +30,7 @@ import qualified Data.Wrapper.PSQInt as Int ;import Data.Wrapper.PSQInt (pattern (:->)) import Network.Address (bucketRange,genBucketSample) import Network.BitTorrent.DHT.Search +import System.Entropy import System.Timeout import Text.PrettyPrint as PP hiding (($$), (<>)) import Text.PrettyPrint.HughesPJClass hiding (($$), (<>)) @@ -268,15 +269,17 @@ forkPollForRefresh interval psq refresh = do again refreshBucket :: forall nid tok ni addr. - ( Show nid, FiniteBits nid, Serialize nid, Ord nid, Ord ni, Hashable nid, Hashable ni, Ord addr ) => + ( Show nid, Serialize nid, Ord nid, Ord ni, Hashable nid, Hashable ni, Ord addr ) => Search nid addr tok ni ni -> TVar (BucketList ni) -> Int -> IO Int refreshBucket sch var n = do tbl <- atomically (readTVar var) let count = bktCount tbl nid = kademliaLocation (searchSpace sch) (thisNode tbl) - sample <- if n+1 >= count -- Is this the last bucket? - then return nid -- Yes? Search our own id. - else genBucketSample nid -- No? Generate a random id. + sample <- if n+1 >= count -- Is this the last bucket? + then return nid -- Yes? Search our own id. + else kademliaSample (searchSpace sch) -- No? Generate a random id. + getEntropy + nid (bucketRange n (n + 1 < count)) fin <- atomically $ newTVar False resultCounter <- atomically $ newTVar Set.empty @@ -314,7 +317,7 @@ refreshBucket sch var n = do bootstrap :: ( Show nid , Serialize nid - , FiniteBits nid + -- , FiniteBits nid , Hashable ni , Hashable nid , Ord ni -- cgit v1.2.3