mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-12 11:52:07 +10:00
fix tracepath
This commit is contained in:
@@ -127,6 +127,38 @@ class ChannelMessageStore {
|
||||
ChannelMessage _messageFromJson(Map<String, dynamic> json) {
|
||||
final rawText = json['text'] as String;
|
||||
final decodedText = Smaz.tryDecodePrefixed(rawText) ?? rawText;
|
||||
|
||||
final rawPathLength = json['pathLength'] as int?;
|
||||
final rawPathBytes = json['pathBytes'] != null
|
||||
? Uint8List.fromList(base64Decode(json['pathBytes'] as String))
|
||||
: Uint8List(0);
|
||||
final rawPathHashWidth = json['pathHashWidth'] as int?;
|
||||
|
||||
int? decodedPathLength = rawPathLength;
|
||||
Uint8List decodedPathBytes = rawPathBytes;
|
||||
int? decodedPathHashWidth = rawPathHashWidth;
|
||||
|
||||
if (rawPathLength != null) {
|
||||
if (rawPathLength == 0xFF || rawPathLength < 0) {
|
||||
decodedPathLength = -1;
|
||||
decodedPathBytes = Uint8List(0);
|
||||
} else if (rawPathLength >= 64) {
|
||||
final mode = (rawPathLength & 0xC0) >> 6;
|
||||
final hopCount = rawPathLength & 0x3F;
|
||||
final width = mode + 1;
|
||||
final byteLen = hopCount * width;
|
||||
decodedPathLength = hopCount;
|
||||
decodedPathHashWidth = width;
|
||||
if (byteLen <= rawPathBytes.length) {
|
||||
decodedPathBytes = rawPathBytes.sublist(0, byteLen);
|
||||
} else {
|
||||
decodedPathBytes = Uint8List(0);
|
||||
}
|
||||
} else if (rawPathLength == 0) {
|
||||
decodedPathBytes = Uint8List(0);
|
||||
}
|
||||
}
|
||||
|
||||
return ChannelMessage(
|
||||
senderKey: json['senderKey'] != null
|
||||
? Uint8List.fromList(base64Decode(json['senderKey']))
|
||||
@@ -144,11 +176,9 @@ class ChannelMessageStore {
|
||||
isOutgoing: json['isOutgoing'] as bool,
|
||||
status: ChannelMessageStatus.values[json['status'] as int],
|
||||
repeatCount: (json['repeatCount'] as int?) ?? 0,
|
||||
pathLength: json['pathLength'] as int?,
|
||||
pathHashWidth: json['pathHashWidth'] as int?,
|
||||
pathBytes: json['pathBytes'] != null
|
||||
? Uint8List.fromList(base64Decode(json['pathBytes'] as String))
|
||||
: Uint8List(0),
|
||||
pathLength: decodedPathLength,
|
||||
pathHashWidth: decodedPathHashWidth,
|
||||
pathBytes: decodedPathBytes,
|
||||
pathVariants: (json['pathVariants'] as List<dynamic>?)
|
||||
?.map((entry) => Uint8List.fromList(base64Decode(entry as String)))
|
||||
.toList(),
|
||||
|
||||
@@ -55,15 +55,40 @@ class ContactDiscoveryStore {
|
||||
final lastSeenMs = json['lastSeen'] as int? ?? 0;
|
||||
final lastMessageMs = json['lastMessageAt'] as int?;
|
||||
final lastModifiedMs = json['lastModified'] as int?;
|
||||
|
||||
final rawPathLength = json['pathLength'] as int? ?? -1;
|
||||
final rawPath = json['path'] != null
|
||||
? Uint8List.fromList(base64Decode(json['path'] as String))
|
||||
: Uint8List(0);
|
||||
|
||||
int decodedPathLength = rawPathLength;
|
||||
Uint8List decodedPath = rawPath;
|
||||
|
||||
if (rawPathLength == 0xFF || rawPathLength < 0) {
|
||||
decodedPathLength = -1;
|
||||
decodedPath = Uint8List(0);
|
||||
} else if (rawPathLength >= 64) {
|
||||
final mode = (rawPathLength & 0xC0) >> 6;
|
||||
final hopCount = rawPathLength & 0x3F;
|
||||
final width = mode + 1;
|
||||
final byteLen = hopCount * width;
|
||||
decodedPathLength = hopCount;
|
||||
if (byteLen <= rawPath.length) {
|
||||
decodedPath = rawPath.sublist(0, byteLen);
|
||||
} else {
|
||||
decodedPath = Uint8List(0);
|
||||
}
|
||||
} else if (rawPathLength == 0) {
|
||||
decodedPath = Uint8List(0);
|
||||
}
|
||||
|
||||
return Contact(
|
||||
publicKey: Uint8List.fromList(base64Decode(json['publicKey'] as String)),
|
||||
name: json['name'] as String? ?? 'Unknown',
|
||||
type: json['type'] as int? ?? 0,
|
||||
flags: json['flags'] as int? ?? 0,
|
||||
pathLength: json['pathLength'] as int? ?? -1,
|
||||
path: json['path'] != null
|
||||
? Uint8List.fromList(base64Decode(json['path'] as String))
|
||||
: Uint8List(0),
|
||||
pathLength: decodedPathLength,
|
||||
path: decodedPath,
|
||||
pathOverride: json['pathOverride'] as int?,
|
||||
pathOverrideBytes: json['pathOverrideBytes'] != null
|
||||
? Uint8List.fromList(
|
||||
|
||||
Reference in New Issue
Block a user