fix(#1223): make the DM flood fallback unconditional, retire Direct

Clearing the stored path and flooding is the only recovery the wire
protocol offers: the radio routes a DM direct whenever it holds a path,
there is no per-send routing field, and flood is how the mesh teaches it
a new route. That makes the fallback part of sending a DM, not a
preference. Owner rulings on #1222:

R1(b): `autoRouteRotationEnabled` is deleted rather than flipped. It
shipped false, so the fallback was unreachable out of the box. Deleting
it also un-hides the route-weight and "Max Message Retries" sliders,
which were behind that toggle while their values applied to every send
regardless. `preparePathForContactSend` keeps flag-off behaviour
explicitly: dropping the gate there would have switched repeater, room
and telemetry command sends over to rotated paths, which nobody ruled on.

R2(a): "Direct" is removed. A forced zero-hop path bought no
reachability, because a DM is matched on the destination hash with no
check of route type or path position, and Auto already settles on zero
hops for a real neighbour. What it did buy was a sticky mode that
suppressed the fallback and failed silently once the contact moved out of
range. A zero-hop override is normalised to Auto at every entry point:
setPathOverride, both contact stores on load, path resolution, and the
labels. Nobody is stranded in a mode the UI no longer offers.

R3(b): `clearPathOnMaxRetry` is retired. It fired after the last attempt
had already failed, so it could only ever help the next message, and the
final attempt now clears the path itself.

R4(a): the final attempt floods even for a hand-picked path. An override
still chooses the route for every earlier attempt.

Tests, three of four proven to fail against the old gating: the selector
runs with no settings service wired at all (was skipped entirely), a
zero-hop override does not suppress it, the fallback does not depend on
the path-history service existing, and an override floods on its final
attempt while writing no path to the radio.

Not in this change: the dead l10n keys the removed toggles leave behind,
and what should re-establish a user's pinned route after the final flood
clears it on the radio. Both noted on #1223.
feat/1198-dm-path-ownership
diffwireauto 2 days ago
parent a9668795b0
commit 627b2849cc

@ -6424,6 +6424,16 @@ class MeshCoreConnector extends ChangeNotifier {
int? pathLen,
Uint8List? pathBytes,
}) async {
// A forced zero-hop path is Auto. It was the "Direct" mode, and picking a
// zero-hop route out of path management is the same thing by another door:
// it pins nothing the radio would not already do, while suppressing the
// flood fallback and going quiet when the contact moves out of range
// (#1223 R2). Normalising here closes every entry point at once.
if (pathLen == 0 && (pathBytes == null || pathBytes.isEmpty)) {
pathLen = null;
pathBytes = null;
}
appLogger.info(
'setPathOverride called for ${contact.name}: pathLen=$pathLen, bytesLen=${pathBytes?.length ?? 0}',
tag: 'Connector',
@ -6482,20 +6492,16 @@ class MeshCoreConnector extends ChangeNotifier {
notifyListeners();
}
/// Used by the repeater, room and telemetry command surfaces, not by DMs.
///
/// Path-history rotation is deliberately NOT applied here. It was reachable
/// only through `autoRouteRotationEnabled`, which defaulted off and is now
/// gone (#1223 R1): dropping the gate without dropping the branch would have
/// silently switched these command sends over to rotated paths, which is a
/// behaviour change on a surface nobody reviewed. These sends resolve from
/// the contact alone, exactly as they did with the flag off.
Future<PathSelection> preparePathForContactSend(Contact contact) async {
PathSelection? autoSelection;
final autoRotationEnabled =
_appSettingsService?.settings.autoRouteRotationEnabled == true;
if (autoRotationEnabled && contact.pathOverride == null) {
final maxRetries = _appSettingsService?.settings.maxMessageRetries ?? 5;
autoSelection = _selectAutoPathForAttempt(
contact.publicKeyHex,
attemptIndex: 0,
maxRetries: maxRetries,
);
}
final resolved = resolvePathSelection(contact, selection: autoSelection);
final resolved = resolvePathSelection(contact);
if (resolved.useFlood) {
await clearContactPath(contact);

@ -24,10 +24,14 @@ extension ContactLocalization on Contact {
}
String pathLabel(AppLocalizations l10n) {
if (pathOverride != null) {
if (pathOverride! < 0) return l10n.chat_floodForced;
if (pathOverride == 0) return l10n.chat_directForced;
return l10n.chat_hopsForced(pathOverride!);
// A zero-hop override was the retired "Direct" mode (#1223 R2). It is not
// an override any more, so the label describes the radio's own path rather
// than claiming a forced route that nothing enforces.
final int? override = pathOverride == 0 ? null : pathOverride;
if (override != null) {
if (override < 0) return l10n.chat_floodForced;
return l10n.chat_hopsForced(override);
}
if (pathLength < 0) return l10n.channelPath_floodPath;
if (pathLength == 0) return l10n.chat_direct;

@ -107,7 +107,6 @@ class Cyr2LatProfile {
class AppSettings {
static const Object _unset = Object();
final bool clearPathOnMaxRetry;
final bool mapShowRepeaters;
final bool mapShowChatNodes;
final bool mapShowOtherNodes;
@ -130,7 +129,6 @@ class AppSettings {
final bool notifyOnNewMessage;
final bool notifyOnNewChannelMessage;
final bool notifyOnNewAdvert;
final bool autoRouteRotationEnabled;
final double maxRouteWeight;
final double initialRouteWeight;
final double routeWeightSuccessIncrement;
@ -206,7 +204,6 @@ class AppSettings {
}
AppSettings({
this.clearPathOnMaxRetry = false,
this.mapShowRepeaters = true,
this.mapShowChatNodes = true,
this.mapShowOtherNodes = true,
@ -227,7 +224,6 @@ class AppSettings {
this.notifyOnNewMessage = true,
this.notifyOnNewChannelMessage = true,
this.notifyOnNewAdvert = true,
this.autoRouteRotationEnabled = false,
this.maxRouteWeight = 5.0,
this.initialRouteWeight = 3.0,
this.routeWeightSuccessIncrement = 0.5,
@ -279,7 +275,6 @@ class AppSettings {
Map<String, dynamic> toJson() {
return {
'clear_path_on_max_retry': clearPathOnMaxRetry,
'map_show_repeaters': mapShowRepeaters,
'map_show_chat_nodes': mapShowChatNodes,
'map_show_other_nodes': mapShowOtherNodes,
@ -300,7 +295,6 @@ class AppSettings {
'notify_on_new_message': notifyOnNewMessage,
'notify_on_new_channel_message': notifyOnNewChannelMessage,
'notify_on_new_advert': notifyOnNewAdvert,
'auto_route_rotation_enabled': autoRouteRotationEnabled,
'max_route_weight': maxRouteWeight,
'initial_route_weight': initialRouteWeight,
'route_weight_success_increment': routeWeightSuccessIncrement,
@ -378,7 +372,6 @@ class AppSettings {
}
return AppSettings(
clearPathOnMaxRetry: json['clear_path_on_max_retry'] as bool? ?? false,
mapShowRepeaters: json['map_show_repeaters'] as bool? ?? true,
mapShowChatNodes: json['map_show_chat_nodes'] as bool? ?? true,
mapShowOtherNodes: json['map_show_other_nodes'] as bool? ?? true,
@ -404,8 +397,6 @@ class AppSettings {
notifyOnNewChannelMessage:
json['notify_on_new_channel_message'] as bool? ?? true,
notifyOnNewAdvert: json['notify_on_new_advert'] as bool? ?? true,
autoRouteRotationEnabled:
json['auto_route_rotation_enabled'] as bool? ?? false,
maxRouteWeight: (json['max_route_weight'] as num?)?.toDouble() ?? 5.0,
initialRouteWeight:
(json['initial_route_weight'] as num?)?.toDouble() ?? 3.0,
@ -522,7 +513,6 @@ class AppSettings {
}
AppSettings copyWith({
bool? clearPathOnMaxRetry,
bool? mapShowRepeaters,
bool? mapShowChatNodes,
bool? mapShowOtherNodes,
@ -543,7 +533,6 @@ class AppSettings {
bool? notifyOnNewMessage,
bool? notifyOnNewChannelMessage,
bool? notifyOnNewAdvert,
bool? autoRouteRotationEnabled,
double? maxRouteWeight,
double? initialRouteWeight,
double? routeWeightSuccessIncrement,
@ -578,7 +567,6 @@ class AppSettings {
String? selectedCyr2latProfileId,
}) {
return AppSettings(
clearPathOnMaxRetry: clearPathOnMaxRetry ?? this.clearPathOnMaxRetry,
mapShowRepeaters: mapShowRepeaters ?? this.mapShowRepeaters,
mapShowChatNodes: mapShowChatNodes ?? this.mapShowChatNodes,
mapShowOtherNodes: mapShowOtherNodes ?? this.mapShowOtherNodes,
@ -603,8 +591,6 @@ class AppSettings {
notifyOnNewChannelMessage:
notifyOnNewChannelMessage ?? this.notifyOnNewChannelMessage,
notifyOnNewAdvert: notifyOnNewAdvert ?? this.notifyOnNewAdvert,
autoRouteRotationEnabled:
autoRouteRotationEnabled ?? this.autoRouteRotationEnabled,
maxRouteWeight: maxRouteWeight ?? this.maxRouteWeight,
initialRouteWeight: initialRouteWeight ?? this.initialRouteWeight,
routeWeightSuccessIncrement:

@ -208,7 +208,10 @@ class Contact {
}
Uint8List get pathBytesForDisplay {
if (pathOverride != null) {
// A zero-hop override was the retired "Direct" mode and no longer pins
// anything, so show the radio's own path rather than an empty route
// (#1223 R2).
if (pathOverride != null && pathOverride != 0) {
if (pathOverride! < 0) return Uint8List(0);
return pathOverrideBytes ?? Uint8List(0);
}

@ -43,8 +43,13 @@ PathSelection resolvePathSelection(
int hopsFor(List<int> bytes) =>
width > 0 ? bytes.length ~/ width : bytes.length;
if (contact.pathOverride != null) {
if (contact.pathOverride! < 0) {
// A zero-hop override was the retired "Direct" mode (#1223 R2). Treat it as
// no override so a value that predates the removal falls through to the
// radio's own path instead of pinning a route the radio would pick anyway.
final int? override = contact.pathOverride == 0 ? null : contact.pathOverride;
if (override != null) {
if (override < 0) {
return const PathSelection(pathBytes: [], hopCount: -1, useFlood: true);
}
final bytes = contact.pathOverrideBytes ?? Uint8List(0);

@ -231,13 +231,15 @@ class _ChatScreenState extends State<ChatScreen> {
builder: (context, connector, _) {
final contact = _resolveContact(connector);
final isFloodMode = contact.pathOverride == -1;
final isDirectMode = contact.pathOverride == 0;
final activeMode = isFloodMode
? 'flood'
: isDirectMode
? 'direct'
: 'auto';
// "Direct" (a forced zero-hop path) is gone. It bought no
// reachability: a DM is matched on the destination hash with no
// check of route type or path position, so a node in range hears
// the transmission whatever path the packet carries, and Auto
// already settles on zero hops for a real neighbour because the
// path return comes back with a length of 0. What it did buy was
// a sticky mode that suppressed the flood fallback and failed
// silently once the contact moved out of range. (#1223 R2)
final activeMode = isFloodMode ? 'flood' : 'auto';
return PopupMenuButton<String>(
icon: Icon(isFloodMode ? Icons.waves : Icons.route),
@ -245,12 +247,6 @@ class _ChatScreenState extends State<ChatScreen> {
onSelected: (mode) async {
if (mode == 'flood') {
await connector.setPathOverride(contact, pathLen: -1);
} else if (mode == 'direct') {
await connector.setPathOverride(
contact,
pathLen: 0,
pathBytes: Uint8List(0),
);
} else {
await connector.setPathOverride(contact, pathLen: null);
}
@ -279,29 +275,6 @@ class _ChatScreenState extends State<ChatScreen> {
],
),
),
PopupMenuItem(
value: 'direct',
child: Row(
children: [
Icon(
Icons.near_me,
size: 20,
color: activeMode == 'direct'
? Theme.of(context).primaryColor
: null,
),
const SizedBox(width: 8),
Text(
context.l10n.chat_direct,
style: TextStyle(
fontWeight: activeMode == 'direct'
? FontWeight.bold
: FontWeight.normal,
),
),
],
),
),
PopupMenuItem(
value: 'flood',
child: Row(
@ -1340,7 +1313,6 @@ class _ChatScreenState extends State<ChatScreen> {
// Check if user has set a path override
if (contact.pathOverride != null) {
if (contact.pathOverride! < 0) return context.l10n.chat_floodForced;
if (contact.pathOverride == 0) return context.l10n.chat_directForced;
return context.l10n.chat_hopsForced(contact.pathOverride!);
}

@ -223,30 +223,6 @@ class MessageSettingsView extends StatelessWidget {
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
SwitchListTile(
secondary: const Icon(Icons.refresh_outlined),
title: Text(context.l10n.appSettings_clearPathOnMaxRetry),
subtitle: Text(
context.l10n.appSettings_clearPathOnMaxRetrySubtitle,
),
value: settingsService.settings.clearPathOnMaxRetry,
onChanged: (value) {
persistSetting(
context,
() => settingsService.setClearPathOnMaxRetry(value),
);
showDismissibleSnackBar(
context,
content: Text(
value
? context.l10n.appSettings_pathsWillBeCleared
: context.l10n.appSettings_pathsWillNotBeCleared,
),
duration: const Duration(seconds: 2),
);
},
),
const Divider(height: 1),
SwitchListTile(
secondary: const Icon(Icons.vertical_align_top),
title: Text(context.l10n.appSettings_jumpToOldestUnread),
@ -257,152 +233,124 @@ class MessageSettingsView extends StatelessWidget {
() => settingsService.setJumpToOldestUnread(value),
),
),
// The route-weight and retry sliders are no longer behind a toggle.
// They were gated on `autoRouteRotationEnabled`, which defaulted off,
// so "Max Message Retries" governed every send while being invisible
// and uneditable unless that toggle happened to be on (#1223 R1).
const Divider(height: 1),
SwitchListTile(
secondary: const Icon(Icons.alt_route),
title: Text(context.l10n.appSettings_autoRouteRotation),
subtitle: Text(context.l10n.appSettings_autoRouteRotationSubtitle),
value: settingsService.settings.autoRouteRotationEnabled,
onChanged: (value) {
persistSetting(
context,
() => settingsService.setAutoRouteRotationEnabled(value),
);
showDismissibleSnackBar(
context,
content: Text(
value
? context.l10n.appSettings_autoRouteRotationEnabled
: context.l10n.appSettings_autoRouteRotationDisabled,
),
duration: const Duration(seconds: 2),
);
},
),
if (settingsService.settings.autoRouteRotationEnabled) ...[
const Divider(height: 1),
ListTile(
title: Text(context.l10n.appSettings_maxRouteWeight),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(context.l10n.appSettings_maxRouteWeightSubtitle),
Slider(
value: settingsService.settings.maxRouteWeight,
min: 1,
max: 10,
divisions: 9,
label: settingsService.settings.maxRouteWeight
.round()
.toString(),
onChanged: (value) => persistSetting(
context,
() => settingsService.setMaxRouteWeight(value),
),
ListTile(
title: Text(context.l10n.appSettings_maxRouteWeight),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(context.l10n.appSettings_maxRouteWeightSubtitle),
Slider(
value: settingsService.settings.maxRouteWeight,
min: 1,
max: 10,
divisions: 9,
label: settingsService.settings.maxRouteWeight
.round()
.toString(),
onChanged: (value) => persistSetting(
context,
() => settingsService.setMaxRouteWeight(value),
),
],
),
),
],
),
const Divider(height: 1),
ListTile(
title: Text(context.l10n.appSettings_initialRouteWeight),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(context.l10n.appSettings_initialRouteWeightSubtitle),
Slider(
value: settingsService.settings.initialRouteWeight,
min: 0.5,
max: 5.0,
divisions: 9,
label: settingsService.settings.initialRouteWeight
.toStringAsFixed(1),
onChanged: (value) => persistSetting(
context,
() => settingsService.setInitialRouteWeight(value),
),
),
const Divider(height: 1),
ListTile(
title: Text(context.l10n.appSettings_initialRouteWeight),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(context.l10n.appSettings_initialRouteWeightSubtitle),
Slider(
value: settingsService.settings.initialRouteWeight,
min: 0.5,
max: 5.0,
divisions: 9,
label: settingsService.settings.initialRouteWeight
.toStringAsFixed(1),
onChanged: (value) => persistSetting(
context,
() => settingsService.setInitialRouteWeight(value),
),
],
),
),
],
),
const Divider(height: 1),
ListTile(
title: Text(context.l10n.appSettings_routeWeightSuccessIncrement),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context
.l10n
.appSettings_routeWeightSuccessIncrementSubtitle,
),
Slider(
value: settingsService.settings.routeWeightSuccessIncrement,
min: 0.1,
max: 2.0,
divisions: 19,
label: settingsService.settings.routeWeightSuccessIncrement
.toStringAsFixed(1),
onChanged: (value) => persistSetting(
context,
() =>
settingsService.setRouteWeightSuccessIncrement(value),
),
),
const Divider(height: 1),
ListTile(
title: Text(context.l10n.appSettings_routeWeightSuccessIncrement),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context.l10n.appSettings_routeWeightSuccessIncrementSubtitle,
),
Slider(
value: settingsService.settings.routeWeightSuccessIncrement,
min: 0.1,
max: 2.0,
divisions: 19,
label: settingsService.settings.routeWeightSuccessIncrement
.toStringAsFixed(1),
onChanged: (value) => persistSetting(
context,
() => settingsService.setRouteWeightSuccessIncrement(value),
),
],
),
),
],
),
const Divider(height: 1),
ListTile(
title: Text(context.l10n.appSettings_routeWeightFailureDecrement),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context
.l10n
.appSettings_routeWeightFailureDecrementSubtitle,
),
Slider(
value: settingsService.settings.routeWeightFailureDecrement,
min: 0.1,
max: 2.0,
divisions: 19,
label: settingsService.settings.routeWeightFailureDecrement
.toStringAsFixed(1),
onChanged: (value) => persistSetting(
context,
() =>
settingsService.setRouteWeightFailureDecrement(value),
),
),
const Divider(height: 1),
ListTile(
title: Text(context.l10n.appSettings_routeWeightFailureDecrement),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context.l10n.appSettings_routeWeightFailureDecrementSubtitle,
),
Slider(
value: settingsService.settings.routeWeightFailureDecrement,
min: 0.1,
max: 2.0,
divisions: 19,
label: settingsService.settings.routeWeightFailureDecrement
.toStringAsFixed(1),
onChanged: (value) => persistSetting(
context,
() => settingsService.setRouteWeightFailureDecrement(value),
),
],
),
),
],
),
const Divider(height: 1),
ListTile(
title: Text(context.l10n.appSettings_maxMessageRetries),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(context.l10n.appSettings_maxMessageRetriesSubtitle),
Slider(
value: settingsService.settings.maxMessageRetries
.toDouble(),
min: 2,
max: 10,
divisions: 8,
label: settingsService.settings.maxMessageRetries
.toString(),
onChanged: (value) => persistSetting(
context,
() => settingsService.setMaxMessageRetries(value.toInt()),
),
),
const Divider(height: 1),
ListTile(
title: Text(context.l10n.appSettings_maxMessageRetries),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(context.l10n.appSettings_maxMessageRetriesSubtitle),
Slider(
value: settingsService.settings.maxMessageRetries.toDouble(),
min: 2,
max: 10,
divisions: 8,
label: settingsService.settings.maxMessageRetries.toString(),
onChanged: (value) => persistSetting(
context,
() => settingsService.setMaxMessageRetries(value.toInt()),
),
],
),
),
],
),
],
),
],
),
);

@ -125,10 +125,6 @@ class AppSettingsService extends ChangeNotifier {
.join(' ');
}
Future<void> setClearPathOnMaxRetry(bool value) async {
await updateSettings(_settings.copyWith(clearPathOnMaxRetry: value));
}
Future<void> setMapShowRepeaters(bool value) async {
await updateSettings(_settings.copyWith(mapShowRepeaters: value));
}
@ -209,10 +205,6 @@ class AppSettingsService extends ChangeNotifier {
await updateSettings(_settings.copyWith(notifyOnNewAdvert: value));
}
Future<void> setAutoRouteRotationEnabled(bool value) async {
await updateSettings(_settings.copyWith(autoRouteRotationEnabled: value));
}
Future<void> setMaxRouteWeight(double value) async {
await updateSettings(_settings.copyWith(maxRouteWeight: value));
}

@ -218,15 +218,37 @@ class MessageRetryService extends ChangeNotifier {
_sendNextForContact(contactKey);
}
static const PathSelection _floodSelection = PathSelection(
pathBytes: [],
hopCount: -1,
useFlood: true,
);
/// The path for this attempt, or null to let the contact's own resolution
/// stand.
///
/// The final attempt always floods. Clearing the stored path and flooding is
/// the only recovery the wire protocol offers, because there is no per-send
/// routing field: the radio routes a DM direct whenever it holds a path, and
/// flood is how the mesh teaches it a new one. That makes the fallback part
/// of sending a DM rather than a preference, so it is no longer behind
/// `autoRouteRotationEnabled` (R1), and a path override no longer suppresses
/// it (R4). An override still picks the route for every earlier attempt.
/// (#1198/#1223)
PathSelection? _selectPathForAttempt(Message message, Contact contact) {
final config = _config;
if (config == null) return null;
final autoRotationEnabled =
config.appSettingsService?.settings.autoRouteRotationEnabled == true;
if (!autoRotationEnabled ||
contact.pathOverride != null ||
config.selectRetryPath == null) {
return null;
final bool isFinalAttempt =
maxRetries <= 0 || message.retryCount >= maxRetries - 1;
// A zero-hop override is the retired "Direct" mode and is not an override
// any more (#1223 R2), so it must not suppress path rotation either.
final bool hasOverride =
contact.pathOverride != null && contact.pathOverride != 0;
if (hasOverride || config.selectRetryPath == null) {
return isFinalAttempt ? _floodSelection : null;
}
final recentSelections = List<PathSelection>.from(
@ -280,27 +302,28 @@ class MessageRetryService extends ChangeNotifier {
// Re-read after potential schedule update
final effectiveMessage = _pendingMessages[messageId] ?? message;
// Sync path settings with device before sending
if (config.setContactPath != null && config.clearContactPath != null) {
// The radio owns the path. It learns one from a path-return and persists
// it (firmware BaseChatMesh::onContactPathRecv, DataStore writes out_path),
// so the client has no business writing a path back to it on a retry. The
// path this send was created with is a snapshot: re-asserting it before
// every attempt overwrote whatever the radio had, including a fresher
// route it had just learned, and guaranteed the clear below never ran.
//
// A user's path override is still pushed to the radio, but at the moment
// they choose it: `setPathOverride()` calls `setContactPath()` itself.
// Re-sending it on every attempt added nothing.
//
// Clearing is kept: it is a per-send routing decision the radio cannot
// make for us, because the wire protocol has no per-send routing field.
// Clearing a dead path is how the mesh re-learns one. (#1198/#1223)
if (config.clearContactPath != null) {
final bool useFlood = currentSelection != null
? currentSelection.useFlood
: (effectiveMessage.pathLength != null &&
effectiveMessage.pathLength! < 0);
final List<int> pathBytes = currentSelection != null
? currentSelection.pathBytes
: effectiveMessage.pathBytes;
final int hopCount = currentSelection != null
? currentSelection.hopCount
: (effectiveMessage.pathLength ?? 0);
if (useFlood) {
await config.clearContactPath!(contact);
} else if (effectiveMessage.pathLength != null) {
await config.setContactPath!(
contact,
Uint8List.fromList(pathBytes),
hopCount,
);
}
}
@ -675,11 +698,11 @@ class MessageRetryService extends ChangeNotifier {
final failedMessage = message.copyWith(status: MessageStatus.failed);
_pendingMessages[messageId] = failedMessage;
if (config?.appSettingsService?.settings.clearPathOnMaxRetry == true &&
config?.clearContactPath != null) {
config!.clearContactPath!(contact);
}
// No path clear here. The final attempt itself floods, which already
// cleared the stored path and gave the mesh its chance to teach the radio
// a new one. Clearing again after the fact could only ever have helped
// the NEXT message, which is why `clearPathOnMaxRetry` is retired (R3).
// (#1223)
_recordPathResultFromMessage(
contact.publicKeyHex,
message,

@ -90,7 +90,10 @@ class ContactDiscoveryStore {
path: json['path'] != null
? Uint8List.fromList(base64Decode(json['path'] as String))
: Uint8List(0),
pathOverride: json['pathOverride'] as int?,
// See contact_store: a stored zero-hop override reads as Auto (#1223 R2).
pathOverride: (json['pathOverride'] as int?) == 0
? null
: json['pathOverride'] as int?,
pathOverrideBytes: json['pathOverrideBytes'] != null
? Uint8List.fromList(
base64Decode(json['pathOverrideBytes'] as String),

@ -170,7 +170,12 @@ class ContactStore {
path: (!isLegacyPathRecord && json['path'] != null)
? Uint8List.fromList(base64Decode(json['path'] as String))
: Uint8List(0),
pathOverride: json['pathOverride'] as int?,
// A stored zero-hop override is the retired "Direct" mode and reads as
// Auto now, so nobody is stranded in a mode the UI no longer offers.
// Rewritten on the next save. (#1223 R2)
pathOverride: (json['pathOverride'] as int?) == 0
? null
: json['pathOverride'] as int?,
pathOverrideBytes: json['pathOverrideBytes'] != null
? Uint8List.fromList(
base64Decode(json['pathOverrideBytes'] as String),

@ -57,8 +57,22 @@ void main() {
expect(_contact(pathOverride: -1).pathLabel(l10n), 'Flood (forced)');
});
test('override == 0 -> direct (forced)', () {
expect(_contact(pathOverride: 0).pathLabel(l10n), 'Direct (forced)');
// "Direct" is gone (#1223 R2). A stored zero-hop override is no longer an
// override, so the label must describe the radio's own path instead of
// claiming a forced route that nothing enforces.
test('override == 0 is not an override, it describes the device path', () {
expect(
_contact(pathLength: 0, pathOverride: 0).pathLabel(l10n),
'Direct',
);
expect(
_contact(pathLength: 3, pathOverride: 0).pathLabel(l10n),
'3 hops',
);
expect(
_contact(pathLength: -1, pathOverride: 0).pathLabel(l10n),
'Flood',
);
});
test('override > 0 -> hops (forced)', () {

@ -59,6 +59,8 @@ Contact _makeContact({
required Uint8List publicKey,
int pathLength = -1,
List<int> path = const [],
int? pathOverride,
List<int>? pathOverrideBytes,
}) {
return Contact(
publicKey: publicKey,
@ -66,6 +68,10 @@ Contact _makeContact({
type: 1,
pathLength: pathLength,
path: Uint8List.fromList(path),
pathOverride: pathOverride,
pathOverrideBytes: pathOverrideBytes == null
? null
: Uint8List.fromList(pathOverrideBytes),
lastSeen: DateTime.now(),
);
}
@ -943,4 +949,270 @@ void main() {
},
);
});
group('the client does not write the radio\'s path on a send (#1198)', () {
// The radio owns the path: it learns one from a path-return and persists
// it. Re-asserting a client-side snapshot before every attempt overwrote
// that, including a fresher route the radio had just learned.
test('a send down a stored path issues no setContactPath at all', () async {
final retryService = MessageRetryService();
final contact = _makeContact(
publicKey: recipientKey,
pathLength: 2,
path: const [0x10, 0x20],
);
final setCalls = <int>[];
final clearCalls = <String>[];
retryService.initialize(
RetryServiceConfig(
sendMessage: (_, _, _, _) async {},
addMessage: (_, _) {},
updateMessage: (_) {},
setContactPath: (_, bytes, hops) => setCalls.add(hops),
clearContactPath: (c) => clearCalls.add(c.publicKeyHex),
),
);
await retryService.sendMessageWithRetry(contact: contact, text: 'hi');
await Future<void>.delayed(const Duration(milliseconds: 20));
expect(
setCalls,
isEmpty,
reason:
'the radio already holds this path; writing it back on a send '
'can only overwrite something fresher',
);
expect(
clearCalls,
isEmpty,
reason: 'a live stored path must not be cleared either',
);
retryService.dispose();
});
test('a flood-mode contact still clears, because that is a per-send '
'routing decision the radio cannot make for us', () async {
final retryService = MessageRetryService();
// pathLength < 0 is flood mode.
final contact = _makeContact(publicKey: recipientKey, pathLength: -1);
final setCalls = <int>[];
final clearCalls = <String>[];
retryService.initialize(
RetryServiceConfig(
sendMessage: (_, _, _, _) async {},
addMessage: (_, _) {},
updateMessage: (_) {},
setContactPath: (_, bytes, hops) => setCalls.add(hops),
clearContactPath: (c) => clearCalls.add(c.publicKeyHex),
),
);
await retryService.sendMessageWithRetry(contact: contact, text: 'hi');
await Future<void>.delayed(const Duration(milliseconds: 20));
expect(
clearCalls.length,
equals(1),
reason: 'clearing is how the mesh re-learns a route; it must survive',
);
expect(setCalls, isEmpty);
retryService.dispose();
});
});
group(
'the flood fallback is part of sending a DM, not a preference (#1223)',
() {
// R1: the fallback was gated on `autoRouteRotationEnabled`, which shipped
// false, so the one recovery the protocol offers was unreachable out of
// the box. R4: a path override suppressed it as well. Both gates are gone.
// Nothing below wires an AppSettingsService, which is the point: there is
// no longer a setting to consult.
test('the retry-path selector is consulted on a plain send, with no '
'settings service wired at all', () async {
final retryService = MessageRetryService();
final contact = _makeContact(
publicKey: recipientKey,
pathLength: 2,
path: const [0x10, 0x20],
);
final selectorCalls = <int>[];
retryService.initialize(
RetryServiceConfig(
sendMessage: (_, _, _, _) async {},
addMessage: (_, _) {},
updateMessage: (_) {},
selectRetryPath: (_, attemptIndex, _, _) {
selectorCalls.add(attemptIndex);
return null;
},
),
);
await retryService.sendMessageWithRetry(contact: contact, text: 'hi');
await Future<void>.delayed(const Duration(milliseconds: 20));
expect(
selectorCalls,
equals([0]),
reason:
'with the flag gone the selector runs on every attempt; before '
'this change a missing or default-off setting skipped it entirely',
);
retryService.dispose();
});
test(
'a zero-hop override no longer counts as an override, so it does not '
'suppress the selector either',
() async {
final retryService = MessageRetryService();
// pathOverride == 0 was "Direct". R2 retires it.
final contact = _makeContact(
publicKey: recipientKey,
pathLength: 2,
path: const [0x10, 0x20],
pathOverride: 0,
pathOverrideBytes: const [],
);
final selectorCalls = <int>[];
retryService.initialize(
RetryServiceConfig(
sendMessage: (_, _, _, _) async {},
addMessage: (_, _) {},
updateMessage: (_) {},
selectRetryPath: (_, attemptIndex, _, _) {
selectorCalls.add(attemptIndex);
return null;
},
),
);
await retryService.sendMessageWithRetry(contact: contact, text: 'hi');
await Future<void>.delayed(const Duration(milliseconds: 20));
expect(
selectorCalls,
equals([0]),
reason: 'a retired mode must not keep acting like a pinned route',
);
retryService.dispose();
},
);
test('with no path history wired, a forced-flood contact still clears, '
'and a stored-path contact on its first attempt does not', () async {
final retryService = MessageRetryService();
final clearCalls = <String>[];
final setCalls = <int>[];
// selectRetryPath is deliberately absent: the fallback must not depend
// on the path-history service existing.
retryService.initialize(
RetryServiceConfig(
sendMessage: (_, _, _, _) async {},
addMessage: (_, _) {},
updateMessage: (_) {},
setContactPath: (_, _, hops) => setCalls.add(hops),
clearContactPath: (c) => clearCalls.add(c.publicKeyHex),
),
);
await retryService.sendMessageWithRetry(
contact: _makeContact(
publicKey: recipientKey,
pathLength: 2,
path: const [0x10, 0x20],
),
text: 'stored path',
);
await Future<void>.delayed(const Duration(milliseconds: 20));
expect(
clearCalls,
isEmpty,
reason: 'a live stored path is not cleared on the first attempt',
);
await retryService.sendMessageWithRetry(
contact: _makeContact(publicKey: _makeKey(0x77), pathLength: -1),
text: 'forced flood',
);
await Future<void>.delayed(const Duration(milliseconds: 20));
expect(
clearCalls.length,
equals(1),
reason: 'clearing the stored path is the only way to request flood',
);
expect(setCalls, isEmpty);
retryService.dispose();
});
test('a manual path override floods on the final attempt instead of '
'failing on a route that is not working', () async {
final retryService = MessageRetryService()..setMaxRetries(2);
// A multi-hop route the user picked by hand in path management.
final contact = _makeContact(
publicKey: recipientKey,
pathLength: 2,
path: const [0x10, 0x20],
pathOverride: 2,
pathOverrideBytes: const [0x10, 0x20],
);
final clearCalls = <String>[];
final setCalls = <int>[];
retryService.initialize(
RetryServiceConfig(
sendMessage: (_, _, _, _) async {},
addMessage: (_, _) {},
updateMessage: (_) {},
setContactPath: (_, _, hops) => setCalls.add(hops),
clearContactPath: (c) => clearCalls.add(c.publicKeyHex),
),
);
await retryService.sendMessageWithRetry(contact: contact, text: 'hi');
await Future<void>.delayed(const Duration(milliseconds: 20));
expect(
clearCalls,
isEmpty,
reason: 'the chosen route gets the ordinary attempts, untouched',
);
// Radio confirms the send and arms a 1 ms delivery timeout, so the
// retry runs without a real ACK. maxRetries of 2 makes attempt 1 final.
retryService.updateMessageFromSent(0x1234, 1);
await Future<void>.delayed(const Duration(milliseconds: 1400));
expect(
clearCalls.length,
equals(1),
reason:
'the final attempt floods even for an override: flooding is how '
'the mesh teaches the radio a route, and a pinned path that is '
'not delivering must not be allowed to suppress it',
);
expect(
setCalls,
isEmpty,
reason: 'and it still never writes a path to the radio (#1198)',
);
retryService.dispose();
});
},
);
}

Loading…
Cancel
Save

Powered by TurnKey Linux.