From 1eeb97ec518dc11a8e6180cb941d4a38ad9a0f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 11 Feb 2021 15:18:06 +0100 Subject: [PATCH] crypto: Expose the new outgoing request method --- .../internal/crypto/DefaultCryptoService.kt | 23 ++++++++++++++----- .../matrix/android/sdk/internal/newCrypto.kt | 14 +++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt index 257f1c9a05..dc321c0a88 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt @@ -22,6 +22,11 @@ import androidx.lifecycle.LiveData import androidx.paging.PagedList import com.squareup.moshi.Types import dagger.Lazy +import java.io.File +import java.util.concurrent.atomic.AtomicBoolean +import javax.inject.Inject +import kotlin.jvm.Throws +import kotlin.math.max import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.cancelChildren @@ -98,11 +103,7 @@ import org.matrix.android.sdk.internal.util.JsonCanonicalizer import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers import org.matrix.olm.OlmManager import timber.log.Timber -import java.io.File -import java.util.concurrent.atomic.AtomicBoolean -import javax.inject.Inject -import kotlin.jvm.Throws -import kotlin.math.max +import uniffi.olm.Request /** * A `CryptoService` class instance manages the end-to-end crypto for a session. @@ -363,7 +364,7 @@ internal class DefaultCryptoService @Inject constructor( } } - private fun internalStart() { + private suspend fun internalStart() { if (isStarted.get() || isStarting.get()) { return } @@ -372,7 +373,17 @@ internal class DefaultCryptoService @Inject constructor( try { olmMachine = OlmMachine(userId, deviceId!!, dataDir) + Timber.v("HELLLO WORLD STARTING CRYPTO ${olmMachine?.identityKeys()}") + + // TODO sent out those requests in a sensible place. + for (request in olmMachine!!.outgoingRequests()) { + when (request) { + is Request.KeysUpload -> Timber.v("HELLO KEYS UPLOAD REQUEST ${request.body}") + is Request.KeysQuery -> Timber.v("HELLO KEYS QUERY REQUEST ${request.body}") + is Request.ToDevice -> Timber.v("HELLO TO DEVICE REQUEST ${request.body}") + } + } } catch (throwable: Throwable) { Timber.v("HELLLO WORLD FAILED CRYPTO $throwable") } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/newCrypto.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/newCrypto.kt index 2e1308f4b6..22da46ee33 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/newCrypto.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/newCrypto.kt @@ -21,6 +21,8 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import uniffi.olm.Device as InnerDevice import uniffi.olm.OlmMachine as InnerMachine +import uniffi.olm.Request +import uniffi.olm.RequestType import uniffi.olm.Sas as InnerSas class Device(inner: InnerDevice, machine: InnerMachine) { @@ -59,6 +61,18 @@ class OlmMachine(user_id: String, device_id: String, path: File) { return this.inner.identityKeys() } + suspend fun outgoingRequests(): List = withContext(Dispatchers.IO) { + inner.outgoingRequests() + } + + suspend fun markRequestAsSent( + request_id: String, + request_type: RequestType, + response_body: String + ) = withContext(Dispatchers.IO) { + inner.markRequestAsSent(request_id, request_type, response_body) + } + suspend fun getDevice(user_id: String, device_id: String): Device? = withContext(Dispatchers.IO) { when (val device: InnerDevice? = inner.getDevice(user_id, device_id)) { null -> null