Refactor LoRa airtime tests and add new functionality
- Updated LoRa airtime calculations in `lora_airtime_test.dart` to reflect new reference values. - Introduced new tests for LDRO behavior and preamble symbol calculations. - Added `contact_path_width_test.dart` to validate path hash width handling in contacts. - Enhanced `model_changes_test.dart` to ensure legacy data migration works correctly. - Created `remote_node_stats_test.dart` to decode and validate remote node statistics. - Implemented `map_marker_parse_test.dart` for parsing marker text with coordinate validation. - Developed `map_tile_cache_key_test.dart` to ensure API keys are excluded from cache keys. - Added `message_retry_failure_test.dart` to test message retry service behavior on failures. - Extended `path_history_service_test.dart` to preserve learned state across path attempts. - Enhanced `received_image_store_test.dart` to handle concurrent writes and review fixes. - Implemented `repeater_command_service_test.dart` to validate command response handling. - Created `store_tolerant_parsing_test.dart` to ensure stores skip malformed records gracefully. - Cleared untranslated JSON file for localization updates.
This commit is contained in:
1 parent
d5f54dfa11
commit
d74587c167
105 files changed
+6419
-2072
No files matched your search
@@ -3,6 +3,7 @@ import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../models/message.dart';
|
||||
import '../models/path_selection.dart';
|
||||
@@ -34,7 +35,7 @@ typedef AckHashMapping = ({
|
||||
});
|
||||
|
||||
class RetryServiceConfig {
|
||||
final void Function(Contact, String, int, int) sendMessage;
|
||||
final FutureOr<void> Function(Contact, String, int, int) sendMessage;
|
||||
final void Function(String, Message) addMessage;
|
||||
final void Function(Message) updateMessage;
|
||||
final Function(Contact)? clearContactPath;
|
||||
@@ -209,21 +210,46 @@ class MessageRetryService extends ChangeNotifier {
|
||||
final messageId = queue.removeAt(0);
|
||||
if (_pendingMessages.containsKey(messageId)) {
|
||||
_activeMessages.add(messageId);
|
||||
_attemptSend(messageId).catchError((e) {
|
||||
debugPrint('_attemptSend threw for $messageId: $e');
|
||||
final msg = _pendingMessages[messageId];
|
||||
if (msg != null) {
|
||||
final failed = msg.copyWith(status: MessageStatus.failed);
|
||||
_pendingMessages[messageId] = failed;
|
||||
_config?.updateMessage(failed);
|
||||
}
|
||||
_onMessageResolved(messageId, contactKey);
|
||||
});
|
||||
_attemptSendOrFail(messageId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _attemptSendOrFail(String messageId) {
|
||||
_attemptSend(messageId).catchError((Object e) {
|
||||
debugPrint('_attemptSend threw for $messageId: $e');
|
||||
_config?.debugLogService?.warn(
|
||||
'Send failed for message $messageId: $e',
|
||||
tag: 'AckHash',
|
||||
);
|
||||
_failMessage(messageId);
|
||||
});
|
||||
}
|
||||
|
||||
/// Marks a message that could not be handed to the radio as failed and
|
||||
/// releases its in-flight slot so the contact's queue keeps moving.
|
||||
void _failMessage(String messageId) {
|
||||
final message = _pendingMessages[messageId];
|
||||
if (message == null) return;
|
||||
_timeoutTimers[messageId]?.cancel();
|
||||
if (message.status != MessageStatus.failed &&
|
||||
message.status != MessageStatus.delivered) {
|
||||
_config?.updateMessage(message.copyWith(status: MessageStatus.failed));
|
||||
}
|
||||
_cleanupMessage(messageId);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Fails every pending and queued message. Call when the radio link drops:
|
||||
/// nothing in flight can be sent or acknowledged any more.
|
||||
void failAllPending() {
|
||||
_sendQueue.clear();
|
||||
for (final messageId in _pendingMessages.keys.toList()) {
|
||||
_failMessage(messageId);
|
||||
}
|
||||
}
|
||||
|
||||
void _onMessageResolved(String messageId, String contactKey) {
|
||||
if (_resolvedMessages.contains(messageId)) return;
|
||||
_resolvedMessages.add(messageId);
|
||||
@@ -358,6 +384,9 @@ class MessageRetryService extends ChangeNotifier {
|
||||
// Compute expected ACK hash that device will return in RESP_CODE_SENT
|
||||
// IMPORTANT: Use the transformed text (with SMAZ encoding if enabled) to match device's hash
|
||||
final selfPubKey = config.getSelfPublicKey?.call();
|
||||
if (config.getSelfPublicKey != null && selfPubKey == null) {
|
||||
throw StateError('Self public key unknown; cannot track ACK');
|
||||
}
|
||||
if (selfPubKey != null) {
|
||||
final outboundText =
|
||||
config.prepareContactOutboundText?.call(contact, message.text) ??
|
||||
@@ -380,7 +409,7 @@ class MessageRetryService extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
config.sendMessage(contact, message.text, attempt, timestampSeconds);
|
||||
await config.sendMessage(contact, message.text, attempt, timestampSeconds);
|
||||
}
|
||||
|
||||
bool updateMessageFromSent(int ackHash, int timeoutMs) {
|
||||
@@ -535,7 +564,8 @@ class MessageRetryService extends ChangeNotifier {
|
||||
tag: 'AckHash',
|
||||
);
|
||||
|
||||
if (message.retryCount < maxRetries - 1) {
|
||||
if (message.retryCount < maxRetries - 1 &&
|
||||
_textFitsAttempt(message, contact, message.retryCount + 1)) {
|
||||
final backoffMs = 1000 * (1 << message.retryCount);
|
||||
|
||||
if (selection != null) {
|
||||
@@ -563,7 +593,7 @@ class MessageRetryService extends ChangeNotifier {
|
||||
|
||||
_timeoutTimers[messageId] = Timer(Duration(milliseconds: backoffMs), () {
|
||||
if (_pendingMessages.containsKey(messageId)) {
|
||||
_attemptSend(messageId);
|
||||
_attemptSendOrFail(messageId);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -598,6 +628,17 @@ class MessageRetryService extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// From attempt 4 on the firmware appends [0][attempt] to the payload and
|
||||
/// rejects text longer than MAX_TEXT_LEN - 2 (BaseChatMesh::composeMsgPacket).
|
||||
bool _textFitsAttempt(Message message, Contact contact, int attempt) {
|
||||
if (attempt <= maxFullLengthTextAttempt) return true;
|
||||
final outboundText =
|
||||
_config?.prepareContactOutboundText?.call(contact, message.text) ??
|
||||
message.text;
|
||||
return utf8.encode(outboundText).length <=
|
||||
maxTextPayloadBytesAfterFullLengthAttempts;
|
||||
}
|
||||
|
||||
void _moveAckHashesToHistory(String messageId) {
|
||||
final ackHashes = _expectedAckHashes.remove(messageId);
|
||||
if (ackHashes != null && ackHashes.isNotEmpty) {
|
||||
|
||||
Reference in new issue
Block a user