mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
add callback for getHost
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
use std::backtrace;
|
|
||||||
use std::collections::{BTreeMap, BTreeSet};
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||||
@@ -63,7 +62,7 @@ pub struct RpcContextSeed {
|
|||||||
pub lxc_manager: Arc<LxcManager>,
|
pub lxc_manager: Arc<LxcManager>,
|
||||||
pub open_authed_continuations: OpenAuthedContinuations<Option<InternedString>>,
|
pub open_authed_continuations: OpenAuthedContinuations<Option<InternedString>>,
|
||||||
pub rpc_continuations: RpcContinuations,
|
pub rpc_continuations: RpcContinuations,
|
||||||
pub callbacks: ServiceCallbacks,
|
pub callbacks: Arc<ServiceCallbacks>,
|
||||||
pub wifi_manager: Option<Arc<RwLock<WpaCli>>>,
|
pub wifi_manager: Option<Arc<RwLock<WpaCli>>>,
|
||||||
pub current_secret: Arc<Jwk>,
|
pub current_secret: Arc<Jwk>,
|
||||||
pub client: Client,
|
pub client: Client,
|
||||||
@@ -231,6 +230,7 @@ impl RpcContext {
|
|||||||
sync_db: watch::Sender::new(db.sequence().await),
|
sync_db: watch::Sender::new(db.sequence().await),
|
||||||
db,
|
db,
|
||||||
account: RwLock::new(account),
|
account: RwLock::new(account),
|
||||||
|
callbacks: net_controller.callbacks.clone(),
|
||||||
net_controller,
|
net_controller,
|
||||||
os_net_service,
|
os_net_service,
|
||||||
s9pk_arch: if config.multi_arch_s9pks.unwrap_or(false) {
|
s9pk_arch: if config.multi_arch_s9pks.unwrap_or(false) {
|
||||||
@@ -245,7 +245,6 @@ impl RpcContext {
|
|||||||
lxc_manager: Arc::new(LxcManager::new()),
|
lxc_manager: Arc::new(LxcManager::new()),
|
||||||
open_authed_continuations: OpenAuthedContinuations::new(),
|
open_authed_continuations: OpenAuthedContinuations::new(),
|
||||||
rpc_continuations: RpcContinuations::new(),
|
rpc_continuations: RpcContinuations::new(),
|
||||||
callbacks: Default::default(),
|
|
||||||
wifi_manager: wifi_interface
|
wifi_manager: wifi_interface
|
||||||
.clone()
|
.clone()
|
||||||
.map(|i| Arc::new(RwLock::new(WpaCli::init(i)))),
|
.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;
|
let count = Arc::strong_count(&self.0) - 1;
|
||||||
tracing::info!("RpcContext dropped. {} left.", count);
|
tracing::info!("RpcContext dropped. {} left.", count);
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
tracing::debug!("{}", backtrace::Backtrace::force_capture());
|
tracing::debug!("{}", std::backtrace::Backtrace::force_capture());
|
||||||
tracing::debug!("{:?}", eyre!(""))
|
tracing::debug!("{:?}", eyre!(""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::net::{Ipv4Addr, SocketAddr};
|
|||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
|
||||||
use color_eyre::eyre::eyre;
|
use color_eyre::eyre::eyre;
|
||||||
use imbl::OrdMap;
|
use imbl::{vector, OrdMap};
|
||||||
use imbl_value::InternedString;
|
use imbl_value::InternedString;
|
||||||
use ipnet::IpNet;
|
use ipnet::IpNet;
|
||||||
use models::{HostId, OptionExt, PackageId};
|
use models::{HostId, OptionExt, PackageId};
|
||||||
@@ -26,6 +26,7 @@ use crate::net::tor::TorController;
|
|||||||
use crate::net::utils::ipv6_is_local;
|
use crate::net::utils::ipv6_is_local;
|
||||||
use crate::net::vhost::{AlpnInfo, TargetInfo, VHostController};
|
use crate::net::vhost::{AlpnInfo, TargetInfo, VHostController};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
use crate::service::effects::callbacks::ServiceCallbacks;
|
||||||
use crate::util::serde::MaybeUtf8String;
|
use crate::util::serde::MaybeUtf8String;
|
||||||
use crate::HOST_IP;
|
use crate::HOST_IP;
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ pub struct NetController {
|
|||||||
pub(super) dns: DnsController,
|
pub(super) dns: DnsController,
|
||||||
pub(super) forward: LanPortForwardController,
|
pub(super) forward: LanPortForwardController,
|
||||||
pub(super) server_hostnames: Vec<Option<InternedString>>,
|
pub(super) server_hostnames: Vec<Option<InternedString>>,
|
||||||
|
pub(crate) callbacks: Arc<ServiceCallbacks>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NetController {
|
impl NetController {
|
||||||
@@ -66,6 +68,7 @@ impl NetController {
|
|||||||
// LAN mDNS
|
// LAN mDNS
|
||||||
Some(hostname.local_domain_name()),
|
Some(hostname.local_domain_name()),
|
||||||
],
|
],
|
||||||
|
callbacks: Arc::new(ServiceCallbacks::default()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +83,7 @@ impl NetController {
|
|||||||
let res = NetService::new(NetServiceData {
|
let res = NetService::new(NetServiceData {
|
||||||
id: Some(package),
|
id: Some(package),
|
||||||
ip,
|
ip,
|
||||||
dns,
|
_dns: dns,
|
||||||
controller: Arc::downgrade(self),
|
controller: Arc::downgrade(self),
|
||||||
binds: BTreeMap::new(),
|
binds: BTreeMap::new(),
|
||||||
})?;
|
})?;
|
||||||
@@ -94,7 +97,7 @@ impl NetController {
|
|||||||
let service = NetService::new(NetServiceData {
|
let service = NetService::new(NetServiceData {
|
||||||
id: None,
|
id: None,
|
||||||
ip: [127, 0, 0, 1].into(),
|
ip: [127, 0, 0, 1].into(),
|
||||||
dns,
|
_dns: dns,
|
||||||
controller: Arc::downgrade(self),
|
controller: Arc::downgrade(self),
|
||||||
binds: BTreeMap::new(),
|
binds: BTreeMap::new(),
|
||||||
})?;
|
})?;
|
||||||
@@ -131,7 +134,7 @@ struct HostBinds {
|
|||||||
pub struct NetServiceData {
|
pub struct NetServiceData {
|
||||||
id: Option<PackageId>,
|
id: Option<PackageId>,
|
||||||
ip: Ipv4Addr,
|
ip: Ipv4Addr,
|
||||||
dns: Arc<()>,
|
_dns: Arc<()>,
|
||||||
controller: Weak<NetController>,
|
controller: Weak<NetController>,
|
||||||
binds: BTreeMap<HostId, HostBinds>,
|
binds: BTreeMap<HostId, HostBinds>,
|
||||||
}
|
}
|
||||||
@@ -576,14 +579,22 @@ impl NetServiceData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrl.db
|
let res = ctrl
|
||||||
|
.db
|
||||||
.mutate(|db| {
|
.mutate(|db| {
|
||||||
host_for(db, self.id.as_ref(), &id)?
|
host_for(db, self.id.as_ref(), &id)?
|
||||||
.as_hostname_info_mut()
|
.as_hostname_info_mut()
|
||||||
.ser(&hostname_info)
|
.ser(&hostname_info)
|
||||||
})
|
})
|
||||||
.await
|
.await;
|
||||||
.result?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -637,7 +648,7 @@ impl NetService {
|
|||||||
data: Arc::new(Mutex::new(NetServiceData {
|
data: Arc::new(Mutex::new(NetServiceData {
|
||||||
id: None,
|
id: None,
|
||||||
ip: Ipv4Addr::new(0, 0, 0, 0),
|
ip: Ipv4Addr::new(0, 0, 0, 0),
|
||||||
dns: Default::default(),
|
_dns: Default::default(),
|
||||||
controller: Default::default(),
|
controller: Default::default(),
|
||||||
binds: BTreeMap::new(),
|
binds: BTreeMap::new(),
|
||||||
})),
|
})),
|
||||||
|
|||||||
Reference in New Issue
Block a user