netzwork_api/interface/mod.rs
1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
7pub struct NetInterface {
8 pub host_uuid: Uuid,
9 pub uuid: Uuid,
10 pub name: String,
11 pub mac_addr: Vec<u8>,
12}
13
14impl fmt::Display for NetInterface {
15 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16 let parts: Vec<String> = vec![self.host_uuid.to_string(), self.name.clone()];
17 write!(f, "{}", parts.join("_"))
18 }
19}
20
21impl NetInterface {
22 // pub fn fingerprint(&self, ip_addr: &IpAddr) -> [u8; 32] {
23 // let mut hash = Hash::new();
24 // hash.update(self.host_id);
25 // hash.update(self.name.clone());
26 // hash.update(ip_addr.to_string());
27 // hash.finalize()
28 // }
29 // pub fn fingerprint_set(&self) -> HashSet<[u8; 32]> {
30 // let mut set = HashSet::new();
31 // for addr in self.ip_addr.iter() {
32 // set.insert(self.fingerprint(addr));
33 // }
34 // set
35 // }
36}
37
38// pub fn identify_interface(
39// known_interfaces: &[NetInterfaceId],
40// remote_socket: &SocketAddr,
41// fingerprint: [u8; 32],
42// ) -> Result<NetInterfaceId, NetzworkApiError> {
43// for iface in known_interfaces.iter() {
44// if iface.ip_addr.contains(&remote_socket.ip())
45// && iface.fingerprint(&remote_socket.ip()) == fingerprint
46// {
47// return Ok(iface.to_owned());
48// };
49// }
50// Err(NetzworkApiError::UnknownNetInterfaceId(format!(
51// "{:?} with fingerprint {:?}",
52// remote_socket, fingerprint
53// )))
54// }
55
56#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
57pub struct NetInterfaceAddr {
58 pub iface_uuid: Uuid,
59 pub uuid: Uuid,
60 pub ip_addr: String,
61 pub active: bool,
62}