mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
Add nearestrelay fallback settings
This commit is contained in:
@@ -113,15 +113,16 @@ class PathHistoryService {
|
|||||||
await initialize();
|
await initialize();
|
||||||
await recordLearnedPath(contact);
|
await recordLearnedPath(contact);
|
||||||
|
|
||||||
|
if (contact.routeHasPath && contact.routeHopCount > 0) {
|
||||||
|
return PathSelection(
|
||||||
|
mode: PathSelectionMode.directCurrent,
|
||||||
|
pathBytes: Uint8List.fromList(contact.routePathBytes),
|
||||||
|
hopCount: contact.routeHopCount,
|
||||||
|
hashSize: contact.routeHashSize,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!autoRouteRotationEnabled) {
|
if (!autoRouteRotationEnabled) {
|
||||||
if (contact.routeHasPath && contact.routeHopCount > 0) {
|
|
||||||
return PathSelection(
|
|
||||||
mode: PathSelectionMode.directCurrent,
|
|
||||||
pathBytes: Uint8List.fromList(contact.routePathBytes),
|
|
||||||
hopCount: contact.routeHopCount,
|
|
||||||
hashSize: contact.routeHashSize,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return PathSelection.flood();
|
return PathSelection.flood();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,21 @@ Contact _buildContact({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Contact _buildContactWithoutRoute({required int seed}) {
|
||||||
|
return Contact(
|
||||||
|
publicKey: Uint8List.fromList(List<int>.generate(32, (i) => i + seed)),
|
||||||
|
type: ContactType.chat,
|
||||||
|
flags: 0,
|
||||||
|
outPathLen: -1,
|
||||||
|
outPath: Uint8List(0),
|
||||||
|
advName: 'Contact $seed',
|
||||||
|
lastAdvert: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||||
|
advLat: 0,
|
||||||
|
advLon: 0,
|
||||||
|
lastMod: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
@@ -40,12 +55,7 @@ void main() {
|
|||||||
|
|
||||||
test('auto rotation ranks best paths before flood', () async {
|
test('auto rotation ranks best paths before flood', () async {
|
||||||
final service = PathHistoryService();
|
final service = PathHistoryService();
|
||||||
final contact = _buildContact(
|
final contact = _buildContactWithoutRoute(seed: 0);
|
||||||
seed: 0,
|
|
||||||
pathBytes: [0xAA, 0xBB],
|
|
||||||
hopCount: 2,
|
|
||||||
hashSize: 1,
|
|
||||||
);
|
|
||||||
final best = PathSelection(
|
final best = PathSelection(
|
||||||
mode: PathSelectionMode.directHistorical,
|
mode: PathSelectionMode.directHistorical,
|
||||||
pathBytes: Uint8List.fromList([0xAA, 0xBB]),
|
pathBytes: Uint8List.fromList([0xAA, 0xBB]),
|
||||||
@@ -105,20 +115,43 @@ void main() {
|
|||||||
expect(secondPick.mode, PathSelectionMode.flood);
|
expect(secondPick.mode, PathSelectionMode.flood);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'current learned route is reused first even with rotation enabled',
|
||||||
|
() async {
|
||||||
|
final service = PathHistoryService();
|
||||||
|
final contact = _buildContact(
|
||||||
|
seed: 9,
|
||||||
|
pathBytes: [0xAA, 0xBB, 0xCC],
|
||||||
|
hopCount: 1,
|
||||||
|
hashSize: 3,
|
||||||
|
);
|
||||||
|
|
||||||
|
await service.initialize();
|
||||||
|
await service.recordPathResult(
|
||||||
|
contact.publicKeyHex,
|
||||||
|
PathSelection(
|
||||||
|
mode: PathSelectionMode.directHistorical,
|
||||||
|
pathBytes: Uint8List.fromList([0x11, 0x22, 0x33]),
|
||||||
|
hopCount: 1,
|
||||||
|
hashSize: 3,
|
||||||
|
),
|
||||||
|
success: true,
|
||||||
|
roundTripTimeMs: 90,
|
||||||
|
);
|
||||||
|
|
||||||
|
final selection = await service.getSelectionForContact(
|
||||||
|
contact,
|
||||||
|
autoRouteRotationEnabled: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(selection.mode, PathSelectionMode.directCurrent);
|
||||||
|
expect(selection.canonicalPath, 'AABBCC');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('no history falls back to flood', () async {
|
test('no history falls back to flood', () async {
|
||||||
final service = PathHistoryService();
|
final service = PathHistoryService();
|
||||||
final contact = Contact(
|
final contact = _buildContactWithoutRoute(seed: 0);
|
||||||
publicKey: Uint8List.fromList(List<int>.generate(32, (i) => i)),
|
|
||||||
type: ContactType.chat,
|
|
||||||
flags: 0,
|
|
||||||
outPathLen: -1,
|
|
||||||
outPath: Uint8List(0),
|
|
||||||
advName: 'No Route',
|
|
||||||
lastAdvert: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
|
||||||
advLat: 0,
|
|
||||||
advLon: 0,
|
|
||||||
lastMod: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
|
||||||
);
|
|
||||||
|
|
||||||
final selection = await service.getSelectionForContact(
|
final selection = await service.getSelectionForContact(
|
||||||
contact,
|
contact,
|
||||||
|
|||||||
Reference in New Issue
Block a user