|
23 | 23 |
|
24 | 24 | import Control.Comonad
|
25 | 25 | import Control.Lens (forOf_)
|
| 26 | +import Control.Monad.Codensity |
26 | 27 | import Data.Map qualified as Map
|
27 | 28 | import Data.Qualified
|
28 | 29 | import Data.Set qualified as Set
|
@@ -141,52 +142,56 @@ processExternalCommit ::
|
141 | 142 | Epoch ->
|
142 | 143 | ExternalCommitAction ->
|
143 | 144 | Maybe UpdatePath ->
|
144 |
| - Sem r () |
| 145 | + Codensity (Sem r) () |
145 | 146 | processExternalCommit senderIdentity lConvOrSub ciphersuite ciphersuiteUpdate epoch action updatePath = do
|
146 | 147 | let convOrSub = tUnqualified lConvOrSub
|
147 | 148 |
|
148 | 149 | -- only members can join a subconversation
|
149 | 150 | forOf_ _SubConv convOrSub $ \(mlsConv, _) ->
|
150 | 151 | unless (isClientMember senderIdentity (mcMembers mlsConv)) $
|
151 |
| - throwS @'MLSSubConvClientNotInParent |
| 152 | + lift $ |
| 153 | + throwS @'MLSSubConvClientNotInParent |
152 | 154 |
|
153 | 155 | -- extract leaf node from update path and validate it
|
154 | 156 | leafNode <-
|
155 | 157 | (.leaf)
|
156 |
| - <$> note |
157 |
| - (mlsProtocolError "External commits need an update path") |
158 |
| - updatePath |
| 158 | + <$> lift |
| 159 | + ( note |
| 160 | + (mlsProtocolError "External commits need an update path") |
| 161 | + updatePath |
| 162 | + ) |
159 | 163 | let groupId = cnvmlsGroupId convOrSub.mlsMeta
|
160 | 164 | let extra = LeafNodeTBSExtraCommit groupId action.add
|
161 | 165 | case validateLeafNode ciphersuite (Just senderIdentity) extra leafNode.value of
|
162 | 166 | Left errMsg ->
|
163 |
| - throw $ |
| 167 | + lift . throw $ |
164 | 168 | mlsProtocolError ("Tried to add invalid LeafNode: " <> errMsg)
|
165 | 169 | Right _ -> pure ()
|
166 | 170 |
|
167 |
| - withCommitLock (fmap (.id) lConvOrSub) groupId epoch $ do |
168 |
| - executeExternalCommitAction lConvOrSub senderIdentity action |
| 171 | + withCommitLock (fmap (.id) lConvOrSub) groupId epoch |
169 | 172 |
|
170 |
| - -- increment epoch number |
171 |
| - lConvOrSub' <- for lConvOrSub incrementEpoch |
| 173 | + lift $ executeExternalCommitAction lConvOrSub senderIdentity action |
172 | 174 |
|
173 |
| - -- fetch backend remove proposals of the previous epoch |
174 |
| - indices0 <- getPendingBackendRemoveProposals groupId epoch |
| 175 | + -- increment epoch number |
| 176 | + lConvOrSub' <- for lConvOrSub $ lift . incrementEpoch |
175 | 177 |
|
176 |
| - -- skip proposals for clients already removed by the external commit |
177 |
| - let indices = maybe id Set.delete action.remove indices0 |
| 178 | + -- fetch backend remove proposals of the previous epoch |
| 179 | + indices0 <- lift $ getPendingBackendRemoveProposals groupId epoch |
178 | 180 |
|
179 |
| - -- set cipher suite |
180 |
| - when ciphersuiteUpdate $ case convOrSub.id of |
181 |
| - Conv cid -> setConversationCipherSuite cid ciphersuite |
182 |
| - SubConv cid sub -> setSubConversationCipherSuite cid sub ciphersuite |
| 181 | + -- skip proposals for clients already removed by the external commit |
| 182 | + let indices = maybe id Set.delete action.remove indices0 |
183 | 183 |
|
184 |
| - -- requeue backend remove proposals for the current epoch |
185 |
| - createAndSendRemoveProposals |
186 |
| - lConvOrSub' |
187 |
| - indices |
188 |
| - (cidQualifiedUser senderIdentity) |
189 |
| - (tUnqualified lConvOrSub').members |
| 184 | + -- set cipher suite |
| 185 | + lift $ when ciphersuiteUpdate $ case convOrSub.id of |
| 186 | + Conv cid -> setConversationCipherSuite cid ciphersuite |
| 187 | + SubConv cid sub -> setSubConversationCipherSuite cid sub ciphersuite |
| 188 | + |
| 189 | + -- requeue backend remove proposals for the current epoch |
| 190 | + createAndSendRemoveProposals |
| 191 | + lConvOrSub' |
| 192 | + (toList indices) |
| 193 | + (cidQualifiedUser senderIdentity) |
| 194 | + (tUnqualified lConvOrSub').members |
190 | 195 |
|
191 | 196 | executeExternalCommitAction ::
|
192 | 197 | forall r.
|
|
0 commit comments