protocol command type - establishing connection

This commit is contained in:
Evgeny Poberezkin 2020-05-07 21:24:18 +01:00
parent ece63ea894
commit a6d963035e

View file

@ -171,25 +171,96 @@ goodSndConn = SCSecured (record
-- protocol commands that participants send -- protocol commands that participants send
data CmdResult = OK | Denied data Result : (a : Type) -> Type where
OK : a -> Result a
Deny : Result a -- access restriction, not some arbitrary error
Error : String -> Result a
record BrkCreateConnRes where
constructor MkBrkCreateConnRes
connId : String
senderConnId : String
Message : Type
Message = String
infix 10 /@
-- operator to define connection state change based on the result
(/@) : ConnectionState
-> ConnectionState
-> (Result a -> ConnectionState)
(/@) okCS failCS = \x => case x of
OK _ => okCS
Deny => failCS
Error _ => failCS
data Command : (ty : Type) data Command : (ty : Type)
-> (from : Participant) -> (act : Participant)
-> (to : Participant) -> (rcv : Participant)
-> (fromConn : ConnectionState) -> (actCS : ConnectionState)
-> (fromConn' : ty -> ConnectionState) -> (rcvCS : ConnectionState)
-> (toConn : ConnectionState) -> (actCS' : ty -> ConnectionState)
-> (toConn' : ty -> ConnectionState) -> (rcvCS' : ty -> ConnectionState)
-> {auto prf : HasState from fromConn} -> {auto prf : HasState act actCS}
-> {auto prf : HasState to toConn} -> {auto prf : HasState rcv rcvCS}
-> Type where -> Type where
SendMsg : String CreateConn : (recipientBrokerKey : Key)
-> Command CmdResult -> Command (Result BrkCreateConnRes)
Sender Broker Recipient Broker
Secured Null Null
(\ok => case ok of (New /@ Null) (New /@ Null)
OK => Secured
Denied => Null) Subscribe : (connId : String)
Secured -> {auto prf : BrokerCS state}
(const Secured) -> Command (Result ())
Recipient Broker
state state
(const state) (const state)
SendInvite : Invitation
-> Command ()
Recipient Sender
New Null
(const Pending) (const New)
ConfirmConn : (connId : String)
-> (senderBrokerKey : Key)
-> {auto prf : BrokerCS bcState}
-> Command (Result ())
Sender Broker
New bcState
(Confirmed /@ New) (const bcState)
DeliverConfirmation : (connId : String)
-> Command (Result ())
Broker Recipient
New New
(const New) (Confirmed /@ New)
SecureConn : (connId : String)
-> (senderKey : Key)
-> Command (Result ())
Recipient Broker
Confirmed New
(Secured /@ Confirmed) (Secured /@ New)
WelcomeMsg : (connId : String)
-> {auto prf : BrokerCS bcState}
-> Command (Result ())
Sender Broker
Confirmed bcState
(const Confirmed) (const bcState)
SendMsg : Message
-> {auto prf : BrokerCS bcState}
-> Command (Result ())
Sender Broker
Secured bcState
(\x => case x of
OK _ => Secured
Error _ => Secured
Deny => Null)
(const bcState)