use std::net::{Ipv4Addr, Ipv6Addr}; use imbl_value::InternedString; use crate::{GatewayId, HostId, ServiceInterfaceId}; use serde::{Deserialize, Serialize}; use ts_rs::TS; #[derive(Clone, Debug, Deserialize, Serialize, TS)] #[ts(export)] #[serde(rename_all = "camelCase")] #[serde(rename_all_fields = "camelCase")] #[serde(tag = "kind")] pub enum HostnameInfo { Ip { gateway: GatewayInfo, public: bool, hostname: IpHostname, }, Onion { hostname: OnionHostname, }, } impl HostnameInfo { pub fn to_san_hostname(&self) -> InternedString { match self { Self::Ip { hostname, .. } => hostname.to_san_hostname(), Self::Onion { hostname } => hostname.to_san_hostname(), } } } #[derive(Clone, Debug, Deserialize, Serialize, TS)] #[ts(export)] #[serde(rename_all = "camelCase")] pub struct GatewayInfo { pub id: GatewayId, pub name: InternedString, pub public: bool, } #[derive(Clone, Debug, Deserialize, Serialize, TS)] #[ts(export)] #[serde(rename_all = "camelCase")] pub struct OnionHostname { #[ts(type = "string")] pub value: InternedString, pub port: Option, pub ssl_port: Option, } impl OnionHostname { pub fn to_san_hostname(&self) -> InternedString { self.value.clone() } } #[derive(Clone, Debug, Deserialize, Serialize, TS)] #[ts(export)] #[serde(rename_all = "camelCase")] #[serde(rename_all_fields = "camelCase")] #[serde(tag = "kind")] pub enum IpHostname { Ipv4 { value: Ipv4Addr, port: Option, ssl_port: Option, }, Ipv6 { value: Ipv6Addr, #[serde(default)] scope_id: u32, port: Option, ssl_port: Option, }, Local { #[ts(type = "string")] value: InternedString, port: Option, ssl_port: Option, }, Domain { #[ts(type = "string")] value: InternedString, port: Option, ssl_port: Option, }, } impl IpHostname { pub fn to_san_hostname(&self) -> InternedString { match self { Self::Ipv4 { value, .. } => InternedString::from_display(value), Self::Ipv6 { value, .. } => InternedString::from_display(value), Self::Local { value, .. } => value.clone(), Self::Domain { value, .. } => value.clone(), } } } #[derive(Clone, Debug, Deserialize, Serialize, TS)] #[ts(export)] #[serde(rename_all = "camelCase")] pub struct ServiceInterface { pub id: ServiceInterfaceId, pub name: String, pub description: String, pub masked: bool, pub address_info: AddressInfo, #[serde(rename = "type")] pub interface_type: ServiceInterfaceType, } #[derive(Clone, Debug, Deserialize, Serialize, TS)] #[ts(export)] #[serde(rename_all = "camelCase")] pub enum ServiceInterfaceType { Ui, P2p, Api, } #[derive(Clone, Debug, Deserialize, Serialize, TS)] #[ts(export)] #[serde(rename_all = "camelCase")] pub struct AddressInfo { pub username: Option, pub host_id: HostId, pub internal_port: u16, #[ts(type = "string | null")] pub scheme: Option, #[ts(type = "string | null")] pub ssl_scheme: Option, pub suffix: String, }