chore: flatten HostnameInfo from enum to struct

HostnameInfo only had one variant (Ip) after removing Tor. Flatten it
into a plain struct with fields gateway, public, hostname. Remove all
kind === 'ip' type guards and narrowing across SDK, frontend, and
container runtime. Update DB migration to strip the kind field.
This commit is contained in:
Aiden McClelland
2026-02-10 13:38:12 -07:00
parent 2ee403e7de
commit 8204074bdf
8 changed files with 47 additions and 64 deletions

View File

@@ -481,7 +481,7 @@ impl NetServiceData {
i.device_type != Some(NetworkInterfaceType::Wireguard)
})
{
bind_hostname_info.push(HostnameInfo::Ip {
bind_hostname_info.push(HostnameInfo {
gateway: gateway.clone(),
public: false,
hostname: IpHostname::Local {
@@ -514,7 +514,7 @@ impl NetServiceData {
.as_ref()
.map_or(false, |ssl| ssl.preferred_external_port == 443)
{
bind_hostname_info.push(HostnameInfo::Ip {
bind_hostname_info.push(HostnameInfo {
gateway: gateway.clone(),
public,
hostname: IpHostname::Domain {
@@ -524,7 +524,7 @@ impl NetServiceData {
},
});
} else {
bind_hostname_info.push(HostnameInfo::Ip {
bind_hostname_info.push(HostnameInfo {
gateway: gateway.clone(),
public,
hostname: IpHostname::Domain {
@@ -540,7 +540,7 @@ impl NetServiceData {
if let Some(ip_info) = &info.ip_info {
let public = info.public();
if let Some(wan_ip) = ip_info.wan_ip {
bind_hostname_info.push(HostnameInfo::Ip {
bind_hostname_info.push(HostnameInfo {
gateway: gateway.clone(),
public: true,
hostname: IpHostname::Ipv4 {
@@ -554,7 +554,7 @@ impl NetServiceData {
match ipnet {
IpNet::V4(net) => {
if !public {
bind_hostname_info.push(HostnameInfo::Ip {
bind_hostname_info.push(HostnameInfo {
gateway: gateway.clone(),
public,
hostname: IpHostname::Ipv4 {
@@ -566,7 +566,7 @@ impl NetServiceData {
}
}
IpNet::V6(net) => {
bind_hostname_info.push(HostnameInfo::Ip {
bind_hostname_info.push(HostnameInfo {
gateway: gateway.clone(),
public: public && !ipv6_is_local(net.addr()),
hostname: IpHostname::Ipv6 {

View File

@@ -9,20 +9,14 @@ use crate::{GatewayId, HostId, ServiceInterfaceId};
#[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,
},
pub struct HostnameInfo {
pub gateway: GatewayInfo,
pub public: bool,
pub hostname: IpHostname,
}
impl HostnameInfo {
pub fn to_san_hostname(&self) -> InternedString {
match self {
Self::Ip { hostname, .. } => hostname.to_san_hostname(),
}
self.hostname.to_san_hostname()
}
}

View File

@@ -58,7 +58,7 @@ impl VersionT for Version {
}
// Remove onion entries from hostnameInfo in server host
remove_onion_hostname_info(
migrate_hostname_info(
db.get_mut("public")
.and_then(|p| p.get_mut("serverInfo"))
.and_then(|s| s.get_mut("network"))
@@ -74,7 +74,7 @@ impl VersionT for Version {
for (_, package) in packages.iter_mut() {
if let Some(hosts) = package.get_mut("hosts").and_then(|h| h.as_object_mut()) {
for (_, host) in hosts.iter_mut() {
remove_onion_hostname_info(Some(host));
migrate_hostname_info(Some(host));
}
}
}
@@ -96,14 +96,21 @@ impl VersionT for Version {
}
}
fn remove_onion_hostname_info(host: Option<&mut Value>) {
fn migrate_hostname_info(host: Option<&mut Value>) {
if let Some(hostname_info) = host
.and_then(|h| h.get_mut("hostnameInfo"))
.and_then(|h| h.as_object_mut())
{
for (_, infos) in hostname_info.iter_mut() {
if let Some(arr) = infos.as_array_mut() {
// Remove onion entries
arr.retain(|info| info.get("kind").and_then(|k| k.as_str()) != Some("onion"));
// Strip "kind" field from remaining entries (HostnameInfo flattened from enum to struct)
for info in arr.iter_mut() {
if let Some(obj) = info.as_object_mut() {
obj.remove("kind");
}
}
}
}
}