Skip to main content

BlockIntegrityScanner

Struct BlockIntegrityScanner 

Source
pub struct BlockIntegrityScanner {
    pub registry: HashMap<String, ScanRecord>,
    pub config: ScannerConfig,
    pub stats: ScannerStats,
}
Expand description

Scans stored blocks for integrity issues.

Callers first register_block each known block, then call scan_block (or scan_all) whenever they want to verify the live data against the registry.

Fields§

§registry: HashMap<String, ScanRecord>

Registry of all known blocks, keyed by CID string.

§config: ScannerConfig

Configuration controlling which checks are performed.

§stats: ScannerStats

Running statistics.

Implementations§

Source§

impl BlockIntegrityScanner

Source

pub fn new(config: ScannerConfig) -> Self

Creates a new scanner with the supplied configuration and an empty registry.

Source

pub fn register_block( &mut self, cid: String, expected_size: u64, data: &[u8], now_secs: u64, )

Registers a block in the scanner’s registry.

The FNV-1a hash of data is computed and stored alongside the supplied metadata so that future scans can detect hash mismatches.

§Parameters
  • cid – Content identifier for the block.
  • expected_size – Expected size of the block in bytes.
  • data – Raw block data used to compute the stored hash.
  • now_secs – Current Unix timestamp in seconds (caller-supplied so the scanner remains deterministic in tests).
Source

pub fn scan_block( &mut self, cid: &str, actual_data: &[u8], scan_time_us: u64, ) -> ScanResult

Scans a single block and returns a ScanResult describing any integrity issues found.

The following checks are performed in order:

  1. Missing block – If cid is not in the registry the result contains a single IntegrityIssue::MissingBlock and all other checks are skipped.
  2. Size mismatch – If actual_data.len() as u64 != expected_size a IntegrityIssue::SizeViolation is added.
  3. Hash verification – When verify_cid_hash is true, the FNV-1a hash of actual_data is compared with the stored hash; a difference adds a IntegrityIssue::CidMismatch.
  4. Magic bytes – When magic_bytes is non-empty and actual_data does not start with those bytes, a IntegrityIssue::CorruptionMarker is added at offset = 0.
  5. Max size – If actual_data.len() as u64 > max_size_bytes a IntegrityIssue::SizeViolation is added (using max_size_bytes as expected).

Stats are updated before returning.

Source

pub fn scan_all( &mut self, blocks: &[(String, Vec<u8>)], scan_time_us: u64, ) -> Vec<ScanResult>

Scans all supplied blocks and returns one ScanResult per block.

Each element in blocks is a (cid, data) pair. The same scan_time_us value is recorded for every block in the batch.

Source

pub fn healthy_blocks(&self) -> Vec<&ScanRecord>

Returns references to all ScanRecords in the registry.

This does not filter by scan history; it simply exposes the full contents of the registry at the time of the call.

Source

pub fn stats(&self) -> &ScannerStats

Returns a reference to the scanner’s accumulated statistics.

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