Files
meshcore-open/lib/helpers/channel_resend_coverage.dart
T
zjs81 25f197c979 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.
2026-10-11 01:25:31 -07:00

54 lines
1.7 KiB
Dart

import 'dart:typed_data';
import '../models/channel_message.dart';
/// Distinct first-hop repeaters heard echoing [message], across every resend
/// (echoes of all attempts merge into the same message's path variants).
///
/// Each first hop is the leading `pathHashWidth` bytes of an echo's path.
/// Zero-hop echoes and a first hop matching our own key prefix are ignored.
Set<String> distinctFirstHopRepeaters(
ChannelMessage message, {
Uint8List? selfPublicKey,
}) {
final width = (message.pathHashWidth ?? 1).clamp(1, 3).toInt();
String? selfPrefix;
if (selfPublicKey != null && selfPublicKey.length >= width) {
selfPrefix = _hex(selfPublicKey, width);
}
final hops = <String>{};
for (final path in [message.pathBytes, ...message.pathVariants]) {
if (path.length < width) continue;
final hop = _hex(path, width);
if (hop != selfPrefix) hops.add(hop);
}
return hops;
}
/// Whether a channel resend has heard [message] travel far enough:
/// an echo through at least [minHops] repeaters, or, when
/// [countDistinctRepeaters] is on, echoes from at least [minHops] different
/// first-hop repeaters.
bool channelResendSatisfied(
ChannelMessage message, {
required int minHops,
required bool countDistinctRepeaters,
Uint8List? selfPublicKey,
}) {
if ((message.pathLength ?? 0) >= minHops) return true;
if (!countDistinctRepeaters) return false;
return distinctFirstHopRepeaters(
message,
selfPublicKey: selfPublicKey,
).length >=
minHops;
}
String _hex(Uint8List bytes, int length) {
final buffer = StringBuffer();
for (var i = 0; i < length; i++) {
buffer.write(bytes[i].toRadixString(16).padLeft(2, '0'));
}
return buffer.toString();
}