```
feat(target-lists): 新增黑白名单管理与实时告警功能 - rid-shared 新增 target_lists 模块,定义名单数据契约 - 地图适配器支持按名单类型着色渲染目标(白/黑/未知) - 新增名单筛选器与目标目录过滤联动 - 实时详情面板支持加入/编辑白名单与黑名单操作 - 新增黑名单命中告警横幅与事件日志高亮 - 新增名单管理浮层(Manager 组件)与徽章展示 - 底图默认切换为影像图,相机初始俯仰角归零 - color-scheme 切换为 dark,新增 glass/workbench 样式 ```
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
//! Versioned synthetic telemetry contract. This is not a device wire protocol.
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod target_lists;
|
||||
|
||||
pub const PROTOCOL_VERSION: u16 = 1;
|
||||
pub const MAX_BATCH: usize = 4096;
|
||||
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
//! Manual target classification, independent of registration and telemetry transport.
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
pub const MAX_ENTRIES: usize = 5000;
|
||||
pub const MAX_NOTE_CHARS: usize = 200;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ListKind {
|
||||
White,
|
||||
Black,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
||||
pub struct Entry {
|
||||
pub target_id: String,
|
||||
pub list_kind: ListKind,
|
||||
pub note: String,
|
||||
pub updated_at: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
||||
pub struct Snapshot {
|
||||
pub revision: u64,
|
||||
pub entries: Vec<Entry>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Mutation {
|
||||
pub list_kind: ListKind,
|
||||
#[serde(default)]
|
||||
pub note: String,
|
||||
pub expected_revision: u64,
|
||||
}
|
||||
|
||||
pub fn valid_target_id(value: &str) -> bool {
|
||||
!value.is_empty()
|
||||
&& value.len() <= 64
|
||||
&& value
|
||||
.bytes()
|
||||
.all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_')
|
||||
}
|
||||
|
||||
/// Alert once per continuous active black-list membership, including list changes.
|
||||
#[derive(Default)]
|
||||
pub struct AlertTracker {
|
||||
active_black: HashSet<String>,
|
||||
}
|
||||
|
||||
impl AlertTracker {
|
||||
pub fn update(&mut self, active: &[String], kinds: &HashMap<String, ListKind>) -> Vec<String> {
|
||||
let current: HashSet<_> = active
|
||||
.iter()
|
||||
.filter(|id| kinds.get(*id) == Some(&ListKind::Black))
|
||||
.cloned()
|
||||
.collect();
|
||||
let mut newly_active: Vec<_> = current.difference(&self.active_black).cloned().collect();
|
||||
newly_active.sort();
|
||||
self.active_black = current;
|
||||
newly_active
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn identities_match_telemetry_limits_without_case_folding() {
|
||||
assert!(valid_target_id(&"A".repeat(64)));
|
||||
assert!(valid_target_id("Drone_01-a"));
|
||||
for value in ["", "with space", "路径", "../id", &"X".repeat(65)] {
|
||||
assert!(!valid_target_id(value));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alerts_are_independent_of_frames_notes_and_view_filters() {
|
||||
let mut tracker = AlertTracker::default();
|
||||
let active = vec!["A".into(), "a".into()];
|
||||
let mut kinds = HashMap::from([("A".into(), ListKind::Black)]);
|
||||
assert_eq!(tracker.update(&active, &kinds), vec!["A"]);
|
||||
for _ in 0..100 {
|
||||
assert!(tracker.update(&active, &kinds).is_empty());
|
||||
}
|
||||
kinds.insert("a".into(), ListKind::White);
|
||||
assert!(tracker.update(&active, &kinds).is_empty());
|
||||
kinds.insert("A".into(), ListKind::White);
|
||||
assert!(tracker.update(&active, &kinds).is_empty());
|
||||
kinds.insert("A".into(), ListKind::Black);
|
||||
assert_eq!(tracker.update(&active, &kinds), vec!["A"]);
|
||||
assert!(tracker.update(&[], &kinds).is_empty());
|
||||
assert_eq!(tracker.update(&active, &kinds), vec!["A"]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user