handleProbes method
Handles the peer's probes and produces this side's plan.
Implementation
Future<ReconcilePlan> handleProbes(List<RangeProbe> probes) async {
final plan = ReconcilePlan();
for (final probe in probes) {
final local = await digest(probe.from, probe.to);
if (local.matches(_asDigest(probe))) continue;
final leaf = probe.count <= leafCount ||
local.count <= leafCount ||
probe.depth >= maxDepth ||
plan.replyProbes.length + 2 > maxProbesPerReply;
final mid = leaf ? null : _midpoint(probe, local);
if (mid == null) {
// A leaf: both sides exchange the range's records; the CRDT merge
// dedups anything both already had.
plan.shipRanges.add(RangeRequest(from: probe.from, to: probe.to));
plan.requestRanges.add(RangeRequest(from: probe.from, to: probe.to));
continue;
}
final low = await digest(probe.from, mid);
final high = await digest(mid, probe.to);
plan.replyProbes
..add(RangeProbe(
from: probe.from,
to: mid,
depth: probe.depth + 1,
count: low.count,
fingerprint: low.fingerprint,
))
..add(RangeProbe(
from: mid,
to: probe.to,
depth: probe.depth + 1,
count: high.count,
fingerprint: high.fingerprint,
));
}
return plan;
}