catch and handle bootstrap join errors
This commit is contained in:
parent
27e5c5f9ce
commit
6ff765c63e
|
@ -138,6 +138,7 @@ fediChordBootstrapJoin ns (joinHost, joinPort) =
|
||||||
initCache bootstrapResponse
|
initCache bootstrapResponse
|
||||||
fediChordJoin bootstrapCache ns
|
fediChordJoin bootstrapCache ns
|
||||||
)
|
)
|
||||||
|
`catch` (\e -> pure . Left $ "Error at bootstrap joining: " <> displayException (e :: IOException))
|
||||||
|
|
||||||
-- | 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.
|
||||||
|
|
|
@ -4,6 +4,7 @@ import Control.Concurrent
|
||||||
import Control.Exception
|
import Control.Exception
|
||||||
import Data.IP (IPv6, toHostAddress6)
|
import Data.IP (IPv6, toHostAddress6)
|
||||||
import System.Environment
|
import System.Environment
|
||||||
|
import Data.Either
|
||||||
|
|
||||||
import Hash2Pub.FediChord
|
import Hash2Pub.FediChord
|
||||||
|
|
||||||
|
@ -23,10 +24,21 @@ main = do
|
||||||
tryJoining (bn:bns) = do
|
tryJoining (bn:bns) = do
|
||||||
j <- fediChordBootstrapJoin thisNode bn
|
j <- fediChordBootstrapJoin thisNode bn
|
||||||
case j of
|
case j of
|
||||||
Left _ -> tryJoining bns
|
Left err -> putStrLn ("join error: " <> err) >> tryJoining bns
|
||||||
Right joined -> pure $ Right joined
|
Right joined -> pure $ Right joined
|
||||||
tryJoining [] = pure $ Left "Exhausted all bootstrap points for joining."
|
tryJoining [] = pure $ Left "Exhausted all bootstrap points for joining."
|
||||||
joinedState <- tryJoining $ confBootstrapNodes conf
|
joinedState <- tryJoining $ confBootstrapNodes conf
|
||||||
|
either (\err ->
|
||||||
|
-- handle unsuccessful join
|
||||||
|
|
||||||
|
putStrLn $ err <> " Error joining, start listening for incoming requests anyways"
|
||||||
|
-- TODO: periodic retry
|
||||||
|
)
|
||||||
|
(\joinedNS ->
|
||||||
|
-- launch main eventloop with successfully joined state
|
||||||
|
putStrLn ("successful join at " <> (show . getNid $ joinedNS))
|
||||||
|
)
|
||||||
|
joinedState
|
||||||
-- stop main thread from terminating during development
|
-- stop main thread from terminating during development
|
||||||
getChar
|
getChar
|
||||||
pure ()
|
pure ()
|
||||||
|
|
Loading…
Reference in a new issue