Fix timeout observations, drop the last-rx feature and evict weak paths
- Record delivery observations with the path of the attempt the ACK belongs to, and skip ambiguous ACKs, so a late direct ACK is not learned as a flood delivery. - Remove secondsSinceLastRx from the timeout model: it measured time since any companion frame, which was near zero at train and predict. - When a contact's path history is full, evict the lowest-scoring path instead of silently dropping new discoveries.
This commit is contained in:
1 parent
6bc6143c4e
commit
82dcab1d92
8 files changed
+70
-31
No files matched your search
@@ -5,12 +5,12 @@ import 'package:meshcore_open/models/contact.dart';
|
||||
import 'package:meshcore_open/models/message.dart';
|
||||
import 'package:meshcore_open/services/message_retry_service.dart';
|
||||
|
||||
Contact _contact() => Contact(
|
||||
Contact _contact({int pathLength = -1, List<int> path = const []}) => Contact(
|
||||
publicKey: Uint8List.fromList(List<int>.generate(32, (i) => 0xAA + i)),
|
||||
name: 'Test',
|
||||
type: 1,
|
||||
pathLength: -1,
|
||||
path: Uint8List(0),
|
||||
pathLength: pathLength,
|
||||
path: Uint8List.fromList(path),
|
||||
lastSeen: DateTime.now(),
|
||||
);
|
||||
|
||||
@@ -19,6 +19,7 @@ void main() {
|
||||
late Map<String, Message> latest;
|
||||
late List<({int attempt, int timestamp})> sends;
|
||||
late int timeoutMs;
|
||||
late List<({int pathLength, int tripTimeMs})> observed;
|
||||
final selfKey = Uint8List(32);
|
||||
|
||||
setUp(() {
|
||||
@@ -28,6 +29,7 @@ void main() {
|
||||
latest = {};
|
||||
sends = [];
|
||||
timeoutMs = 20;
|
||||
observed = [];
|
||||
service.initialize(
|
||||
RetryServiceConfig(
|
||||
sendMessage: (_, _, attempt, timestamp) async {
|
||||
@@ -38,6 +40,8 @@ void main() {
|
||||
getSelfPublicKey: () => selfKey,
|
||||
calculateTimeout: (_, _, {String? contactKey, int? deviceTimeoutMs}) =>
|
||||
timeoutMs,
|
||||
onDeliveryObserved: (_, pathLength, _, tripTimeMs) =>
|
||||
observed.add((pathLength: pathLength, tripTimeMs: tripTimeMs)),
|
||||
),
|
||||
);
|
||||
});
|
||||
@@ -92,4 +96,21 @@ void main() {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 1100));
|
||||
expect(sends, hasLength(1));
|
||||
});
|
||||
|
||||
test('late ACK is observed with the path of the attempt it acks', () async {
|
||||
final direct = _contact(pathLength: 2, path: [0x11, 0x22]);
|
||||
await service.sendMessageWithRetry(contact: direct, text: 'hello');
|
||||
await pumpEventQueue();
|
||||
|
||||
// Attempt 0 times out; the retry then goes out as a flood.
|
||||
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||
service.updatePendingContact(_contact());
|
||||
await Future<void>.delayed(const Duration(milliseconds: 1100));
|
||||
expect(sends.map((s) => s.attempt), [0, 1]);
|
||||
|
||||
service.handleAckReceived(ackHashFor(0), 700);
|
||||
|
||||
expect(latest.values.single.status, MessageStatus.delivered);
|
||||
expect(observed, [(pathLength: 2, tripTimeMs: 700)]);
|
||||
});
|
||||
}
|
||||
@@ -602,6 +602,33 @@ void main() {
|
||||
// Group 4: handlePathUpdated
|
||||
// -------------------------------------------------------------------------
|
||||
group('handlePathUpdated', () {
|
||||
test('full history evicts the weakest path for a new one', () async {
|
||||
final pubKey = _hex('full');
|
||||
for (int i = 0; i < 100; i++) {
|
||||
svc.handlePathUpdated(
|
||||
_makeContact(publicKeyHex: pubKey, pathLength: 2, path: [i, 0xEE]),
|
||||
);
|
||||
await _flush();
|
||||
}
|
||||
const weak = PathSelection(
|
||||
pathBytes: [7, 0xEE],
|
||||
hopCount: 2,
|
||||
useFlood: false,
|
||||
);
|
||||
svc.recordPathResult(pubKey, weak, success: false);
|
||||
svc.recordPathResult(pubKey, weak, success: false);
|
||||
|
||||
svc.handlePathUpdated(
|
||||
_makeContact(publicKeyHex: pubKey, pathLength: 2, path: [0xFF, 0xEE]),
|
||||
);
|
||||
await _flush();
|
||||
|
||||
final paths = svc.getRecentPaths(pubKey).map((p) => p.pathBytes);
|
||||
expect(paths, hasLength(100));
|
||||
expect(paths, contains(equals([0xFF, 0xEE])));
|
||||
expect(paths, isNot(contains(equals([7, 0xEE]))));
|
||||
});
|
||||
|
||||
test(
|
||||
'pathLength >= 0 with path bytes → records path using pathLength',
|
||||
() async {
|
||||
|
||||
@@ -156,7 +156,6 @@ DeliveryObservation _obs({
|
||||
contactKey: contactKey,
|
||||
pathLength: pathLength,
|
||||
messageBytes: messageBytes,
|
||||
secondsSinceLastRx: 5,
|
||||
isFlood: pathLength < 0,
|
||||
deliveryMs: deliveryMs,
|
||||
timestamp: DateTime.now(),
|
||||
|
||||
Reference in new issue
Block a user