S048: prove until the triggering version is sure; parts check counts three starts

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-26 14:17:46 -06:00
commit 9f38019b14
2 changed files with 10 additions and 8 deletions

View file

@ -223,22 +223,24 @@ async fn range(link: &Link, part: &LivePart, file: &PartialFile, stop: &mut Stop
async fn sure_range(link: &Link, first: u64, end: Option<u64>, stop: &mut Stop) -> Result<Response> {
for _ in 0..PROOF_TRIES {
let (response, unsure) = send_range(link, first, end, stop).await?;
if unsure.is_none() {
return Ok(response);
}
let Some(version) = unsure else { return Ok(response) };
drop(response);
// Only replies of the same size are unsure, so the size is known.
let until = end.or(link.version.size).unwrap_or(first);
prove(link, first, (until - first).min(SAMPLE), stop).await?;
prove(link, &version, first, (until - first).min(SAMPLE), stop).await?;
}
Err(Error::Changed)
}
/// Asks for `len` bytes at `at` until a sure reply and one of another version can be compared. The same bytes make that
/// version sure; other bytes, or no sure reply at all, mean the file changed.
async fn prove(link: &Link, at: u64, len: u64, stop: &mut Stop) -> Result<()> {
/// Asks for `len` bytes at `at` until a sure reply and one of another version can be compared, and so until `version` is
/// sure. The same bytes make a version sure; other bytes, or no sure reply at all, mean the file changed.
async fn prove(link: &Link, version: &Validators, at: u64, len: u64, stop: &mut Stop) -> Result<()> {
let mut other = None;
for _ in 0..PROOF_TRIES {
// Maybe by another part meanwhile.
if link.sure(version) {
return Ok(());
}
// The known sample's place, once there is one.
let (at, len) = link.farm.sample.lock().unwrap().as_ref().map_or((at, len), |(at, d)| (*at, d.len() as u64));
let (response, unsure) = send_range(link, at, Some(at + len), stop).await?;

View file

@ -103,7 +103,7 @@ async fn a_farm_downloads_in_parts() {
let log = b.server.requests_for(PATH);
let range = |r: &&medlar_testserver::Request| r.header("range")?.strip_prefix("bytes=")?.split('-').next()?.parse::<u64>().ok();
let starts: BTreeSet<_> = log.iter().filter(|r| r.status == 206).filter_map(|r| range(&r)).collect();
assert!(starts.len() >= 4, "parts in parallel: {starts:?}");
assert!(starts.len() >= 3, "parts in parallel: {starts:?}");
assert!(b.store.task(id).unwrap().farm, "the farm is kept");
}