validation

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FastFailReleaseProbe added in v0.3.0

func FastFailReleaseProbe(
	ctx context.Context,
	files []FastFailFile,
	poolManager pool.Manager,
	segmentSamplePercentage int,
	maxConnections int,
	timeout time.Duration,
) (bool, error)

FastFailReleaseProbe is the cheap phase-1 reachability gate for an NZB import. It flattens all candidate segments across the release and Stats a single sample (usenet.SelectSegmentsForValidation: first 3 + last 2 + random middle, min 5 / max 55 for the whole release), cancelling the remaining Stats on the first miss.

Returns (missing, err):

  • err is reserved for infrastructure failures (pool unavailable/nil).
  • missing reports whether any sampled segment was unreachable. A 430 / Stat failure / timeout yields (true, nil) — not an error — so the caller can escalate to the per-file FastFailCheckFiles sweep to map exactly which files are broken. A clean release returns (false, nil) and the caller proceeds straight to parsing, paying only this sample's worth of Stats.

func ValidateSegmentsForFile

func ValidateSegmentsForFile(
	filename string,
	fileSize int64,
	segments []*metapb.SegmentData,
	encryption metapb.Encryption,
) error

ValidateSegmentsForFile performs local structural validation of file segments including size verification. It validates that segments are structurally sound (valid offsets, non-empty IDs) and that their total size matches the expected file size (accounting for encryption overhead). Network reachability is handled solely by the fast-fail pass at import start.

Types

type FastFailFile added in v0.3.0

type FastFailFile struct {
	Filename string
	Segments []*metapb.SegmentData
	// GroupKey identifies the multi-volume set this file belongs to (e.g. a RAR
	// base name). Empty means the file is standalone. When any member of a group
	// is found unreachable, FastFailCheckFiles skips the remaining Stats for that
	// group and marks every member Broken — a missing volume dooms the whole set
	// (no PAR2 repair at import time), so probing the rest is wasted work.
	GroupKey string
}

FastFailFile is the minimal file surface needed for early segment reachability checks.

type FastFailFileResult added in v0.3.0

type FastFailFileResult struct {
	Broken            bool
	MissingSegmentIDs []string // segment IDs whose Stat failed
	// SampledCount is how many of the file's segments were Stat-checked (the
	// sample size), needed to project the release-wide miss rate for the
	// tolerant damage policy.
	SampledCount int
}

FastFailFileResult records the reachability outcome for a single FastFailFile. Results from FastFailCheckFiles are index-aligned with the input slice.

func FastFailCheckFiles added in v0.3.0

func FastFailCheckFiles(
	ctx context.Context,
	files []FastFailFile,
	poolManager pool.Manager,
	segmentSamplePercentage int,
	maxConnections int,
	timeout time.Duration,
	progressTracker progress.ProgressTracker,
) ([]FastFailFileResult, error)

FastFailCheckFiles stats a per-file sample of segments from all files. Every file with segments is checked — broken files are excluded from parsing, and if only PAR2 files survive the import fails naturally. Pass nil Segments for files that should be skipped (e.g. PAR2/sidecars) to keep index alignment while avoiding wasted Stat round-trips. Returns one result per input file (index-aligned). Files with no segments are skipped. Infrastructure failures (pool unavailable) are returned as an error; per-segment Stat failures mark the owning file Broken. progressTracker may be nil; when set it reports completed Stats as work progresses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL