crypto: Expose the new outgoing request method

This commit is contained in:
Damir Jelić 2021-02-11 15:18:06 +01:00
parent e16c5d07e5
commit 1eeb97ec51
2 changed files with 31 additions and 6 deletions

View File

@ -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")
}

View File

@ -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<Request> = 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