mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-05 02:26:01 +00:00
establishConnection protocol flow
This commit is contained in:
@@ -124,6 +124,8 @@ st2 = SPending :<==> SNew :<==| SConfirmed
|
||||
-- stBad = SPending :<==> SConfirmed :<==| SConfirmed
|
||||
|
||||
|
||||
infixl 4 :>>, :>>=
|
||||
|
||||
data Command res (from :: Participant) (to :: Participant) state state' :: Type where
|
||||
CreateConn :: Prf HasState 'Sender s
|
||||
=> CreateConnRequest
|
||||
@@ -203,8 +205,12 @@ data Command res (from :: Participant) (to :: Participant) state state' :: Type
|
||||
-> Command b from1 to2 s1 s3
|
||||
|
||||
|
||||
infix 6 ==>
|
||||
(==>) :: from -> to -> (from, to)
|
||||
from ==> to = (from, to)
|
||||
|
||||
infix 5 &:
|
||||
(&:) :: Sing from
|
||||
(&:) :: (Sing from, Sing to)
|
||||
-> Command a from to s1 s2
|
||||
-> Command a from to s1 s2
|
||||
(&:) _ c = c
|
||||
|
||||
27
definitions/src/Simplex/Messaging/Scenarios.hs
Normal file
27
definitions/src/Simplex/Messaging/Scenarios.hs
Normal file
@@ -0,0 +1,27 @@
|
||||
{-# LANGUAGE BlockArguments #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
|
||||
module Simplex.Messaging.Scenarios where
|
||||
|
||||
import Simplex.Messaging.Protocol
|
||||
import Simplex.Messaging.Types
|
||||
|
||||
establishConnection :: Command ()
|
||||
'Recipient 'Broker
|
||||
('None <==> 'None <==| 'None)
|
||||
('Secured <==> 'Secured <==| 'Secured)
|
||||
establishConnection =
|
||||
SRecipient ==> SBroker &: CreateConn "123" :>>= -- recipient's public key for broker
|
||||
\CreateConnResponse{..} ->
|
||||
SRecipient ==> SBroker &: Subscribe :>> -- TODO add subscribed state
|
||||
SRecipient ==> SSender &: SendInvite "invite" :>> -- TODO invitation object
|
||||
SSender ==> SBroker &: ConfirmConn "456" :>> -- sender's public key for broker"
|
||||
SBroker ==> SRecipient &: PushConfirm :>>=
|
||||
\senderKey ->
|
||||
SRecipient ==> SBroker &: SecureConn senderKey :>>
|
||||
SSender ==> SBroker &: SendWelcome :>>
|
||||
SBroker ==> SRecipient &: PushWelcome :>>
|
||||
SSender ==> SBroker &: SendMsg "Hello" :>>
|
||||
SBroker ==> SRecipient &: PushMsg :>>
|
||||
SRecipient ==> SBroker &: DeleteMsg
|
||||
@@ -9,7 +9,11 @@ import GHC.Generics()
|
||||
|
||||
newtype CreateConnRequest = CreateConnRequest
|
||||
{ recipientKey :: Key
|
||||
} deriving (Show, Generic, ToJSON, FromJSON)
|
||||
} deriving (Eq, Show, Generic, ToJSON, FromJSON)
|
||||
|
||||
instance IsString CreateConnRequest where
|
||||
fromString = CreateConnRequest . pack
|
||||
|
||||
|
||||
data CreateConnResponse = CreateConnResponse
|
||||
{ recipientId :: String
|
||||
@@ -20,6 +24,10 @@ newtype SecureConnRequest = SecureConnRequest
|
||||
{ senderKey :: Key
|
||||
} deriving (Show, Generic, ToJSON, FromJSON)
|
||||
|
||||
instance IsString SecureConnRequest where
|
||||
fromString = SecureConnRequest . pack
|
||||
|
||||
|
||||
data Message = Message
|
||||
{ id :: Base64EncodedString
|
||||
, ts :: TimeStamp
|
||||
@@ -35,6 +43,10 @@ newtype SendMessageRequest = SendMessageRequest
|
||||
{ msg :: Base64EncodedString
|
||||
} deriving (Show, Generic, ToJSON, FromJSON)
|
||||
|
||||
instance IsString SendMessageRequest where
|
||||
fromString = SendMessageRequest . pack
|
||||
|
||||
|
||||
type Key = Base64EncodedString
|
||||
type Base64EncodedString = Text
|
||||
type TimeStamp = Text
|
||||
|
||||
Reference in New Issue
Block a user