This commit is contained in:
Dmitry Zuikov 2024-09-16 19:26:06 +03:00
parent 7375a52788
commit fdb16f96b7
1 changed files with 28 additions and 28 deletions

View File

@ -53,43 +53,43 @@ loadGroupKey = do
flip fix 0 $ \next -> \case flip fix 0 $ \next -> \case
attempt | attempt > 2 -> mzero attempt | attempt > 2 -> mzero
attempt -> do attempt -> do
let readers = view refChanHeadReaders rch let readers = view refChanHeadReaders rch
gkHash <- liftIO (try @_ @IOError $ readFile gkF) gkHash <- liftIO (try @_ @IOError $ readFile gkF)
<&> either (const Nothing) ( (=<<) (fromStringMay @HashRef) . headMay . lines ) <&> either (const Nothing) ( (=<<) (fromStringMay @HashRef) . headMay . lines )
debug $ "GK0" <+> pretty gkHash debug $ "GK0" <+> pretty gkHash
case gkHash of case gkHash of
Nothing -> do Nothing -> do
debug "generate new group key" debug "generate new group key"
gknew <- generateGroupKey @'HBS2Basic Nothing (HS.toList readers) gknew <- generateGroupKey @'HBS2Basic Nothing (HS.toList readers)
ha <- writeAsMerkle sto (serialise gknew) ha <- writeAsMerkle sto (serialise gknew)
liftIO $ writeFile gkF (show $ pretty ha) liftIO $ writeFile gkF (show $ pretty ha)
next (succ attempt) next (succ attempt)
Just h -> do Just h -> do
now <- liftIO $ getPOSIXTime <&> round now <- liftIO $ getPOSIXTime <&> round
gk' <- loadGroupKeyMaybe @s sto h gk' <- loadGroupKeyMaybe @s sto h
(_,gk) <- maybe1 gk' (rm gkF >> next (succ attempt)) (pure . (h,)) (_,gk) <- maybe1 gk' (rm gkF >> next (succ attempt)) (pure . (h,))
let ts = getGroupKeyTimestamp gk & fromMaybe 0 let ts = getGroupKeyTimestamp gk & fromMaybe 0
-- FIXME: timeout-hardcode -- FIXME: timeout-hardcode
-- $class: hardcode -- $class: hardcode
if | now - ts > 2592000 -> do if | now - ts > 2592000 -> do
rm gkF rm gkF
next (succ attempt) next (succ attempt)
| HM.keysSet (recipients gk) /= readers -> do | HM.keysSet (recipients gk) /= readers -> do
rm gkF rm gkF
next (succ attempt) next (succ attempt)
| otherwise -> do | otherwise -> do
pure (h,gk) pure (h,gk)