pub struct IpcClient<Crypto, Com, Ses>where
Crypto: CryptoProvider<Com, Ses>,
Com: CommunicationBackend,
Ses: SessionRepository<Crypto::Session>,{
crypto: Crypto,
communication: Com,
sessions: Ses,
handlers: RpcHandlerRegistry,
incoming: RwLock<Option<Receiver<IncomingMessage>>>,
cancellation_token: RwLock<Option<CancellationToken>>,
}
Expand description
An IPC client that handles communication between different components and clients. It uses a crypto provider to encrypt and decrypt messages, a communication backend to send and receive messages, and a session repository to persist sessions.
Fields§
§crypto: Crypto
§communication: Com
§sessions: Ses
§handlers: RpcHandlerRegistry
§incoming: RwLock<Option<Receiver<IncomingMessage>>>
§cancellation_token: RwLock<Option<CancellationToken>>
Implementations§
Source§impl<Crypto, Com, Ses> IpcClient<Crypto, Com, Ses>where
Crypto: CryptoProvider<Com, Ses>,
Com: CommunicationBackend,
Ses: SessionRepository<Crypto::Session>,
impl<Crypto, Com, Ses> IpcClient<Crypto, Com, Ses>where
Crypto: CryptoProvider<Com, Ses>,
Com: CommunicationBackend,
Ses: SessionRepository<Crypto::Session>,
Sourcepub fn new(crypto: Crypto, communication: Com, sessions: Ses) -> Arc<Self>
pub fn new(crypto: Crypto, communication: Com, sessions: Ses) -> Arc<Self>
Create a new IPC client with the provided crypto provider, communication backend, and session repository.
Sourcepub async fn start(self: &Arc<Self>)
pub async fn start(self: &Arc<Self>)
Start the IPC client, which will begin listening for incoming messages and processing them. This will be done in a separate task, allowing the client to receive messages asynchronously. The client will stop automatically if an error occurs during message processing or if the cancellation token is triggered.
Note: The client can and will send messages in the background while it is running, even if no active subscriptions are present.
Sourcepub async fn is_running(self: &Arc<Self>) -> bool
pub async fn is_running(self: &Arc<Self>) -> bool
Check if the IPC client task is currently running.
Sourcepub async fn stop(self: &Arc<Self>)
pub async fn stop(self: &Arc<Self>)
Stop the IPC client task. This will stop listening for incoming messages.
Sourcepub async fn register_rpc_handler<H>(self: &Arc<Self>, handler: H)
pub async fn register_rpc_handler<H>(self: &Arc<Self>, handler: H)
Register a new RPC handler for processing incoming RPC requests. The handler will be executed by the IPC client when an RPC request is received and the response will be sent back over IPC.
Sourcepub async fn send(
self: &Arc<Self>,
message: OutgoingMessage,
) -> Result<(), Crypto::SendError>
pub async fn send( self: &Arc<Self>, message: OutgoingMessage, ) -> Result<(), Crypto::SendError>
Send a message
Sourcepub async fn subscribe(
self: &Arc<Self>,
topic: Option<String>,
) -> Result<IpcClientSubscription, SubscribeError>
pub async fn subscribe( self: &Arc<Self>, topic: Option<String>, ) -> Result<IpcClientSubscription, SubscribeError>
Create a subscription to receive messages, optionally filtered by topic.
Setting the topic to None
will receive all messages.
Sourcepub async fn subscribe_typed<Payload>(
self: &Arc<Self>,
) -> Result<IpcClientTypedSubscription<Payload>, SubscribeError>where
Payload: DeserializeOwned + PayloadTypeName,
pub async fn subscribe_typed<Payload>(
self: &Arc<Self>,
) -> Result<IpcClientTypedSubscription<Payload>, SubscribeError>where
Payload: DeserializeOwned + PayloadTypeName,
Create a subscription to receive messages that can be deserialized into the provided payload type.
Sourcepub async fn request<Request>(
self: &Arc<Self>,
request: Request,
destination: Endpoint,
cancellation_token: Option<CancellationToken>,
) -> Result<Request::Response, RequestError>where
Request: RpcRequest,
pub async fn request<Request>(
self: &Arc<Self>,
request: Request,
destination: Endpoint,
cancellation_token: Option<CancellationToken>,
) -> Result<Request::Response, RequestError>where
Request: RpcRequest,
Send a request to the specified destination and wait for a response. The destination must have a registered RPC handler for the request type, otherwise an error will be returned by the remote endpoint.