use fidl_fuchsia_overnet_protocol::TRANSFER_KEY_LENGTH;
use rand::Rng;
#[derive(PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Hash, Debug)]
pub struct NodeId(pub u64);
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Endpoint {
Client,
Server,
}
impl NodeId {
pub fn circuit_string(&self) -> String {
format!("{:x}", self.0)
}
pub fn from_circuit_string(id: &str) -> Result<Self, ()> {
Ok(NodeId(u64::from_str_radix(id, 16).map_err(|_| ())?))
}
}
impl From<u64> for NodeId {
fn from(id: u64) -> Self {
NodeId(id)
}
}
impl From<NodeId> for fidl_fuchsia_overnet_protocol::NodeId {
fn from(id: NodeId) -> Self {
Self { id: id.0 }
}
}
impl From<&NodeId> for fidl_fuchsia_overnet_protocol::NodeId {
fn from(id: &NodeId) -> Self {
Self { id: id.0 }
}
}
impl From<fidl_fuchsia_overnet_protocol::NodeId> for NodeId {
fn from(id: fidl_fuchsia_overnet_protocol::NodeId) -> Self {
id.id.into()
}
}
#[derive(PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Debug, Hash)]
pub struct NodeLinkId(pub u64);
impl From<u64> for NodeLinkId {
fn from(id: u64) -> Self {
NodeLinkId(id)
}
}
pub(crate) type TransferKey = [u8; TRANSFER_KEY_LENGTH as usize];
pub(crate) fn generate_transfer_key() -> TransferKey {
rand::thread_rng().gen::<TransferKey>()
}