display Regions in received Messages and allow reply to same region.
This commit is contained in:
1 parent
d5f54dfa11
commit
20e01145e6
9 files changed
+177
-15
No files matched your search
@@ -3572,8 +3572,10 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
String? originalText,
|
||||
String? translatedLanguageCode,
|
||||
String? translationModelId,
|
||||
String? region,
|
||||
}) async {
|
||||
if (!isConnected || text.isEmpty) return;
|
||||
final sendRegion = region ?? getChannelRegion(channel.index);
|
||||
|
||||
// Check if this is a reaction - if so, process it immediately instead of adding as a message
|
||||
final reactionInfo = ReactionHelper.parseReaction(text);
|
||||
@@ -3631,6 +3633,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
originalText: originalText,
|
||||
translatedLanguageCode: translatedLanguageCode,
|
||||
translationModelId: translationModelId,
|
||||
region: sendRegion,
|
||||
);
|
||||
_addChannelMessage(channel.index, message);
|
||||
_pendingChannelSentQueue.add(message.messageId);
|
||||
@@ -3645,7 +3648,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
expectsGenericAck: true,
|
||||
successCode: respCodeSent,
|
||||
);
|
||||
}, region: getChannelRegion(channel.index));
|
||||
}, region: sendRegion);
|
||||
}
|
||||
|
||||
/// Minimum companion firmware version code that implements
|
||||
@@ -5821,6 +5824,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
pathHashWidth: packet.pathHashWidth,
|
||||
pathBytes: packet.pathBytes,
|
||||
channelIndex: channel.index,
|
||||
region: _resolveTransportRegion(packet),
|
||||
packetHash: pktHash,
|
||||
);
|
||||
|
||||
@@ -6423,10 +6427,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
final hasTransport =
|
||||
routeType == _routeTransportFlood ||
|
||||
routeType == _routeTransportDirect;
|
||||
if (hasTransport) {
|
||||
// Skip reserved bytes in transport header made up of two u16 fields
|
||||
reader.skipBytes(4);
|
||||
}
|
||||
final transportCodes = hasTransport ? reader.readBytes(4) : null;
|
||||
final pathLenRaw = reader.readByte();
|
||||
final pathByteLen = _decodePathByteLen(pathLenRaw);
|
||||
final pathBytes = reader.readBytes(pathByteLen);
|
||||
@@ -6438,6 +6439,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
payloadType: (header >> _phTypeShift) & _phTypeMask,
|
||||
payloadVer: (header >> _phVerShift) & _phVerMask,
|
||||
pathLenRaw: pathLenRaw,
|
||||
transportCodes: transportCodes,
|
||||
pathBytes: pathBytes,
|
||||
payload: payload,
|
||||
);
|
||||
@@ -6452,6 +6454,30 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
return digest[0];
|
||||
}
|
||||
|
||||
String? _resolveTransportRegion(_RawPacket packet) {
|
||||
if (packet.routeType != _routeTransportFlood ||
|
||||
packet.transportCodes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final candidates = <String>{
|
||||
...RegionStore().loadRegions(),
|
||||
..._channelRegions.values,
|
||||
}.where((region) => region.trim().isNotEmpty).toList()..sort();
|
||||
String? match;
|
||||
for (final region in candidates) {
|
||||
final code = floodTransportCode(
|
||||
scopeKey: floodScopeKeyForRegion(region),
|
||||
payloadType: packet.payloadType,
|
||||
payload: packet.payload,
|
||||
);
|
||||
if (!_pathsEqual(code, packet.transportCodes!.sublist(0, 2))) continue;
|
||||
if (match != null) return null;
|
||||
match = region;
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
/// Firmware-compatible packet hash: SHA256(payloadType + payload) -> first 8 bytes as hex.
|
||||
String _computePacketHash(int payloadType, Uint8List payload) {
|
||||
final input = Uint8List(1 + payload.length);
|
||||
@@ -6599,6 +6625,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
pathBytes: message.pathBytes,
|
||||
pathVariants: message.pathVariants,
|
||||
channelIndex: message.channelIndex,
|
||||
region: message.region,
|
||||
messageId: message.messageId,
|
||||
replyToMessageId: originalMessage.messageId,
|
||||
replyToSenderName: originalMessage.senderName,
|
||||
@@ -6635,6 +6662,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
pathHashWidth: existing.pathHashWidth ?? processedMessage.pathHashWidth,
|
||||
pathBytes: mergedPathBytes,
|
||||
pathVariants: mergedPathVariants,
|
||||
region: existing.region ?? processedMessage.region,
|
||||
packetHash: existing.packetHash ?? processedMessage.packetHash,
|
||||
// Mark as sent when first repeat is heard
|
||||
status: promotedFromPending
|
||||
@@ -7586,6 +7614,7 @@ class _RawPacket {
|
||||
final int payloadType;
|
||||
final int payloadVer;
|
||||
final int pathLenRaw;
|
||||
final Uint8List? transportCodes;
|
||||
final Uint8List pathBytes;
|
||||
final Uint8List payload;
|
||||
|
||||
@@ -7595,6 +7624,7 @@ class _RawPacket {
|
||||
required this.payloadType,
|
||||
required this.payloadVer,
|
||||
required this.pathLenRaw,
|
||||
required this.transportCodes,
|
||||
required this.pathBytes,
|
||||
required this.payload,
|
||||
});
|
||||
|
||||
@@ -1040,9 +1040,29 @@ Uint8List buildSetFloodScopeFrame(String region) {
|
||||
return Uint8List.fromList([cmdSetFloodScope, 0]);
|
||||
}
|
||||
|
||||
final name = region.startsWith('#') ? region : '#$region';
|
||||
final hash = crypto.sha256.convert(utf8.encode(name)).bytes;
|
||||
final scope = Uint8List.fromList(hash.sublist(0, 16));
|
||||
final scope = floodScopeKeyForRegion(region);
|
||||
|
||||
return Uint8List.fromList([cmdSetFloodScope, 0, ...scope]);
|
||||
}
|
||||
|
||||
Uint8List floodScopeKeyForRegion(String region) {
|
||||
final name = region.startsWith('#') ? region : '#$region';
|
||||
final hash = crypto.sha256.convert(utf8.encode(name)).bytes;
|
||||
return Uint8List.fromList(hash.sublist(0, 16));
|
||||
}
|
||||
|
||||
Uint8List floodTransportCode({
|
||||
required Uint8List scopeKey,
|
||||
required int payloadType,
|
||||
required Uint8List payload,
|
||||
}) {
|
||||
final input = Uint8List(1 + payload.length)
|
||||
..[0] = payloadType
|
||||
..setRange(1, 1 + payload.length, payload);
|
||||
final code = crypto.Hmac(crypto.sha256, scopeKey).convert(input).bytes;
|
||||
if (code[0] == 0 && code[1] == 0) return Uint8List.fromList([1, 0]);
|
||||
if (code[0] == 0xFF && code[1] == 0xFF) {
|
||||
return Uint8List.fromList([0xFE, 0xFF]);
|
||||
}
|
||||
return Uint8List.fromList(code.sublist(0, 2));
|
||||
}
|
||||
Reference in new issue
Block a user