diff options
author | joe <joe@jerkface.net> | 2017-11-08 00:44:20 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-11-08 02:30:43 -0500 |
commit | f7526e5dee6543404bedd1a13829305c9a107f15 (patch) | |
tree | d6c1372017854c30f6ef454557b7745bd9d7a638 /src/Network/Kademlia | |
parent | f76e017cf2e7a4af0db21d3b7006e85752b217fb (diff) |
Use 15 second refresh interval when bootstrapping.
Diffstat (limited to 'src/Network/Kademlia')
-rw-r--r-- | src/Network/Kademlia/Bootstrap.hs | 24 |
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 | ||
267 | effectiveRefreshInterval :: BucketRefresher nid ni -> Int -> STM POSIXTime | ||
268 | effectiveRefreshInterval 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 | -- |