Copyright | (c) simplex.chat |
---|---|
License | AGPL-3 |
Maintainer | chat@simplex.chat |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
This module provides a functional client API for SMP protocol.
See https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md
Synopsis
- data SMPClient
- getSMPClient :: SMPServer -> SMPClientConfig -> TBQueue SMPServerTransmission -> IO () -> IO (Either SMPClientError SMPClient)
- closeSMPClient :: SMPClient -> IO ()
- createSMPQueue :: SMPClient -> RecipientPrivateKey -> RecipientPublicKey -> ExceptT SMPClientError IO (RecipientId, SenderId)
- subscribeSMPQueue :: SMPClient -> RecipientPrivateKey -> RecipientId -> ExceptT SMPClientError IO ()
- secureSMPQueue :: SMPClient -> RecipientPrivateKey -> RecipientId -> SenderPublicKey -> ExceptT SMPClientError IO ()
- sendSMPMessage :: SMPClient -> Maybe SenderPrivateKey -> SenderId -> MsgBody -> ExceptT SMPClientError IO ()
- ackSMPMessage :: SMPClient -> RecipientPrivateKey -> QueueId -> ExceptT SMPClientError IO ()
- suspendSMPQueue :: SMPClient -> RecipientPrivateKey -> QueueId -> ExceptT SMPClientError IO ()
- deleteSMPQueue :: SMPClient -> RecipientPrivateKey -> QueueId -> ExceptT SMPClientError IO ()
- sendSMPCommand :: SMPClient -> Maybe SafePrivateKey -> QueueId -> Cmd -> ExceptT SMPClientError IO Cmd
- data SMPClientError
- data SMPClientConfig = SMPClientConfig {
- qSize :: Natural
- defaultPort :: ServiceName
- tcpTimeout :: Int
- smpPing :: Int
- smpCommandSize :: Int
- smpDefaultConfig :: SMPClientConfig
- type SMPServerTransmission = (SMPServer, RecipientId, Command 'Broker)
Connect (disconnect) client to (from) SMP server
SMPClient
is a handle used to send commands to a specific SMP server.
The only exported selector is blockSize that is negotiated with the server during the TCP transport handshake.
Use getSMPClient
to connect to an SMP server and create a client handle.
getSMPClient :: SMPServer -> SMPClientConfig -> TBQueue SMPServerTransmission -> IO () -> IO (Either SMPClientError SMPClient) Source #
Connects to SMPServer
using passed client configuration
and queue for messages and notifications.
A single queue can be used for multiple SMPClient
instances,
as SMPServerTransmission
includes server information.
closeSMPClient :: SMPClient -> IO () Source #
Disconnects SMP client from the server and terminates client threads.
SMP protocol command functions
createSMPQueue :: SMPClient -> RecipientPrivateKey -> RecipientPublicKey -> ExceptT SMPClientError IO (RecipientId, SenderId) Source #
subscribeSMPQueue :: SMPClient -> RecipientPrivateKey -> RecipientId -> ExceptT SMPClientError IO () Source #
Subscribe to the SMP queue.
secureSMPQueue :: SMPClient -> RecipientPrivateKey -> RecipientId -> SenderPublicKey -> ExceptT SMPClientError IO () Source #
Secure the SMP queue by adding a sender public key.
sendSMPMessage :: SMPClient -> Maybe SenderPrivateKey -> SenderId -> MsgBody -> ExceptT SMPClientError IO () Source #
ackSMPMessage :: SMPClient -> RecipientPrivateKey -> QueueId -> ExceptT SMPClientError IO () Source #
Acknowledge message delivery (server deletes the message).
suspendSMPQueue :: SMPClient -> RecipientPrivateKey -> QueueId -> ExceptT SMPClientError IO () Source #
Irreversibly suspend SMP queue. The existing messages from the queue will still be delivered.
https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#suspend-queue
deleteSMPQueue :: SMPClient -> RecipientPrivateKey -> QueueId -> ExceptT SMPClientError IO () Source #
Irreversibly delete SMP queue and all messages in it.
https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#delete-queue
sendSMPCommand :: SMPClient -> Maybe SafePrivateKey -> QueueId -> Cmd -> ExceptT SMPClientError IO Cmd Source #
Send any SMP command (Cmd
type).
Supporting types and client configuration
data SMPClientError Source #
SMP client error type.
SMPServerError ErrorType | Correctly parsed SMP server ERR response. This error is forwarded to the agent client as `ERR SMP err`. |
SMPResponseError ErrorType | Invalid server response that failed to parse. Forwarded to the agent client as `ERR BROKER RESPONSE`. |
SMPUnexpectedResponse | Different response from what is expected to a certain SMP command,
e.g. server should respond |
SMPResponseTimeout | Used for TCP connection and command response timeouts. Forwarded to the agent client as `ERR BROKER TIMEOUT`. |
SMPNetworkError | Failure to establish TCP connection. Forwarded to the agent client as `ERR BROKER NETWORK`. |
SMPTransportError TransportError | TCP transport handshake or some other transport error. Forwarded to the agent client as `ERR BROKER TRANSPORT e`. |
SMPSignatureError CryptoError | Error when cryptographically "signing" the command. |
Instances
Eq SMPClientError Source # | |
Defined in Simplex.Messaging.Client (==) :: SMPClientError -> SMPClientError -> Bool # (/=) :: SMPClientError -> SMPClientError -> Bool # | |
Show SMPClientError Source # | |
Defined in Simplex.Messaging.Client showsPrec :: Int -> SMPClientError -> ShowS # show :: SMPClientError -> String # showList :: [SMPClientError] -> ShowS # | |
Exception SMPClientError Source # | |
Defined in Simplex.Messaging.Client |
data SMPClientConfig Source #
SMP client configuration.
SMPClientConfig | |
|
smpDefaultConfig :: SMPClientConfig Source #
Default SMP client configuration.
type SMPServerTransmission = (SMPServer, RecipientId, Command 'Broker) Source #
Type synonym for transmission from some SPM server queue.