zebra_rpc/methods/types/
peer_info.rs

1//! An array of [`PeerInfo`] is the output of the `getpeerinfo` RPC method.
2
3use derive_getters::Getters;
4use derive_new::new;
5use zebra_network::{types::MetaAddr, PeerSocketAddr};
6
7/// Item of the `getpeerinfo` response
8#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize, Getters, new)]
9pub struct PeerInfo {
10    /// The IP address and port of the peer
11    #[getter(copy)]
12    pub(crate) addr: PeerSocketAddr,
13
14    /// Inbound (true) or Outbound (false)
15    pub(crate) inbound: bool,
16}
17
18/// Response type for the `getpeerinfo` RPC method.
19pub type GetPeerInfoResponse = Vec<PeerInfo>;
20
21impl From<MetaAddr> for PeerInfo {
22    fn from(meta_addr: MetaAddr) -> Self {
23        Self {
24            addr: meta_addr.addr(),
25            inbound: meta_addr.is_inbound(),
26        }
27    }
28}
29
30impl Default for PeerInfo {
31    fn default() -> Self {
32        Self {
33            addr: PeerSocketAddr::unspecified(),
34            inbound: false,
35        }
36    }
37}