Files
MeshCore/src/helpers/TempRadioReplyBarrier.h
T
mikecarper a88ced23b6 Fix OTA resume, CLI identity, radio persistence, and network sessions
Distinguish OTA read failures from missing blocks and select unique raw-flash checkpoints by MID and target. Keep deferred CLI requests and replies bound to immutable command identity and full authenticated keys.

Gate radio mutations on their exact reply delivery, recover coding-rate restoration, and roll back failed Companion preference writes. Preserve accepted low duty cycles across reboot.

Retain partial network writes, cancel displaced client operations, and reject malformed or stalled framed input. Add regression and CI coverage, and size-optimize the RAK4631 Ethernet build without dropping features.
2026-09-15 14:32:40 -07:00

57 lines
1.9 KiB
C++

#pragma once
namespace mesh {
// A parameterized TempRadio command changes the modulation used to carry its
// own remote-CLI reply. A wall-clock delay cannot prove that the reply has
// left a busy outbound queue, so keep the scheduled handoff blocked by the
// exact packet objects on both profiles until Dispatcher reports TX completion.
// At least one successful TX permits the handoff, after both copies drain. This class is
// deliberately pointer-only: packet ownership stays with Dispatcher.
class TempRadioReplyBarrier {
const void* _packet = nullptr;
const void* _copy = nullptr;
bool _armed = false;
bool _succeeded = false;
bool remove(const void* packet) {
if (!_armed || packet == nullptr) return false;
if (packet == _packet) _packet = nullptr;
else if (packet == _copy) _copy = nullptr;
else return false;
return true;
}
public:
// Collect the Dispatcher-created second copy during queue admission. Retry
// bookkeeping can call onSendFail before admission; it must not resolve this.
void prepare(const void* packet) { clear(); _packet = packet; }
void trackCopy(const void* original, const void* copy) {
if (original && original == _packet && copy != original) _copy = copy;
}
void arm(const void* packet) {
if (packet != _packet) prepare(packet);
_armed = packet != nullptr;
}
void clear() { _packet = _copy = nullptr; _armed = _succeeded = false; }
bool waiting() const { return _armed && (_packet || _copy); }
bool succeeded() const { return _armed && _succeeded; }
bool contains(const void* packet) const {
return _armed && packet && (packet == _packet || packet == _copy);
}
bool complete(const void* packet) {
if (!remove(packet)) return false;
_succeeded = true;
return true;
}
// Cancel the transition only when every admitted copy has failed.
bool fail(const void* packet) {
return remove(packet) && !waiting() && !_succeeded;
}
};
} // namespace mesh