S048: farm rule only over HTTP (FTP keeps mtime as proof of change); http test builds

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
astar76 2026-11-26 14:28:22 -06:00
commit 3500a4c25b
4 changed files with 17 additions and 7 deletions

View file

@ -175,7 +175,7 @@ async fn fetch_whole(
let here = if url == task.url { source.at(&probe.url) } else { source.mirror(&url)?.at(&probe.url) };
let mut link = Link::new(client.clone(), here, probe.ranges, probe.version.clone(), task.farm);
// The bytes here are of the version first seen; replies of another one with the same size are checked by their bytes.
if !parts.is_empty() && !compared && !old(&task).same_file(&link.version) && old(&task).maybe_same(&link.version) {
if !parts.is_empty() && !compared && !old(&task).same_file(&link.version) && link.maybe_same(&old(&task)) {
link.version = old(&task);
}
let (file, parts) = match file {
@ -283,7 +283,7 @@ async fn open_one(client: &Client, task: &Task, parts: &[Part], source: Source,
if first {
// Another server of a farm differs in dates only; the bytes tell when the parts go on.
let old = old(task);
return if old.same_file(&probe.version) || old.maybe_same(&probe.version) { Ok((probe, false)) } else { Err(Error::Changed) };
return if old.same_file(&probe.version) || source.web() && old.maybe_same(&probe.version) { Ok((probe, false)) } else { Err(Error::Changed) };
}
let link = NewLink { url: source.url.to_string(), ..NewLink::default() };
let checked = relink::check(client, task, parts, link, source, stop).await?;
@ -372,7 +372,7 @@ async fn resume(
compared: bool,
stop: &mut Stop,
) -> Result<(Arc<PartialFile>, Vec<Part>)> {
if !compared && !old(task).same_file(&link.version) && !old(task).maybe_same(&link.version) {
if !compared && !old(task).same_file(&link.version) && !link.maybe_same(&old(task)) {
return Err(Error::Changed);
}
let file = Arc::new(file);

View file

@ -63,6 +63,11 @@ impl Link {
self.farm.sample.lock().unwrap().get_or_insert((at, data));
}
/// Of a farm's other server maybe, to be told by the bytes. Only over HTTP: other links have no farms.
pub(super) fn maybe_same(&self, version: &Validators) -> bool {
self.source.web() && self.version.maybe_same(version)
}
/// Of the version the bytes here are of, or of one shown to have the same bytes.
fn sure(&self, version: &Validators) -> bool {
self.version.same_file(version) || self.farm.proven.lock().unwrap().iter().any(|p| p == version)
@ -281,7 +286,7 @@ async fn send_range(link: &Link, first: u64, end: Option<u64>, stop: &mut Stop)
let range = ContentRange::of(headers).ok_or_else(|| Error::BadReply("no usable Content-Range".into()))?;
let version = Validators::of(headers, range.total);
let unsure = !link.sure(&version);
if unsure && !link.version.maybe_same(&version) {
if unsure && !link.maybe_same(&version) {
return Err(Error::Changed);
}
if range.first != first || end.is_some_and(|e| range.last >= e) {
@ -296,10 +301,10 @@ async fn send_range(link: &Link, first: u64, end: Option<u64>, stop: &mut Stop)
if link.version.same_file(&version) {
return Err(Error::RangeIgnored);
}
if link.version.maybe_same(&version) && if_range.take().is_some() {
if link.maybe_same(&version) && if_range.take().is_some() {
continue;
}
if link.farm() && link.version.maybe_same(&version) {
if link.farm() && link.maybe_same(&version) {
return Err(Error::RangeIgnored);
}
return Err(if comes_as_page(link, headers) { Error::Page } else { Error::Changed });

View file

@ -212,6 +212,11 @@ pub struct Source {
const HOPS: usize = 10;
impl Source {
/// HTTP or HTTPS, not a remote of its own (FTP, SFTP).
pub(crate) fn web(&self) -> bool {
self.remote.is_none()
}
pub fn new(url: &str) -> Result<Source> {
let url = Url::parse(url).map_err(|_| Error::Link)?;
let remote = Remote::of(&url).map(Arc::new);

View file

@ -335,7 +335,7 @@ async fn one_part(b: &Bench, path: &str, done: u64) -> (Result<()>, Vec<u8>, Par
let (_keep, mut stop) = watch::channel(false);
let source = Source::new(&b.server.url(path)).unwrap();
let p = probe(&b.client, &source, &mut stop).await.unwrap();
let link = Link { client: b.client.clone(), source, ranges: true, version: p.version };
let link = Link { client: b.client.clone(), source, ranges: true, version: p.version, farm: Default::default() };
let (file, name) = PartialFile::create(&b.folder(), "part", &Default::default()).unwrap();
std::fs::write(partial_path(&b.folder(), &name), vec![0; 200_000]).unwrap();
let part = LivePart::new(Part { start: 100_000, end: Some(200_000), done: 0 });