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: ScannerConfigConfiguration controlling which checks are performed.
stats: ScannerStatsRunning statistics.
Implementations§
Source§impl BlockIntegrityScanner
impl BlockIntegrityScanner
Sourcepub fn new(config: ScannerConfig) -> Self
pub fn new(config: ScannerConfig) -> Self
Creates a new scanner with the supplied configuration and an empty registry.
Sourcepub fn register_block(
&mut self,
cid: String,
expected_size: u64,
data: &[u8],
now_secs: u64,
)
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).
Sourcepub fn scan_block(
&mut self,
cid: &str,
actual_data: &[u8],
scan_time_us: u64,
) -> ScanResult
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:
- Missing block – If
cidis not in the registry the result contains a singleIntegrityIssue::MissingBlockand all other checks are skipped. - Size mismatch – If
actual_data.len() as u64 != expected_sizeaIntegrityIssue::SizeViolationis added. - Hash verification – When
verify_cid_hashistrue, the FNV-1a hash ofactual_datais compared with the stored hash; a difference adds aIntegrityIssue::CidMismatch. - Magic bytes – When
magic_bytesis non-empty andactual_datadoes not start with those bytes, aIntegrityIssue::CorruptionMarkeris added atoffset = 0. - Max size – If
actual_data.len() as u64 > max_size_bytesaIntegrityIssue::SizeViolationis added (usingmax_size_bytesasexpected).
Stats are updated before returning.
Sourcepub fn scan_all(
&mut self,
blocks: &[(String, Vec<u8>)],
scan_time_us: u64,
) -> Vec<ScanResult>
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.
Sourcepub fn healthy_blocks(&self) -> Vec<&ScanRecord>
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.
Sourcepub fn stats(&self) -> &ScannerStats
pub fn stats(&self) -> &ScannerStats
Returns a reference to the scanner’s accumulated statistics.
Auto Trait Implementations§
impl Freeze for BlockIntegrityScanner
impl RefUnwindSafe for BlockIntegrityScanner
impl Send for BlockIntegrityScanner
impl Sync for BlockIntegrityScanner
impl Unpin for BlockIntegrityScanner
impl UnsafeUnpin for BlockIntegrityScanner
impl UnwindSafe for BlockIntegrityScanner
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