mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-13 12:22:01 +10:00
path aware
This commit is contained in:
@@ -4274,6 +4274,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
String senderName,
|
||||
DateTime timestamp, {
|
||||
Uint8List? pathBytes,
|
||||
int? pathHashWidth,
|
||||
bool notify = false,
|
||||
}) {
|
||||
final normalized = senderName.trim().toLowerCase();
|
||||
@@ -4297,7 +4298,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
for (var i = 0; i < _contacts.length; i++) {
|
||||
final contact = _contacts[i];
|
||||
if (contact.type != advTypeChat) continue;
|
||||
if (_pathMatchesContact(pathBytes, contact.publicKey)) {
|
||||
if (_pathMatchesContact(pathBytes, contact.publicKey, pathHashWidth: pathHashWidth)) {
|
||||
matches.add(i);
|
||||
}
|
||||
}
|
||||
@@ -4314,8 +4315,8 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
bool _pathMatchesContact(Uint8List pathBytes, Uint8List publicKey) {
|
||||
final w = _pathHashByteWidth;
|
||||
bool _pathMatchesContact(Uint8List pathBytes, Uint8List publicKey, {int? pathHashWidth}) {
|
||||
final w = pathHashWidth ?? _pathHashByteWidth;
|
||||
if (pathBytes.isEmpty || publicKey.length < w) return false;
|
||||
for (int i = 0; i + w <= pathBytes.length; i += w) {
|
||||
final prefix = pathBytes.sublist(i, i + w);
|
||||
@@ -4731,6 +4732,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
message.senderName,
|
||||
message.timestamp,
|
||||
pathBytes: message.pathBytes,
|
||||
pathHashWidth: message.pathHashWidth,
|
||||
);
|
||||
final isNew = _addChannelMessage(message.channelIndex!, message);
|
||||
if (isNew && !message.isOutgoing) {
|
||||
@@ -4806,6 +4808,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
isOutgoing: false,
|
||||
status: ChannelMessageStatus.sent,
|
||||
pathLength: packet.isFlood ? packet.hopCount : 0,
|
||||
pathHashWidth: packet.pathHashWidth,
|
||||
pathBytes: packet.pathBytes,
|
||||
channelIndex: channel.index,
|
||||
packetHash: pktHash,
|
||||
@@ -4815,6 +4818,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
parsed.senderName,
|
||||
message.timestamp,
|
||||
pathBytes: message.pathBytes,
|
||||
pathHashWidth: message.pathHashWidth,
|
||||
);
|
||||
final isNew = _addChannelMessage(channel.index, message);
|
||||
if (isNew && !message.isOutgoing) {
|
||||
@@ -6358,6 +6362,7 @@ class _RawPacket {
|
||||
routeType == _routeFlood || routeType == _routeTransportFlood;
|
||||
|
||||
int get hopCount => pathLenRaw & 63;
|
||||
int get pathHashWidth => ((pathLenRaw >> 6) & 0x03) + 1;
|
||||
}
|
||||
|
||||
class _ParsedText {
|
||||
|
||||
@@ -41,6 +41,7 @@ class ChannelMessage {
|
||||
final List<Repeat> repeats;
|
||||
final int repeatCount;
|
||||
final int? pathLength;
|
||||
final int? pathHashWidth;
|
||||
final Uint8List pathBytes;
|
||||
final List<Uint8List> pathVariants;
|
||||
final int? channelIndex;
|
||||
@@ -66,6 +67,7 @@ class ChannelMessage {
|
||||
this.repeats = const [],
|
||||
this.repeatCount = 0,
|
||||
this.pathLength,
|
||||
this.pathHashWidth,
|
||||
Uint8List? pathBytes,
|
||||
List<Uint8List>? pathVariants,
|
||||
this.channelIndex,
|
||||
@@ -93,6 +95,7 @@ class ChannelMessage {
|
||||
List<Repeat>? repeats,
|
||||
int? repeatCount,
|
||||
int? pathLength,
|
||||
int? pathHashWidth,
|
||||
Uint8List? pathBytes,
|
||||
List<Uint8List>? pathVariants,
|
||||
String? packetHash,
|
||||
@@ -129,6 +132,7 @@ class ChannelMessage {
|
||||
repeats: repeats ?? this.repeats,
|
||||
repeatCount: repeatCount ?? this.repeatCount,
|
||||
pathLength: pathLength ?? this.pathLength,
|
||||
pathHashWidth: pathHashWidth ?? this.pathHashWidth,
|
||||
pathBytes: pathBytes ?? this.pathBytes,
|
||||
pathVariants: pathVariants ?? this.pathVariants,
|
||||
channelIndex: channelIndex,
|
||||
@@ -155,6 +159,7 @@ class ChannelMessage {
|
||||
|
||||
int pathLen;
|
||||
int txtType;
|
||||
int? packetPathHashWidth;
|
||||
Uint8List pathBytes = Uint8List(0);
|
||||
int channelIdx;
|
||||
if (code == respCodeChannelMsgRecvV3) {
|
||||
@@ -165,7 +170,7 @@ class ChannelMessage {
|
||||
channelIdx = reader.readByte();
|
||||
final pathByte = reader.readUInt8();
|
||||
// pathByte packs: top 2 bits = hash width mode, low 6 bits = hop count
|
||||
final packetPathHashWidth = ((pathByte & 0xC0) >> 6) + 1;
|
||||
packetPathHashWidth = ((pathByte & 0xC0) >> 6) + 1;
|
||||
final hopCount = pathByte & 0x3F;
|
||||
pathLen = hopCount;
|
||||
// If a path is present, read hopCount * width bytes
|
||||
@@ -215,6 +220,7 @@ class ChannelMessage {
|
||||
isOutgoing: false,
|
||||
status: ChannelMessageStatus.sent,
|
||||
pathLength: pathLen,
|
||||
pathHashWidth: packetPathHashWidth,
|
||||
pathBytes: pathBytes,
|
||||
channelIndex: channelIdx,
|
||||
);
|
||||
|
||||
@@ -110,6 +110,7 @@ class ChannelMessageStore {
|
||||
'channelIndex': msg.channelIndex,
|
||||
'repeatCount': msg.repeatCount,
|
||||
'pathLength': msg.pathLength,
|
||||
'pathHashWidth': msg.pathHashWidth,
|
||||
'pathBytes': base64Encode(msg.pathBytes),
|
||||
'pathVariants': msg.pathVariants.map(base64Encode).toList(),
|
||||
'repeats': msg.repeats.map(_repeatToJson).toList(),
|
||||
@@ -144,6 +145,7 @@ class ChannelMessageStore {
|
||||
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),
|
||||
|
||||
Reference in New Issue
Block a user