path aware fix

This commit is contained in:
PacoX
2026-05-18 08:57:13 +02:00
parent 119590434a
commit cf27c59c84
3 changed files with 159 additions and 22 deletions
+23 -19
View File
@@ -41,20 +41,23 @@ class ChannelMessagePathScreen extends StatelessWidget {
final primaryPath = !channelMessage && !message.isOutgoing
? Uint8List.fromList(primaryPathTmp.reversed.toList())
: primaryPathTmp;
final hops = _buildPathHops(primaryPath, connector, l10n);
final hashByteWidth = (message.pathHashWidth ?? connector.pathHashByteWidth)
.clamp(1, 4)
.toInt();
final hops = _buildPathHops(primaryPath, connector, l10n, hashByteWidth);
final hasHopDetails = primaryPath.isNotEmpty;
// Convert path byte length to hop count based on device width
final width = connector.pathHashByteWidth.clamp(1, 4);
final observedHopCount = _hopCountFromBytes(primaryPath.length, width);
// Convert path byte length to hop count using the packet width.
// Legacy messages fall back to the current connector width.
final observedHopCount = _hopCountFromBytes(primaryPath.length, hashByteWidth);
final reportedHopCount = message.pathLength == null
? null
: (message.pathLength! < 0
? message.pathLength
: _hopCountFromBytes(message.pathLength!, width));
? null
: (message.pathLength! < 0
? message.pathLength
: _hopCountFromBytes(message.pathLength!, hashByteWidth));
final effectiveHopCount = observedHopCount > 0
? observedHopCount
: reportedHopCount;
? observedHopCount
: reportedHopCount;
final observedLabel = _formatObservedHops(
observedHopCount,
@@ -78,9 +81,7 @@ class ChannelMessagePathScreen extends StatelessWidget {
flipPathAround: true,
reversePathAround:
!(!channelMessage && !message.isOutgoing),
pathHashByteWidth: context
.read<MeshCoreConnector>()
.pathHashByteWidth,
pathHashByteWidth: hashByteWidth,
),
),
),
@@ -113,7 +114,7 @@ class ChannelMessagePathScreen extends StatelessWidget {
style: Theme.of(context).textTheme.titleSmall,
),
const SizedBox(height: 8),
_buildPathVariants(context, extraPaths, width),
_buildPathVariants(context, extraPaths, hashByteWidth),
const SizedBox(height: 16),
],
Text(
@@ -227,7 +228,7 @@ class ChannelMessagePathScreen extends StatelessWidget {
subtitle: Text(
hop.hasLocation
? '${hop.position!.latitude.toStringAsFixed(5)}, '
'${hop.position!.longitude.toStringAsFixed(5)}'
'${hop.position!.longitude.toStringAsFixed(5)}'
: l10n.channelPath_noLocationData,
),
),
@@ -490,8 +491,10 @@ class _ChannelMessagePathMapScreenState
: selectedPathTmp;
final selectedIndex = _indexForPath(selectedPath, observedPaths);
final hops = _buildPathHops(selectedPath, connector, context.l10n);
final width = connector.pathHashByteWidth.clamp(1, 4);
final width = (widget.message.pathHashWidth ?? connector.pathHashByteWidth)
.clamp(1, 4)
.toInt();
final hops = _buildPathHops(selectedPath, connector, context.l10n, width);
final points = <LatLng>[];
@@ -647,7 +650,7 @@ class _ChannelMessagePathMapScreenState
final l10n = context.l10n;
final width = context.read<MeshCoreConnector>().pathHashByteWidth.clamp(
1,
8,
4,
);
final selectedPath = paths[selectedIndex];
final label = selectedPath.isPrimary
@@ -949,10 +952,11 @@ List<_PathHop> _buildPathHops(
Uint8List pathBytes,
MeshCoreConnector connector,
AppLocalizations l10n,
int hashByteWidth,
) {
if (pathBytes.isEmpty) return const [];
final width = connector.pathHashByteWidth.clamp(1, 4);
final width = hashByteWidth.clamp(1, 4);
final candidatesByHashBytes = <String, List<Contact>>{};
final allContacts = connector.allContacts;
+6 -3
View File
@@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:meshcore_open/helpers/path_helper.dart';
import 'package:meshcore_open/screens/path_trace_map.dart';
import 'package:meshcore_open/widgets/app_bar.dart';
import 'package:provider/provider.dart';
@@ -264,7 +265,7 @@ class _MapScreenState extends State<MapScreen> {
final anchorKeys = allContactsWithLocation
.map(
(c) =>
'${c.publicKeyHex}:${c.latitude}:${c.longitude}:${c.path.isNotEmpty ? c.path.last : ""}',
'${c.publicKeyHex}:${c.latitude}:${c.longitude}:${PathHelper.formatHopHex(c.path.isNotEmpty ? c.path.sublist(max(0, c.path.length - connector.pathHashByteWidth.clamp(1, 4))) : const [])}',
)
.join(',');
final cacheKey =
@@ -711,8 +712,7 @@ class _MapScreenState extends State<MapScreen> {
// Collect the contact-side (last-hop) repeater from every known path.
// path = [device-side hop, ..., contact-side hop]
// Only path.last is actually within radio range of the contact using
// earlier bytes would anchor against our own side of the network.
// Only the last hop chunk is actually within radio range of the contact.
final pathSets = <List<int>>[
contact.path.toList(),
...pathHistory
@@ -2398,6 +2398,9 @@ class _MapScreenState extends State<MapScreen> {
title: l10n.contacts_pathTrace,
path: Uint8List.fromList(_pathTrace),
flipPathAround: true,
pathHashByteWidth: context
.read<MeshCoreConnector>()
.pathHashByteWidth,
),
),
);