fix(#1062): fail-closed channel sync, ingress barrier, slot identity diff

Epic A of #1061, fixing the #1060 class: the client's slot-to-channel map could silently diverge from the device and misroute notifications and conversations.

- A slot the device never answers for is UNKNOWN: tracked, surfaced via a persistent channels-screen banner with Retry, and never backfilled from the previous list. Lookups for it fail closed, including notification evaluation, which now suppresses instead of defaulting to noisy.

- Ingress barrier: live channel traffic holds until this connection's list is confirmed, then flushes. Pull-based message frames are never dropped (the radio already popped them); lossy raw sniffs stay bounded. Raw-RX no longer matches the offline cache.

- Per-slot unread counts survive a sync only when the slot keeps the same PSK; identity changes are listed in a dismissible notice and logged.

- A sync with unconfirmed slots does not overwrite the last fully-confirmed offline cache; a sync that fails on a live connection retries itself.

New strings English-only per the #1021-era ruling; regenerated l10n + untranslated.json committed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
docs/1053-play-automation
diffwireauto 4 weeks ago committed by Strycher
parent 180c01e670
commit afbacbc7eb

@ -579,6 +579,38 @@ class MeshCoreConnector extends ChangeNotifier {
int _totalChannelsToRequest = 0;
List<Channel> _previousChannelsCache = [];
static const int _maxChannelSyncRetries = 3;
// #1062: fail-closed channel sync. A slot the device never answered for is
// UNKNOWN: tracked here, surfaced to the UI, and never backfilled from a
// previous list (that backfill is how a stale slot map misrouted
// notifications and conversations, #1060).
final Set<int> _unconfirmedChannelSlots = {};
/// Device slots this connection's sync could not confirm. Non-empty means
/// the channel list has holes the UI must surface (#1062).
Set<int> get unconfirmedChannelSlots =>
Set.unmodifiable(_unconfirmedChannelSlots);
// #1062: ingress barrier. Live channel traffic is held while this
// connection's channel list is not yet synced, then flushed, so a message
// is never filed against a guessed slot map.
bool _channelListSynced = false;
final List<Uint8List> _heldChannelMsgFrames = [];
final List<Uint8List> _heldRawChannelFrames = [];
static const int _maxHeldChannelFrames = 64;
/// Human-readable per-slot identity changes found by the latest completed
/// sync (old name -> new name). Surfaced once by the channels screen (#1062).
final List<String> _slotIdentityChanges = [];
List<String> get slotIdentityChanges =>
List.unmodifiable(_slotIdentityChanges);
/// User dismissed the slot-identity-change notice (#1062).
void acknowledgeSlotIdentityChanges() {
_slotIdentityChanges.clear();
notifyListeners();
}
static const int _channelSyncTimeoutMs = 2000; // 2 second timeout per channel
static const Duration _batteryPollInterval = Duration(seconds: 120);
@ -4039,6 +4071,20 @@ class MeshCoreConnector extends ChangeNotifier {
@visibleForTesting
void setConnectedForTest() => _state = MeshCoreConnectionState.connected;
// #1062 test hooks: drive the sync timeout path without real timers, seed
// the offline cache, and observe the fail-closed slot lookup.
@visibleForTesting
void handleChannelSyncTimeoutForTest(int channelIndex) =>
_handleChannelSyncTimeout(channelIndex);
@visibleForTesting
void seedCachedChannelsForTest(List<Channel> channels) {
_cachedChannels = List<Channel>.from(channels);
}
@visibleForTesting
Channel? findChannelByIndexForTest(int index) => _findChannelByIndex(index);
@visibleForTesting
void setAppDebugLogServiceForTest(AppDebugLogService service) =>
_appDebugLogService = service;
@ -4126,6 +4172,14 @@ class MeshCoreConnector extends ChangeNotifier {
_nextChannelIndexToRequest = 0;
_totalChannelsToRequest = 0;
_previousChannelsCache.clear();
// #1062: a new connection starts with an unconfirmed list. Held MESSAGE
// frames are kept: the radio already popped them from its queue, so they
// exist nowhere else, and the next confirmed sync files them. Raw sniff
// frames are lossy observations; a dead connection's are stale.
_channelListSynced = false;
_unconfirmedChannelSlots.clear();
_slotIdentityChanges.clear();
_heldRawChannelFrames.clear();
}
bool get _shouldAutoReconnect =>
@ -6233,6 +6287,11 @@ class MeshCoreConnector extends ChangeNotifier {
_isLoadingChannels = true;
_isSyncingChannels = true;
_hasLoadedChannels = false;
// Re-engage the ingress barrier for the duration of the sync: filing
// against a list that is mid-replacement is the same hazard as filing
// against a stale one (#1062).
_channelListSynced = false;
_unconfirmedChannelSlots.clear();
_previousChannelsCache = List<Channel>.from(_channels);
_channels.clear();
_nextChannelIndexToRequest = 0;
@ -6254,6 +6313,11 @@ class MeshCoreConnector extends ChangeNotifier {
return;
}
// Queued continuations from retries can land after the sync already
// finished; without this guard they re-enter _completeChannelSync against
// the reset counters (#1062).
if (!_isSyncingChannels) return;
if (_channelSyncInFlight) return;
// Check if we've requested all channels
@ -6298,26 +6362,18 @@ class MeshCoreConnector extends ChangeNotifier {
_channelSyncInFlight = false;
unawaited(_requestNextChannel());
} else {
// Max retries reached for this channel, restore from cache and move to next
debugPrint(
'[ChannelSync] Max retries reached for channel $channelIndex, attempting cache restore',
// Max retries reached: the slot's contents are UNKNOWN. It used to be
// restored from the previous list here, which silently pinned a
// pre-reconfiguration channel at this index and misrouted notifications
// and conversations (#1060). Fail closed instead: leave the slot empty,
// record it, surface it (#1062).
_unconfirmedChannelSlots.add(channelIndex);
_appDebugLogService?.error(
'Channel sync: device never answered for slot $channelIndex; '
'slot left unknown, not restored from cache',
tag: 'ChannelSync',
);
// Try to restore this channel from cache
try {
final cachedChannel = _previousChannelsCache.firstWhere(
(c) => c.index == channelIndex,
);
if (!cachedChannel.isEmpty) {
_channels.add(cachedChannel);
debugPrint(
'[ChannelSync] Restored channel $channelIndex (${cachedChannel.name}) from cache',
);
}
} catch (e) {
// No cached channel found, that's okay
}
// Move to next channel
_nextChannelIndexToRequest++;
_channelSyncRetries = 0;
@ -6331,25 +6387,66 @@ class MeshCoreConnector extends ChangeNotifier {
_channelSyncTimeout?.cancel();
debugPrint(
'[ChannelSync] Sync complete: received ${_channels.length}/$_totalChannelsToRequest channels',
'[ChannelSync] Sync complete: received ${_channels.length}/$_totalChannelsToRequest channels'
'${_unconfirmedChannelSlots.isEmpty ? '' : ', unconfirmed slots: $_unconfirmedChannelSlots'}',
);
_cleanupChannelSync(completed: true);
// Cache channels for offline use
_cachedChannels = List<Channel>.from(_channels);
unawaited(
_channelStore.saveChannels(_channels).catchError((Object e) {
_appDebugLogService?.error(
'Failed to persist channels (channel sync): $e',
tag: 'ChannelStore',
// #1062: per-slot identity diff against the last persisted truth. A slot
// whose PSK changed got a different channel; say so once instead of
// letting per-slot state ride across identities.
_slotIdentityChanges.clear();
for (final fresh in _channels) {
final prior = _cachedChannels.cast<Channel?>().firstWhere(
(c) => c?.index == fresh.index,
orElse: () => null,
);
if (prior != null &&
!prior.isEmpty &&
!fresh.isEmpty &&
prior.pskHex != fresh.pskHex) {
_slotIdentityChanges.add(
'slot ${fresh.index}: ${prior.name} -> ${fresh.name}',
);
}),
);
_appDebugLogService?.warn(
'Channel slot ${fresh.index} changed identity on the radio: '
'"${prior.name}" -> "${fresh.name}"',
tag: 'ChannelSync',
);
}
}
if (_unconfirmedChannelSlots.isEmpty) {
// Full confirmation: the fresh list is the truth, replace the cache.
_cachedChannels = List<Channel>.from(_channels);
unawaited(
_channelStore.saveChannels(_channels).catchError((Object e) {
_appDebugLogService?.error(
'Failed to persist channels (channel sync): $e',
tag: 'ChannelStore',
);
}),
);
} else {
// Holes: keep the last fully-confirmed persisted list for offline use
// rather than overwriting it with a partial one. The holes are surfaced
// via [unconfirmedChannelSlots] and lookups for those slots fail closed.
_appDebugLogService?.error(
'Channel sync finished with unconfirmed slots '
'$_unconfirmedChannelSlots; cached list NOT overwritten. '
'Retry the sync to confirm them.',
tag: 'ChannelSync',
);
}
_recalculateCachedChannelsUnreadTotal();
// Apply ordering and notify UI
_applyChannelOrder();
// #1062: open the ingress barrier and file what arrived mid-sync.
_channelListSynced = true;
_flushHeldChannelFrames();
notifyListeners();
// #839: one-time migration of the pre-per-radio notify state into THIS
@ -6380,6 +6477,50 @@ class MeshCoreConnector extends ChangeNotifier {
);
}
/// Replays channel traffic held while the list was unconfirmed (#1062).
/// Runs after [_channelListSynced] flips true, so the handlers file against
/// the fresh list; a frame whose slot is still unconfirmed re-holds.
void _flushHeldChannelFrames() {
if (_heldChannelMsgFrames.isEmpty && _heldRawChannelFrames.isEmpty) return;
final msgFrames = List<Uint8List>.from(_heldChannelMsgFrames);
final rawFrames = List<Uint8List>.from(_heldRawChannelFrames);
_heldChannelMsgFrames.clear();
_heldRawChannelFrames.clear();
_appDebugLogService?.info(
'Channel list synced; filing ${msgFrames.length} held message frame(s) '
'and ${rawFrames.length} held raw frame(s)',
tag: 'ChannelSync',
);
for (final f in msgFrames) {
_handleIncomingChannelMessage(f);
}
for (final f in rawFrames) {
_handleLogRxData(f);
}
}
/// Holds a frame behind the ingress barrier. Message frames are pull-based
/// replies the radio has already popped from its queue, so they are NEVER
/// dropped (the hold only lives for the seconds a sync takes). Raw sniff
/// frames are lossy by nature and stay bounded: overflow drops the oldest
/// and says so loudly (#1062).
void _holdChannelFrame(
List<Uint8List> queue,
Uint8List frame,
String kind, {
required bool bounded,
}) {
if (bounded && queue.length >= _maxHeldChannelFrames) {
queue.removeAt(0);
_appDebugLogService?.error(
'Held-$kind queue overflow while the channel list is unconfirmed; '
'dropped the oldest held frame',
tag: 'ChannelSync',
);
}
queue.add(Uint8List.fromList(frame));
}
void _cleanupChannelSync({required bool completed}) {
_isSyncingChannels = false;
_channelSyncInFlight = false;
@ -6406,6 +6547,16 @@ class MeshCoreConnector extends ChangeNotifier {
// Keep cache on failure/disconnection for future attempts
if (!completed) {
// #1062: a failed sync on a live connection leaves the ingress barrier
// closed with nothing scheduled to open it; retry rather than letting
// held messages starve. (A dead connection re-syncs on reconnect.)
if (isConnected) {
_channelsChangedDebounce?.cancel();
_channelsChangedDebounce = Timer(
const Duration(seconds: 3),
() => unawaited(getChannels(force: true)),
);
}
notifyListeners();
}
}
@ -9229,9 +9380,21 @@ class MeshCoreConnector extends ChangeNotifier {
// Per-channel notification level, keyed by the channel's PSK identity so
// the setting survives a rename and does not follow a reused slot (#259).
// Evaluated against resolvedText so a translated mention still matches.
// #1062: an unknown slot means an unknown PSK means an unknowable mode;
// fail closed (no notification) rather than defaulting to noisy.
final slotChannel = _findChannelByIndex(channelIndex);
if (slotChannel == null &&
_unconfirmedChannelSlots.contains(channelIndex)) {
_appDebugLogService?.warn(
'Suppressing notification for channel slot $channelIndex: slot is '
'unconfirmed, its notify mode cannot be resolved',
tag: 'ChannelSync',
);
return;
}
final mode = _appSettingsService!.channelNotifyMode(
devicePrefix: selfPublicKeyHex,
pskHex: _findChannelByIndex(channelIndex)?.pskHex,
pskHex: slotChannel?.pskHex,
);
switch (mode) {
case ChannelNotifyMode.off:
@ -9266,6 +9429,17 @@ class MeshCoreConnector extends ChangeNotifier {
if (_isSyncingQueuedMessages) {
_handleQueuedMessageReceived();
}
// #1062 ingress barrier: never file a message against a channel list that
// this connection has not confirmed; hold it and flush post-sync.
if (isConnected && !_channelListSynced) {
_holdChannelFrame(
_heldChannelMsgFrames,
frame,
'message',
bounded: false,
);
return;
}
final parsed = ChannelMessage.fromFrame(frame);
if (parsed != null && parsed.channelIndex != null) {
// Device-composed (outgoing) messages legitimately carry our own name and
@ -9338,11 +9512,16 @@ class MeshCoreConnector extends ChangeNotifier {
final channelHash = payload.readByte();
final encrypted = Uint8List.fromList(payload.readRemainingBytes());
// Use cached channels as fallback if live channels not yet loaded
final channelsToSearch = _channels.isNotEmpty
? _channels
: _cachedChannels;
for (final channel in channelsToSearch) {
// #1062 ingress barrier: a raw frame is filed by matching its channel
// hash against the CLIENT's list and reusing that object's index, so a
// stale or mid-sync list files it into the wrong conversation. Hold
// until this connection's list is confirmed; never match the offline
// cache (its indexes may describe a layout the radio no longer has).
if (!_channelListSynced) {
_holdChannelFrame(_heldRawChannelFrames, frame, 'raw', bounded: true);
return;
}
for (final channel in _channels) {
if (channel.isEmpty) continue;
final hash = _computeChannelHash(channel.psk);
if (hash != channelHash) continue;
@ -9645,12 +9824,14 @@ class MeshCoreConnector extends ChangeNotifier {
'[ChannelSync] Received channel ${channel.index}: ${channel.isEmpty ? "empty" : channel.name}',
);
// Preserve unread count from cached channel
// Preserve unread count from the cached channel, but only when the slot
// still holds the SAME channel. An unread count following the slot across
// an identity change is another channel's count (#1062).
final cachedChannel = _cachedChannels.cast<Channel?>().firstWhere(
(c) => c?.index == channel.index,
orElse: () => null,
);
if (cachedChannel != null) {
if (cachedChannel != null && cachedChannel.pskHex == channel.pskHex) {
channel.unreadCount = cachedChannel.unreadCount;
}
@ -9750,6 +9931,10 @@ class MeshCoreConnector extends ChangeNotifier {
}
Channel? _findChannelByIndex(int index) {
// #1062: an unconfirmed slot's contents are unknown. Returning the cached
// occupant here is how a stale identity (wrong PSK, wrong name) attached
// itself to live traffic; fail closed instead.
if (_unconfirmedChannelSlots.contains(index)) return null;
return _channels.cast<Channel?>().firstWhere(
(c) => c?.index == index,
orElse: () => null,

@ -836,6 +836,24 @@
"channels_noChannelsConfigured": "No channels configured",
"channels_addPublicChannel": "Add Public Channel",
"channels_searchChannels": "Search channels...",
"channels_unconfirmedSlots": "The radio did not confirm channel slot(s) {slots}. Those channels are unknown until a sync succeeds.",
"@channels_unconfirmedSlots": {
"placeholders": {
"slots": {
"type": "String"
}
}
},
"channels_retrySync": "Retry sync",
"channels_slotIdentityChanged": "Channel layout changed on the radio: {changes}",
"@channels_slotIdentityChanged": {
"placeholders": {
"changes": {
"type": "String"
}
}
},
"common_dismiss": "Dismiss",
"channels_noChannelsFound": "No channels found",
"channels_channelIndex": "Channel {index}",
"@channels_channelIndex": {

@ -2818,6 +2818,30 @@ abstract class AppLocalizations {
/// **'Search channels...'**
String get channels_searchChannels;
/// No description provided for @channels_unconfirmedSlots.
///
/// In en, this message translates to:
/// **'The radio did not confirm channel slot(s) {slots}. Those channels are unknown until a sync succeeds.'**
String channels_unconfirmedSlots(String slots);
/// No description provided for @channels_retrySync.
///
/// In en, this message translates to:
/// **'Retry sync'**
String get channels_retrySync;
/// No description provided for @channels_slotIdentityChanged.
///
/// In en, this message translates to:
/// **'Channel layout changed on the radio: {changes}'**
String channels_slotIdentityChanged(String changes);
/// No description provided for @common_dismiss.
///
/// In en, this message translates to:
/// **'Dismiss'**
String get common_dismiss;
/// No description provided for @channels_noChannelsFound.
///
/// In en, this message translates to:

@ -1579,6 +1579,22 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get channels_searchChannels => 'Търсене на канали...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'Няма намерени канали';

@ -1573,6 +1573,22 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get channels_searchChannels => 'Suche Kanäle...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'Keine Kanäle gefunden';

@ -1555,6 +1555,22 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get channels_searchChannels => 'Search channels...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'No channels found';

@ -1574,6 +1574,22 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get channels_searchChannels => 'Buscar canales...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'No se encontraron canales';

@ -1579,6 +1579,22 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get channels_searchChannels => 'Rechercher des canaux...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'Aucun canal trouvé';

@ -1580,6 +1580,22 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get channels_searchChannels => 'Keresési opciók...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'Nincs megtalálható csatorna';

@ -1575,6 +1575,22 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get channels_searchChannels => 'Cerca canali...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'Nessun canale trovato';

@ -1523,6 +1523,22 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get channels_searchChannels => '検索オプション...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'チャンネルが見つかりませんでした';

@ -1518,6 +1518,22 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get channels_searchChannels => '검색 채널...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => '채널을 찾을 수 없습니다.';

@ -1566,6 +1566,22 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get channels_searchChannels => 'Zoek kanalen...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'Geen kanalen gevonden';

@ -1585,6 +1585,22 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get channels_searchChannels => 'Wyszukaj kanały...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'Brak znalezionych kanałów';

@ -1575,6 +1575,22 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get channels_searchChannels => 'Pesquisar canais...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'Nenhum canal encontrado';

@ -1576,6 +1576,22 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get channels_searchChannels => 'Поиск каналов...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'Каналы не найдены';

@ -1566,6 +1566,22 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get channels_searchChannels => 'Vyhľadávajte kanály...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'Neobsiahlo sa žiadnych kanálov.';

@ -1563,6 +1563,22 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get channels_searchChannels => 'Poišči kanale...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'Ne najdem kanalov.';

@ -1557,6 +1557,22 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get channels_searchChannels => 'Sök kanaler...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'Inga kanaler hittades';

@ -1571,6 +1571,22 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get channels_searchChannels => 'Пошук каналів...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => 'Каналів не знайдено';

@ -1504,6 +1504,22 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get channels_searchChannels => '搜索频道...';
@override
String channels_unconfirmedSlots(String slots) {
return 'The radio did not confirm channel slot(s) $slots. Those channels are unknown until a sync succeeds.';
}
@override
String get channels_retrySync => 'Retry sync';
@override
String channels_slotIdentityChanged(String changes) {
return 'Channel layout changed on the radio: $changes';
}
@override
String get common_dismiss => 'Dismiss';
@override
String get channels_noChannelsFound => '未找到任何频道';

@ -187,6 +187,41 @@ class _ChannelsScreenState extends State<ChannelsScreen>
return Column(
children: [
// #1062: persistent, undismissable while true. A slot the
// radio never confirmed means its channel is unknown; a
// 4-second toast is not an error surface (SAFELANE 6).
if (connector.unconfirmedChannelSlots.isNotEmpty)
MaterialBanner(
backgroundColor: Theme.of(
context,
).colorScheme.errorContainer,
content: Text(
context.l10n.channels_unconfirmedSlots(
connector.unconfirmedChannelSlots.toList().join(', '),
),
),
actions: [
TextButton(
onPressed: () =>
unawaited(connector.getChannels(force: true)),
child: Text(context.l10n.channels_retrySync),
),
],
),
if (connector.slotIdentityChanges.isNotEmpty)
MaterialBanner(
content: Text(
context.l10n.channels_slotIdentityChanged(
connector.slotIdentityChanges.join('; '),
),
),
actions: [
TextButton(
onPressed: connector.acknowledgeSlotIdentityChanges,
child: Text(context.l10n.common_dismiss),
),
],
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(

@ -0,0 +1,203 @@
// #1062 (Epic A of #1061, fixing #1060): the channel sync is fail-closed and
// atomic, live filing waits behind an ingress barrier, and per-slot state
// never follows a slot across an identity change.
//
// The #1060 field case: a wipe + config re-import rearranged the device's
// channel slots; the old sync backfilled unanswered slots from the previous
// list, so notifications fired for the wrong channel and messages rendered
// inside the wrong conversation.
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/connector/meshcore_connector.dart';
import 'package:meshcore_open/connector/meshcore_protocol.dart';
import 'package:meshcore_open/models/channel.dart';
import 'package:meshcore_open/storage/prefs_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';
Uint8List _channelInfoFrame({
required int index,
required String name,
required int pskSeed,
}) {
final frame = Uint8List(50);
frame[0] = respCodeChannelInfo;
frame[1] = index;
final nameBytes = name.codeUnits;
for (var i = 0; i < nameBytes.length && i < 31; i++) {
frame[2 + i] = nameBytes[i];
}
for (var i = 0; i < 16; i++) {
frame[34 + i] = (pskSeed + i) & 0xFF;
}
return frame;
}
Uint8List _v3ChannelMsgFrame({required int channelIdx, String text = 'A: hi'}) {
return Uint8List.fromList([
respCodeChannelMsgRecvV3,
0, 0, 0,
channelIdx,
1, // path_len: 1 hop, width 1
txtTypePlain,
0x40, 0xE2, 0x01, 0x00,
...text.codeUnits,
]);
}
Channel _channel(int index, String name, int pskSeed) {
final psk = Uint8List.fromList(
List<int>.generate(16, (i) => (pskSeed + i) & 0xFF),
);
return Channel(index: index, name: name, psk: psk);
}
MeshCoreConnector _connector() {
final c = MeshCoreConnector();
c.sendFrameOverrideForTest = (_) {};
c.setConnectedForTest();
c.setSelfPublicKeyForTest(
Uint8List.fromList(List<int>.generate(32, (i) => i)),
);
return c;
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() async {
SharedPreferences.setMockInitialValues({});
PrefsManager.reset();
await PrefsManager.initialize();
});
test(
'an unanswered slot stays UNKNOWN, never backfilled from cache (#1060)',
() async {
final c = _connector();
c.seedCachedChannelsForTest([_channel(1, 'StaleOccupant', 70)]);
await c.getChannels(maxChannels: 2);
c.handleFrameForTest(
_channelInfoFrame(index: 0, name: 'Fresh0', pskSeed: 10),
);
// Slot 1 never answers: exhaust the retries.
for (var i = 0; i <= 3; i++) {
c.handleChannelSyncTimeoutForTest(1);
await Future<void>.delayed(Duration.zero);
}
expect(c.unconfirmedChannelSlots, {1});
expect(c.channels.map((ch) => ch.name), ['Fresh0']);
expect(
c.channels.any((ch) => ch.name == 'StaleOccupant'),
isFalse,
reason: 'the stale cache occupant must not be restored into the slot',
);
expect(
c.findChannelByIndexForTest(1),
isNull,
reason: 'lookups for an unconfirmed slot fail closed',
);
},
);
test(
'messages arriving mid-sync are held, then filed after the sync',
() async {
final c = _connector();
await c.getChannels(maxChannels: 2);
// Barrier is up: a pushed message must not file yet.
c.handleFrameForTest(_v3ChannelMsgFrame(channelIdx: 0));
expect(c.channelMessagesForTest[0], isNull);
c.handleFrameForTest(
_channelInfoFrame(index: 0, name: 'Alpha', pskSeed: 10),
);
await Future<void>.delayed(Duration.zero);
c.handleFrameForTest(
_channelInfoFrame(index: 1, name: 'Beta', pskSeed: 30),
);
await Future<void>.delayed(Duration.zero);
expect(c.unconfirmedChannelSlots, isEmpty);
expect(
c.channelMessagesForTest[0],
isNotNull,
reason: 'the held frame files once the list is confirmed',
);
expect(c.channelMessagesForTest[0]!.single.text, 'hi');
},
);
test(
'unread count does not follow a slot across an identity change',
() async {
final c = _connector();
final stale = _channel(0, 'OldChannel', 70)..unreadCount = 5;
c.seedCachedChannelsForTest([stale]);
await c.getChannels(maxChannels: 1);
// Same slot, different PSK: a different channel lives here now.
c.handleFrameForTest(
_channelInfoFrame(index: 0, name: 'NewChannel', pskSeed: 10),
);
await Future<void>.delayed(Duration.zero);
expect(c.channels.single.name, 'NewChannel');
expect(
c.channels.single.unreadCount,
0,
reason: 'another identity\'s unread count must not ride the slot',
);
expect(c.slotIdentityChanges, isNotEmpty);
},
);
test(
'unread count IS preserved when the slot keeps the same channel',
() async {
final c = _connector();
final same = _channel(0, 'Keep', 10)..unreadCount = 7;
c.seedCachedChannelsForTest([same]);
await c.getChannels(maxChannels: 1);
c.handleFrameForTest(
_channelInfoFrame(index: 0, name: 'Keep', pskSeed: 10),
);
await Future<void>.delayed(Duration.zero);
expect(c.channels.single.unreadCount, 7);
expect(c.slotIdentityChanges, isEmpty);
},
);
test(
'a sync with unconfirmed slots does not overwrite the offline cache',
() async {
final c = _connector();
c.seedCachedChannelsForTest([
_channel(0, 'GoodCache0', 10),
_channel(1, 'GoodCache1', 30),
]);
await c.getChannels(maxChannels: 2);
c.handleFrameForTest(
_channelInfoFrame(index: 0, name: 'Fresh0', pskSeed: 10),
);
for (var i = 0; i <= 3; i++) {
c.handleChannelSyncTimeoutForTest(1);
await Future<void>.delayed(Duration.zero);
}
expect(c.unconfirmedChannelSlots, {1});
// The confirmed slot is live; the unconfirmed one is a hole, and the last
// fully-confirmed cache survives for the next attempt (slot 0 lookup still
// resolves, slot 1 fails closed).
expect(c.findChannelByIndexForTest(0)?.name, 'Fresh0');
expect(c.findChannelByIndexForTest(1), isNull);
},
);
}

@ -126,6 +126,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -465,6 +469,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -804,6 +812,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -1143,6 +1155,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -1482,6 +1498,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -1821,6 +1841,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -2160,6 +2184,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -2499,6 +2527,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -2838,6 +2870,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -3177,6 +3213,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -3516,6 +3556,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -3855,6 +3899,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -4194,6 +4242,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -4533,6 +4585,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -4872,6 +4928,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -5211,6 +5271,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",
@ -5550,6 +5614,10 @@
"contact_remoteCli",
"contact_remoteCliSubtitle",
"contact_cliConsole",
"channels_unconfirmedSlots",
"channels_retrySync",
"channels_slotIdentityChanged",
"common_dismiss",
"channels_notifications",
"channels_notifyAll",
"channels_notifyMentionsOnly",

Loading…
Cancel
Save

Powered by TurnKey Linux.