subscribe lwwref

This commit is contained in:
Dmitry Zuikov 2024-03-14 13:43:01 +03:00
parent b6c85789b9
commit 97521d4577
3 changed files with 16 additions and 5 deletions

View File

@ -160,13 +160,17 @@ export key refs = do
reflog <- asks _refLogAPI
ip <- asks _progress
subscribeLWWRef key
lww@LWWBlockData{..} <- waitOrInitLWWRef
let puk0 = fromLwwRefKey key
debug $ red $ pretty $ AsBase58 lwwRefLogPubKey
(sk0,pk0) <- liftIO $ runKeymanClient do
creds <- loadCredentials lwwRefLogPubKey
>>= orThrowUser "can't load credentials"
creds <- loadCredentials puk0
>>= orThrowUser ("can't load credentials" <+> pretty (AsBase58 puk0))
pure ( view peerSignSk creds, view peerSignPk creds )
(puk,sk) <- derivedKey @HBS2Basic @'Sign lwwRefSeed sk0

View File

@ -72,6 +72,8 @@ importRepoWait lwwKey = do
meet <- newTVarIO (mempty :: HashMap HashRef Int)
subscribeLWWRef lwwKey
flip fix (IWaitLWWBlock 20) $ \next -> \case
IWaitLWWBlock w | w <= 0 -> do
@ -86,9 +88,8 @@ importRepoWait lwwKey = do
pause @'Seconds 2
next (IWaitLWWBlock (pred w))
Just blk -> do
error "FOUND SHIT!"
pure ()
Just (LWWBlockData{..}) -> do
next (IWaitRefLog 20 lwwRefLogPubKey)
IWaitRefLog w puk | w <= 0 -> do
throwIO ImportRefLogNotFound

View File

@ -3,6 +3,7 @@ module HBS2.Git.Client.RefLog where
import HBS2.Git.Client.Prelude
import HBS2.Git.Client.App.Types
import HBS2.Git.Data.RefLog
import HBS2.Git.Data.LWWBlock
data RefLogRequestTimeout = RefLogRequestTimeout
deriving (Show,Typeable)
@ -20,6 +21,11 @@ subscribeRefLog puk = do
void $ callService @RpcPollAdd api (puk, "reflog", 13)
subscribeLWWRef :: (GitPerks m, MonadReader GitEnv m) => LWWRefKey HBS2Basic -> m ()
subscribeLWWRef puk = do
api <- asks _peerAPI
void $ callService @RpcPollAdd api (fromLwwRefKey puk, "lwwref", 17)
getRefLogMerkle :: (GitPerks m, MonadReader GitEnv m) => RefLogId -> m (Maybe HashRef)
getRefLogMerkle puk = do