Skip to content

Commit

Permalink
Simplify and cleanup MLS message handling (#2844)
Browse files Browse the repository at this point in the history
* Store group info outside commit processing

* Extract external commit logic

* Avoid multiple pattern matches on sender

* Remove redundand epoch check

* Add ClientId to MLS messaging API

* Add CHANGELOG entry

* Store group info bundle after processing commit
  • Loading branch information
pcapriotti authored Nov 15, 2022
1 parent 6c313ca commit 815cbbd
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 132 deletions.
1 change: 1 addition & 0 deletions changelog.d/5-internal/refactor-mls-message
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor and simplify MLS message handling logic
3 changes: 3 additions & 0 deletions libs/wire-api/src/Wire/API/Routes/Public.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Wire.API.Routes.Public
ZLocalUser,
ZConn,
ZOptUser,
ZOptClient,
ZOptConn,
ZBot,
ZConversation,
Expand Down Expand Up @@ -179,6 +180,8 @@ type ZProvider = ZAuthServant 'ZAuthProvider InternalAuthDefOpts

type ZOptUser = ZAuthServant 'ZAuthUser '[Servant.Optional, Servant.Strict]

type ZOptClient = ZAuthServant 'ZAuthClient '[Servant.Optional, Servant.Strict]

type ZOptConn = ZAuthServant 'ZAuthConn '[Servant.Optional, Servant.Strict]

instance HasSwagger api => HasSwagger (ZAuthServant 'ZAuthUser _opts :> api) where
Expand Down
3 changes: 3 additions & 0 deletions libs/wire-api/src/Wire/API/Routes/Public/Galley/MLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type MLSMessagingAPI =
:> CanThrow 'MissingLegalholdConsent
:> CanThrow MLSProposalFailure
:> "messages"
:> ZOptClient
:> ZConn
:> ReqBody '[MLS] (RawMLS SomeMessage)
:> MultiVerb1 'POST '[JSON] (Respond 201 "Message sent" [Event])
Expand All @@ -91,6 +92,7 @@ type MLSMessagingAPI =
:> CanThrow 'MissingLegalholdConsent
:> CanThrow MLSProposalFailure
:> "messages"
:> ZOptClient
:> ZConn
:> ReqBody '[MLS] (RawMLS SomeMessage)
:> MultiVerb1 'POST '[JSON] (Respond 201 "Message sent" MLSMessageSendingStatus)
Expand Down Expand Up @@ -118,6 +120,7 @@ type MLSMessagingAPI =
:> CanThrow 'MissingLegalholdConsent
:> CanThrow MLSProposalFailure
:> "commit-bundles"
:> ZOptClient
:> ZConn
:> ReqBody '[CommitBundleMimeType] CommitBundle
:> MultiVerb1 'POST '[JSON] (Respond 201 "Commit accepted and forwarded" MLSMessageSendingStatus)
Expand Down
4 changes: 2 additions & 2 deletions services/galley/src/Galley/API/Federation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ sendMLSCommitBundle remoteDomain msr =
qcnv <- E.getConversationIdByGroupId (msgGroupId msg) >>= noteS @'ConvNotFound
when (qUnqualified qcnv /= F.msrConvId msr) $ throwS @'MLSGroupConversationMismatch
F.MLSMessageResponseUpdates . map lcuUpdate
<$> postMLSCommitBundle loc (qUntagged sender) qcnv Nothing bundle
<$> postMLSCommitBundle loc (qUntagged sender) Nothing qcnv Nothing bundle

sendMLSMessage ::
( Members
Expand Down Expand Up @@ -680,7 +680,7 @@ sendMLSMessage remoteDomain msr =
qcnv <- E.getConversationIdByGroupId (msgGroupId msg) >>= noteS @'ConvNotFound
when (qUnqualified qcnv /= F.msrConvId msr) $ throwS @'MLSGroupConversationMismatch
F.MLSMessageResponseUpdates . map lcuUpdate
<$> postMLSMessage loc (qUntagged sender) qcnv Nothing raw
<$> postMLSMessage loc (qUntagged sender) Nothing qcnv Nothing raw

class ToGalleyRuntimeError (effs :: EffectRow) r where
mapToGalleyError ::
Expand Down
Loading

0 comments on commit 815cbbd

Please sign in to comment.