iroh_node_util/rpc/client/
node.rs1use std::collections::BTreeMap;
5
6use anyhow::Result;
7use quic_rpc::RpcClient;
8
9use super::net::NodeStatus;
10use crate::rpc::proto::{node::*, RpcService};
11
12#[derive(Debug, Clone)]
14#[repr(transparent)]
15pub struct Client {
16 pub(super) rpc: RpcClient<RpcService>,
17}
18
19impl Client {
20 pub fn new(rpc: RpcClient<RpcService>) -> Self {
22 Self { rpc }
23 }
24
25 pub async fn shutdown(&self, force: bool) -> Result<()> {
30 self.rpc.rpc(ShutdownRequest { force }).await?;
31 Ok(())
32 }
33
34 pub async fn stats(&self) -> Result<BTreeMap<String, CounterStats>> {
36 let res = self.rpc.rpc(StatsRequest {}).await??;
37 Ok(res.stats)
38 }
39
40 pub async fn status(&self) -> Result<NodeStatus> {
42 let response = self.rpc.rpc(StatusRequest).await??;
43 Ok(response)
44 }
45}