mirror of
https://github.com/house-of-vanity/yggman.git
synced 2025-10-23 20:59:08 +00:00
Added agent
This commit is contained in:
31
src/agent.rs
31
src/agent.rs
@@ -57,6 +57,7 @@ enum ServerMessage {
|
|||||||
allowed_public_keys: Vec<String>,
|
allowed_public_keys: Vec<String>,
|
||||||
},
|
},
|
||||||
Update {
|
Update {
|
||||||
|
listen: Vec<String>,
|
||||||
peers: Vec<String>,
|
peers: Vec<String>,
|
||||||
allowed_public_keys: Vec<String>,
|
allowed_public_keys: Vec<String>,
|
||||||
},
|
},
|
||||||
@@ -251,19 +252,20 @@ async fn handle_server_message(msg: ServerMessage, ygg_config_path: &str) -> Res
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ServerMessage::Update {
|
ServerMessage::Update {
|
||||||
|
listen,
|
||||||
peers,
|
peers,
|
||||||
allowed_public_keys,
|
allowed_public_keys,
|
||||||
} => {
|
} => {
|
||||||
info!("Received configuration update:");
|
info!("Received configuration update:");
|
||||||
|
info!(" Updated listen endpoints: {:?}", listen);
|
||||||
info!(" Updated peers: {} configured", peers.len());
|
info!(" Updated peers: {} configured", peers.len());
|
||||||
for peer in &peers {
|
for peer in &peers {
|
||||||
debug!(" - {}", peer);
|
debug!(" - {}", peer);
|
||||||
}
|
}
|
||||||
info!(" Updated allowed keys: {} configured", allowed_public_keys.len());
|
info!(" Updated allowed keys: {} configured", allowed_public_keys.len());
|
||||||
|
|
||||||
// Apply configuration update to Yggdrasil
|
// Apply full configuration update to Yggdrasil
|
||||||
// For updates we need to read current config and update only peers/allowed keys
|
match update_yggdrasil_config_full(ygg_config_path, &listen, &peers, &allowed_public_keys).await {
|
||||||
match update_yggdrasil_config(ygg_config_path, &peers, &allowed_public_keys).await {
|
|
||||||
Ok(_) => info!("Configuration update successfully applied to {}", ygg_config_path),
|
Ok(_) => info!("Configuration update successfully applied to {}", ygg_config_path),
|
||||||
Err(e) => error!("Failed to update Yggdrasil config: {}", e),
|
Err(e) => error!("Failed to update Yggdrasil config: {}", e),
|
||||||
}
|
}
|
||||||
@@ -371,4 +373,27 @@ async fn update_yggdrasil_config(
|
|||||||
|
|
||||||
info!("Yggdrasil configuration updated in {}", config_path);
|
info!("Yggdrasil configuration updated in {}", config_path);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn update_yggdrasil_config_full(
|
||||||
|
config_path: &str,
|
||||||
|
listen: &[String],
|
||||||
|
peers: &[String],
|
||||||
|
allowed_public_keys: &[String]
|
||||||
|
) -> Result<()> {
|
||||||
|
// Read current config
|
||||||
|
let current_config = tokio::fs::read_to_string(config_path).await?;
|
||||||
|
let mut config: serde_json::Value = serde_json::from_str(¤t_config)?;
|
||||||
|
|
||||||
|
// Update listen, peers and allowed public keys
|
||||||
|
config["Listen"] = serde_json::json!(listen);
|
||||||
|
config["Peers"] = serde_json::json!(peers);
|
||||||
|
config["AllowedPublicKeys"] = serde_json::json!(allowed_public_keys);
|
||||||
|
|
||||||
|
// Write updated config back
|
||||||
|
let updated_config = serde_json::to_string_pretty(&config)?;
|
||||||
|
tokio::fs::write(config_path, updated_config).await?;
|
||||||
|
|
||||||
|
info!("Yggdrasil configuration fully updated in {}", config_path);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
@@ -31,6 +31,7 @@ pub enum ServerMessage {
|
|||||||
allowed_public_keys: Vec<String>,
|
allowed_public_keys: Vec<String>,
|
||||||
},
|
},
|
||||||
Update {
|
Update {
|
||||||
|
listen: Vec<String>,
|
||||||
peers: Vec<String>,
|
peers: Vec<String>,
|
||||||
allowed_public_keys: Vec<String>,
|
allowed_public_keys: Vec<String>,
|
||||||
},
|
},
|
||||||
|
@@ -35,6 +35,7 @@ pub async fn broadcast_configuration_update(node_manager: &Arc<NodeManager>) {
|
|||||||
for (node_id, tx) in connections.iter() {
|
for (node_id, tx) in connections.iter() {
|
||||||
if let Some(config) = configs.get(node_id) {
|
if let Some(config) = configs.get(node_id) {
|
||||||
let update = ServerMessage::Update {
|
let update = ServerMessage::Update {
|
||||||
|
listen: config.listen.clone(),
|
||||||
peers: config.peers.clone(),
|
peers: config.peers.clone(),
|
||||||
allowed_public_keys: config.allowed_public_keys.clone(),
|
allowed_public_keys: config.allowed_public_keys.clone(),
|
||||||
};
|
};
|
||||||
@@ -46,6 +47,7 @@ pub async fn broadcast_configuration_update(node_manager: &Arc<NodeManager>) {
|
|||||||
} else {
|
} else {
|
||||||
// Node was deleted, send empty configuration to disconnect agent gracefully
|
// Node was deleted, send empty configuration to disconnect agent gracefully
|
||||||
let update = ServerMessage::Update {
|
let update = ServerMessage::Update {
|
||||||
|
listen: vec![],
|
||||||
peers: vec![],
|
peers: vec![],
|
||||||
allowed_public_keys: vec![],
|
allowed_public_keys: vec![],
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user