pub struct DataIntegrityAuditor {
pub config: AuditConfig,
pub checksums: HashMap<String, BlockChecksum>,
pub repair_history: VecDeque<RepairRecord>,
pub total_audited: u64,
pub total_passed: u64,
pub total_failed: u64,
}Expand description
Proactive data integrity auditing system.
Continuously verifies stored blocks using configurable checksum algorithms, detects silent corruption, and tracks repair history.
Fields§
§config: AuditConfigConfiguration.
checksums: HashMap<String, BlockChecksum>Map from CID → stored checksum record.
repair_history: VecDeque<RepairRecord>Bounded ring of repair records (newest at the back).
total_audited: u64Total audit operations performed.
total_passed: u64Total audits that produced a Passed result.
total_failed: u64Total audits that produced a Failed result.
Implementations§
Source§impl DataIntegrityAuditor
impl DataIntegrityAuditor
Sourcepub fn new(config: AuditConfig) -> Self
pub fn new(config: AuditConfig) -> Self
Create a new auditor with the supplied configuration.
Sourcepub fn compute_checksum(data: &[u8], algo: &ChecksumAlgo) -> u32
pub fn compute_checksum(data: &[u8], algo: &ChecksumAlgo) -> u32
Compute a checksum over data using algo.
Sourcepub fn compute_crc32(data: &[u8]) -> u32
pub fn compute_crc32(data: &[u8]) -> u32
CRC-32 (Castagnoli, polynomial 0xEDB88320).
Sourcepub fn compute_adler32(data: &[u8]) -> u32
pub fn compute_adler32(data: &[u8]) -> u32
Adler-32.
Sourcepub fn compute_fnv_xor64(data: &[u8]) -> u32
pub fn compute_fnv_xor64(data: &[u8]) -> u32
FNV-1a 64-bit → 32-bit via XOR folding.
Sourcepub fn register_block(&mut self, cid: String, data: &[u8], now: u64)
pub fn register_block(&mut self, cid: String, data: &[u8], now: u64)
Compute the block’s checksum and store it, overwriting any prior record.
§Parameters
cid— content identifier.data— raw block bytes.now— current Unix timestamp (seconds).
Sourcepub fn audit_block(&mut self, cid: &str, data: &[u8]) -> AuditResult
pub fn audit_block(&mut self, cid: &str, data: &[u8]) -> AuditResult
Audit a single block: recompute its checksum and compare with the stored value.
Updates total_audited, total_passed, and total_failed.
If config.auto_repair is true and the check fails, a repair is
automatically scheduled (with source = "auto" and detected_at = 0).
Sourcepub fn audit_batch(&mut self, blocks: &[(String, Vec<u8>)]) -> Vec<AuditResult>
pub fn audit_batch(&mut self, blocks: &[(String, Vec<u8>)]) -> Vec<AuditResult>
Audit a batch of blocks, respecting config.audit_batch_size.
Processes at most audit_batch_size entries and returns one
AuditResult per processed block.
Sourcepub fn schedule_repair(&mut self, cid: String, now: u64, source: String)
pub fn schedule_repair(&mut self, cid: String, now: u64, source: String)
Record a repair request for cid.
Pushes a new RepairRecord with repaired_at = None to the back of
the history ring. If the ring exceeds max_repair_history the oldest
entry is evicted from the front.
Sourcepub fn mark_repaired(&mut self, cid: &str, now: u64) -> bool
pub fn mark_repaired(&mut self, cid: &str, now: u64) -> bool
Mark the most-recently scheduled (still-pending) repair for cid as
completed.
Scans the history from newest to oldest. Returns true if a pending
record was found and updated, false otherwise.
Sourcepub fn integrity_rate(&self) -> f64
pub fn integrity_rate(&self) -> f64
Ratio of passed audits to total audits. Returns 0.0 when nothing
has been audited yet.
Sourcepub fn pending_repairs(&self) -> Vec<&RepairRecord>
pub fn pending_repairs(&self) -> Vec<&RepairRecord>
All repair records for which repaired_at.is_none().
Sourcepub fn auditor_stats(&self) -> AuditorStats
pub fn auditor_stats(&self) -> AuditorStats
Snapshot of the current auditor statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DataIntegrityAuditor
impl RefUnwindSafe for DataIntegrityAuditor
impl Send for DataIntegrityAuditor
impl Sync for DataIntegrityAuditor
impl Unpin for DataIntegrityAuditor
impl UnsafeUnpin for DataIntegrityAuditor
impl UnwindSafe for DataIntegrityAuditor
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more