From f76e017cf2e7a4af0db21d3b7006e85752b217fb Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 8 Nov 2017 00:35:10 -0500 Subject: pollForRefresh: fromEnum POSIXTime gives picoseconds. --- src/Network/Kademlia/Bootstrap.hs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/Network/Kademlia') diff --git a/src/Network/Kademlia/Bootstrap.hs b/src/Network/Kademlia/Bootstrap.hs index 595659d2..b71704d9 100644 --- a/src/Network/Kademlia/Bootstrap.hs +++ b/src/Network/Kademlia/Bootstrap.hs @@ -126,10 +126,10 @@ updateRefresherIO sch ping BucketRefresher{..} = BucketRefresher -- | Fork a refresh loop. Kill the returned thread to terminate it. forkPollForRefresh :: SensibleNodeId nid ni => BucketRefresher nid ni -> IO ThreadId -forkPollForRefresh BucketRefresher{ refreshInterval - , refreshQueue - , refreshBuckets - , refreshSearch } = fork $ do +forkPollForRefresh r@BucketRefresher{ refreshInterval + , refreshQueue + , refreshBuckets + , refreshSearch } = fork $ do myThreadId >>= flip labelThread "pollForRefresh" fix $ \again -> do join $ atomically $ do @@ -137,7 +137,9 @@ forkPollForRefresh BucketRefresher{ refreshInterval maybe retry (return . go again) nextup where refresh :: Int -> IO Int - refresh = refreshBucket refreshSearch refreshBuckets + refresh n = do + hPutStrLn stderr $ "Refresh time! "++ show n + refreshBucket r n go again ( bktnum :-> refresh_time ) = do now <- getPOSIXTime @@ -152,7 +154,9 @@ forkPollForRefresh BucketRefresher{ refreshInterval _ <- refresh bktnum return () return () - seconds -> threadDelay ( seconds * 1000000 ) + picoseconds -> do + hPutStrLn stderr $ show (picoseconds `div` 10^12) ++ " seconds until refresh " ++ show bktnum + threadDelay ( picoseconds `div` 10^6 ) again @@ -184,9 +188,11 @@ checkBucketFull space var resultCounter fin n found_node = do _ -> False -- okay, good enough, let's quit. -refreshBucket :: (Hashable a, Hashable t, Ord t, Ord addr, Ord a, Show t) => - Search t addr tok a a -> TVar (BucketList a) -> Int -> IO Int -refreshBucket sch var n = do +refreshBucket :: (Show nid, Ord ni, Ord nid, Hashable nid, Hashable ni) => + BucketRefresher nid ni -> Int -> IO Int +refreshBucket r@BucketRefresher{ refreshSearch = sch + , refreshBuckets = var } + n = do tbl <- atomically (readTVar var) let count = bktCount tbl nid = kademliaLocation (searchSpace sch) (thisNode tbl) @@ -216,9 +222,9 @@ refreshBucket sch var n = do return rcount refreshLastBucket :: SensibleNodeId nid ni => BucketRefresher nid ni -> IO () -refreshLastBucket r@BucketRefresher { refreshBuckets, refreshSearch } = do +refreshLastBucket r@BucketRefresher { refreshBuckets } = do cnt <- atomically $ bktCount <$> readTVar refreshBuckets - void $ refreshBucket refreshSearch refreshBuckets (cnt - 1) + void $ refreshBucket r (cnt - 1) bootstrap :: (Ord ni, Ord nid, Hashable nid, Hashable ni, Foldable t, Foldable t1, Show nid) => BucketRefresher nid ni -- cgit v1.2.3