add callback for getHost

This commit is contained in:
Aiden McClelland
2025-03-21 11:17:05 -06:00
parent 9e63f3f7c6
commit b8ff331ccc
2 changed files with 22 additions and 12 deletions

View File

@@ -1,4 +1,3 @@
use std::backtrace;
use std::collections::{BTreeMap, BTreeSet};
use std::future::Future;
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
@@ -63,7 +62,7 @@ pub struct RpcContextSeed {
pub lxc_manager: Arc<LxcManager>,
pub open_authed_continuations: OpenAuthedContinuations<Option<InternedString>>,
pub rpc_continuations: RpcContinuations,
pub callbacks: ServiceCallbacks,
pub callbacks: Arc<ServiceCallbacks>,
pub wifi_manager: Option<Arc<RwLock<WpaCli>>>,
pub current_secret: Arc<Jwk>,
pub client: Client,
@@ -231,6 +230,7 @@ impl RpcContext {
sync_db: watch::Sender::new(db.sequence().await),
db,
account: RwLock::new(account),
callbacks: net_controller.callbacks.clone(),
net_controller,
os_net_service,
s9pk_arch: if config.multi_arch_s9pks.unwrap_or(false) {
@@ -245,7 +245,6 @@ impl RpcContext {
lxc_manager: Arc::new(LxcManager::new()),
open_authed_continuations: OpenAuthedContinuations::new(),
rpc_continuations: RpcContinuations::new(),
callbacks: Default::default(),
wifi_manager: wifi_interface
.clone()
.map(|i| Arc::new(RwLock::new(WpaCli::init(i)))),
@@ -492,7 +491,7 @@ impl Drop for RpcContext {
let count = Arc::strong_count(&self.0) - 1;
tracing::info!("RpcContext dropped. {} left.", count);
if count > 0 {
tracing::debug!("{}", backtrace::Backtrace::force_capture());
tracing::debug!("{}", std::backtrace::Backtrace::force_capture());
tracing::debug!("{:?}", eyre!(""))
}
}

View File

@@ -3,7 +3,7 @@ use std::net::{Ipv4Addr, SocketAddr};
use std::sync::{Arc, Weak};
use color_eyre::eyre::eyre;
use imbl::OrdMap;
use imbl::{vector, OrdMap};
use imbl_value::InternedString;
use ipnet::IpNet;
use models::{HostId, OptionExt, PackageId};
@@ -26,6 +26,7 @@ use crate::net::tor::TorController;
use crate::net::utils::ipv6_is_local;
use crate::net::vhost::{AlpnInfo, TargetInfo, VHostController};
use crate::prelude::*;
use crate::service::effects::callbacks::ServiceCallbacks;
use crate::util::serde::MaybeUtf8String;
use crate::HOST_IP;
@@ -37,6 +38,7 @@ pub struct NetController {
pub(super) dns: DnsController,
pub(super) forward: LanPortForwardController,
pub(super) server_hostnames: Vec<Option<InternedString>>,
pub(crate) callbacks: Arc<ServiceCallbacks>,
}
impl NetController {
@@ -66,6 +68,7 @@ impl NetController {
// LAN mDNS
Some(hostname.local_domain_name()),
],
callbacks: Arc::new(ServiceCallbacks::default()),
})
}
@@ -80,7 +83,7 @@ impl NetController {
let res = NetService::new(NetServiceData {
id: Some(package),
ip,
dns,
_dns: dns,
controller: Arc::downgrade(self),
binds: BTreeMap::new(),
})?;
@@ -94,7 +97,7 @@ impl NetController {
let service = NetService::new(NetServiceData {
id: None,
ip: [127, 0, 0, 1].into(),
dns,
_dns: dns,
controller: Arc::downgrade(self),
binds: BTreeMap::new(),
})?;
@@ -131,7 +134,7 @@ struct HostBinds {
pub struct NetServiceData {
id: Option<PackageId>,
ip: Ipv4Addr,
dns: Arc<()>,
_dns: Arc<()>,
controller: Weak<NetController>,
binds: BTreeMap<HostId, HostBinds>,
}
@@ -576,14 +579,22 @@ impl NetServiceData {
}
}
ctrl.db
let res = ctrl
.db
.mutate(|db| {
host_for(db, self.id.as_ref(), &id)?
.as_hostname_info_mut()
.ser(&hostname_info)
})
.await
.result?;
.await;
res.result?;
if let Some(pkg_id) = self.id.as_ref() {
if res.revision.is_some() {
if let Some(cbs) = ctrl.callbacks.get_host_info(&(pkg_id.clone(), id)) {
cbs.call(vector![]).await?;
}
}
}
Ok(())
}
@@ -637,7 +648,7 @@ impl NetService {
data: Arc::new(Mutex::new(NetServiceData {
id: None,
ip: Ipv4Addr::new(0, 0, 0, 0),
dns: Default::default(),
_dns: Default::default(),
controller: Default::default(),
binds: BTreeMap::new(),
})),