Skip to main content

Module discover

Module discover 

Source
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. Implements RpcRequest with NAME = "DiscoverRequest".
  • DiscoverResponse: Contains a version string identifying the responding client.
  • DiscoverHandler: A pre-built RpcHandler that responds to DiscoverRequest with a fixed DiscoverResponse. Register it on an IpcClient to 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 handler
  • ipcRequestDiscover(client, destination, abortSignal?): sends a discover request

Structs§

DiscoverHandler
A simple handler for the DiscoverRequest that always returns the same response. Used to enable discovery/ping functionality and provide version information.
DiscoverRequest
A request to discover/ping a client.
DiscoverResponse
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 destination answers a DiscoverRequest, retrying until it does or cancellation_token is cancelled.