Avoid legacy OTA proof collisions
This commit is contained in:
1 parent
dc4a8808c0
commit
610eef7529
7 files changed
+136
-19
No files matched your search
@@ -419,6 +419,7 @@ bool OtaManager::queueServeJob(const uint8_t* mid, uint16_t block, uint16_t want
|
||||
ServeJob& job = _serve_jobs[i];
|
||||
if (job.block != block || memcmp(job.mid, mid, 4) != 0) continue;
|
||||
job.pending_mask |= (uint16_t)(want_mask & ~job.emitted_mask);
|
||||
if (want_mask == 0) job.proof_requested = true;
|
||||
return true;
|
||||
}
|
||||
if (_n_serve_jobs >= OTA_SERVE_QUEUE) return false;
|
||||
@@ -427,6 +428,8 @@ bool OtaManager::queueServeJob(const uint8_t* mid, uint16_t block, uint16_t want
|
||||
job.block = block;
|
||||
job.pending_mask = want_mask;
|
||||
job.emitted_mask = 0;
|
||||
job.proof_ready_at = 0;
|
||||
job.proof_requested = want_mask == 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -455,6 +458,18 @@ uint32_t OtaManager::manifestEgressGapMs() const {
|
||||
return (uint32_t)gap;
|
||||
}
|
||||
|
||||
uint32_t OtaManager::proofEgressGapMs() const {
|
||||
if (_radio_packet_airtime_ms == 0) return OTA_PROOF_EGRESS_MIN_GAP_MS;
|
||||
// The adapter may have one response transmitting and two more admitted. Start this timer when the final
|
||||
// DATA is accepted, so cover all three packet-service intervals before opening the legacy-request turn.
|
||||
uint64_t gap = (uint64_t)_radio_packet_airtime_ms * _tx_spacing_permille
|
||||
* OTA_PROOF_EGRESS_DRAIN_PACKETS;
|
||||
gap = (gap + 999u) / 1000u;
|
||||
if (gap < OTA_PROOF_EGRESS_MIN_GAP_MS) gap = OTA_PROOF_EGRESS_MIN_GAP_MS;
|
||||
if (gap > OTA_PROOF_EGRESS_MAX_GAP_MS) gap = OTA_PROOF_EGRESS_MAX_GAP_MS;
|
||||
return (uint32_t)gap;
|
||||
}
|
||||
|
||||
void OtaManager::clearPendingEgress() {
|
||||
_n_manifest_jobs = 0;
|
||||
_n_serve_jobs = 0;
|
||||
@@ -635,10 +650,23 @@ void OtaManager::serviceEgress() {
|
||||
const uint16_t bit = (uint16_t)(1u << fragment);
|
||||
job.pending_mask &= (uint16_t)~bit;
|
||||
job.emitted_mask |= bit;
|
||||
if (job.pending_mask == 0) {
|
||||
// Legacy receivers transmit REQ_PROOF as soon as the last DATA fragment arrives. Do not admit our
|
||||
// proactive proof into the radio queue at the same instant: the two half-duplex transmissions would
|
||||
// collide and force the receiver onto its multi-second retry tick. Include every response that the
|
||||
// adapter can already have admitted ahead of this proof, then retain a bounded fast-link floor.
|
||||
job.proof_ready_at = _now_ms + proofEgressGapMs();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// An explicit legacy REQ_PROOF proves that the source has returned to RX and bypasses the proactive delay.
|
||||
// A newer receiver sends no request unless the proof was lost, so its normal proactive path waits for the
|
||||
// radio-aware gap and remains compatible with the existing proof-grace deadline.
|
||||
if (!job.proof_requested && job.proof_ready_at != 0
|
||||
&& (int32_t)(_now_ms - job.proof_ready_at) < 0) return;
|
||||
|
||||
uint8_t proof[32 * 4];
|
||||
uint8_t np = merkle_gen_proof(v->m.leaves, v->m.block_count, job.block, v->scratch, proof);
|
||||
ProofMsg pm;
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
// driven by a host simulation; a thin Mesh adapter wires it to PAYLOAD_TYPE_OTA on device.
|
||||
//
|
||||
// Transfer keeps 1 KB logical blocks. A server paces each block's self-describing DATA fragments through a
|
||||
// bounded response queue and follows them with the Merkle PROOF. A newer fetcher waits briefly for that
|
||||
// proactive proof; the existing REQ_PROOF message remains as a loss/legacy-server fallback.
|
||||
// bounded response queue and follows them with the Merkle PROOF. A short radio-aware turnaround gap lets a
|
||||
// legacy fetcher send its immediate REQ_PROOF without colliding with that proactive proof; newer fetchers wait
|
||||
// briefly for the proactive proof and retain REQ_PROOF as a loss/legacy-server fallback.
|
||||
|
||||
namespace mesh {
|
||||
namespace ota {
|
||||
@@ -68,6 +69,15 @@ typedef bool (*ServeReadFn)(void* ctx, uint32_t off, uint8_t* buf, uint32_t len)
|
||||
#ifndef OTA_MANIFEST_EGRESS_MAX_GAP_MS
|
||||
#define OTA_MANIFEST_EGRESS_MAX_GAP_MS 1000 // do not outrun the receiver's one-second retry observation
|
||||
#endif
|
||||
#ifndef OTA_PROOF_EGRESS_DRAIN_PACKETS
|
||||
#define OTA_PROOF_EGRESS_DRAIN_PACKETS 3 // one active TX plus the two paced-response queue credits
|
||||
#endif
|
||||
#ifndef OTA_PROOF_EGRESS_MIN_GAP_MS
|
||||
#define OTA_PROOF_EGRESS_MIN_GAP_MS 100 // fast-link legacy request turnaround floor
|
||||
#endif
|
||||
#ifndef OTA_PROOF_EGRESS_MAX_GAP_MS
|
||||
#define OTA_PROOF_EGRESS_MAX_GAP_MS 3000 // bounded by the legacy receiver's normal retry cadence
|
||||
#endif
|
||||
// Leaf-diff warm-start (motatool folder-capture only): bulk-fetch the target's leaves[], diff a seed build
|
||||
// locally, pull DATA only for mismatches. OTA_LEAVES is bitmap-fragmented like OTA_MANIFEST so a want_mask
|
||||
// retry never re-bursts (anti-deadlock). The mask is a fixed uint16, so leaves are capped at MAXFRAG frags.
|
||||
@@ -493,6 +503,7 @@ private:
|
||||
bool queueServeJob(const uint8_t* mid, uint16_t block, uint16_t want_mask);
|
||||
bool queueManifestJob(const uint8_t* mid, uint16_t want_mask);
|
||||
uint32_t manifestEgressGapMs() const;
|
||||
uint32_t proofEgressGapMs() const;
|
||||
bool serviceManifestEgress();
|
||||
void popManifestJob();
|
||||
bool loadActiveServeBlock();
|
||||
@@ -555,6 +566,8 @@ private:
|
||||
uint16_t block = 0;
|
||||
uint16_t pending_mask = 0;
|
||||
uint16_t emitted_mask = 0;
|
||||
uint32_t proof_ready_at = 0;
|
||||
bool proof_requested = false;
|
||||
};
|
||||
ServeJob _serve_jobs[OTA_SERVE_QUEUE];
|
||||
uint8_t _n_serve_jobs = 0;
|
||||
|
||||
Reference in new issue
Block a user