Copyright | (c) simplex.chat |
---|---|
License | AGPL-3 |
Maintainer | chat@simplex.chat |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
This module defines SMP protocol agent with SQLite persistence.
See https://github.com/simplex-chat/simplexmq/blob/master/protocol/agent-protocol.md
Synopsis
- runSMPAgent :: (MonadRandom m, MonadUnliftIO m) => ATransport -> AgentConfig -> m ()
- runSMPAgentBlocking :: (MonadRandom m, MonadUnliftIO m) => ATransport -> TMVar Bool -> AgentConfig -> m ()
- getAgentClient :: (MonadUnliftIO m, MonadReader Env m) => m AgentClient
- runAgentClient :: (MonadUnliftIO m, MonadReader Env m) => AgentClient -> m ()
- data AgentClient = AgentClient {
- rcvQ :: TBQueue (ATransmission 'Client)
- subQ :: TBQueue (ATransmission 'Agent)
- msgQ :: TBQueue SMPServerTransmission
- smpClients :: TVar (Map SMPServer SMPClient)
- subscrSrvrs :: TVar (Map SMPServer (Map ConnId RcvQueue))
- subscrConns :: TVar (Map ConnId SMPServer)
- activations :: TVar (Map ConnId (Async ()))
- connMsgQueues :: TVar (Map ConnId (TQueue PendingMsg))
- connMsgDeliveries :: TVar (Map ConnId (Async ()))
- srvMsgQueues :: TVar (Map SMPServer (TQueue PendingMsg))
- srvMsgDeliveries :: TVar (Map SMPServer (Async ()))
- reconnections :: TVar [Async ()]
- clientId :: Int
- agentEnv :: Env
- smpSubscriber :: Async ()
- lock :: TMVar ()
- type AgentMonad m = (MonadUnliftIO m, MonadReader Env m, MonadError AgentErrorType m)
- type AgentErrorMonad m = (MonadUnliftIO m, MonadError AgentErrorType m)
- getSMPAgentClient :: (MonadRandom m, MonadUnliftIO m) => AgentConfig -> m AgentClient
- disconnectAgentClient :: MonadUnliftIO m => AgentClient -> m ()
- withAgentLock :: MonadUnliftIO m => AgentClient -> m a -> m a
- createConnection :: AgentErrorMonad m => AgentClient -> SConnectionMode c -> m (ConnId, ConnectionRequest c)
- joinConnection :: AgentErrorMonad m => AgentClient -> ConnectionRequest c -> ConnInfo -> m ConnId
- allowConnection :: AgentErrorMonad m => AgentClient -> ConnId -> ConfirmationId -> ConnInfo -> m ()
- acceptContact :: AgentErrorMonad m => AgentClient -> ConfirmationId -> ConnInfo -> m ConnId
- rejectContact :: AgentErrorMonad m => AgentClient -> ConnId -> ConfirmationId -> m ()
- subscribeConnection :: AgentErrorMonad m => AgentClient -> ConnId -> m ()
- sendMessage :: AgentErrorMonad m => AgentClient -> ConnId -> MsgBody -> m AgentMsgId
- ackMessage :: AgentErrorMonad m => AgentClient -> ConnId -> AgentMsgId -> m ()
- suspendConnection :: AgentErrorMonad m => AgentClient -> ConnId -> m ()
- deleteConnection :: AgentErrorMonad m => AgentClient -> ConnId -> m ()
SMP agent over TCP
runSMPAgent :: (MonadRandom m, MonadUnliftIO m) => ATransport -> AgentConfig -> m () Source #
Runs an SMP agent as a TCP service using passed configuration.
See a full agent executable here: https://github.com/simplex-chat/simplexmq/blob/master/apps/smp-agent/Main.hs
runSMPAgentBlocking :: (MonadRandom m, MonadUnliftIO m) => ATransport -> TMVar Bool -> AgentConfig -> m () Source #
Runs an SMP agent as a TCP service using passed configuration with signalling.
This function uses passed TMVar to signal when the server is ready to accept TCP requests (True) and when it is disconnected from the TCP socket once the server thread is killed (False).
queue-based SMP agent
getAgentClient :: (MonadUnliftIO m, MonadReader Env m) => m AgentClient Source #
Creates an SMP agent client instance that receives commands and sends responses via TBQueue
s.
runAgentClient :: (MonadUnliftIO m, MonadReader Env m) => AgentClient -> m () Source #
Runs an SMP agent instance that receives commands and sends responses via TBQueue
s.
SMP agent functional API
data AgentClient Source #
AgentClient | |
|
type AgentMonad m = (MonadUnliftIO m, MonadReader Env m, MonadError AgentErrorType m) Source #
Agent monad with MonadReader Env and MonadError AgentErrorType
type AgentErrorMonad m = (MonadUnliftIO m, MonadError AgentErrorType m) Source #
getSMPAgentClient :: (MonadRandom m, MonadUnliftIO m) => AgentConfig -> m AgentClient Source #
Creates an SMP agent client instance
disconnectAgentClient :: MonadUnliftIO m => AgentClient -> m () Source #
withAgentLock :: MonadUnliftIO m => AgentClient -> m a -> m a Source #
createConnection :: AgentErrorMonad m => AgentClient -> SConnectionMode c -> m (ConnId, ConnectionRequest c) Source #
Create SMP agent connection (NEW command)
joinConnection :: AgentErrorMonad m => AgentClient -> ConnectionRequest c -> ConnInfo -> m ConnId Source #
Join SMP agent connection (JOIN command)
allowConnection :: AgentErrorMonad m => AgentClient -> ConnId -> ConfirmationId -> ConnInfo -> m () Source #
Allow connection to continue after CONF notification (LET command)
acceptContact :: AgentErrorMonad m => AgentClient -> ConfirmationId -> ConnInfo -> m ConnId Source #
Accept contact after REQ notification (ACPT command)
rejectContact :: AgentErrorMonad m => AgentClient -> ConnId -> ConfirmationId -> m () Source #
Reject contact (RJCT command)
subscribeConnection :: AgentErrorMonad m => AgentClient -> ConnId -> m () Source #
Subscribe to receive connection messages (SUB command)
sendMessage :: AgentErrorMonad m => AgentClient -> ConnId -> MsgBody -> m AgentMsgId Source #
Send message to the connection (SEND command)
ackMessage :: AgentErrorMonad m => AgentClient -> ConnId -> AgentMsgId -> m () Source #
suspendConnection :: AgentErrorMonad m => AgentClient -> ConnId -> m () Source #
Suspend SMP agent connection (OFF command)
deleteConnection :: AgentErrorMonad m => AgentClient -> ConnId -> m () Source #
Delete SMP agent connection (DEL command)