summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Network/Kademlia/Bootstrap.hs24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/Network/Kademlia/Bootstrap.hs b/src/Network/Kademlia/Bootstrap.hs
index b71704d9..f160000d 100644
--- a/src/Network/Kademlia/Bootstrap.hs
+++ b/src/Network/Kademlia/Bootstrap.hs
@@ -146,8 +146,10 @@ forkPollForRefresh r@BucketRefresher{ refreshInterval
146 case fromEnum (refresh_time - now) of 146 case fromEnum (refresh_time - now) of
147 x | x <= 0 -> do -- Refresh time! 147 x | x <= 0 -> do -- Refresh time!
148 -- Move it to the back of the refresh queue. 148 -- Move it to the back of the refresh queue.
149 atomically $ modifyTVar' refreshQueue 149 atomically $ do
150 $ Int.insert bktnum (now + refreshInterval) 150 interval <- effectiveRefreshInterval r bktnum
151 modifyTVar' refreshQueue
152 $ Int.insert bktnum (now + interval)
151 -- Now fork the refresh operation. 153 -- Now fork the refresh operation.
152 -- TODO: We should probably propogate the kill signal to this thread. 154 -- TODO: We should probably propogate the kill signal to this thread.
153 fork $ do myThreadId >>= flip labelThread ("refresh."++show bktnum) 155 fork $ do myThreadId >>= flip labelThread ("refresh."++show bktnum)
@@ -262,6 +264,24 @@ bootstrap r@BucketRefresher { refreshSearch = sch
262 -- maintenance. 264 -- maintenance.
263 265
264 266
267effectiveRefreshInterval :: BucketRefresher nid ni -> Int -> STM POSIXTime
268effectiveRefreshInterval BucketRefresher{ refreshInterval
269 , refreshBuckets
270 , bootstrapMode } num = do
271 tbl <- readTVar refreshBuckets
272 bootstrapping <- readTVar bootstrapMode
273 case bootstrapping of
274 False -> return refreshInterval
275 True -> do
276 -- When bootstrapping, refresh interval for non-full buckets is only 15 seconds.
277 let fullcount = R.defaultBucketSize
278 count = fromMaybe fullcount $ listToMaybe $ drop (num - 1) $ R.shape tbl
279 if count == fullcount
280 then return refreshInterval
281 else return 15 -- seconds
282
283
284
265-- | Reschedule a bucket's refresh-time. It should be called whenever a bucket 285-- | Reschedule a bucket's refresh-time. It should be called whenever a bucket
266-- changes. This will typically be invoked from 'tblTransition'. 286-- changes. This will typically be invoked from 'tblTransition'.
267-- 287--