From 8f011b7cd6d278bda67b7a00026fc965a88ecd08 Mon Sep 17 00:00:00 2001 From: Rajesh Ramsaroop Date: Tue, 21 May 2024 13:41:06 -0400 Subject: [PATCH 1/2] use peer key string --- DittoHealthMetrics/build.gradle | 28 +++++++++++++------ .../live.ditto.dittoheartbeat/Heartbeat.kt | 24 ++++------------ .../usecase/HashPeerKeyUseCase.kt | 13 --------- .../usecase/PresenceFlowUseCase.kt | 7 ++--- .../live/ditto/dittotoolsapp/HeartbeatView.kt | 5 ++-- gradle/libs.versions.toml | 2 +- 6 files changed, 33 insertions(+), 46 deletions(-) delete mode 100644 DittoPresenceDegradationReporter/src/main/java/live/ditto/presencedegradationreporter/usecase/HashPeerKeyUseCase.kt diff --git a/DittoHealthMetrics/build.gradle b/DittoHealthMetrics/build.gradle index 2cd3afa..96e678d 100644 --- a/DittoHealthMetrics/build.gradle +++ b/DittoHealthMetrics/build.gradle @@ -1,6 +1,6 @@ plugins { - alias libs.plugins.com.android.library - alias libs.plugins.org.jetbrains.kotlin.android + id "com.android.library" + id "org.jetbrains.kotlin.android" } ext.libraryGroupId = "live.ditto" @@ -11,15 +11,27 @@ apply from: "$rootProject.projectDir/gradle/deploy.gradle" apply from: "$rootProject.projectDir/gradle/android-common.gradle" android { - namespace 'live.ditto.dittohealthmetrics' + namespace "live.ditto.health" } dependencies { + androidTestImplementation libs.androidx.test.ext.junit + + implementation libs.androidx.compose.material3.material3 + implementation libs.androidx.compose.ui.ui + implementation libs.androidx.compose.ui.uiTooling + implementation libs.androidx.compose.ui.uiToolingPreview + implementation libs.androidx.navigation.navigationCompose + implementation libs.live.ditto.ditto + // Dependency constraint for ditto + constraints { + implementation(libs.live.ditto.ditto) { + version { + strictly "[4.5.0,)" + } + } + } + implementation platform(libs.androidx.compose.composeBom) - implementation libs.core.ktx - implementation libs.androidx.appcompat.appcompat - implementation libs.material testImplementation libs.junit.junit - androidTestImplementation libs.androidx.test.ext.junit - androidTestImplementation libs.espresso.core } \ No newline at end of file diff --git a/DittoHeartbeat/src/main/java/live.ditto.dittoheartbeat/Heartbeat.kt b/DittoHeartbeat/src/main/java/live.ditto.dittoheartbeat/Heartbeat.kt index 9909519..5dbf21d 100644 --- a/DittoHeartbeat/src/main/java/live.ditto.dittoheartbeat/Heartbeat.kt +++ b/DittoHeartbeat/src/main/java/live.ditto.dittoheartbeat/Heartbeat.kt @@ -1,14 +1,10 @@ package live.ditto.dittoheartbeat import android.os.Build -import android.provider.SyncStateContract.Constants import androidx.annotation.RequiresApi -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.launch import live.ditto.Ditto import live.ditto.DittoConnectionType import live.ditto.DittoPeer @@ -16,7 +12,6 @@ import live.ditto.DittoSyncSubscription import live.ditto.dittohealthmetrics.HealthMetric import live.ditto.dittohealthmetrics.HealthMetricProvider import org.joda.time.DateTime -import java.util.Base64 import java.util.concurrent.atomic.AtomicBoolean data class DittoHeartbeatConfig( @@ -48,7 +43,7 @@ lateinit var info: DittoHeartbeatInfo private fun updateHealthMetrics(config: DittoHeartbeatConfig) { val newHealthMetrics = mutableMapOf() - config.healthMetricProviders.forEach { provider -> + config.healthMetricProviders?.forEach { provider -> newHealthMetrics[provider.metricName] = provider.getCurrentState() } info.healthMetrics = newHealthMetrics @@ -78,7 +73,7 @@ fun startHeartbeat(ditto: Ditto, config: DittoHeartbeatConfig): Flow { val presenceGraph = ditto.presence.graph return presenceGraph.remotePeers } -val myCoroutineScope = CoroutineScope(Dispatchers.Main) fun addToCollection(info: DittoHeartbeatInfo, config: DittoHeartbeatConfig, ditto: Ditto) { val metaData = config.metaData ?: emptyMap() val doc = mapOf( @@ -126,7 +114,7 @@ fun getConnections(presenceSnapshotDirectlyConnectedPeers: List?, dit val connectionsMap: MutableMap = mutableMapOf() presenceSnapshotDirectlyConnectedPeers?.forEach { connection -> - val connectionsTypeMap = getConnectionTypeCount(connection = connection) + val connectionsTypeMap = getConnectionTypeCount(dittoPeer = connection) val connectionMap: Map = mapOf( "deviceName" to connection.deviceName, @@ -137,18 +125,18 @@ fun getConnections(presenceSnapshotDirectlyConnectedPeers: List?, dit "lan" to connectionsTypeMap["lan"], ) - connectionsMap[byteArrayToHash(connection.peerKey)] = connectionMap + connectionsMap[connection.peerKeyString] = connectionMap } return connectionsMap } -fun getConnectionTypeCount(connection: DittoPeer): Map { +fun getConnectionTypeCount(dittoPeer: DittoPeer): Map { var bt = 0 var p2pWifi = 0 var lan = 0 - connection.connections.forEach { connection -> + dittoPeer.connections.forEach { connection -> when (connection.connectionType) { DittoConnectionType.Bluetooth -> bt += 1 DittoConnectionType.P2PWiFi -> p2pWifi += 1 diff --git a/DittoPresenceDegradationReporter/src/main/java/live/ditto/presencedegradationreporter/usecase/HashPeerKeyUseCase.kt b/DittoPresenceDegradationReporter/src/main/java/live/ditto/presencedegradationreporter/usecase/HashPeerKeyUseCase.kt deleted file mode 100644 index 0e406c8..0000000 --- a/DittoPresenceDegradationReporter/src/main/java/live/ditto/presencedegradationreporter/usecase/HashPeerKeyUseCase.kt +++ /dev/null @@ -1,13 +0,0 @@ -package live.ditto.presencedegradationreporter.usecase - -import live.ditto.DittoPeerKey -import java.math.BigInteger -import java.security.MessageDigest - -class HashPeerKeyUseCase { - private val md5 = MessageDigest.getInstance("md5") - - operator fun invoke(peerKey: DittoPeerKey): String = BigInteger(1, md5.digest(peerKey)) - .toString(16) - .padStart(32, '0') -} \ No newline at end of file diff --git a/DittoPresenceDegradationReporter/src/main/java/live/ditto/presencedegradationreporter/usecase/PresenceFlowUseCase.kt b/DittoPresenceDegradationReporter/src/main/java/live/ditto/presencedegradationreporter/usecase/PresenceFlowUseCase.kt index 323cfcf..a140ed2 100644 --- a/DittoPresenceDegradationReporter/src/main/java/live/ditto/presencedegradationreporter/usecase/PresenceFlowUseCase.kt +++ b/DittoPresenceDegradationReporter/src/main/java/live/ditto/presencedegradationreporter/usecase/PresenceFlowUseCase.kt @@ -13,8 +13,7 @@ import live.ditto.presencedegradationreporter.model.PeerTransportInfo class PresenceFlowUseCase( - private val ditto: Ditto, - private val hashPeerKeyUseCase: HashPeerKeyUseCase = HashPeerKeyUseCase() + private val ditto: Ditto ) { operator fun invoke(bufferCapacity: Int = Channel.UNLIMITED) = callbackFlow { val observer = ditto.presence.observe { graph -> @@ -26,7 +25,7 @@ class PresenceFlowUseCase( transportInfo = localPeerTransportInfo, connected = true, lastSeen = seenAt, - key = hashPeerKeyUseCase(graph.localPeer.peerKey), + key = graph.localPeer.peerKeyString, ) val remotePeers = graph.remotePeers.map { @@ -37,7 +36,7 @@ class PresenceFlowUseCase( transportInfo = peerTransportInfo, connected = true, lastSeen = seenAt, - key = hashPeerKeyUseCase(it.peerKey), + key = it.peerKeyString, ) } diff --git a/app/src/main/java/live/ditto/dittotoolsapp/HeartbeatView.kt b/app/src/main/java/live/ditto/dittotoolsapp/HeartbeatView.kt index 89a5390..4e60655 100644 --- a/app/src/main/java/live/ditto/dittotoolsapp/HeartbeatView.kt +++ b/app/src/main/java/live/ditto/dittotoolsapp/HeartbeatView.kt @@ -29,7 +29,8 @@ fun ShowHeartbeatData(ditto: Ditto) { val config = DittoHeartbeatConfig( //id for testing only. Unique id will not persist id = UUID.randomUUID().toString(), - secondsInterval = 30 + secondsInterval = 30, + healthMetricProviders = emptyList() ) DisposableEffect(Unit) { @@ -80,7 +81,6 @@ fun HeartbeatInfoCard(heartbeatInfo: DittoHeartbeatInfo) { @Suppress("UNCHECKED_CAST") val typedConnection = connection as Map // Type cast connection to Map ConnectionInfo(connection = typedConnection) - } else { } } } @@ -95,6 +95,7 @@ fun HeartbeatHeader(heartbeatInfo: DittoHeartbeatInfo) { Text("SDK: ${heartbeatInfo.sdk}") Text("Last Updated: ${heartbeatInfo.lastUpdated}") Text("remotePeersCount: ${heartbeatInfo.presenceSnapshotDirectlyConnectedPeersCount}", color = Color.Black) + Text("Peer key: ${heartbeatInfo.peerKey}") } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5dcb770..0bac29c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,7 +9,7 @@ androidx-navigation = "2.5.3" androidx-test-ext = "1.1.5" androidx-webkit = "1.7.0" datastorePreferences = "1.0.0" -ditto = "4.5.0" +ditto = "4.7.0" live-ditto-databrowser = "0.0.5" live-ditto-exportlogs = "0.0.4" live-ditto-diskusage = "0.0.6" From 96a6988db60f89ad02f37591c1c0891c2b496054 Mon Sep 17 00:00:00 2001 From: Rajesh Ramsaroop Date: Thu, 23 May 2024 10:22:54 -0400 Subject: [PATCH 2/2] update min versions for sdk's that require 4.7.0 --- DittoHeartbeat/build.gradle | 2 +- DittoPresenceDegradationReporter/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DittoHeartbeat/build.gradle b/DittoHeartbeat/build.gradle index 1533748..f1ffc00 100644 --- a/DittoHeartbeat/build.gradle +++ b/DittoHeartbeat/build.gradle @@ -29,7 +29,7 @@ dependencies { constraints { implementation(libs.live.ditto.ditto) { version { - strictly "[4.5.0,)" + strictly "[4.7.0,)" } } } diff --git a/DittoPresenceDegradationReporter/build.gradle b/DittoPresenceDegradationReporter/build.gradle index b8a96e7..23a852f 100644 --- a/DittoPresenceDegradationReporter/build.gradle +++ b/DittoPresenceDegradationReporter/build.gradle @@ -28,7 +28,7 @@ dependencies { constraints { implementation(libs.live.ditto.ditto) { version { - strictly "[4.5.0,)" + strictly "[4.7.0,)" } } }