From 1739669e4714752529ce84ad48ebf17ad942784d Mon Sep 17 00:00:00 2001 From: voidlizard Date: Sun, 13 Oct 2024 16:36:24 +0300 Subject: [PATCH] wip, gossip on policy update --- hbs2-peer/app/MailboxProtoWorker.hs | 14 ++++++++++++-- hbs2-peer/app/RPC2/Mailbox.hs | 5 +++-- hbs2-peer/lib/HBS2/Peer/Proto/Mailbox.hs | 4 ---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/hbs2-peer/app/MailboxProtoWorker.hs b/hbs2-peer/app/MailboxProtoWorker.hs index 4ad57f9f..c57362b5 100644 --- a/hbs2-peer/app/MailboxProtoWorker.hs +++ b/hbs2-peer/app/MailboxProtoWorker.hs @@ -168,7 +168,7 @@ instance ( s ~ Encryption e, e ~ L4Proto Right{} -> pure $ Right () Left{} -> pure $ Left (MailboxCreateFailed "database operation") - mailboxSetPolicy MailboxProtoWorker{..} sbox = do + mailboxSetPolicy me@MailboxProtoWorker{..} sbox = do -- check policy version -- check policy has peers -- write policy block @@ -211,7 +211,17 @@ instance ( s ~ Encryption e, e ~ L4Proto on conflict (mailbox) do update set hash = excluded.hash |] (MailboxRefKey @s who, PolicyHash what) - -- TODO: ASAP-gossip-new-state + + void $ runMaybeT do + msp <- mailboxGetStatus me (MailboxRefKey @s who) + >>= toMPlus + >>= toMPlus + + creds <- mailboxGetCredentials @s me + let box = makeSignedBox @s (view peerSignPk creds) (view peerSignSk creds) msp + + liftIO $ withPeerM mpwPeerEnv do + gossip (MailBoxProtoV1 @s @e (MailboxStatus box)) pure what diff --git a/hbs2-peer/app/RPC2/Mailbox.hs b/hbs2-peer/app/RPC2/Mailbox.hs index f3926430..0076e35d 100644 --- a/hbs2-peer/app/RPC2/Mailbox.hs +++ b/hbs2-peer/app/RPC2/Mailbox.hs @@ -29,8 +29,9 @@ import Lens.Micro.Platform import Control.Monad.Reader import Control.Monad.Trans.Maybe -type ForMailboxRPC m = (MonadIO m, HasRpcContext MailboxAPI RPC2Context m) - +type ForMailboxRPC m = ( MonadIO m + , HasRpcContext MailboxAPI RPC2Context m + ) instance (MonadIO m) => HandleMethod m RpcMailboxPoke where diff --git a/hbs2-peer/lib/HBS2/Peer/Proto/Mailbox.hs b/hbs2-peer/lib/HBS2/Peer/Proto/Mailbox.hs index 62b69e97..2219f198 100644 --- a/hbs2-peer/lib/HBS2/Peer/Proto/Mailbox.hs +++ b/hbs2-peer/lib/HBS2/Peer/Proto/Mailbox.hs @@ -71,7 +71,6 @@ data MailBoxProtoMessage s e = SendMessage (Message s) -- already has signed box | CheckMailbox (Maybe Word64) (MailboxKey s) | MailboxStatus (SignedBox (MailBoxStatusPayload s) s) -- signed by peer - | SetPolicy (SignedBox (SetPolicyPayload s) s) | DeleteMessages (SignedBox (DeleteMessagesPayload s) s) deriving stock (Generic) @@ -340,9 +339,6 @@ mailboxProto inner adapter mess = deferred @p do void $ mailboxAcceptStatus adapter (MailboxRefKey mbsMailboxKey) who content - SetPolicy{} -> do - none - DeleteMessages{} -> do none