tuwunel_service/integrity/short_ids/
mod.rs1pub(crate) mod check;
9pub(crate) mod gc;
10pub(crate) mod identity;
11pub(crate) mod references;
12pub(crate) mod rooms;
13pub(crate) mod state;
14
15use serde::{Deserialize, Serialize};
16use tuwunel_core::{
17 Result,
18 smallvec::SmallVec,
19 utils::{TryReadyExt, u64_from_bytes},
20};
21
22use self::check::check;
23use super::{Check, ScanExt, tally};
24use crate::Services;
25
26pub(crate) type Identity = SmallVec<[u8; 48]>;
27
28pub(super) static CHECK: Check = Check {
29 name: "short-ids",
30 about: "Short event and state key ids pair one to one, every state resolves cleanly onto \
31 sound ones, and no unreachable state or unowned short room id remains",
32 quiescent: true,
33 walk: |services, limit| tally(check(services), limit),
34};
35
36#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
41#[serde(into = "u8", try_from = "u8")]
42pub(crate) enum Shape {
43 EventAlias = 1,
45
46 StatekeyAlias = 2,
48
49 DanglingWinner = 3,
51
52 PromotableReverse = 4,
54
55 EventAliasEntry = 12,
57
58 StatekeyAliasEntry = 13,
60
61 AffectedState = 15,
63
64 DiffCollision = 19,
66
67 EventOrphanEntry = 23,
69
70 StatekeyOrphanEntry = 24,
72
73 AuthChainCache = 27,
75
76 UnreachableState = 29,
78
79 PurgeResidue = 32,
81
82 LiveRoomAlias = 33,
84
85 DeclinedMarker = 37,
87}
88
89#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
90#[serde(rename_all = "snake_case")]
91pub(crate) enum Reason {
92 Identity,
93 HistoricalState,
94 References,
95 Ownership,
96}
97
98pub(crate) fn short_of(bytes: &[u8]) -> Option<u64> { u64_from_bytes(bytes).ok() }
99
100#[tracing::instrument(level = "debug", skip(services, init, step))]
101async fn sweep<T: Send>(
102 services: &Services,
103 column: &str,
104 init: T,
105 step: impl Fn(T, &[u8], &[u8]) -> T + Sync,
106) -> Result<T> {
107 services.db[column]
108 .raw_stream()
109 .scanned(&services.server)
110 .ready_try_fold(init, |acc, (key, value)| Ok(step(acc, key, value)))
111 .await
112}