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.Agent

Description

This module defines SMP protocol agent with SQLite persistence.

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

Synopsis

SMP agent functional API

data AgentClient Source #

Constructors

AgentClient 

Fields

type AE a = ExceptT AgentErrorType IO a Source #

data SubscriptionsInfo Source #

Instances

Instances details
FromJSON SubscriptionsInfo Source # 
Instance details

Defined in Simplex.Messaging.Agent.Client

Methods

parseJSON :: Value -> Parser SubscriptionsInfo

parseJSONList :: Value -> Parser [SubscriptionsInfo]

omittedField :: Maybe SubscriptionsInfo

ToJSON SubscriptionsInfo Source # 
Instance details

Defined in Simplex.Messaging.Agent.Client

Show SubscriptionsInfo Source # 
Instance details

Defined in Simplex.Messaging.Agent.Client

Methods

showsPrec :: Int -> SubscriptionsInfo -> ShowS

show :: SubscriptionsInfo -> String

showList :: [SubscriptionsInfo] -> ShowS

data ValueOrRef a Source #

Constructors

VRValue (Maybe Int) a 
VRRef Int 

Instances

Instances details
Functor ValueOrRef Source # 
Instance details

Defined in Simplex.Messaging.Agent

Methods

fmap :: (a -> b) -> ValueOrRef a -> ValueOrRef b

(<$) :: a -> ValueOrRef b -> ValueOrRef a

getSMPAgentClient :: AgentConfig -> InitialAgentServers -> DBStore -> Bool -> IO AgentClient Source #

Creates an SMP agent client instance

withConnLock :: AgentClient -> ConnId -> Text -> AM a -> AM a Source #

withInvLock :: AgentClient -> ByteString -> Text -> AM a -> AM a Source #

createUser :: AgentClient -> NonEmpty (ServerCfg 'PSMP) -> NonEmpty (ServerCfg 'PXFTP) -> AE UserId Source #

deleteUser :: AgentClient -> UserId -> Bool -> AE () Source #

Delete user record optionally deleting all user's connections on SMP servers

createConnectionAsync :: ConnectionModeI c => AgentClient -> UserId -> ACorrId -> Bool -> SConnectionMode c -> InitialKeys -> SubscriptionMode -> AE ConnId Source #

Create SMP agent connection (NEW command) asynchronously, synchronous response is new connection id

setConnShortLinkAsync :: AgentClient -> ACorrId -> ConnId -> UserConnLinkData 'CMContact -> Maybe CRClientData -> AE () Source #

Create or update user's contact connection short link (LSET command) asynchronously, no synchronous response

getConnShortLinkAsync :: AgentClient -> UserId -> ACorrId -> Maybe ConnId -> ConnShortLink 'CMContact -> AE ConnId Source #

Get and verify data from short link (LGETLKEY command) asynchronously, synchronous response is newpassed connection id

joinConnectionAsync :: AgentClient -> UserId -> ACorrId -> Maybe ConnId -> Bool -> ConnectionRequestUri c -> ConnInfo -> PQSupport -> SubscriptionMode -> AE ConnId Source #

Join SMP agent connection (JOIN command) asynchronously, synchronous response is new connection id. If connId is provided (for contact URIs), it updates the existing connection record created by getConnShortLinkAsync.

allowConnectionAsync :: AgentClient -> ACorrId -> ConnId -> ConfirmationId -> ConnInfo -> AE () Source #

Allow connection to continue after CONF notification (LET command), no synchronous response

acceptContactAsync :: AgentClient -> UserId -> ACorrId -> Bool -> ConfirmationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AE ConnId Source #

Accept contact after REQ notification (ACPT command) asynchronously, synchronous response is new connection id

ackMessageAsync :: AgentClient -> ACorrId -> ConnId -> AgentMsgId -> Maybe MsgReceiptInfo -> AE () Source #

Acknowledge message (ACK command) asynchronously, no synchronous response

switchConnectionAsync :: AgentClient -> ACorrId -> ConnId -> AE ConnectionStats Source #

Switch connection to the new receive queue

deleteConnectionAsync :: AgentClient -> Bool -> ConnId -> AE () Source #

Delete SMP agent connection (DEL command) asynchronously, no synchronous response

deleteConnectionsAsync :: AgentClient -> Bool -> [ConnId] -> AE () Source #

Delete SMP agent connections using batch commands asynchronously, no synchronous response

createConnection :: ConnectionModeI c => AgentClient -> NetworkRequestMode -> UserId -> Bool -> Bool -> SConnectionMode c -> Maybe (UserConnLinkData c) -> Maybe CRClientData -> InitialKeys -> SubscriptionMode -> AE (ConnId, (CreatedConnLink c, Maybe ClientServiceId)) Source #

Create SMP agent connection (NEW command)

prepareConnectionLink :: AgentClient -> UserId -> KeyPairEd25519 -> ByteString -> Bool -> Maybe CRClientData -> AE (CreatedConnLink 'CMContact, PreparedLinkParams) Source #

Prepare connection link for contact mode (no network call). Caller provides root signing key pair and link entity ID. Returns the created link and internal params. The link address is fully determined at this point.

createConnectionForLink :: AgentClient -> NetworkRequestMode -> UserId -> Bool -> CreatedConnLink 'CMContact -> PreparedLinkParams -> UserConnLinkData 'CMContact -> InitialKeys -> SubscriptionMode -> AE ConnId Source #

Create connection for prepared link (single network call). Validates that server response matches the prepared link.

setConnShortLink :: AgentClient -> NetworkRequestMode -> ConnId -> SConnectionMode c -> UserConnLinkData c -> Maybe CRClientData -> AE (ConnShortLink c) Source #

Create or update user's contact connection short link

getConnShortLink :: AgentClient -> NetworkRequestMode -> UserId -> ConnShortLink c -> AE (FixedLinkData c, ConnLinkData c) Source #

Get and verify data from short link. For 1-time invitations it preserves the key to allow retries

deleteLocalInvShortLink :: AgentClient -> ConnShortLink 'CMInvitation -> AE () Source #

This irreversibly deletes short link data, and it won't be retrievable again

changeConnectionUser :: AgentClient -> UserId -> ConnId -> UserId -> AE () Source #

Changes the user id associated with a connection

prepareConnectionToJoin :: AgentClient -> UserId -> Bool -> ConnectionRequestUri c -> PQSupport -> AE ConnId Source #

Create SMP agent connection without queue (to be joined with joinConnection passing connection ID). This method is required to prevent race condition when confirmation from peer is received before the caller of joinConnection saves connection ID to the database. Instead of it we could send confirmation asynchronously, but then it would be harder to report "link deleted" (SMP AUTH) interactively, so this approach is simpler overall.

prepareConnectionToAccept :: AgentClient -> UserId -> Bool -> ConfirmationId -> PQSupport -> AE ConnId Source #

Create SMP agent connection without queue (to be joined with acceptContact passing invitation ID).

joinConnection :: AgentClient -> NetworkRequestMode -> UserId -> ConnId -> Bool -> ConnectionRequestUri c -> ConnInfo -> PQSupport -> SubscriptionMode -> AE (SndQueueSecured, Maybe ClientServiceId) Source #

Join SMP agent connection (JOIN command).

allowConnection :: AgentClient -> ConnId -> ConfirmationId -> ConnInfo -> AE () Source #

Allow connection to continue after CONF notification (LET command)

acceptContact :: AgentClient -> NetworkRequestMode -> UserId -> ConnId -> Bool -> ConfirmationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AE (SndQueueSecured, Maybe ClientServiceId) Source #

Accept contact after REQ notification (ACPT command)

rejectContact :: AgentClient -> ConfirmationId -> AE () Source #

Reject contact (RJCT command)

data DatabaseDiff a Source #

Constructors

DatabaseDiff 

Fields

Instances

Instances details
Functor DatabaseDiff Source # 
Instance details

Defined in Simplex.Messaging.Agent

Methods

fmap :: (a -> b) -> DatabaseDiff a -> DatabaseDiff b

(<$) :: a -> DatabaseDiff b -> DatabaseDiff a

FromJSON a => FromJSON (DatabaseDiff a) Source # 
Instance details

Defined in Simplex.Messaging.Agent

Methods

parseJSON :: Value -> Parser (DatabaseDiff a)

parseJSONList :: Value -> Parser [DatabaseDiff a]

omittedField :: Maybe (DatabaseDiff a)

ToJSON a => ToJSON (DatabaseDiff a) Source # 
Instance details

Defined in Simplex.Messaging.Agent

Methods

toJSON :: DatabaseDiff a -> Value

toEncoding :: DatabaseDiff a -> Encoding

toJSONList :: [DatabaseDiff a] -> Value

toEncodingList :: [DatabaseDiff a] -> Encoding

omitField :: DatabaseDiff a -> Bool

Show a => Show (DatabaseDiff a) Source # 
Instance details

Defined in Simplex.Messaging.Agent

Methods

showsPrec :: Int -> DatabaseDiff a -> ShowS

show :: DatabaseDiff a -> String

showList :: [DatabaseDiff a] -> ShowS

subscribeConnection :: AgentClient -> ConnId -> AE (Maybe ClientServiceId) Source #

Subscribe to receive connection messages (SUB command)

subscribeConnections :: AgentClient -> [ConnId] -> AE (Map ConnId (Either AgentErrorType (Maybe ClientServiceId))) Source #

Subscribe to receive connection messages from multiple connections, batching commands when possible

subscribeAllConnections :: AgentClient -> Bool -> Maybe UserId -> AE () Source #

Subscribe to all connections

getConnectionMessages :: AgentClient -> NonEmpty ConnMsgReq -> IO (NonEmpty (Either AgentErrorType (Maybe SMPMsgMeta))) Source #

Get messages for connections (GET commands)

getNotificationConns :: AgentClient -> CbNonce -> ByteString -> AE (NonEmpty NotificationInfo) Source #

Get connections for received notification

sendMessage :: AgentClient -> ConnId -> PQEncryption -> MsgFlags -> MsgBody -> AE (AgentMsgId, PQEncryption) Source #

Send message to the connection (SEND command)

sendMessages :: AgentClient -> [MsgReq] -> AE [Either AgentErrorType (AgentMsgId, PQEncryption)] Source #

Send multiple messages to different connections (SEND command)

sendMessagesB :: Traversable t => AgentClient -> t (Either AgentErrorType MsgReq) -> AE (t (Either AgentErrorType (AgentMsgId, PQEncryption))) Source #

switchConnection :: AgentClient -> NetworkRequestMode -> ConnId -> AE ConnectionStats Source #

Switch connection to the new receive queue

abortConnectionSwitch :: AgentClient -> ConnId -> AE ConnectionStats Source #

Abort switching connection to the new receive queue

synchronizeRatchet :: AgentClient -> ConnId -> PQSupport -> Bool -> AE ConnectionStats Source #

Re-synchronize connection ratchet keys

suspendConnection :: AgentClient -> NetworkRequestMode -> ConnId -> AE () Source #

Suspend SMP agent connection (OFF command)

deleteConnection :: AgentClient -> NetworkRequestMode -> ConnId -> AE () Source #

Delete SMP agent connection (DEL command)

deleteConnections :: AgentClient -> NetworkRequestMode -> [ConnId] -> AE (Map ConnId (Either AgentErrorType ())) Source #

Delete multiple connections, batching commands when possible

getConnectionServers :: AgentClient -> ConnId -> AE ConnectionStats Source #

get servers used for connection

getConnectionRatchetAdHash :: AgentClient -> ConnId -> AE ByteString Source #

get connection ratchet associated data hash for verification (should match peer AD hash)

setProtocolServers :: forall p. (ProtocolTypeI p, UserProtocol p) => AgentClient -> UserId -> NonEmpty (ServerCfg p) -> IO () Source #

Change servers to be used for creating new queues. This function will set all servers as enabled in case all passed servers are disabled.

checkUserServers :: Text -> NonEmpty (ServerCfg p) -> IO () Source #

setNetworkConfig :: AgentClient -> NetworkConfig -> IO () Source #

set SOCKS5 proxy on/off and optionally set TCP timeouts for fast network

verifyNtfToken :: AgentClient -> NetworkRequestMode -> DeviceToken -> CbNonce -> ByteString -> AE () Source #

Verify device notifications token

toggleConnectionNtfs :: AgentClient -> ConnId -> Bool -> AE () Source #

Set connection notifications on/off

xftpStartWorkers :: AgentClient -> Maybe FilePath -> AE () Source #

xftpStartSndWorkers :: AgentClient -> Maybe FilePath -> AE () Source #

xftpDeleteRcvFile :: AgentClient -> RcvFileId -> IO () Source #

Delete XFTP rcv file (deletes work files from file system and db records)

xftpDeleteRcvFiles :: AgentClient -> [RcvFileId] -> IO () Source #

Delete multiple rcv files, batching operations when possible (deletes work files from file system and db records)

xftpSendFile :: AgentClient -> UserId -> CryptoFile -> Int -> AE SndFileId Source #

Send XFTP file

xftpDeleteSndFileInternal :: AgentClient -> SndFileId -> IO () Source #

Delete XFTP snd file internally (deletes work files from file system and db records)

xftpDeleteSndFilesInternal :: AgentClient -> [SndFileId] -> IO () Source #

Delete multiple snd files internally, batching operations when possible (deletes work files from file system and db records)

xftpDeleteSndFileRemote :: AgentClient -> UserId -> SndFileId -> ValidFileDescription 'FSender -> IO () Source #

Delete XFTP snd file chunks on servers

xftpDeleteSndFilesRemote :: AgentClient -> UserId -> [(SndFileId, ValidFileDescription 'FSender)] -> IO () Source #

Delete XFTP snd file chunks on servers for multiple snd files, batching operations when possible

rcNewHostPairing :: AgentClient -> IO RCHostPairing Source #

Create new remote host pairing

rcConnectHost :: AgentClient -> RCHostPairing -> Value -> Bool -> Maybe RCCtrlAddress -> Maybe Word16 -> AE RCHostConnection Source #

start TLS server for remote host with optional multicast

rcConnectCtrl :: AgentClient -> RCVerifiedInvitation -> Maybe RCCtrlPairing -> Value -> AE RCCtrlConnection Source #

connect to remote controller via URI

rcDiscoverCtrl :: AgentClient -> NonEmpty RCCtrlPairing -> AE (RCCtrlPairing, RCVerifiedInvitation) Source #

connect to known remote controller via multicast

foregroundAgent :: AgentClient -> IO () Source #

Activate operations

suspendAgent :: AgentClient -> Int -> IO () Source #

Suspend operations with max delay to deliver pending messages

execAgentStoreSQL :: AgentClient -> Text -> AE [Text] Source #

logConnection :: AgentClient -> Bool -> IO () Source #