mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-22 15:22:07 +00:00
all parties have resource state of the same kind
This commit is contained in:
1 parent
cf3afbac8a
commit
2b07f80828
8 files changed
+74
-131
No files matched your search
@@ -11,13 +11,12 @@
|
||||
module Simplex.Messaging.Broker where
|
||||
|
||||
import Control.Monad.Trans.Except
|
||||
import Control.Protocol (PartyCmd (..))
|
||||
import Polysemy.Internal
|
||||
import Simplex.Messaging.Protocol
|
||||
|
||||
instance Monad m => PartyProtocol m Broker where
|
||||
api ::
|
||||
SimplexCommand from (Cmd Broker s s') a ->
|
||||
SimplexCommand from '(Broker, s, s') a ->
|
||||
Connection Broker s ->
|
||||
ExceptT String m (a, Connection Broker s')
|
||||
api (CreateConn _) = apiStub
|
||||
@@ -29,7 +28,7 @@ instance Monad m => PartyProtocol m Broker where
|
||||
api (DeleteMsg _ _) = apiStub
|
||||
|
||||
action ::
|
||||
SimplexCommand (Cmd Broker s s') to a ->
|
||||
SimplexCommand '(Broker, s, s') to a ->
|
||||
Connection Broker s ->
|
||||
ExceptT String m a ->
|
||||
ExceptT String m (Connection Broker s')
|
||||
@@ -40,14 +39,14 @@ type SimplexBroker = SimplexParty Broker
|
||||
|
||||
api' ::
|
||||
Member SimplexBroker r =>
|
||||
SimplexCommand from (Cmd Broker s s') a ->
|
||||
SimplexCommand from '(Broker, s, s') a ->
|
||||
Connection Broker s ->
|
||||
Sem r (Either String (a, Connection Broker s'))
|
||||
api' cmd conn = send $ Api cmd conn
|
||||
|
||||
action' ::
|
||||
Member SimplexBroker r =>
|
||||
SimplexCommand (Cmd Broker s s') to a ->
|
||||
SimplexCommand '(Broker, s, s') to a ->
|
||||
Connection Broker s ->
|
||||
Either String a ->
|
||||
Sem r (Either String (Connection Broker s'))
|
||||
|
||||
@@ -11,20 +11,19 @@
|
||||
module Simplex.Messaging.Client where
|
||||
|
||||
import Control.Monad.Trans.Except
|
||||
import Control.Protocol (PartyCmd (..))
|
||||
import Polysemy.Internal
|
||||
import Simplex.Messaging.Protocol
|
||||
|
||||
instance Monad m => PartyProtocol m Recipient where
|
||||
api ::
|
||||
SimplexCommand from (Cmd Recipient s s') a ->
|
||||
SimplexCommand from '(Recipient, s, s') a ->
|
||||
Connection Recipient s ->
|
||||
ExceptT String m (a, Connection Recipient s')
|
||||
api (PushConfirm _ _) = apiStub
|
||||
api (PushMsg _ _) = apiStub
|
||||
|
||||
action ::
|
||||
SimplexCommand (Cmd Recipient s s') to a ->
|
||||
SimplexCommand '(Recipient, s, s') to a ->
|
||||
Connection Recipient s ->
|
||||
ExceptT String m a ->
|
||||
ExceptT String m (Connection Recipient s')
|
||||
@@ -37,13 +36,13 @@ instance Monad m => PartyProtocol m Recipient where
|
||||
|
||||
instance Monad m => PartyProtocol m Sender where
|
||||
api ::
|
||||
SimplexCommand from (Cmd Sender s s') a ->
|
||||
SimplexCommand from '(Sender, s, s') a ->
|
||||
Connection Sender s ->
|
||||
ExceptT String m (a, Connection Sender s')
|
||||
api (SendInvite _) = apiStub
|
||||
|
||||
action ::
|
||||
SimplexCommand (Cmd Sender s s') to a ->
|
||||
SimplexCommand '(Sender, s, s') to a ->
|
||||
Connection Sender s ->
|
||||
ExceptT String m a ->
|
||||
ExceptT String m (Connection Sender s')
|
||||
@@ -56,14 +55,14 @@ type SimplexSender = SimplexParty Sender
|
||||
|
||||
rApi ::
|
||||
Member SimplexRecipient r =>
|
||||
SimplexCommand from (Cmd Recipient s s') a ->
|
||||
SimplexCommand from '(Recipient, s, s') a ->
|
||||
Connection Recipient s ->
|
||||
Sem r (Either String (a, Connection Recipient s'))
|
||||
rApi cmd conn = send $ Api cmd conn
|
||||
|
||||
rAction ::
|
||||
Member SimplexRecipient r =>
|
||||
SimplexCommand (Cmd Recipient s s') to a ->
|
||||
SimplexCommand '(Recipient, s, s') to a ->
|
||||
Connection Recipient s ->
|
||||
Either String a ->
|
||||
Sem r (Either String (Connection Recipient s'))
|
||||
@@ -71,14 +70,14 @@ rAction cmd conn res = send $ Action cmd conn res
|
||||
|
||||
sApi ::
|
||||
Member SimplexSender r =>
|
||||
SimplexCommand from (Cmd Sender s s') a ->
|
||||
SimplexCommand from '(Sender, s, s') a ->
|
||||
Connection Sender s ->
|
||||
Sem r (Either String (a, Connection Sender s'))
|
||||
sApi cmd conn = send $ Api cmd conn
|
||||
|
||||
sAction ::
|
||||
Member SimplexSender r =>
|
||||
SimplexCommand (Cmd Sender s s') to a ->
|
||||
SimplexCommand '(Sender, s, s') to a ->
|
||||
Connection Sender s ->
|
||||
Either String a ->
|
||||
Sem r (Either String (Connection Sender s'))
|
||||
|
||||
@@ -25,75 +25,75 @@ import Simplex.Messaging.Types
|
||||
|
||||
type SimplexProtocol = Protocol SimplexCommand '[Recipient, Broker, Sender]
|
||||
|
||||
data SimplexCommand :: Command Party where
|
||||
data SimplexCommand :: Command Party ConnState where
|
||||
CreateConn ::
|
||||
PublicKey ->
|
||||
SimplexCommand
|
||||
(Cmd Recipient None New)
|
||||
(Cmd Broker None New)
|
||||
'(Recipient, None, New)
|
||||
'(Broker, None, New)
|
||||
CreateConnResponse
|
||||
Subscribe ::
|
||||
Enabled rs bs =>
|
||||
ConnId ->
|
||||
SimplexCommand
|
||||
(Cmd Recipient rs rs)
|
||||
(Cmd Broker bs bs)
|
||||
'(Recipient, rs, rs)
|
||||
'(Broker, bs, bs)
|
||||
()
|
||||
Unsubscribe ::
|
||||
Enabled rs bs =>
|
||||
ConnId ->
|
||||
SimplexCommand
|
||||
(Cmd Recipient rs rs)
|
||||
(Cmd Broker bs bs)
|
||||
'(Recipient, rs, rs)
|
||||
'(Broker, bs, bs)
|
||||
()
|
||||
SendInvite ::
|
||||
Invitation ->
|
||||
SimplexCommand
|
||||
(Cmd Recipient New Pending)
|
||||
(Cmd Sender None New)
|
||||
'(Recipient, New, Pending)
|
||||
'(Sender, None, New)
|
||||
()
|
||||
ConfirmConn ::
|
||||
SenderConnId ->
|
||||
Encrypted ->
|
||||
SimplexCommand
|
||||
(Cmd Sender New Confirmed)
|
||||
(Cmd Broker New New)
|
||||
'(Sender, New, Confirmed)
|
||||
'(Broker, New, New)
|
||||
()
|
||||
PushConfirm ::
|
||||
ConnId ->
|
||||
Message ->
|
||||
SimplexCommand
|
||||
(Cmd Broker New New)
|
||||
(Cmd Recipient Pending Confirmed)
|
||||
'(Broker, New, New)
|
||||
'(Recipient, Pending, Confirmed)
|
||||
()
|
||||
SecureConn ::
|
||||
ConnId ->
|
||||
PublicKey ->
|
||||
SimplexCommand
|
||||
(Cmd Recipient Confirmed Secured)
|
||||
(Cmd Broker New Secured)
|
||||
'(Recipient, Confirmed, Secured)
|
||||
'(Broker, New, Secured)
|
||||
()
|
||||
SendMsg ::
|
||||
(ss == Confirmed || ss == Secured) ~ True =>
|
||||
SenderConnId ->
|
||||
Encrypted ->
|
||||
SimplexCommand
|
||||
(Cmd Sender ss Secured)
|
||||
(Cmd Broker Secured Secured)
|
||||
'(Sender, ss, Secured)
|
||||
'(Broker, Secured, Secured)
|
||||
()
|
||||
PushMsg ::
|
||||
ConnId ->
|
||||
Message ->
|
||||
SimplexCommand
|
||||
(Cmd Broker Secured Secured)
|
||||
(Cmd Recipient Secured Secured)
|
||||
'(Broker, Secured, Secured)
|
||||
'(Recipient, Secured, Secured)
|
||||
()
|
||||
DeleteMsg ::
|
||||
ConnId ->
|
||||
MessageId ->
|
||||
SimplexCommand
|
||||
(Cmd Recipient Secured Secured)
|
||||
(Cmd Broker Secured Secured)
|
||||
'(Recipient, Secured, Secured)
|
||||
'(Broker, Secured, Secured)
|
||||
()
|
||||
|
||||
-- connection type stub for all participants, TODO move from idris
|
||||
@@ -106,11 +106,11 @@ data
|
||||
|
||||
class Monad m => PartyProtocol m (p :: Party) where
|
||||
api ::
|
||||
SimplexCommand from (Cmd p s s') a ->
|
||||
SimplexCommand from '(p, s, s') a ->
|
||||
Connection p s ->
|
||||
ExceptT String m (a, Connection p s')
|
||||
action ::
|
||||
SimplexCommand (Cmd p s s') to a ->
|
||||
SimplexCommand '(p, s, s') to a ->
|
||||
Connection p s ->
|
||||
ExceptT String m a ->
|
||||
ExceptT String m (Connection p s')
|
||||
@@ -123,11 +123,11 @@ actionStub _ _ = throwE "action not implemented"
|
||||
|
||||
data SimplexParty (p :: Party) m a where
|
||||
Api ::
|
||||
SimplexCommand from (Cmd p s s') x ->
|
||||
SimplexCommand from '(p, s, s') x ->
|
||||
Connection p s ->
|
||||
SimplexParty p m (Either String (x, Connection p s'))
|
||||
Action ::
|
||||
SimplexCommand (Cmd p s s') to x ->
|
||||
SimplexCommand '(p, s, s') to x ->
|
||||
Connection p s ->
|
||||
Either String x ->
|
||||
SimplexParty p m (Either String (Connection p s'))
|
||||
@@ -26,7 +26,7 @@ b = SBroker
|
||||
s :: Sing Sender
|
||||
s = SSender
|
||||
|
||||
establishConnection :: SimplexProtocol (None |: None |: None) (Secured |: Secured |: Secured) ()
|
||||
establishConnection :: SimplexProtocol '[None, None, None] '[Secured, Secured, Secured] ()
|
||||
establishConnection = do
|
||||
comment "Establish simplex messaging connection and send first message"
|
||||
r ->: b $ CreateConn "BODbZxmtKUUF1l8pj4nVjQ"
|
||||
|
||||
Reference in new issue
Block a user