SMP agent: data types for connections and message delivery

This commit is contained in:
Evgeny Poberezkin
2020-12-26 10:58:50 +00:00
parent 2a87a1b5c9
commit c195c79367
3 changed files with 54 additions and 4 deletions
+1 -1
View File
@@ -104,4 +104,4 @@ digraph SMPAgent {
uAgent -> runClient [style=dashed label="fork" color=orange fontcolor=orange]
}
}
}
+3 -3
View File
@@ -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
+50
View File
@@ -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