simplexmq-6.5.0.16: SimpleXMQ message broker
Copyright(c) simplex.chat
LicenseAGPL-3
Maintainerchat@simplex.chat
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Simplex.Messaging.Client

Description

This module provides a functional client API for SMP protocol.

See https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md

Synopsis

Connect (disconnect) client to (from) SMP server

type TransportSession msg = (UserId, ProtoServer msg, Maybe ByteString) Source #

Transport session key - includes entity ID if `sessionMode = TSMEntity`. Please note that for SMP connection ID is used as entity ID, not queue ID.

data ProtocolClient v err msg Source #

SMPClient is a handle used to send commands to a specific SMP server.

Use getSMPClient to connect to an SMP server and create a client handle.

getProtocolClient :: forall v err msg. Protocol v err msg => TVar ChaChaDRG -> NetworkRequestMode -> TransportSession msg -> ProtocolClientConfig v -> [HostName] -> Maybe (TBQueue (ServerTransmissionBatch v err msg)) -> UTCTime -> (ProtocolClient v err msg -> IO ()) -> IO (Either (ProtocolClientError err) (ProtocolClient v err msg)) Source #

Connects to ProtocolServer 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.

closeProtocolClient :: ProtocolClient v err msg -> IO () Source #

Disconnects client from the server and terminates client threads.

useWebPort :: NetworkConfig -> [HostName] -> ProtocolServer p -> Bool Source #

isPresetDomain :: [HostName] -> TransportHost -> Bool Source #

SMP protocol command functions

subscribeSMPQueues :: SMPClient -> NonEmpty (RecipientId, RcvPrivateAuthKey) -> IO (NonEmpty (Either SMPClientError (Maybe ServiceId))) Source #

Subscribe to multiple SMP queues batching commands if supported. This command is always sent in background request mode

streamSubscribeSMPQueues :: SMPClient -> NonEmpty (RecipientId, RcvPrivateAuthKey) -> ([(RecipientId, Either SMPClientError (Maybe ServiceId))] -> IO ()) -> IO () Source #

getSMPMessage :: SMPClient -> RcvPrivateAuthKey -> RecipientId -> ExceptT SMPClientError IO (Maybe RcvMessage) Source #

Get message from SMP queue. The server returns ERR PROHIBITED if a client uses SUB and GET via the same transport connection for the same queue

https://github.covm/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#receive-a-message-from-the-queue This command is always sent in interactive request mode, as NSE has limited time

subscribeSMPQueuesNtfs :: SMPClient -> NonEmpty (NotifierId, NtfPrivateAuthKey) -> IO (NonEmpty (Either SMPClientError (Maybe ServiceId))) Source #

Subscribe to multiple SMP queues notifications batching commands if supported. This command is always sent in background request mode

subscribeService :: forall p. (PartyI p, ServiceParty p) => SMPClient -> SParty p -> ExceptT SMPClientError IO Int64 Source #

secureSndSMPQueue :: SMPClient -> NetworkRequestMode -> SndPrivateAuthKey -> SenderId -> ExceptT SMPClientError IO () Source #

Secure the SMP queue via sender queue ID.

addSMPQueueLink :: SMPClient -> NetworkRequestMode -> RcvPrivateAuthKey -> RecipientId -> LinkId -> QueueLinkData -> ExceptT SMPClientError IO () Source #

Add or update date for queue link

secureGetSMPQueueLink :: SMPClient -> NetworkRequestMode -> SndPrivateAuthKey -> LinkId -> ExceptT SMPClientError IO (SenderId, QueueLinkData) Source #

Get 1-time inviation SMP queue link data and secure the queue via queue link ID.

getSMPQueueLink :: SMPClient -> NetworkRequestMode -> LinkId -> ExceptT SMPClientError IO (SenderId, QueueLinkData) Source #

Get contact address SMP queue link data.

disableSMPQueueNotifications :: SMPClient -> RcvPrivateAuthKey -> RecipientId -> ExceptT SMPClientError IO () Source #

Disable notifications for the queue for push notifications server.

https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#disable-notifications-command This command is always sent in background request mode

enableSMPQueuesNtfs :: SMPClient -> NonEmpty (RecipientId, RcvPrivateAuthKey, NtfPublicAuthKey, RcvNtfPublicDhKey) -> IO (NonEmpty (Either SMPClientError (NotifierId, RcvNtfPublicDhKey))) Source #

Enable notifications for the multiple queues for push notifications server. This command is always sent in background request mode

disableSMPQueuesNtfs :: SMPClient -> NonEmpty (RecipientId, RcvPrivateAuthKey) -> IO (NonEmpty (Either SMPClientError ())) Source #

Disable notifications for multiple queues for push notifications server. This command is always sent in background request mode

ackSMPMessage :: SMPClient -> RcvPrivateAuthKey -> QueueId -> MsgId -> ExceptT SMPClientError IO () Source #

Acknowledge message delivery (server deletes the message).

https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#acknowledge-message-delivery This command is always sent in background request mode

suspendSMPQueue :: SMPClient -> NetworkRequestMode -> RcvPrivateAuthKey -> 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

deleteSMPQueues :: SMPClient -> NetworkRequestMode -> NonEmpty (RecipientId, RcvPrivateAuthKey) -> IO (NonEmpty (Either SMPClientError ())) Source #

Delete multiple SMP queues batching commands if supported.

sendProtocolCommand :: forall v err msg. Protocol v err msg => ProtocolClient v err msg -> NetworkRequestMode -> Maybe APrivateAuthKey -> EntityId -> ProtoCommand msg -> ExceptT (ProtocolClientError err) IO msg Source #

Send Protocol command

sendProtocolCommands :: forall v err msg. Protocol v err msg => ProtocolClient v err msg -> NetworkRequestMode -> NonEmpty (ClientCommand msg) -> IO (NonEmpty (Response err msg)) Source #

Send multiple commands with batching and collect responses

Supporting types and client configuration

data ProtocolClientError err Source #

SMP client error type.

Constructors

PCEProtocolError err

Correctly parsed SMP server ERR response. This error is forwarded to the agent client as `ERR SMP err`.

PCEResponseError err

Invalid server response that failed to parse. Forwarded to the agent client as `ERR BROKER RESPONSE`.

PCEUnexpectedResponse ByteString

Different response from what is expected to a certain SMP command, e.g. server should respond IDS or ERR to NEW command, other responses would result in this error. Forwarded to the agent client as `ERR BROKER UNEXPECTED`.

PCEResponseTimeout

Used for TCP connection and command response timeouts. Forwarded to the agent client as `ERR BROKER TIMEOUT`.

PCENetworkError NetworkError

Failure to establish TCP connection. Forwarded to the agent client as `ERR BROKER NETWORK`.

PCEIncompatibleHost

No host compatible with network configuration

PCEServiceUnavailable

Service is unavailable for command that requires service connection

PCETransportError TransportError

TCP transport handshake or some other transport error. Forwarded to the agent client as `ERR BROKER TRANSPORT e`.

PCECryptoError CryptoError

Error when cryptographically "signing" the command or when initializing crypto_box.

PCEIOError IOException

IO Error

Instances

Instances details
(Typeable err, Show err) => Exception (ProtocolClientError err) Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

toException :: ProtocolClientError err -> SomeException

fromException :: SomeException -> Maybe (ProtocolClientError err)

displayException :: ProtocolClientError err -> String

Show err => Show (ProtocolClientError err) Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

showsPrec :: Int -> ProtocolClientError err -> ShowS

show :: ProtocolClientError err -> String

showList :: [ProtocolClientError err] -> ShowS

Eq err => Eq (ProtocolClientError err) Source # 
Instance details

Defined in Simplex.Messaging.Client

data ProxyClientError Source #

Constructors

ProxyProtocolError

protocol error response from proxy

ProxyUnexpectedResponse

unexpexted response

Fields

ProxyResponseError

error between proxy and server

Instances

Instances details
FromJSON ProxyClientError Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

parseJSON :: Value -> Parser ProxyClientError

parseJSONList :: Value -> Parser [ProxyClientError]

omittedField :: Maybe ProxyClientError

ToJSON ProxyClientError Source # 
Instance details

Defined in Simplex.Messaging.Client

Exception ProxyClientError Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

toException :: ProxyClientError -> SomeException

fromException :: SomeException -> Maybe ProxyClientError

displayException :: ProxyClientError -> String

Show ProxyClientError Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

showsPrec :: Int -> ProxyClientError -> ShowS

show :: ProxyClientError -> String

showList :: [ProxyClientError] -> ShowS

Eq ProxyClientError Source # 
Instance details

Defined in Simplex.Messaging.Client

StrEncoding ProxyClientError Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

strEncode :: ProxyClientError -> ByteString Source #

strDecode :: ByteString -> Either String ProxyClientError Source #

strP :: Parser ProxyClientError Source #

data Response err msg Source #

Constructors

Response 

Fields

data ProtocolClientConfig v Source #

protocol client configuration.

Constructors

ProtocolClientConfig 

Fields

data NetworkConfig Source #

network configuration for the client

Constructors

NetworkConfig 

Fields

Instances

Instances details
FromJSON NetworkConfig Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

parseJSON :: Value -> Parser NetworkConfig

parseJSONList :: Value -> Parser [NetworkConfig]

omittedField :: Maybe NetworkConfig

ToJSON NetworkConfig Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

toJSON :: NetworkConfig -> Value

toEncoding :: NetworkConfig -> Encoding

toJSONList :: [NetworkConfig] -> Value

toEncodingList :: [NetworkConfig] -> Encoding

omitField :: NetworkConfig -> Bool

Show NetworkConfig Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

showsPrec :: Int -> NetworkConfig -> ShowS

show :: NetworkConfig -> String

showList :: [NetworkConfig] -> ShowS

Eq NetworkConfig Source # 
Instance details

Defined in Simplex.Messaging.Client

data NetworkTimeout Source #

Constructors

NetworkTimeout 

Fields

Instances

Instances details
FromJSON NetworkTimeout Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

parseJSON :: Value -> Parser NetworkTimeout

parseJSONList :: Value -> Parser [NetworkTimeout]

omittedField :: Maybe NetworkTimeout

ToJSON NetworkTimeout Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

toJSON :: NetworkTimeout -> Value

toEncoding :: NetworkTimeout -> Encoding

toJSONList :: [NetworkTimeout] -> Value

toEncodingList :: [NetworkTimeout] -> Encoding

omitField :: NetworkTimeout -> Bool

Show NetworkTimeout Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

showsPrec :: Int -> NetworkTimeout -> ShowS

show :: NetworkTimeout -> String

showList :: [NetworkTimeout] -> ShowS

Eq NetworkTimeout Source # 
Instance details

Defined in Simplex.Messaging.Client

data HostMode Source #

Constructors

HMOnionViaSocks

prefer (or require) onion hosts when connecting via SOCKS proxy

HMOnion

prefer (or require) onion hosts

HMPublic

prefer (or require) public hosts

Instances

Instances details
FromJSON HostMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

parseJSON :: Value -> Parser HostMode

parseJSONList :: Value -> Parser [HostMode]

omittedField :: Maybe HostMode

ToJSON HostMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

toJSON :: HostMode -> Value

toEncoding :: HostMode -> Encoding

toJSONList :: [HostMode] -> Value

toEncodingList :: [HostMode] -> Encoding

omitField :: HostMode -> Bool

Show HostMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

showsPrec :: Int -> HostMode -> ShowS

show :: HostMode -> String

showList :: [HostMode] -> ShowS

Eq HostMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

(==) :: HostMode -> HostMode -> Bool

(/=) :: HostMode -> HostMode -> Bool

data SocksMode Source #

Constructors

SMAlways

always use SOCKS proxy when enabled

SMOnion

use SOCKS proxy only for .onion hosts when no public host is available This mode is used in SMP proxy and in notifications server to minimize SOCKS proxy usage.

Instances

Instances details
FromJSON SocksMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

parseJSON :: Value -> Parser SocksMode

parseJSONList :: Value -> Parser [SocksMode]

omittedField :: Maybe SocksMode

ToJSON SocksMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

toJSON :: SocksMode -> Value

toEncoding :: SocksMode -> Encoding

toJSONList :: [SocksMode] -> Value

toEncodingList :: [SocksMode] -> Encoding

omitField :: SocksMode -> Bool

Show SocksMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

showsPrec :: Int -> SocksMode -> ShowS

show :: SocksMode -> String

showList :: [SocksMode] -> ShowS

Eq SocksMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

(==) :: SocksMode -> SocksMode -> Bool

(/=) :: SocksMode -> SocksMode -> Bool

StrEncoding SocksMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

strEncode :: SocksMode -> ByteString Source #

strDecode :: ByteString -> Either String SocksMode Source #

strP :: Parser SocksMode Source #

data SMPProxyMode Source #

Instances

Instances details
FromJSON SMPProxyMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

parseJSON :: Value -> Parser SMPProxyMode

parseJSONList :: Value -> Parser [SMPProxyMode]

omittedField :: Maybe SMPProxyMode

ToJSON SMPProxyMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

toJSON :: SMPProxyMode -> Value

toEncoding :: SMPProxyMode -> Encoding

toJSONList :: [SMPProxyMode] -> Value

toEncodingList :: [SMPProxyMode] -> Encoding

omitField :: SMPProxyMode -> Bool

Show SMPProxyMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

showsPrec :: Int -> SMPProxyMode -> ShowS

show :: SMPProxyMode -> String

showList :: [SMPProxyMode] -> ShowS

Eq SMPProxyMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

(==) :: SMPProxyMode -> SMPProxyMode -> Bool

(/=) :: SMPProxyMode -> SMPProxyMode -> Bool

StrEncoding SMPProxyMode Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

strEncode :: SMPProxyMode -> ByteString Source #

strDecode :: ByteString -> Either String SMPProxyMode Source #

strP :: Parser SMPProxyMode Source #

data SMPProxyFallback Source #

Instances

Instances details
FromJSON SMPProxyFallback Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

parseJSON :: Value -> Parser SMPProxyFallback

parseJSONList :: Value -> Parser [SMPProxyFallback]

omittedField :: Maybe SMPProxyFallback

ToJSON SMPProxyFallback Source # 
Instance details

Defined in Simplex.Messaging.Client

Show SMPProxyFallback Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

showsPrec :: Int -> SMPProxyFallback -> ShowS

show :: SMPProxyFallback -> String

showList :: [SMPProxyFallback] -> ShowS

Eq SMPProxyFallback Source # 
Instance details

Defined in Simplex.Messaging.Client

StrEncoding SMPProxyFallback Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

strEncode :: SMPProxyFallback -> ByteString Source #

strDecode :: ByteString -> Either String SMPProxyFallback Source #

strP :: Parser SMPProxyFallback Source #

data SMPWebPortServers Source #

Constructors

SWPAll 
SWPPreset 
SWPOff 

Instances

Instances details
FromJSON SMPWebPortServers Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

parseJSON :: Value -> Parser SMPWebPortServers

parseJSONList :: Value -> Parser [SMPWebPortServers]

omittedField :: Maybe SMPWebPortServers

ToJSON SMPWebPortServers Source # 
Instance details

Defined in Simplex.Messaging.Client

Show SMPWebPortServers Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

showsPrec :: Int -> SMPWebPortServers -> ShowS

show :: SMPWebPortServers -> String

showList :: [SMPWebPortServers] -> ShowS

Eq SMPWebPortServers Source # 
Instance details

Defined in Simplex.Messaging.Client

StrEncoding SMPWebPortServers Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

strEncode :: SMPWebPortServers -> ByteString Source #

strDecode :: ByteString -> Either String SMPWebPortServers Source #

strP :: Parser SMPWebPortServers Source #

defaultClientConfig :: Maybe [ALPN] -> Bool -> VersionRange v -> ProtocolClientConfig v Source #

Default protocol client configuration.

clientSocksCredentials :: ProtocolTypeI (ProtoType msg) => NetworkConfig -> UTCTime -> TransportSession msg -> Maybe SocksCredentials Source #

textToHostMode :: Text -> Either String HostMode Source #

type ServerTransmissionBatch v err msg = (TransportSession msg, Version v, SessionId, NonEmpty (EntityId, ServerTransmission err msg)) Source #

Type synonym for transmission from SPM servers. Batch response is presented as a single ServerTransmissionBatch tuple.

data ServerTransmission err msg Source #

Constructors

STEvent (Either (ProtocolClientError err) msg) 
STResponse (ProtoCommand msg) (Either (ProtocolClientError err) msg) 
STUnexpectedError (ProtocolClientError err) 

type ClientCommand msg = (EntityId, Maybe APrivateAuthKey, ProtoCommand msg) Source #

Type for client command data

For testing

type PCTransmission err msg = (Either TransportError SentRawTransmission, Request err msg) Source #

mkTransmission :: Protocol v err msg => ProtocolClient v err msg -> ClientCommand msg -> IO (PCTransmission err msg) Source #

authTransmission :: Maybe (THandleAuth 'TClient) -> Bool -> Maybe APrivateAuthKey -> CbNonce -> ByteString -> Either TransportError (Maybe TAuthorizations) Source #

smpClientStub :: TVar ChaChaDRG -> ByteString -> VersionSMP -> Maybe (THandleAuth 'TClient) -> IO SMPClient Source #

For debugging

data TBQueueInfo Source #

Constructors

TBQueueInfo 

Fields

Instances

Instances details
FromJSON TBQueueInfo Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

parseJSON :: Value -> Parser TBQueueInfo

parseJSONList :: Value -> Parser [TBQueueInfo]

omittedField :: Maybe TBQueueInfo

ToJSON TBQueueInfo Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

toJSON :: TBQueueInfo -> Value

toEncoding :: TBQueueInfo -> Encoding

toJSONList :: [TBQueueInfo] -> Value

toEncodingList :: [TBQueueInfo] -> Encoding

omitField :: TBQueueInfo -> Bool

Show TBQueueInfo Source # 
Instance details

Defined in Simplex.Messaging.Client

Methods

showsPrec :: Int -> TBQueueInfo -> ShowS

show :: TBQueueInfo -> String

showList :: [TBQueueInfo] -> ShowS

getTBQueueInfo :: TBQueue a -> STM TBQueueInfo Source #

nonBlockingWriteTBQueue :: TBQueue a -> a -> IO () Source #