fiber_json_types/peer.rs
1//! Peer management types for the Fiber Network JSON-RPC API.
2
3use crate::schema_helpers::*;
4use crate::serde_utils::Pubkey;
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8/// The type of transport to filter by when resolving peer addresses.
9#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema)]
10#[serde(rename_all = "snake_case")]
11pub enum TransportType {
12 /// TCP transport (e.g. /ip4/1.2.3.4/tcp/8080)
13 Tcp,
14 /// WebSocket transport (e.g. /ip4/1.2.3.4/tcp/8080/ws)
15 Ws,
16 /// WebSocket Secure transport (e.g. /dns/example.com/tcp/443/wss)
17 Wss,
18}
19
20/// Parameters for connecting to a peer.
21#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
22pub struct ConnectPeerParams {
23 /// The address of the peer to connect to (as a multiaddr string).
24 /// Either `address` or `pubkey` must be provided.
25 #[schemars(schema_with = "schema_as_string_optional")]
26 pub address: Option<String>,
27 /// The public key of the peer to connect to.
28 /// The node resolves the address from locally synced graph data.
29 pub pubkey: Option<Pubkey>,
30 /// Whether to save the peer address to the peer store.
31 pub save: Option<bool>,
32 /// Filter addresses by transport type when connecting by pubkey.
33 /// If not specified, the node uses target-specific defaults:
34 /// native builds choose from `tcp` addresses only, while wasm builds choose from `ws`/`wss`.
35 pub addr_type: Option<TransportType>,
36}
37
38/// Parameters for disconnecting from a peer.
39#[derive(Serialize, Deserialize, Debug, JsonSchema)]
40pub struct DisconnectPeerParams {
41 /// The public key of the peer to disconnect.
42 pub pubkey: Pubkey,
43}
44
45/// The information about a peer connected to the node.
46#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
47pub struct PeerInfo {
48 /// The identity public key of the peer.
49 pub pubkey: Pubkey,
50
51 /// The multi-address associated with the connecting peer (as a string).
52 /// Note: this is only the address which used for connecting to the peer, not all addresses of the peer.
53 /// The `graph_nodes` in Graph rpc module will return all addresses of the peer.
54 #[schemars(schema_with = "schema_as_string")]
55 pub address: String,
56}
57
58/// The result of the `list_peers` RPC method.
59#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
60pub struct ListPeersResult {
61 /// A list of connected peers.
62 pub peers: Vec<PeerInfo>,
63}