refactor trying to join on any bootstrap node into own function
contributes to #56
This commit is contained in:
parent
d293cc05d1
commit
56ca2b53cc
11
app/Main.hs
11
app/Main.hs
|
@ -21,17 +21,8 @@ main = do
|
||||||
(serverSock, thisNode) <- fediChordInit conf
|
(serverSock, thisNode) <- fediChordInit conf
|
||||||
-- currently no masking is necessary, as there is nothing to clean up
|
-- currently no masking is necessary, as there is nothing to clean up
|
||||||
cacheWriterThread <- forkIO $ cacheWriter thisNode
|
cacheWriterThread <- forkIO $ cacheWriter thisNode
|
||||||
thisNodeSnap <- readTVarIO thisNode
|
|
||||||
realNode <- readTVarIO $ parentRealNode thisNodeSnap
|
|
||||||
-- try joining the DHT using one of the provided bootstrapping nodes
|
-- try joining the DHT using one of the provided bootstrapping nodes
|
||||||
let
|
joinedState <- tryBootstrapJoining thisNode
|
||||||
tryJoining (bn:bns) = do
|
|
||||||
j <- fediChordBootstrapJoin thisNode bn
|
|
||||||
case j of
|
|
||||||
Left err -> putStrLn ("join error: " <> err) >> tryJoining bns
|
|
||||||
Right joined -> pure $ Right joined
|
|
||||||
tryJoining [] = pure $ Left "Exhausted all bootstrap points for joining."
|
|
||||||
joinedState <- tryJoining $ bootstrapNodes realNode
|
|
||||||
either (\err -> do
|
either (\err -> do
|
||||||
-- handle unsuccessful join
|
-- handle unsuccessful join
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ module Hash2Pub.FediChord (
|
||||||
, fediChordInit
|
, fediChordInit
|
||||||
, fediChordJoin
|
, fediChordJoin
|
||||||
, fediChordBootstrapJoin
|
, fediChordBootstrapJoin
|
||||||
|
, tryBootstrapJoining
|
||||||
, fediMainThreads
|
, fediMainThreads
|
||||||
, RealNode (..)
|
, RealNode (..)
|
||||||
, nodeStateInit
|
, nodeStateInit
|
||||||
|
@ -166,6 +167,25 @@ fediChordBootstrapJoin nsSTM (joinHost, joinPort) =
|
||||||
)
|
)
|
||||||
`catch` (\e -> pure . Left $ "Error at bootstrap joining: " <> displayException (e :: IOException))
|
`catch` (\e -> pure . Left $ "Error at bootstrap joining: " <> displayException (e :: IOException))
|
||||||
|
|
||||||
|
|
||||||
|
-- | Try joining the DHT through any of the bootstrapping nodes until it succeeds.
|
||||||
|
tryBootstrapJoining :: LocalNodeStateSTM -> IO (Either String LocalNodeStateSTM)
|
||||||
|
tryBootstrapJoining nsSTM = do
|
||||||
|
bss <- atomically $ do
|
||||||
|
nsSnap <- readTVar nsSTM
|
||||||
|
realNodeSnap <- readTVar $ parentRealNode nsSnap
|
||||||
|
pure $ bootstrapNodes realNodeSnap
|
||||||
|
tryJoining bss
|
||||||
|
where
|
||||||
|
tryJoining (bn:bns) = do
|
||||||
|
j <- fediChordBootstrapJoin nsSTM bn
|
||||||
|
case j of
|
||||||
|
Left err -> putStrLn ("join error: " <> err) >> tryJoining bns
|
||||||
|
Right joined -> pure $ Right joined
|
||||||
|
tryJoining [] = pure $ Left "Exhausted all bootstrap points for joining."
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- | join a node to the DHT, using the provided cache snapshot for resolving the new
|
-- | join a node to the DHT, using the provided cache snapshot for resolving the new
|
||||||
-- node's position.
|
-- node's position.
|
||||||
fediChordJoin :: NodeCache -- ^ a snapshot of the NodeCache to
|
fediChordJoin :: NodeCache -- ^ a snapshot of the NodeCache to
|
||||||
|
|
Loading…
Reference in a new issue