Skip to main content

DataIntegrityAuditor

Struct DataIntegrityAuditor 

Source
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: AuditConfig

Configuration.

§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: u64

Total audit operations performed.

§total_passed: u64

Total audits that produced a Passed result.

§total_failed: u64

Total audits that produced a Failed result.

Implementations§

Source§

impl DataIntegrityAuditor

Source

pub fn new(config: AuditConfig) -> Self

Create a new auditor with the supplied configuration.

Source

pub fn compute_checksum(data: &[u8], algo: &ChecksumAlgo) -> u32

Compute a checksum over data using algo.

Source

pub fn compute_crc32(data: &[u8]) -> u32

CRC-32 (Castagnoli, polynomial 0xEDB88320).

Source

pub fn compute_adler32(data: &[u8]) -> u32

Adler-32.

Source

pub fn compute_fnv_xor64(data: &[u8]) -> u32

FNV-1a 64-bit → 32-bit via XOR folding.

Source

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).
Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn integrity_rate(&self) -> f64

Ratio of passed audits to total audits. Returns 0.0 when nothing has been audited yet.

Source

pub fn pending_repairs(&self) -> Vec<&RepairRecord>

All repair records for which repaired_at.is_none().

Source

pub fn auditor_stats(&self) -> AuditorStats

Snapshot of the current auditor statistics.

Trait Implementations§

Source§

impl Debug for DataIntegrityAuditor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more