tracks and displays connection tentatives on relay settings

This commit is contained in:
Vitor Pamplona
2026-03-11 08:42:32 -04:00
parent ca9074e6f5
commit 71574a5ce0
4 changed files with 29 additions and 3 deletions
@@ -33,6 +33,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.res.stringResource
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.service.countToHumanReadable
import com.vitorpamplona.amethyst.service.countToHumanReadableBytes
@@ -43,6 +44,7 @@ import com.vitorpamplona.amethyst.ui.theme.HalfStartPadding
import com.vitorpamplona.amethyst.ui.theme.Size15Modifier
import com.vitorpamplona.amethyst.ui.theme.allGoodColor
import com.vitorpamplona.amethyst.ui.theme.placeholderText
import com.vitorpamplona.amethyst.ui.theme.redColorOnSecondSurface
import com.vitorpamplona.amethyst.ui.theme.warningColor
@Composable
@@ -126,18 +128,22 @@ fun RelayStatusRow(
onLongPress = {
accountViewModel.toastManager.toast(
R.string.errors,
R.string.errors_description,
R.string.connection_success_rate_description,
)
},
)
},
) {
val successRate = ((item.relayStat.connectionCompleted / item.relayStat.connectionTentatives.toFloat()) * 100).toInt()
Icon(
imageVector = Icons.Default.SyncProblem,
stringRes(R.string.errors),
modifier = Size15Modifier,
tint =
if (item.relayStat.errorCounter > 0) {
if (successRate < 0.1) {
MaterialTheme.colorScheme.redColorOnSecondSurface
} else if (successRate < 0.60) {
MaterialTheme.colorScheme.warningColor
} else {
MaterialTheme.colorScheme.allGoodColor
@@ -145,7 +151,7 @@ fun RelayStatusRow(
)
Text(
text = countToHumanReadable(item.relayStat.errorCounter, "errors"),
text = stringResource(R.string.uptime, successRate),
maxLines = 1,
fontSize = Font12SP,
modifier = HalfStartPadding,
+2
View File
@@ -137,6 +137,7 @@
<string name="bytes">Bytes</string>
<string name="error">Error</string>
<string name="errors">Errors</string>
<string name="connection_success_rate_description">Percentage of successful connections to the relay</string>
<string name="errors_description">The number of connection errors in this session</string>
<string name="home_feed">Home Feed</string>
<string name="private_message_feed">Private Message Feed</string>
@@ -1743,4 +1744,5 @@
<string name="following_accounts">Following %1$d accounts…</string>
<string name="import_follows_tips">"Enter the profile of a friend or community leader. You can use their npub, NIP-05 address, or a Namecoin name like alice@example.bit or id/alice for blockchain-verified identities."</string>
<string name="select_all">Select All</string>
<string name="uptime">%1$d% uptime</string>
</resources>
@@ -32,6 +32,8 @@ class RelayStat(
var errorCounter: Int = 0,
var pingInMs: Int = 0,
var compression: Boolean = false,
var connectionTentatives: Int = 0,
var connectionCompleted: Int = 0,
) {
val messages = LruCache<IRelayDebugMessage, IRelayDebugMessage>(100)
@@ -63,6 +65,14 @@ class RelayStat(
sentBytes += bytesUsedInMemory
}
fun newConnection() {
connectionTentatives++
}
fun connectionCompleted() {
connectionCompleted++
}
fun newSpam(
link1: String,
link2: String,
@@ -46,6 +46,13 @@ class RelayStats(
private val clientListener =
object : IRelayClientListener {
override fun onConnecting(relay: IRelayClient) {
super.onConnecting(relay)
with(get(relay.url)) {
newConnection()
}
}
override fun onConnected(
relay: IRelayClient,
pingMillis: Int,
@@ -54,6 +61,7 @@ class RelayStats(
with(get(relay.url)) {
pingInMs = pingMillis
compression = compressed
connectionCompleted()
}
}