rollback-pr review

This commit is contained in:
PacoX
2026-05-17 17:44:30 +02:00
parent d66b16a4e8
commit 23f29f2cda
6 changed files with 60 additions and 141 deletions
+2 -7
View File
@@ -36,7 +36,6 @@ import '../widgets/translated_message_content.dart';
import '../widgets/unread_divider.dart';
import 'channel_message_path_screen.dart';
import 'map_screen.dart';
import '../helpers/path_helper.dart';
class ChannelChatScreen extends StatefulWidget {
final Channel channel;
@@ -1434,12 +1433,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
}
String _formatPathPrefixes(Uint8List pathBytes) {
final width = PathHelper.detectPathHashWidth(
pathBytes,
fallback: context.read<MeshCoreConnector>().pathHashByteWidth,
);
return PathHelper.splitPathBytes(pathBytes, width)
.map(PathHelper.formatHopHex)
return pathBytes
.map((b) => b.toRadixString(16).padLeft(2, '0').toUpperCase())
.join(',');
}
}
+13 -12
View File
@@ -45,16 +45,16 @@ class ChannelMessagePathScreen extends StatelessWidget {
final hasHopDetails = primaryPath.isNotEmpty;
// Convert path byte length to hop count based on device width
final width = primaryPath.isNotEmpty
? PathHelper.detectPathHashWidth(primaryPath, fallback: connector.pathHashByteWidth)
: connector.pathHashByteWidth.clamp(1, 4);
final width = connector.pathHashByteWidth.clamp(1, 4);
final observedHopCount = _hopCountFromBytes(primaryPath.length, width);
final reportedHopCount = message.pathLength == null
? null
: (message.pathLength! < 0
? message.pathLength
: _hopCountFromBytes(message.pathLength!, width));
final effectiveHopCount = observedHopCount > 0 ? observedHopCount : reportedHopCount;
? message.pathLength
: _hopCountFromBytes(message.pathLength!, width));
final effectiveHopCount = observedHopCount > 0
? observedHopCount
: reportedHopCount;
final observedLabel = _formatObservedHops(
observedHopCount,
@@ -76,11 +76,11 @@ class ChannelMessagePathScreen extends StatelessWidget {
title: context.l10n.contacts_repeaterPathTrace,
path: primaryPath,
flipPathAround: true,
reversePathAround: !(!channelMessage && !message.isOutgoing),
pathHashByteWidth: PathHelper.detectPathHashWidth(
primaryPath,
fallback: context.read<MeshCoreConnector>().pathHashByteWidth,
),
reversePathAround:
!(!channelMessage && !message.isOutgoing),
pathHashByteWidth: context
.read<MeshCoreConnector>()
.pathHashByteWidth,
),
),
),
@@ -951,7 +951,8 @@ List<_PathHop> _buildPathHops(
AppLocalizations l10n,
) {
if (pathBytes.isEmpty) return const [];
final width = PathHelper.detectPathHashWidth(pathBytes, fallback: connector.pathHashByteWidth);
final width = connector.pathHashByteWidth.clamp(1, 4);
final candidatesByHashBytes = <String, List<Contact>>{};
final allContacts = connector.allContacts;
+39 -43
View File
@@ -114,9 +114,8 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
Contact? _targetContact;
String _formatPathPrefixes(Uint8List pathBytes) {
final width = PathHelper.detectPathHashWidth(pathBytes, fallback: widget.pathHashByteWidth);
return PathHelper.splitPathBytes(pathBytes, width)
.map(PathHelper.formatHopHex)
return PathHelper.splitPathBytes(pathBytes, widget.pathHashByteWidth)
.map(PathHelper.formatHopHex)
.join(',');
}
@@ -215,11 +214,28 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
}
final mirroredHops = <Uint8List>[...pathHops];
// Mirror the path without duplicating the pivot hop.
if (pathHops.length > 1) {
mirroredHops.addAll(
pathHops.sublist(0, pathHops.length - 1).reversed,
);
final isRepeaterOrRoom = widget.targetContact?.type == advTypeRepeater ||
widget.targetContact?.type == advTypeRoom;
if (isRepeaterOrRoom) {
final pk = widget.targetContact?.publicKey;
if (pk != null && pk.length >= hopWidth) {
mirroredHops.add(Uint8List.fromList(pk.sublist(0, hopWidth)));
} else {
mirroredHops.add(
Uint8List.fromList(
pk != null && pk.isNotEmpty ? [pk[0]] : const [0],
),
);
}
// For repeaters/rooms, include full reversed path
mirroredHops.addAll(pathHops.reversed);
} else {
// For non-repeater/room targets, reverse without duplicating the pivot hop
if (pathHops.length > 1) {
mirroredHops.addAll(
pathHops.sublist(0, pathHops.length - 1).reversed,
);
}
}
final traceBytes = <int>[];
@@ -327,21 +343,14 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
final buffer = BufferReader(frame);
try {
buffer.skipBytes(2); // Skip push code and reserved byte
// Read the packed path byte: top2 bits = hash width mode, low6 bits = hop count
final pathByte = buffer.readUInt8();
final packetPathHashWidth = ((pathByte & 0xC0) >> 6) + 1;
final hopCount = pathByte & 0x3F;
// Skip flag byte + tag (4) + auth code (4)
buffer.skipBytes(5);
buffer.skipBytes(4);
final pathBytes = buffer.readBytes(hopCount * packetPathHashWidth);
final packetWidth = packetPathHashWidth;
int pathLength = buffer.readUInt8();
buffer.skipBytes(5); // Skip Flag byte and tag data
buffer.skipBytes(4); // Skip auth code
final pathBytes = buffer.readBytes(pathLength);
final pathData = PathHelper.splitPathBytes(
pathBytes,
packetWidth,
widget.pathHashByteWidth,
);
List<double> snrData = buffer
.readRemainingBytes()
.map((snr) => snr.toSigned(8).toDouble() / 4)
@@ -359,25 +368,15 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
lastSeen: DateTime.now(),
);
if (widget.pathContacts != null) {
final orderedContacts = widget.pathContacts!;
if (orderedContacts.length == pathData.length) {
pathContacts = {
for (var i = 0; i < pathData.length; i++)
_hopKey(pathData[i]): orderedContacts[i],
};
} else {
final hopWidth = packetWidth.clamp(1, pubKeySize);
pathContacts = {
for (var c in orderedContacts)
if (c.publicKey.length >= hopWidth)
_hopKey(Uint8List.fromList(c.publicKey.sublist(0, hopWidth))): c,
};
}
final hopWidth = widget.pathHashByteWidth.clamp(1, pubKeySize);
pathContacts = {
for (var c in widget.pathContacts!)
if (c.publicKey.length >= hopWidth)
_hopKey(Uint8List.fromList(c.publicKey.sublist(0, hopWidth))): c,
};
} else {
final contacts = connector.allContactsUnfiltered;
contacts.where((c) => c.type != advTypeChat).forEach((repeater) {
final hopWidthPreview = pathData.isNotEmpty ? pathData.first.length : packetWidth.clamp(1, pubKeySize);
if (lastContact.latitude != null &&
lastContact.longitude != null &&
repeater.hasLocation &&
@@ -387,17 +386,12 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
LatLng(repeater.latitude!, repeater.longitude!),
) >
_maxRepeaterMatchDistanceMeters) {
// skip repeaters that are far away from the last one with known GPS
// (no logging here)
return; //skip reapeaters that are far away from the last one with known GPS, to avoid false matches
}
for (final repeaterData in pathData) {
final hopWidth = repeaterData.length;
if (repeater.publicKey.length < hopWidth) continue;
if (listEquals(repeater.publicKey.sublist(0, hopWidth), repeaterData)) {
pathContacts[_hopKey(repeaterData)] = repeater;
lastContact = repeater;
}
@@ -417,7 +411,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
(c) =>
c.hasLocation &&
c.path.isNotEmpty &&
_hopKey(_lastHopChunk(c.path, packetWidth)) ==
_hopKey(_lastHopChunk(c.path, widget.pathHashByteWidth)) ==
hopKey,
)
.toList();
@@ -464,7 +458,9 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
(c) =>
c.hasLocation &&
c.path.isNotEmpty &&
_hopKey(_lastHopChunk(c.path, packetWidth)) ==
_hopKey(
_lastHopChunk(c.path, widget.pathHashByteWidth),
) ==
lastHopKey,
)
.toList();