Copyright | (c) simplex.chat |
---|---|
License | AGPL-3 |
Maintainer | chat@simplex.chat |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Types, parsers, serializers and functions to send and receive SMP agent protocol commands and responses.
See https://github.com/simplex-chat/simplexmq/blob/master/protocol/agent-protocol.md
Synopsis
- type ConnInfo = ByteString
- data ACommand (p :: AParty) where
- NEW :: AConnectionMode -> ACommand Client
- INV :: AConnectionRequest -> ACommand Agent
- JOIN :: AConnectionRequest -> ConnInfo -> ACommand Client
- CONF :: ConfirmationId -> ConnInfo -> ACommand Agent
- LET :: ConfirmationId -> ConnInfo -> ACommand Client
- REQ :: InvitationId -> ConnInfo -> ACommand Agent
- ACPT :: InvitationId -> ConnInfo -> ACommand Client
- RJCT :: InvitationId -> ACommand Client
- INFO :: ConnInfo -> ACommand Agent
- CON :: ACommand Agent
- SUB :: ACommand Client
- END :: ACommand Agent
- DOWN :: ACommand Agent
- UP :: ACommand Agent
- SEND :: MsgBody -> ACommand Client
- MID :: AgentMsgId -> ACommand Agent
- SENT :: AgentMsgId -> ACommand Agent
- MERR :: AgentMsgId -> AgentErrorType -> ACommand Agent
- MSG :: MsgMeta -> MsgBody -> ACommand Agent
- ACK :: AgentMsgId -> ACommand Client
- OFF :: ACommand Client
- DEL :: ACommand Client
- OK :: ACommand Agent
- ERR :: AgentErrorType -> ACommand Agent
- data AParty
- data SAParty :: AParty -> Type where
- type MsgHash = ByteString
- data MsgMeta = MsgMeta {
- integrity :: MsgIntegrity
- recipient :: (AgentMsgId, UTCTime)
- broker :: (MsgId, UTCTime)
- sender :: (AgentMsgId, UTCTime)
- data SMPMessage
- = SMPConfirmation { }
- | SMPMessage {
- senderMsgId :: AgentMsgId
- senderTimestamp :: SenderTimestamp
- previousMsgHash :: MsgHash
- agentMessage :: AMessage
- data AMessage where
- HELLO :: VerificationKey -> AckMode -> AMessage
- REPLY :: ConnectionRequest CMInvitation -> AMessage
- A_MSG :: MsgBody -> AMessage
- A_INV :: ConnectionRequest CMInvitation -> ConnInfo -> AMessage
- data SMPServer = SMPServer {}
- data SMPQueueUri = SMPQueueUri {}
- data ConnectionMode
- data SConnectionMode (m :: ConnectionMode) where
- data AConnectionMode = forall m. ACM (SConnectionMode m)
- cmInvitation :: AConnectionMode
- cmContact :: AConnectionMode
- class ConnectionModeI (m :: ConnectionMode) where
- data ConnectionRequest (m :: ConnectionMode) where
- data AConnectionRequest = forall m. ACR (SConnectionMode m) (ConnectionRequest m)
- data ConnReqData = ConnReqData {}
- data ConnReqScheme
- simplexChat :: ConnReqScheme
- data AgentErrorType
- data CommandErrorType
- = PROHIBITED
- | SYNTAX
- | NO_CONN
- | SIZE
- | LARGE
- data ConnectionErrorType
- data BrokerErrorType
- data SMPAgentError
- type ATransmission p = (ACorrId, ConnId, ACommand p)
- type ATransmissionOrError p = (ACorrId, ConnId, Either AgentErrorType (ACommand p))
- type ARawTransmission = (ByteString, ByteString, ByteString)
- type ConnId = ByteString
- type ConfirmationId = ByteString
- type InvitationId = ByteString
- newtype AckMode = AckMode OnOff
- data OnOff
- data MsgIntegrity
- data MsgErrorType
- data QueueStatus
- type SignatureKey = APrivateKey
- type VerificationKey = PublicKey
- type EncryptionKey = PublicKey
- type DecryptionKey = SafePrivateKey
- type ACorrId = ByteString
- type AgentMsgId = Int64
- serializeCommand :: ACommand p -> ByteString
- serializeSMPMessage :: SMPMessage -> ByteString
- serializeMsgIntegrity :: MsgIntegrity -> ByteString
- serializeServer :: SMPServer -> ByteString
- serializeSMPQueueUri :: SMPQueueUri -> ByteString
- reservedServerKey :: PublicKey
- serializeConnMode :: AConnectionMode -> ByteString
- serializeConnMode' :: ConnectionMode -> ByteString
- connMode :: SConnectionMode m -> ConnectionMode
- connMode' :: ConnectionMode -> AConnectionMode
- serializeConnReq :: AConnectionRequest -> ByteString
- serializeConnReq' :: ConnectionRequest m -> ByteString
- serializeAgentError :: AgentErrorType -> ByteString
- commandP :: Parser ACmd
- parseSMPMessage :: ByteString -> Either AgentErrorType SMPMessage
- smpServerP :: Parser SMPServer
- smpQueueUriP :: Parser SMPQueueUri
- connModeT :: Text -> Maybe ConnectionMode
- connReqP :: Parser AConnectionRequest
- connReqP' :: forall m. ConnectionModeI m => Parser (ConnectionRequest m)
- msgIntegrityP :: Parser MsgIntegrity
- agentErrorTypeP :: Parser AgentErrorType
- agentMessageP :: Parser AMessage
- tPut :: (Transport c, MonadIO m) => c -> ATransmission p -> m ()
- tGet :: forall c m p. (Transport c, MonadIO m) => SAParty p -> c -> m (ATransmissionOrError p)
- tPutRaw :: Transport c => c -> ARawTransmission -> IO ()
- tGetRaw :: Transport c => c -> IO ARawTransmission
SMP agent protocol types
type ConnInfo = ByteString Source #
data ACommand (p :: AParty) where Source #
Parameterized type for SMP agent protocol commands and responses from all participants.
NEW :: AConnectionMode -> ACommand Client | |
INV :: AConnectionRequest -> ACommand Agent | |
JOIN :: AConnectionRequest -> ConnInfo -> ACommand Client | |
CONF :: ConfirmationId -> ConnInfo -> ACommand Agent | |
LET :: ConfirmationId -> ConnInfo -> ACommand Client | |
REQ :: InvitationId -> ConnInfo -> ACommand Agent | |
ACPT :: InvitationId -> ConnInfo -> ACommand Client | |
RJCT :: InvitationId -> ACommand Client | |
INFO :: ConnInfo -> ACommand Agent | |
CON :: ACommand Agent | |
SUB :: ACommand Client | |
END :: ACommand Agent | |
DOWN :: ACommand Agent | |
UP :: ACommand Agent | |
SEND :: MsgBody -> ACommand Client | |
MID :: AgentMsgId -> ACommand Agent | |
SENT :: AgentMsgId -> ACommand Agent | |
MERR :: AgentMsgId -> AgentErrorType -> ACommand Agent | |
MSG :: MsgMeta -> MsgBody -> ACommand Agent | |
ACK :: AgentMsgId -> ACommand Client | |
OFF :: ACommand Client | |
DEL :: ACommand Client | |
OK :: ACommand Agent | |
ERR :: AgentErrorType -> ACommand Agent |
SMP agent protocol participants.
data SAParty :: AParty -> Type where Source #
Singleton types for SMP agent protocol participants.
type MsgHash = ByteString Source #
Agent message metadata sent to the client
MsgMeta | |
|
data SMPMessage Source #
SMP message formats.
SMPConfirmation | SMP confirmation (see SMP protocol) |
| |
SMPMessage | Agent message header and envelope for client messages (see SMP agent protocol) |
|
Instances
Show SMPMessage Source # | |
Defined in Simplex.Messaging.Agent.Protocol showsPrec :: Int -> SMPMessage -> ShowS # show :: SMPMessage -> String # showList :: [SMPMessage] -> ShowS # |
Messages sent between SMP agents once SMP queue is secured.
HELLO :: VerificationKey -> AckMode -> AMessage | the first message in the queue to validate it is secured |
REPLY :: ConnectionRequest CMInvitation -> AMessage | reply queue information |
A_MSG :: MsgBody -> AMessage | agent envelope for the client message |
A_INV :: ConnectionRequest CMInvitation -> ConnInfo -> AMessage | connection request with the invitation to connect |
SMP server location and transport key digest (hash).
data SMPQueueUri Source #
SMP queue information sent out-of-band.
Instances
Eq SMPQueueUri Source # | |
Defined in Simplex.Messaging.Agent.Protocol (==) :: SMPQueueUri -> SMPQueueUri -> Bool # (/=) :: SMPQueueUri -> SMPQueueUri -> Bool # | |
Show SMPQueueUri Source # | |
Defined in Simplex.Messaging.Agent.Protocol showsPrec :: Int -> SMPQueueUri -> ShowS # show :: SMPQueueUri -> String # showList :: [SMPQueueUri] -> ShowS # | |
FromField SMPQueueUri Source # | |
Defined in Simplex.Messaging.Agent.Store.SQLite | |
ToField SMPQueueUri Source # | |
Defined in Simplex.Messaging.Agent.Store.SQLite toField :: SMPQueueUri -> SQLData # |
data ConnectionMode Source #
Instances
Eq ConnectionMode Source # | |
Defined in Simplex.Messaging.Agent.Protocol (==) :: ConnectionMode -> ConnectionMode -> Bool # (/=) :: ConnectionMode -> ConnectionMode -> Bool # | |
Show ConnectionMode Source # | |
Defined in Simplex.Messaging.Agent.Protocol showsPrec :: Int -> ConnectionMode -> ShowS # show :: ConnectionMode -> String # showList :: [ConnectionMode] -> ShowS # | |
FromField ConnectionMode Source # | |
Defined in Simplex.Messaging.Agent.Store.SQLite | |
ToField ConnectionMode Source # | |
Defined in Simplex.Messaging.Agent.Store.SQLite toField :: ConnectionMode -> SQLData # | |
TestEquality SConnectionMode Source # | |
Defined in Simplex.Messaging.Agent.Protocol testEquality :: forall (a :: k) (b :: k). SConnectionMode a -> SConnectionMode b -> Maybe (a :~: b) # |
data SConnectionMode (m :: ConnectionMode) where Source #
Instances
TestEquality SConnectionMode Source # | |
Defined in Simplex.Messaging.Agent.Protocol testEquality :: forall (a :: k) (b :: k). SConnectionMode a -> SConnectionMode b -> Maybe (a :~: b) # | |
Eq (SConnectionMode m) Source # | |
Defined in Simplex.Messaging.Agent.Protocol (==) :: SConnectionMode m -> SConnectionMode m -> Bool # (/=) :: SConnectionMode m -> SConnectionMode m -> Bool # | |
Show (SConnectionMode m) Source # | |
Defined in Simplex.Messaging.Agent.Protocol showsPrec :: Int -> SConnectionMode m -> ShowS # show :: SConnectionMode m -> String # showList :: [SConnectionMode m] -> ShowS # | |
ToField (SConnectionMode c) Source # | |
Defined in Simplex.Messaging.Agent.Store.SQLite toField :: SConnectionMode c -> SQLData # |
data AConnectionMode Source #
forall m. ACM (SConnectionMode m) |
Instances
Eq AConnectionMode Source # | |
Defined in Simplex.Messaging.Agent.Protocol (==) :: AConnectionMode -> AConnectionMode -> Bool # (/=) :: AConnectionMode -> AConnectionMode -> Bool # | |
Show AConnectionMode Source # | |
Defined in Simplex.Messaging.Agent.Protocol showsPrec :: Int -> AConnectionMode -> ShowS # show :: AConnectionMode -> String # showList :: [AConnectionMode] -> ShowS # | |
FromField AConnectionMode Source # | |
Defined in Simplex.Messaging.Agent.Store.SQLite |
class ConnectionModeI (m :: ConnectionMode) where Source #
Instances
data ConnectionRequest (m :: ConnectionMode) where Source #
CRInvitation :: ConnReqData -> ConnectionRequest CMInvitation | |
CRContact :: ConnReqData -> ConnectionRequest CMContact |
Instances
Eq (ConnectionRequest m) Source # | |
Defined in Simplex.Messaging.Agent.Protocol (==) :: ConnectionRequest m -> ConnectionRequest m -> Bool # (/=) :: ConnectionRequest m -> ConnectionRequest m -> Bool # | |
Show (ConnectionRequest m) Source # | |
Defined in Simplex.Messaging.Agent.Protocol showsPrec :: Int -> ConnectionRequest m -> ShowS # show :: ConnectionRequest m -> String # showList :: [ConnectionRequest m] -> ShowS # | |
(Typeable c, ConnectionModeI c) => FromField (ConnectionRequest c) Source # | |
Defined in Simplex.Messaging.Agent.Store.SQLite fromField :: FieldParser (ConnectionRequest c) # | |
ToField (ConnectionRequest c) Source # | |
Defined in Simplex.Messaging.Agent.Store.SQLite toField :: ConnectionRequest c -> SQLData # |
data AConnectionRequest Source #
forall m. ACR (SConnectionMode m) (ConnectionRequest m) |
Instances
Eq AConnectionRequest Source # | |
Defined in Simplex.Messaging.Agent.Protocol (==) :: AConnectionRequest -> AConnectionRequest -> Bool # (/=) :: AConnectionRequest -> AConnectionRequest -> Bool # | |
Show AConnectionRequest Source # | |
Defined in Simplex.Messaging.Agent.Protocol showsPrec :: Int -> AConnectionRequest -> ShowS # show :: AConnectionRequest -> String # showList :: [AConnectionRequest] -> ShowS # | |
FromField AConnectionRequest Source # | |
ToField AConnectionRequest Source # | |
Defined in Simplex.Messaging.Agent.Store.SQLite toField :: AConnectionRequest -> SQLData # |
data ConnReqData Source #
Instances
Eq ConnReqData Source # | |
Defined in Simplex.Messaging.Agent.Protocol (==) :: ConnReqData -> ConnReqData -> Bool # (/=) :: ConnReqData -> ConnReqData -> Bool # | |
Show ConnReqData Source # | |
Defined in Simplex.Messaging.Agent.Protocol showsPrec :: Int -> ConnReqData -> ShowS # show :: ConnReqData -> String # showList :: [ConnReqData] -> ShowS # |
data ConnReqScheme Source #
Instances
Eq ConnReqScheme Source # | |
Defined in Simplex.Messaging.Agent.Protocol (==) :: ConnReqScheme -> ConnReqScheme -> Bool # (/=) :: ConnReqScheme -> ConnReqScheme -> Bool # | |
Show ConnReqScheme Source # | |
Defined in Simplex.Messaging.Agent.Protocol showsPrec :: Int -> ConnReqScheme -> ShowS # show :: ConnReqScheme -> String # showList :: [ConnReqScheme] -> ShowS # |
data AgentErrorType Source #
Error type used in errors sent to agent clients.
CMD CommandErrorType | command or response error |
CONN ConnectionErrorType | connection errors |
SMP ErrorType | SMP protocol errors forwarded to agent clients |
BROKER BrokerErrorType | SMP server errors |
AGENT SMPAgentError | errors of other agents |
INTERNAL String | agent implementation or dependency errors |
Instances
data CommandErrorType Source #
SMP agent protocol command or response error.
PROHIBITED | command is prohibited in this context |
SYNTAX | command syntax is invalid |
NO_CONN | entity ID is required with this command |
SIZE | message size is not correct (no terminating space) |
LARGE | message does not fit in SMP block |
Instances
data ConnectionErrorType Source #
Connection error.
NOT_FOUND | connection alias is not in the database |
DUPLICATE | connection alias already exists |
SIMPLEX | connection is simplex, but operation requires another queue |
Instances
data BrokerErrorType Source #
SMP server errors.
RESPONSE ErrorType | invalid server response (failed to parse) |
UNEXPECTED | unexpected response |
NETWORK | network error |
TRANSPORT TransportError | handshake or other transport error |
TIMEOUT | command response timeout |
Instances
data SMPAgentError Source #
Errors of another SMP agent.
A_MESSAGE | possibly should include bytestring that failed to parse |
A_PROHIBITED | possibly should include the prohibited SMP/agent message |
A_ENCRYPTION | cannot RSA/AES-decrypt or parse decrypted header |
A_SIGNATURE | invalid RSA signature |
Instances
type ATransmission p = (ACorrId, ConnId, ACommand p) Source #
Parsed SMP agent protocol transmission.
type ATransmissionOrError p = (ACorrId, ConnId, Either AgentErrorType (ACommand p)) Source #
SMP agent protocol transmission or transmission error.
type ARawTransmission = (ByteString, ByteString, ByteString) Source #
Raw (unparsed) SMP agent protocol transmission.
type ConnId = ByteString Source #
SMP agent connection alias.
type ConfirmationId = ByteString Source #
type InvitationId = ByteString Source #
data MsgIntegrity Source #
Result of received message integrity validation.
Instances
Eq MsgIntegrity Source # | |
Defined in Simplex.Messaging.Agent.Protocol (==) :: MsgIntegrity -> MsgIntegrity -> Bool # (/=) :: MsgIntegrity -> MsgIntegrity -> Bool # | |
Show MsgIntegrity Source # | |
Defined in Simplex.Messaging.Agent.Protocol showsPrec :: Int -> MsgIntegrity -> ShowS # show :: MsgIntegrity -> String # showList :: [MsgIntegrity] -> ShowS # | |
FromField MsgIntegrity Source # | |
Defined in Simplex.Messaging.Agent.Store.SQLite | |
ToField MsgIntegrity Source # | |
Defined in Simplex.Messaging.Agent.Store.SQLite toField :: MsgIntegrity -> SQLData # |
data MsgErrorType Source #
Error of message integrity validation.
Instances
Eq MsgErrorType Source # | |
Defined in Simplex.Messaging.Agent.Protocol (==) :: MsgErrorType -> MsgErrorType -> Bool # (/=) :: MsgErrorType -> MsgErrorType -> Bool # | |
Show MsgErrorType Source # | |
Defined in Simplex.Messaging.Agent.Protocol showsPrec :: Int -> MsgErrorType -> ShowS # show :: MsgErrorType -> String # showList :: [MsgErrorType] -> ShowS # |
data QueueStatus Source #
SMP queue status.
New | queue is created |
Confirmed | queue is confirmed by the sender |
Secured | queue is secured with sender key (only used by the queue recipient) |
Active | queue is active |
Disabled | queue is disabled (only used by the queue recipient) |
Instances
Eq QueueStatus Source # | |
Defined in Simplex.Messaging.Agent.Protocol (==) :: QueueStatus -> QueueStatus -> Bool # (/=) :: QueueStatus -> QueueStatus -> Bool # | |
Read QueueStatus Source # | |
Defined in Simplex.Messaging.Agent.Protocol readsPrec :: Int -> ReadS QueueStatus # readList :: ReadS [QueueStatus] # readPrec :: ReadPrec QueueStatus # readListPrec :: ReadPrec [QueueStatus] # | |
Show QueueStatus Source # | |
Defined in Simplex.Messaging.Agent.Protocol showsPrec :: Int -> QueueStatus -> ShowS # show :: QueueStatus -> String # showList :: [QueueStatus] -> ShowS # | |
FromField QueueStatus Source # | |
Defined in Simplex.Messaging.Agent.Store.SQLite | |
ToField QueueStatus Source # | |
Defined in Simplex.Messaging.Agent.Store.SQLite toField :: QueueStatus -> SQLData # |
type SignatureKey = APrivateKey Source #
Private key used to sign SMP commands
type VerificationKey = PublicKey Source #
Public key used by SMP server to authorize (verify) SMP commands.
type EncryptionKey = PublicKey Source #
Public key used to E2E encrypt SMP messages.
type DecryptionKey = SafePrivateKey Source #
Private key used to E2E decrypt SMP messages.
type ACorrId = ByteString Source #
type AgentMsgId = Int64 Source #
Parse and serialize
serializeCommand :: ACommand p -> ByteString Source #
Serialize SMP agent command.
serializeSMPMessage :: SMPMessage -> ByteString Source #
Serialize SMP message.
serializeMsgIntegrity :: MsgIntegrity -> ByteString Source #
Serialize message integrity validation result.
serializeServer :: SMPServer -> ByteString Source #
Serialize SMP server location.
serializeSMPQueueUri :: SMPQueueUri -> ByteString Source #
Serialize SMP queue information that is sent out-of-band.
connMode :: SConnectionMode m -> ConnectionMode Source #
serializeAgentError :: AgentErrorType -> ByteString Source #
Serialize SMP agent protocol error.
parseSMPMessage :: ByteString -> Either AgentErrorType SMPMessage Source #
Parse SMP message.
smpServerP :: Parser SMPServer Source #
SMP server location parser.
smpQueueUriP :: Parser SMPQueueUri Source #
SMP queue information parser.
connReqP' :: forall m. ConnectionModeI m => Parser (ConnectionRequest m) Source #
msgIntegrityP :: Parser MsgIntegrity Source #
Message integrity validation result parser.
agentErrorTypeP :: Parser AgentErrorType Source #
SMP agent protocol error parser.
TCP transport functions
tPut :: (Transport c, MonadIO m) => c -> ATransmission p -> m () Source #
Send SMP agent protocol command (or response) to TCP connection.
tGet :: forall c m p. (Transport c, MonadIO m) => SAParty p -> c -> m (ATransmissionOrError p) Source #
Receive client and agent transmissions from TCP connection.