release: NX9-WG v1.0.0
This commit is contained in:
1 parent
c8a9b7cde6
commit
4dfe42fe68
42 files changed
+4689
-336
No files matched your search
@@ -349,6 +349,49 @@ pub async fn update_peer_handshake(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Update operational telemetry (learned remote endpoint and last handshake timestamp) from kernel.
|
||||
pub async fn update_peer_learned_telemetry(
|
||||
pool: &SqlitePool,
|
||||
id: Uuid,
|
||||
handshake_at: Option<NaiveDateTime>,
|
||||
endpoint: Option<&str>,
|
||||
) -> Result<()> {
|
||||
let id_str = id.to_string();
|
||||
let handshake_str = handshake_at.as_ref().map(format_datetime);
|
||||
|
||||
if handshake_str.is_none() && endpoint.is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut query = String::from("UPDATE peers SET ");
|
||||
let mut set_clauses = Vec::new();
|
||||
|
||||
if handshake_str.is_some() {
|
||||
set_clauses.push("last_handshake_at = ?");
|
||||
}
|
||||
if endpoint.is_some() {
|
||||
set_clauses.push("endpoint = ?");
|
||||
}
|
||||
query.push_str(&set_clauses.join(", "));
|
||||
query.push_str(" WHERE id = ?");
|
||||
|
||||
let mut q = sqlx::query(&query);
|
||||
if let Some(ref hs) = handshake_str {
|
||||
q = q.bind(hs);
|
||||
}
|
||||
if let Some(ep) = endpoint {
|
||||
q = q.bind(ep);
|
||||
}
|
||||
q = q.bind(&id_str);
|
||||
|
||||
let result = q.execute(pool).await.map_err(DbError::Sqlx)?;
|
||||
if result.rows_affected() == 0 {
|
||||
return Err(DbError::NotFound(format!("Peer '{id_str}' not found")));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Delete a peer by UUID.
|
||||
pub async fn delete_peer(pool: &SqlitePool, id: Uuid) -> Result<()> {
|
||||
let id_str = id.to_string();
|
||||
|
||||
@@ -349,6 +349,15 @@ impl Store {
|
||||
crate::peers::update_peer_handshake(&self.pool, id, handshake_at).await
|
||||
}
|
||||
|
||||
pub async fn update_peer_learned_telemetry(
|
||||
&self,
|
||||
id: uuid::Uuid,
|
||||
handshake_at: Option<chrono::NaiveDateTime>,
|
||||
endpoint: Option<&str>,
|
||||
) -> Result<()> {
|
||||
crate::peers::update_peer_learned_telemetry(&self.pool, id, handshake_at, endpoint).await
|
||||
}
|
||||
|
||||
pub async fn delete_peer(&self, id: uuid::Uuid) -> Result<()> {
|
||||
crate::peers::delete_peer(&self.pool, id).await
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user