Skip to main content

samod_core/network/
peer_metadata.rs

1use crate::StorageId;
2
3use super::wire_protocol;
4
5/// Metadata about a peer from the handshake.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct PeerMetadata {
8    /// Whether the peer expects to connect again with this storage ID
9    pub is_ephemeral: bool,
10    /// The storage ID of this peer
11    pub storage_id: Option<StorageId>,
12}
13
14impl PeerMetadata {
15    /// Convert to wire protocol PeerMetadata for sending over network
16    pub(crate) fn to_wire(&self) -> wire_protocol::PeerMetadata {
17        wire_protocol::PeerMetadata {
18            storage_id: self.storage_id.clone(),
19            is_ephemeral: self.is_ephemeral,
20        }
21    }
22
23    /// Convert from wire protocol PeerMetadata when receiving from network
24    pub(crate) fn from_wire(wire: wire_protocol::PeerMetadata) -> Self {
25        Self {
26            is_ephemeral: wire.is_ephemeral,
27            storage_id: wire.storage_id,
28        }
29    }
30}