Fix review findings, add default flood scope, and address recent issues
Review fixes: - Keep stored message history beyond the 200-message window; stop messages leaking between radios; reset link/session state on disconnect - Accept firmware's 176-byte RX frames over USB/TCP - Hold APP_START during contact sync; contact-sync watchdog; replay DMs from not-yet-known senders; tombstone late command replies; finish channel sync on ERR_NOT_FOUND; fail region-scoped sends cleanly - DM retry watchdog when RESP_CODE_SENT never arrives; late repeater CLI replies; ACK hash collisions; UTF-8-safe name truncation - Image pipeline: delete-during-decode, lifecycle cancels, decoder memory release, entry cap, dead worker recovery, atomic model writes - Storage: deterministic reaction hash across web/native, Smaz double-decode, per-entry parsing, per-radio path history and regions, review-mode data isolation - UI: safe channel slot selection, byte-length name limits, double-send guard, mounted checks, localized hardcoded strings - Skip persisted-store reload on repeat SELF_INFO Features: - Radio default flood scope (firmware ver 11+) and explicit unscoped sends (ver 12+) - Scan for nearby nodes (#570) - Optional distinct first-hop repeater counting for channel resend (#589) - Optional region next to hop count (#580) Issues: - Message text follows system font size (#569) - Repeater/room password field accepts 20 chars (#576) - TCP auto-reconnect and keepalive (#571) - Order feeds by local receive time; flag future timestamps (#584) - Coding rate help text (#568), French "Favoris" (#575) - iOS/macOS app badge now clears Translations for all new strings in every locale.
This commit is contained in:
1 parent
a64a33d0c0
commit
25f197c979
120 files changed
+10424
-687
No files matched your search
@@ -17,7 +17,14 @@ class PendingCommandReply {
|
||||
final Uint8List? matchKey;
|
||||
final String? channelSendQueueId;
|
||||
final Completer<void>? completer;
|
||||
final DateTime createdAt = DateTime.now();
|
||||
final DateTime createdAt;
|
||||
|
||||
/// Set when the sender gave up waiting. The entry then stays queued as a
|
||||
/// tombstone so the firmware's late reply is absorbed here instead of being
|
||||
/// credited to the next command.
|
||||
DateTime? timedOutAt;
|
||||
|
||||
bool get isTombstone => timedOutAt != null;
|
||||
|
||||
PendingCommandReply({
|
||||
required this.commandCode,
|
||||
@@ -25,7 +32,8 @@ class PendingCommandReply {
|
||||
this.matchKey,
|
||||
this.channelSendQueueId,
|
||||
this.completer,
|
||||
});
|
||||
DateTime? createdAt,
|
||||
}) : createdAt = createdAt ?? DateTime.now();
|
||||
}
|
||||
|
||||
/// Success reply for each command whose single reply is OK/ERR or a specific
|
||||
@@ -53,6 +61,7 @@ int? replyCodeForCommand(Uint8List data) {
|
||||
case cmdSetAutoAddConfig:
|
||||
case cmdSetPathHashMode:
|
||||
case cmdSendChannelData:
|
||||
case cmdSetDefaultFloodScope:
|
||||
return respCodeOk;
|
||||
case cmdSendTxtMsg:
|
||||
case cmdSendLogin:
|
||||
@@ -88,6 +97,8 @@ int? replyCodeForCommand(Uint8List data) {
|
||||
return respCodeAutoAddConfig;
|
||||
case cmdGetAllowedRepeatFreq:
|
||||
return respCodeAllowedRepeatFreq;
|
||||
case cmdGetDefaultFloodScope:
|
||||
return respCodeDefaultFloodScope;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -96,11 +107,20 @@ int? replyCodeForCommand(Uint8List data) {
|
||||
/// and answers each with OK, ERR or a specific RESP_CODE, so an ERR belongs
|
||||
/// to the oldest pending command and an OK to the oldest one expecting OK.
|
||||
class PendingCommandReplies {
|
||||
PendingCommandReplies({required this.staleAfter});
|
||||
PendingCommandReplies({
|
||||
required this.staleAfter,
|
||||
this.tombstoneLifetime = const Duration(seconds: 10),
|
||||
DateTime Function()? clock,
|
||||
}) : _clock = clock ?? DateTime.now;
|
||||
|
||||
/// Entries older than this are dropped so a lost reply cannot swallow a
|
||||
/// later, unrelated OK/ERR. Awaited entries time out in sendFrame first.
|
||||
final Duration staleAfter;
|
||||
|
||||
/// How long a timed-out entry waits for its late reply. Kept short so a
|
||||
/// reply that never comes swallows at most a brief window of replies.
|
||||
final Duration tombstoneLifetime;
|
||||
final DateTime Function() _clock;
|
||||
final List<PendingCommandReply> _queue = [];
|
||||
|
||||
int get length => _queue.length;
|
||||
@@ -123,6 +143,7 @@ class PendingCommandReplies {
|
||||
: null,
|
||||
channelSendQueueId: channelSendQueueId,
|
||||
completer: waitForReply ? Completer<void>() : null,
|
||||
createdAt: _clock(),
|
||||
);
|
||||
if (pending.completer != null) {
|
||||
// The sender awaits this future after transport I/O; attach an error
|
||||
@@ -135,11 +156,19 @@ class PendingCommandReplies {
|
||||
|
||||
void remove(PendingCommandReply pending) => _queue.remove(pending);
|
||||
|
||||
/// Marks [pending] as abandoned by its sender. It keeps its place in the
|
||||
/// FIFO so a late reply is consumed by it rather than misattributed.
|
||||
void markTimedOut(PendingCommandReply pending) {
|
||||
if (!_queue.contains(pending)) return;
|
||||
pending.timedOutAt = _clock();
|
||||
}
|
||||
|
||||
void clear() => _queue.clear();
|
||||
|
||||
/// Completes the oldest command whose success reply is [frame]'s code.
|
||||
bool completeReply(Uint8List frame) {
|
||||
if (frame.isEmpty) return false;
|
||||
_pruneStale();
|
||||
final code = frame[0];
|
||||
if (code == respCodeOk || code == respCodeErr) return false;
|
||||
final key = code == respCodeContact && frame.length >= 1 + pubKeySize
|
||||
@@ -156,20 +185,24 @@ class PendingCommandReplies {
|
||||
}
|
||||
|
||||
/// Attributes RESP_CODE_OK; commands expecting a specific reply are skipped.
|
||||
/// Returns null when no command matches or a timed-out entry absorbed it.
|
||||
PendingCommandReply? takeOk() {
|
||||
_pruneStale();
|
||||
final index = _queue.indexWhere((p) => p.replyCode == respCodeOk);
|
||||
if (index < 0) return null;
|
||||
final pending = _queue.removeAt(index);
|
||||
if (pending.isTombstone) return null;
|
||||
pending.completer?.complete();
|
||||
return pending;
|
||||
}
|
||||
|
||||
/// Attributes RESP_CODE_ERR to the oldest pending command.
|
||||
/// Returns null when nothing is pending or a timed-out entry absorbed it.
|
||||
PendingCommandReply? takeErr(int errCode) {
|
||||
_pruneStale();
|
||||
if (_queue.isEmpty) return null;
|
||||
final pending = _queue.removeAt(0);
|
||||
if (pending.isTombstone) return null;
|
||||
pending.completer?.completeError(
|
||||
Exception('Command failed with error code $errCode'),
|
||||
);
|
||||
@@ -177,7 +210,13 @@ class PendingCommandReplies {
|
||||
}
|
||||
|
||||
void _pruneStale() {
|
||||
final cutoff = DateTime.now().subtract(staleAfter);
|
||||
_queue.removeWhere((p) => p.createdAt.isBefore(cutoff));
|
||||
final now = _clock();
|
||||
final cutoff = now.subtract(staleAfter);
|
||||
final tombstoneCutoff = now.subtract(tombstoneLifetime);
|
||||
_queue.removeWhere(
|
||||
(p) =>
|
||||
p.createdAt.isBefore(cutoff) ||
|
||||
(p.timedOutAt?.isBefore(tombstoneCutoff) ?? false),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user