mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
prevent gateways from getting stuck empty
This commit is contained in:
@@ -223,7 +223,7 @@ regex = "1.10.2"
|
||||
reqwest = { version = "0.12.4", features = ["json", "socks", "stream"] }
|
||||
reqwest_cookie_store = "0.8.0"
|
||||
rpassword = "7.2.0"
|
||||
rpc-toolkit = { git = "https://github.com/Start9Labs/rpc-toolkit.git", branch = "master" }
|
||||
rpc-toolkit = { git = "https://github.com/Start9Labs/rpc-toolkit.git", rev = "068db90" }
|
||||
rust-argon2 = "2.0.0"
|
||||
safelog = { version = "0.4.8", git = "https://github.com/Start9Labs/arti.git", branch = "patch/disable-exit", optional = true }
|
||||
semver = { version = "1.0.20", features = ["serde"] }
|
||||
|
||||
@@ -130,7 +130,6 @@ async fn list_interfaces(
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Parser, TS)]
|
||||
#[ts(export)]
|
||||
struct NetworkInterfaceSetPublicParams {
|
||||
gateway: GatewayId,
|
||||
public: Option<bool>,
|
||||
@@ -147,7 +146,6 @@ async fn set_public(
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Parser, TS)]
|
||||
#[ts(export)]
|
||||
struct UnsetPublicParams {
|
||||
gateway: GatewayId,
|
||||
}
|
||||
@@ -163,7 +161,6 @@ async fn unset_public(
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Parser, TS)]
|
||||
#[ts(export)]
|
||||
struct ForgetGatewayParams {
|
||||
gateway: GatewayId,
|
||||
}
|
||||
@@ -176,7 +173,6 @@ async fn forget_iface(
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Parser, TS)]
|
||||
#[ts(export)]
|
||||
struct RenameGatewayParams {
|
||||
id: GatewayId,
|
||||
name: InternedString,
|
||||
@@ -404,6 +400,12 @@ async fn watcher(
|
||||
) {
|
||||
loop {
|
||||
let res: Result<(), Error> = async {
|
||||
Command::new("systemctl")
|
||||
.arg("start")
|
||||
.arg("NetworkManager")
|
||||
.invoke(ErrorKind::Network)
|
||||
.await?;
|
||||
|
||||
let connection = Connection::system().await?;
|
||||
|
||||
let netman_proxy = NetworkManagerProxy::new(&connection).await?;
|
||||
@@ -435,49 +437,60 @@ async fn watcher(
|
||||
loop {
|
||||
until
|
||||
.run(async {
|
||||
let devices = netman_proxy.all_devices().await?;
|
||||
let mut ifaces = BTreeSet::new();
|
||||
let mut jobs = Vec::new();
|
||||
for device in devices {
|
||||
use futures::future::Either;
|
||||
|
||||
let device_proxy =
|
||||
device::DeviceProxy::new(&connection, device.clone()).await?;
|
||||
let iface = InternedString::intern(device_proxy.ip_interface().await?);
|
||||
if iface.is_empty() {
|
||||
loop {
|
||||
let devices = netman_proxy.all_devices().await?;
|
||||
if devices.is_empty() {
|
||||
tracing::warn!(
|
||||
"NetworkManager returned no devices. Trying again..."
|
||||
);
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
continue;
|
||||
}
|
||||
let iface: GatewayId = iface.into();
|
||||
if watch_activation.peek(|a| a.contains_key(&iface)) {
|
||||
jobs.push(Either::Left(watch_activated(
|
||||
let mut ifaces = BTreeSet::new();
|
||||
let mut jobs = Vec::new();
|
||||
for device in devices {
|
||||
use futures::future::Either;
|
||||
|
||||
let device_proxy =
|
||||
device::DeviceProxy::new(&connection, device.clone()).await?;
|
||||
let iface =
|
||||
InternedString::intern(device_proxy.ip_interface().await?);
|
||||
if iface.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let iface: GatewayId = iface.into();
|
||||
if watch_activation.peek(|a| a.contains_key(&iface)) {
|
||||
jobs.push(Either::Left(watch_activated(
|
||||
&connection,
|
||||
device_proxy.clone(),
|
||||
iface.clone(),
|
||||
&watch_activation,
|
||||
)));
|
||||
}
|
||||
|
||||
jobs.push(Either::Right(watch_ip(
|
||||
&connection,
|
||||
device_proxy.clone(),
|
||||
iface.clone(),
|
||||
&watch_activation,
|
||||
&watch_ip_info,
|
||||
)));
|
||||
ifaces.insert(iface);
|
||||
}
|
||||
|
||||
jobs.push(Either::Right(watch_ip(
|
||||
&connection,
|
||||
device_proxy.clone(),
|
||||
iface.clone(),
|
||||
&watch_ip_info,
|
||||
)));
|
||||
ifaces.insert(iface);
|
||||
}
|
||||
|
||||
watch_ip_info.send_if_modified(|m| {
|
||||
let mut changed = false;
|
||||
for (iface, info) in OrdMapIterMut::from(m) {
|
||||
if !ifaces.contains(iface) {
|
||||
info.ip_info = None;
|
||||
changed = true;
|
||||
watch_ip_info.send_if_modified(|m| {
|
||||
let mut changed = false;
|
||||
for (iface, info) in OrdMapIterMut::from(m) {
|
||||
if !ifaces.contains(iface) {
|
||||
info.ip_info = None;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
changed
|
||||
});
|
||||
futures::future::try_join_all(jobs).await?;
|
||||
changed
|
||||
});
|
||||
futures::future::try_join_all(jobs).await?;
|
||||
|
||||
break;
|
||||
}
|
||||
Ok::<_, Error>(())
|
||||
})
|
||||
.await?;
|
||||
|
||||
@@ -49,7 +49,7 @@ pub mod net;
|
||||
pub mod rpc;
|
||||
pub mod rpc_client;
|
||||
pub mod serde;
|
||||
pub mod squashfs;
|
||||
// pub mod squashfs;
|
||||
pub mod sync;
|
||||
pub mod tui;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user