Let a new trace replace the previous attempt on its connection

This commit is contained in:
mikecarper committed 2026-10-27 14:08:50 -07:00
1 parent 2a6d59474d
commit 6ac2ec357a
6 files changed
+180 -22

No files matched your search

+16 -8
View File
@@ -39,7 +39,8 @@ uint32_t CompanionDelayedReplies::radioBudget(const Reply& reply) {
uint32_t budget = reply.timeout > maximum - extra
? maximum : reply.timeout + extra;
if (!reply.terminal) {
// Official apps start an estimate + 5s timer when they receive SENT.
// Request clients add five seconds to SENT's estimate. Keep this longer
// radio window for traces too; their owner may replace one sooner.
const uint32_t host_budget = reply.timeout > maximum - HOST_EXTRA_TIMEOUT_MS
? maximum : reply.timeout + HOST_EXTRA_TIMEOUT_MS;
if (host_budget > budget) budget = host_budget;
@@ -77,14 +78,18 @@ bool CompanionDelayedReplies::store(Reply& reply, const uint8_t* frame,
return true;
}
bool CompanionDelayedReplies::expired(const Reply& reply, uint32_t now) {
return due(now, reply.phase == AwaitAdmission
? reply.delivery_deadline : reply.radio_deadline)
|| (reply.sent_pending && due(now, reply.sent_deadline));
}
bool CompanionDelayedReplies::service(Reply& reply,
BaseSerialInterface* serial, uint32_t now) {
if (reply.phase == Empty || reply.phase == Reserved) return false;
if (reply.terminal) return due(now, reply.radio_deadline);
if (serial == nullptr || !serial->isReplyRouteAvailable(reply.route)
|| due(now, reply.phase == AwaitAdmission
? reply.delivery_deadline : reply.radio_deadline)
|| (reply.sent_pending && due(now, reply.sent_deadline))) return true;
|| expired(reply, now)) return true;
if (reply.sent_pending) {
uint8_t sent[10];
sent[0] = 6; // RESP_CODE_SENT, unchanged Companion wire format.
@@ -257,9 +262,14 @@ void CompanionDelayedReplies::retireTrace(uint8_t history, uint32_t now,
bool CompanionDelayedReplies::reserveBinaryTrace(uint32_t tag, uint32_t auth,
BaseSerialInterface* route, uint32_t now) {
if (hasBinaryTrace() || route == nullptr) return false;
if (route == nullptr) return false;
if (trace.phase >= AwaitRadio && expired(trace, now)) retireBinaryTrace(now);
if (hasBinaryTrace() && trace.route != route) return false;
// Reserve the replacement first. A duplicate/quarantined tuple or full
// history must not cancel the current trace. Retired replies stay isolated.
uint8_t history = reserveTrace(tag, auth, now);
if (history == NO_HISTORY) return false;
if (hasBinaryTrace()) retireBinaryTrace(now);
trace.route = route;
trace.tag = tag;
trace.auth = auth;
@@ -309,9 +319,7 @@ bool CompanionDelayedReplies::hasReplyForRoute(BaseSerialInterface* route, uint3
const Reply* slots[] = { &request, &trace };
for (const Reply* reply : slots) {
if (reply->phase >= AwaitRadio && reply->route == route
&& !due(now, reply->phase == AwaitAdmission
? reply->delivery_deadline : reply->radio_deadline)
&& !(reply->sent_pending && due(now, reply->sent_deadline))) return true;
&& !expired(*reply, now)) return true;
}
return false;
}
+3
View File
@@ -52,6 +52,7 @@ private:
static uint32_t retirementDeadline(uint32_t now, uint32_t radio_deadline,
uint32_t floor);
static uint32_t radioBudget(const Reply& reply);
static bool expired(const Reply& reply, uint32_t now);
static void reset(Reply& reply);
static void arm(Reply& reply, uint32_t timeout, bool flood, uint32_t now);
static bool store(Reply& reply, const uint8_t* frame, size_t len, uint32_t now);
@@ -78,6 +79,8 @@ public:
uint8_t reserveTrace(uint32_t tag, uint32_t auth, uint32_t now);
void abandonTrace(uint8_t history);
void retireTrace(uint8_t history, uint32_t now, uint32_t radio_deadline);
// A fresh tuple on the same route replaces its current binary trace.
// Refused reservations leave the current operation intact.
bool reserveBinaryTrace(uint32_t tag, uint32_t auth,
BaseSerialInterface* route, uint32_t now);
void armBinaryTrace(uint32_t timeout, uint32_t now);