Expand description
§Discover
A built-in RPC request/response pair for client discovery and health checking over IPC.
§Purpose
The discover module provides a simple “ping” mechanism that allows one IPC endpoint to check whether another endpoint is alive and reachable. The responding endpoint includes its version string, which can be used for compatibility checks.
§Types
DiscoverRequest: An empty RPC request that acts as a ping. ImplementsRpcRequestwithNAME = "DiscoverRequest".DiscoverResponse: Contains aversionstring identifying the responding client.DiscoverHandler: A pre-builtRpcHandlerthat responds toDiscoverRequestwith a fixedDiscoverResponse. Register it on anIpcClientto make that client discoverable.
§Usage
§Responding to discover requests
Register the handler so the client responds to incoming discover requests:
let handler = DiscoverHandler::new(DiscoverResponse {
version: "1.0.0".to_string(),
});
ipc_client.register_rpc_handler(handler).await;§Sending a discover request
Send a discover request to a specific endpoint:
let response = ipc_client
.request::<DiscoverRequest>(
DiscoverRequest,
destination_endpoint,
None, // optional cancellation token
)
.await?;
println!("Remote version: {}", response.version);§Waiting for a peer
wait_for_peer retries discover requests until the destination answers or the optional cancellation
token is cancelled. Use it before sending to a peer that may not have started yet, since messages
sent before then are lost. An error answer from the peer, or a local subscribe error such as the
client not running, is returned without retrying:
let response = wait_for_peer(&ipc_client, destination_endpoint, None).await?;
println!("Remote version: {}", response.version);§WASM
In WASM contexts, two functions are exported:
ipcRegisterDiscoverHandler(client, response): registers the handleripcRequestDiscover(client, destination, abortSignal?): sends a discover request
Structs§
- Discover
Handler - A simple handler for the
DiscoverRequestthat always returns the same response. Used to enable discovery/ping functionality and provide version information. - Discover
Request - A request to discover/ping a client.
- Discover
Response - The response to a discover/ping request.
Constants§
- ATTEMPT_
TIMEOUT 🔒 - Upper bound for a single discover attempt in
wait_for_peer, so a lost message cannot stall the wait. Must stay longer than the Noise handshake timeout (2s), so a handshake finishes or fails on its own first. - RETRY_
DELAY 🔒 - Pause between failed discover attempts in
wait_for_peer.
Functions§
- wait_
for_ peer - Waits until
destinationanswers aDiscoverRequest, retrying until it does orcancellation_tokenis cancelled.