etcp: keepalive sleep-протокол на флагах (KA_FLAG_SLEEP + sleep_time, announce-retry, ack/echo)

This commit is contained in:
evgeny committed 2026-09-21 23:30:39 +03:00
1 parent 8a9d8d0097
commit 5628138d16
9 files changed
+318 -142

No files matched your search

@@ -46,6 +46,7 @@ class ConfigProvider(private val context: Context) {
private val chatStandbyActiveSec = intPreferencesKey("chat_standby_active_sec")
private val chatStandbySleepSec = intPreferencesKey("chat_standby_sleep_sec")
private val chatStandbyMinSleepSec = intPreferencesKey("chat_standby_min_sleep_sec")
private val chatStandbyKeepaliveMs = intPreferencesKey("chat_standby_keepalive_ms")
private val chatGroupAutoconnect = intPreferencesKey("chat_group_autoconnect")
private val firstLaunchDone = booleanPreferencesKey("first_launch_done")
private val connectionModeKey = stringPreferencesKey("connection_mode")
@@ -131,6 +132,7 @@ class ConfigProvider(private val context: Context) {
key == "chat.standby_active_sec" -> context.dataStore.data.first()[chatStandbyActiveSec] ?: 2
key == "chat.standby_sleep_sec" -> context.dataStore.data.first()[chatStandbySleepSec] ?: 60
key == "chat.standby_min_sleep_sec" -> context.dataStore.data.first()[chatStandbyMinSleepSec] ?: 15
key == "chat.standby_keepalive_ms" -> context.dataStore.data.first()[chatStandbyKeepaliveMs] ?: 30000
key == "chat.group_autoconnect" -> context.dataStore.data.first()[chatGroupAutoconnect] ?: 1
else -> 0
}
@@ -162,6 +164,7 @@ class ConfigProvider(private val context: Context) {
"chat.standby_active_sec" -> prefs[chatStandbyActiveSec] = value.toIntOrNull() ?: 2
"chat.standby_sleep_sec" -> prefs[chatStandbySleepSec] = value.toIntOrNull() ?: 60
"chat.standby_min_sleep_sec" -> prefs[chatStandbyMinSleepSec] = value.toIntOrNull() ?: 15
"chat.standby_keepalive_ms" -> prefs[chatStandbyKeepaliveMs] = value.toIntOrNull() ?: 30000
"chat.group_autoconnect" -> prefs[chatGroupAutoconnect] = value.toIntOrNull() ?: 1
}
}
@@ -442,6 +445,7 @@ class ConfigProvider(private val context: Context) {
appendLine("standby_active_sec=${getInt("chat.standby_active_sec")}")
appendLine("standby_sleep_sec=${getInt("chat.standby_sleep_sec")}")
appendLine("standby_min_sleep_sec=${getInt("chat.standby_min_sleep_sec")}")
appendLine("standby_keepalive_ms=${getInt("chat.standby_keepalive_ms")}")
appendLine("group_autoconnect=${getInt("chat.group_autoconnect")}")
appendLine()
appendLine("[debug]")
@@ -117,6 +117,7 @@ private fun GeneralSettingsTab(vm: ChatViewModel, dirty: Boolean, onDirty: (Bool
var standbyActiveSec by remember { mutableStateOf("2") }
var standbySleepSec by remember { mutableStateOf("60") }
var standbyMinSleepSec by remember { mutableStateOf("15") }
var standbyKeepaliveMs by remember { mutableStateOf("30000") }
val pubKey by vm.pubKey.collectAsState()
val generatingKeys by vm.generatingKeys.collectAsState()
@@ -147,6 +148,7 @@ private fun GeneralSettingsTab(vm: ChatViewModel, dirty: Boolean, onDirty: (Bool
standbyActiveSec = provider.getInt("chat.standby_active_sec").toString()
standbySleepSec = provider.getInt("chat.standby_sleep_sec").toString()
standbyMinSleepSec = provider.getInt("chat.standby_min_sleep_sec").toString()
standbyKeepaliveMs = provider.getInt("chat.standby_keepalive_ms").toString()
val port = logUdpPort.toIntOrNull() ?: 0
if (logUdpIp.isNotEmpty() && port > 0) NativeLib.setUdpLogTarget(logUdpIp, port)
val stored = provider.getString("debug.categories") ?: ""
@@ -345,6 +347,11 @@ private fun GeneralSettingsTab(vm: ChatViewModel, dirty: Boolean, onDirty: (Bool
scope.launch { provider.setValue("chat.standby_min_sleep_sec", v) }; NativeLib.setChatSetting("standby_min_sleep_sec", v) } },
label = { Text("Min sleep (sec)") }, modifier = Modifier.heightIn(min = 40.dp),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), singleLine = true)
OutlinedTextField(standbyKeepaliveMs,
{ v -> standbyKeepaliveMs = v; val nb = v.toIntOrNull(); if (nb != null && nb in 1000..600000) {
scope.launch { provider.setValue("chat.standby_keepalive_ms", v) }; NativeLib.setChatSetting("standby_keepalive_ms", v) } },
label = { Text("Keepalive in sleep (ms)") }, modifier = Modifier.heightIn(min = 40.dp),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), singleLine = true)
HorizontalDivider(Modifier.padding(vertical = 8.dp))