diff --git a/design/agent2.gv b/design/agent2.gv index 6b5c9a99f..e65fa5171 100644 --- a/design/agent2.gv +++ b/design/agent2.gv @@ -104,4 +104,4 @@ digraph SMPAgent { uAgent -> runClient [style=dashed label="fork" color=orange fontcolor=orange] } -} \ No newline at end of file +} diff --git a/src/Simplex/Messaging/Agent/Command.hs b/src/Simplex/Messaging/Agent/Command.hs index 99351af8e..a558ea71d 100644 --- a/src/Simplex/Messaging/Agent/Command.hs +++ b/src/Simplex/Messaging/Agent/Command.hs @@ -12,7 +12,7 @@ import Control.Monad.IO.Class import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.Kind -import Data.Time.Clock +import Data.Time.Clock (UTCTime) import Network.Socket import Simplex.Messaging.Server.Transmission (Encoded, MsgBody, PublicKey, QueueId) import Simplex.Messaging.Transport @@ -40,7 +40,7 @@ data ACommand (a :: AParty) where SUB :: ConnAlias -> SubMode -> ACommand User END :: ConnAlias -> ACommand Agent QST :: ConnAlias -> QueueDirection -> ACommand User - STAT :: ConnAlias -> QueueDirection -> Maybe ConnState -> Maybe SubMode -> ACommand Agent + STAT :: ConnAlias -> QueueDirection -> Maybe QueueState -> Maybe SubMode -> ACommand Agent SEND :: ConnAlias -> MsgBody -> ACommand User MSG :: ConnAlias -> AgentMsgId -> UTCTime -> UTCTime -> MsgStatus -> MsgBody -> ACommand Agent ACK :: ConnAlias -> AgentMsgId -> ACommand User @@ -84,7 +84,7 @@ type VerificationKey = PublicKey data QueueDirection = SND | RCV deriving (Show) -data ConnState = New | Pending | Confirmed | Secured | Active | Disabled +data QueueState = New | Confirmed | Secured | Active | Disabled deriving (Show) type AgentMsgId = Int diff --git a/src/Simplex/Messaging/Agent/ConnStore.hs b/src/Simplex/Messaging/Agent/ConnStore.hs new file mode 100644 index 000000000..b465d1af6 --- /dev/null +++ b/src/Simplex/Messaging/Agent/ConnStore.hs @@ -0,0 +1,50 @@ +{-# LANGUAGE DuplicateRecordFields #-} + +module Simplex.Messaging.Agent.ConnStore where + +import Data.Time.Clock (UTCTime) +import Simplex.Messaging.Agent.Command +import Simplex.Messaging.Server.Transmission (Encoded, PublicKey, QueueId) + +data ReceiveQueue = ReceiveQueue + { server :: SMPServer, + rcvId :: QueueId, + rcvPrivateKey :: PrivateKey, + sndId :: Maybe QueueId, + sndKey :: Maybe PublicKey, + decryptKey :: PrivateKey, + verifyKey :: Maybe PublicKey, + status :: QueueState, + ackMode :: AckMode + } + +data SendQueue = SendQueue + { server :: SMPServer, + sndId :: QueueId, + sndPrivateKey :: PrivateKey, + encryptKey :: PublicKey, + signKey :: PrivateKey, + status :: QueueState, + ackMode :: AckMode + } + +data Connection + = ReceiveConnection {connAlias :: ConnAlias, rcvQueue :: ReceiveQueue} + | SendConnection {connAlias :: ConnAlias, sndQueue :: SendQueue} + | DuplexConnection {connAlias :: ConnAlias, rcvQueue :: ReceiveQueue, sndQueue :: SendQueue} + +data MessageDelivery = MessageDelivery + { connAlias :: ConnAlias, + agentMsgId :: Int, + timestamp :: UTCTime, + message :: AMessage, + direction :: QueueDirection, + msgStatus :: DeliveryStatus + } + +type PrivateKey = Encoded + +data DeliveryStatus + = MDTransmitted -- SMP: SEND sent / MSG received + | MDConfirmed -- SMP: OK received / ACK sent + | MDAcknowledged -- SAMP: RCVD sent to agent client / ACK received from agent client and sent to the server