From 25f44f3a4572e2f7cbc6f4d9e5193989d6d21fd1 Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Wed, 24 Jun 2020 01:19:53 +0200 Subject: [PATCH] look up additional neighbours if necessary for #44 --- src/Hash2Pub/FediChord.hs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Hash2Pub/FediChord.hs b/src/Hash2Pub/FediChord.hs index a5967ad..db4ac61 100644 --- a/src/Hash2Pub/FediChord.hs +++ b/src/Hash2Pub/FediChord.hs @@ -217,15 +217,30 @@ stabiliseThread nsSTM = forever $ do -- TODO: update successfully stabilised nodes in cache -- try looking up additional neighbours if list too short + forM_ [(length $ predecessors updatedNs)..(kNeighbours updatedNs)] (\_ -> do + ns' <- readTVarIO nsSTM + nextEntry <- requestQueryID ns' $ pred . getNid $ atDef (toRemoteNodeState ns') (predecessors ns') (-1) + atomically $ do + latestNs <- readTVar nsSTM + writeTVar nsSTM $ addPredecessors [nextEntry] latestNs + ) +-- + forM_ [(length $ successors updatedNs)..(kNeighbours updatedNs)] (\_ -> do + ns' <- readTVarIO nsSTM + nextEntry <- requestQueryID ns' $ succ . getNid $ atDef (toRemoteNodeState ns') (successors ns') (-1) + atomically $ do + latestNs <- readTVar nsSTM + writeTVar nsSTM $ addSuccessors [nextEntry] latestNs + ) -- TODO: make delay configurable threadDelay (60 * 1000) where stabiliseClosestResponder :: LocalNodeState - -> (LocalNodeState -> [RemoteNodeState]) - -> Int - -> [RemoteNodeState] -- ^ delete accumulator - -> IO (Either String ([RemoteNodeState], [RemoteNodeState])) -- ^ (nodes to be deleted, successfully pinged potential neighbours) + -> (LocalNodeState -> [RemoteNodeState]) + -> Int + -> [RemoteNodeState] -- ^ delete accumulator + -> IO (Either String ([RemoteNodeState], [RemoteNodeState])) -- ^ (nodes to be deleted, successfully pinged potential neighbours) stabiliseClosestResponder ns neighbourGetter neighbourNum deleteAcc | isNothing (currentNeighbour ns neighbourGetter neighbourNum) = pure $ Left "exhausted all neigbours" | otherwise = do