From 9b99eadcf77fca4deecc481cbc6b402e8b050a18 Mon Sep 17 00:00:00 2001 From: ericz Date: Sat, 23 May 2026 23:28:01 +0200 Subject: [PATCH 1/2] forgot the bytewise reverse of the outgoing path --- lib/screens/channel_message_path_screen.dart | 67 ++++++++++++++------ 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/lib/screens/channel_message_path_screen.dart b/lib/screens/channel_message_path_screen.dart index afd2c028..238c1802 100644 --- a/lib/screens/channel_message_path_screen.dart +++ b/lib/screens/channel_message_path_screen.dart @@ -38,24 +38,33 @@ class ChannelMessagePathScreen extends StatelessWidget { message.pathVariants, ); + final hashByteWidth = + (message.pathHashWidth ?? connector.pathHashByteWidth) + .clamp(1, 4) + .toInt(); final primaryPath = !channelMessage && !message.isOutgoing - ? Uint8List.fromList(primaryPathTmp.reversed.toList()) + ? _reversePathByHop(primaryPathTmp, hashByteWidth) : primaryPathTmp; - final hashByteWidth = (message.pathHashWidth ?? connector.pathHashByteWidth) - .clamp(1, 4) - .toInt(); - final hops = _buildPathHops(primaryPath, connector, l10n, hashByteWidth); + final hops = _buildPathHops( + primaryPath, + connector, + l10n, + hashByteWidth, + ); final hasHopDetails = primaryPath.isNotEmpty; // Convert observed path byte length to hop count using the packet width. // Legacy messages fall back to the current connector width. // Reported path length (V3+) is already stored as a hop count; preserve // the negative flood sentinel when present. - final observedHopCount = _hopCountFromBytes(primaryPath.length, hashByteWidth); + final observedHopCount = _hopCountFromBytes( + primaryPath.length, + hashByteWidth, + ); final reportedHopCount = message.pathLength; final effectiveHopCount = observedHopCount > 0 - ? observedHopCount - : reportedHopCount; + ? observedHopCount + : reportedHopCount; final observedLabel = _formatObservedHops( observedHopCount, @@ -226,7 +235,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, ), ), @@ -482,16 +491,15 @@ class _ChannelMessagePathMapScreenState primaryPath, ); - final selectedPath = - ((!widget.message.isOutgoing && !widget.channelMessage) || - (widget.message.isOutgoing && widget.channelMessage)) - ? Uint8List.fromList(selectedPathTmp.reversed.toList()) - : selectedPathTmp; - final width = (widget.message.pathHashWidth ?? connector.pathHashByteWidth) .clamp(1, 4) .toInt(); + final selectedPath = + ((!widget.message.isOutgoing && !widget.channelMessage) || + (widget.message.isOutgoing && widget.channelMessage)) + ? _reversePathByHop(selectedPathTmp, width) + : selectedPathTmp; final selectedIndex = _indexForPath(selectedPathTmp, observedPaths); final hops = _buildPathHops( selectedPath, @@ -941,7 +949,10 @@ class _PathHop { String get displayLabel { final prefixLabel = hopBytes != null && hopBytes!.isNotEmpty - ? hopBytes!.map((b) => b.toRadixString(16).padLeft(2, '0')).join('').toUpperCase() + ? hopBytes! + .map((b) => b.toRadixString(16).padLeft(2, '0')) + .join('') + .toUpperCase() : _formatPrefix(prefix); return '($prefixLabel) ${_resolveName(contact, l10n)}'; } @@ -1070,9 +1081,21 @@ String _formatPrefix(int prefix) { } String _formatPathPrefixes(Uint8List pathBytes, int hashByteWidth) { - return PathHelper.splitPathBytes(pathBytes, hashByteWidth) - .map(PathHelper.formatHopHex) - .join(','); + return PathHelper.splitPathBytes( + pathBytes, + hashByteWidth, + ).map(PathHelper.formatHopHex).join(','); +} + +Uint8List _reversePathByHop(Uint8List pathBytes, int hashByteWidth) { + final hops = PathHelper.splitPathBytes(pathBytes, hashByteWidth); + if (hops.length <= 1) return Uint8List.fromList(pathBytes); + + final reversedBytes = []; + for (final hop in hops.reversed) { + reversedBytes.addAll(hop); + } + return Uint8List.fromList(reversedBytes); } int _hopCountFromBytes(int byteCount, int hashByteWidth) { @@ -1081,7 +1104,11 @@ int _hopCountFromBytes(int byteCount, int hashByteWidth) { return (byteCount + width - 1) ~/ width; } -String _formatHopCount(int byteCount, int hashByteWidth, AppLocalizations l10n) { +String _formatHopCount( + int byteCount, + int hashByteWidth, + AppLocalizations l10n, +) { return l10n.chat_hopsCount(_hopCountFromBytes(byteCount, hashByteWidth)); } From acbe4dcc490c5fba0499c3747ce8e68fde878f10 Mon Sep 17 00:00:00 2001 From: ericz Date: Sun, 24 May 2026 10:04:44 +0200 Subject: [PATCH 2/2] remove inversal for outgoing path --- lib/screens/channel_message_path_screen.dart | 28 +++----------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/lib/screens/channel_message_path_screen.dart b/lib/screens/channel_message_path_screen.dart index 238c1802..bf3c201d 100644 --- a/lib/screens/channel_message_path_screen.dart +++ b/lib/screens/channel_message_path_screen.dart @@ -33,7 +33,7 @@ class ChannelMessagePathScreen extends StatelessWidget { return Consumer( builder: (context, connector, _) { final l10n = context.l10n; - final primaryPathTmp = _selectPrimaryPath( + final primaryPath = _selectPrimaryPath( message.pathBytes, message.pathVariants, ); @@ -42,9 +42,6 @@ class ChannelMessagePathScreen extends StatelessWidget { (message.pathHashWidth ?? connector.pathHashByteWidth) .clamp(1, 4) .toInt(); - final primaryPath = !channelMessage && !message.isOutgoing - ? _reversePathByHop(primaryPathTmp, hashByteWidth) - : primaryPathTmp; final hops = _buildPathHops( primaryPath, connector, @@ -86,8 +83,7 @@ class ChannelMessagePathScreen extends StatelessWidget { title: context.l10n.contacts_repeaterPathTrace, path: primaryPath, flipPathAround: true, - reversePathAround: - !(!channelMessage && !message.isOutgoing), + reversePathAround: false, pathHashByteWidth: hashByteWidth, ), ), @@ -485,7 +481,7 @@ class _ChannelMessagePathMapScreenState widget.message.pathVariants, ); final isDesktop = _isDesktopPlatform(defaultTargetPlatform); - final selectedPathTmp = _resolveSelectedPath( + final selectedPath = _resolveSelectedPath( _selectedPath, observedPaths, primaryPath, @@ -495,12 +491,7 @@ class _ChannelMessagePathMapScreenState (widget.message.pathHashWidth ?? connector.pathHashByteWidth) .clamp(1, 4) .toInt(); - final selectedPath = - ((!widget.message.isOutgoing && !widget.channelMessage) || - (widget.message.isOutgoing && widget.channelMessage)) - ? _reversePathByHop(selectedPathTmp, width) - : selectedPathTmp; - final selectedIndex = _indexForPath(selectedPathTmp, observedPaths); + final selectedIndex = _indexForPath(selectedPath, observedPaths); final hops = _buildPathHops( selectedPath, connector, @@ -1087,17 +1078,6 @@ String _formatPathPrefixes(Uint8List pathBytes, int hashByteWidth) { ).map(PathHelper.formatHopHex).join(','); } -Uint8List _reversePathByHop(Uint8List pathBytes, int hashByteWidth) { - final hops = PathHelper.splitPathBytes(pathBytes, hashByteWidth); - if (hops.length <= 1) return Uint8List.fromList(pathBytes); - - final reversedBytes = []; - for (final hop in hops.reversed) { - reversedBytes.addAll(hop); - } - return Uint8List.fromList(reversedBytes); -} - int _hopCountFromBytes(int byteCount, int hashByteWidth) { if (byteCount <= 0) return 0; final width = hashByteWidth.clamp(1, 4);