tuwunel_service/integrity/
userroomid_highlightcount.rs1use std::fmt;
8
9use futures::Stream;
10use tuwunel_core::{Result, utils::TryReadyExt};
11use tuwunel_database::{KeyBuf, keyval::Buffer};
12
13use super::{Check, Report, ScanExt, tally};
14use crate::Services;
15
16type Value = Buffer<8>;
17
18const ROOM_SIGIL: &[u8] = b"!";
19
20pub(super) static CHECK: Check = Check {
21 name: "highlight-keys",
22 about: "No userroomid_highlightcount key leads with a room id",
23 quiescent: false,
24 walk: |services, limit| tally(scan(services), limit),
25};
26
27pub struct Finding {
32 pub key: KeyBuf,
34
35 pub value: Value,
37}
38
39#[tracing::instrument(level = "trace", skip_all)]
46pub fn scan(services: &Services) -> impl Stream<Item = Result<Finding>> + Send + '_ {
47 services.db["userroomid_highlightcount"]
48 .raw_scan()
49 .scanned(&services.server)
50 .ready_try_skip_while(|(key, _)| Ok(*key < ROOM_SIGIL))
51 .ready_try_take_while(|(key, _)| Ok(key.starts_with(ROOM_SIGIL)))
52 .ready_and_then(|(key, value)| {
53 Ok(Finding {
54 key: KeyBuf::from_slice(key),
55 value: Value::from_slice(value),
56 })
57 })
58}
59
60impl Report for Finding {
61 fn kind(&self) -> &'static str { "room-keyed-row" }
62}
63
64impl fmt::Display for Finding {
65 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66 write!(f, "last-read marker in the highlight-count column: {}", self.key.escape_ascii())
67 }
68}