225 releases

new 0.4.66 Feb 23, 2024
0.4.65 Feb 21, 2024
0.4.18 Jan 31, 2024
0.3.11 Jan 23, 2024
0.1.53 Nov 29, 2023

#936 in Network programming

Download history 203/week @ 2023-11-03 382/week @ 2023-11-10 446/week @ 2023-11-17 633/week @ 2023-11-24 538/week @ 2023-12-01 898/week @ 2023-12-08 537/week @ 2023-12-15 442/week @ 2023-12-22 307/week @ 2023-12-29 893/week @ 2024-01-05 1072/week @ 2024-01-12 747/week @ 2024-01-19 797/week @ 2024-01-26 825/week @ 2024-02-02 1530/week @ 2024-02-09 4997/week @ 2024-02-16

8,336 downloads per month
Used in sn-node-manager

GPL-3.0 license

12K SLoC

Safenode RPC Client

This crate provides a client for the RPC protocol for interacting with safenode. It wraps the Protobuf-generated code and types such that users of the RPC protocol don't need to redefine that code.

It also provides a binary which is a CLI for interacting with a running safenode instance via the protocol.

RPC Actions

The RpcActions trait defines the protocol that is currently available for interacting with safenode:

node_info: Returns information about the node, such as its peer ID and version.
network_info: Retrieves network-related information, such as the peers currently connected to the node.
record_addresses: Provides a list of the node's record addresses.
gossipsub_subscribe: Subscribes to a specific topic on the gossipsub network.
gossipsub_unsubscribe: Unsubscribes from a given topic on the gossipsub network.
gossipsub_publish: Publishes a message to a specified topic on the gossipsub network.
restart_node: Requests the node to restart.
stop_node: Requests the node to stop its operations.
update_node: Updates the node with provided parameters.

Users of the crate can program against the trait rather than the RpcClient implementation.

This can facilitate behaviour-based unit testing, like so:

use mockall::mock;
use mockall::predicate::*;

mock! {
    pub RpcClient {}
    impl RpcClientInterface for RpcClient {
        async fn node_info(&self) -> RpcResult<NodeInfo>;
        async fn network_info(&self) -> RpcResult<NetworkInfo>;
        async fn record_addresses(&self) -> Result<Vec<RecordAddress>>;
        async fn gossipsub_subscribe(&self, topic: &str) -> Result<()>;
        async fn gossipsub_unsubscribe(&self, topic: &str) -> Result<()>;
        async fn gossipsub_publish(&self, topic: &str, message: &str) -> Result<()>;
        async fn node_restart(&self, delay_millis: u64) -> Result<()>;
        async fn node_stop(&self, delay_millis: u64) -> Result<()>;
        async fn node_update(&self, delay_millis: u64) -> Result<()>;

Binary Usage

Run cargo run -- <ADDR> <command> to connect to a node. Provide the address of the node's RPC service, e.g. Followed by the command to execute. Some of the commands available are:

  • info: Retrieve information about the node itself
  • netinfo: Retrieve information about the node's connections to the network
  • events: Start listening for node events
  • transfers: Start listening for transfers events
  • subscribe: Subscribe to a given Gossipsub topic
  • unsubscribe: Unsubscribe from a given Gossipsub topic
  • publish: Publish a msg on a given Gossipsub topic
  • restart: Restart the node after the specified delay
  • stop: Stop the node after the specified delay
  • update: Update to latest safenode released version, and restart it

For more information about each command, run cargo run -- <command> --help.


~1.5M SLoC