From e617029edcce093eae4a797ddbf2b0b9547b1ea2 Mon Sep 17 00:00:00 2001 From: Vitor Hugo Schwaab Date: Wed, 18 Sep 2024 14:32:42 +0200 Subject: [PATCH] chore: solve conflicts --- .../ProteusClientCryptoBoxImpl.kt | 4 -- .../message/NewMessageEventHandler.kt | 38 ++------------ .../message/ProteusMessageUnpacker.kt | 51 +++++++------------ 3 files changed, 22 insertions(+), 71 deletions(-) diff --git a/cryptography/src/jvmMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt b/cryptography/src/jvmMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt index 20651728488..125f41ed96b 100644 --- a/cryptography/src/jvmMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt +++ b/cryptography/src/jvmMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt @@ -91,11 +91,7 @@ class ProteusClientCryptoBoxImpl( override suspend fun encrypt(message: ByteArray, sessionId: CryptoSessionId): ByteArray { return wrapException { box.encryptFromSession(sessionId.value, message) -<<<<<<< HEAD } ?: throw ProteusException(null, ProteusException.Code.SESSION_NOT_FOUND, ProteusException.SESSION_NOT_FOUND_INT) -======= - } ?: throw ProteusException(null, ProteusException.Code.SESSION_NOT_FOUND) ->>>>>>> 987b78283d (fix(proteus): prevent missing messages by using transactions [WPB-10873] (#2992)) } override suspend fun encryptBatched(message: ByteArray, sessionIds: List): Map { diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/NewMessageEventHandler.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/NewMessageEventHandler.kt index 9477f334c5e..c4ae6921d38 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/NewMessageEventHandler.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/NewMessageEventHandler.kt @@ -74,48 +74,15 @@ internal class NewMessageEventHandlerImpl( "protocol" to "Proteus" ) -<<<<<<< HEAD - if (it is ProteusFailure && it.proteusException.code == ProteusException.Code.DUPLICATE_MESSAGE) { - logger.i("Ignoring duplicate event: ${logMap.toJsonElement()}") - return - } - - logger.e("Failed to decrypt event: ${logMap.toJsonElement()}") - - val errorCode = if (it is ProteusFailure) it.proteusException.intCode else null - - applicationMessageHandler.handleDecryptionError( - eventId = event.id, - conversationId = event.conversationId, - messageInstant = event.messageInstant, - senderUserId = event.senderUserId, - senderClientId = event.senderClientId, - content = MessageContent.FailedDecryption( - encodedData = event.encryptedExternalContent?.data, - errorCode = errorCode, - isDecryptionResolved = false, - senderUserId = event.senderUserId, - clientId = ClientId(event.senderClientId.value) - ) - ) - eventLogger.logFailure(it, "protocol" to "Proteus") - }.onSuccess { - if (it is MessageUnpackResult.ApplicationMessage) { - processApplicationMessage(it, deliveryInfo) - } - eventLogger.logSuccess( - "protocol" to "Proteus", - "messageType" to it.messageTypeDescription, - ) -======= if (it is ProteusFailure && it.proteusException.code == ProteusException.Code.DUPLICATE_MESSAGE) { logger.i("Ignoring duplicate event: ${logMap.toJsonElement()}") return ->>>>>>> 987b78283d (fix(proteus): prevent missing messages by using transactions [WPB-10873] (#2992)) } logger.e("Failed to decrypt event: ${logMap.toJsonElement()}") + val errorCode = if (it is ProteusFailure) it.proteusException.intCode else null + applicationMessageHandler.handleDecryptionError( eventId = event.id, conversationId = event.conversationId, @@ -124,6 +91,7 @@ internal class NewMessageEventHandlerImpl( senderClientId = event.senderClientId, content = MessageContent.FailedDecryption( encodedData = event.encryptedExternalContent?.data, + errorCode = errorCode, isDecryptionResolved = false, senderUserId = event.senderUserId, clientId = ClientId(event.senderClientId.value) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/ProteusMessageUnpacker.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/ProteusMessageUnpacker.kt index 4216ca6a61a..0a7ceb43724 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/ProteusMessageUnpacker.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/ProteusMessageUnpacker.kt @@ -27,6 +27,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.logger.obfuscateId import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.ProteusFailure +import com.wire.kalium.logic.data.client.ProteusClientProvider import com.wire.kalium.logic.data.event.Event import com.wire.kalium.logic.data.id.IdMapper import com.wire.kalium.logic.data.message.PlainMessageBlob @@ -34,7 +35,6 @@ import com.wire.kalium.logic.data.message.ProtoContent import com.wire.kalium.logic.data.message.ProtoContentMapper import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.di.MapperProvider -import com.wire.kalium.logic.data.client.ProteusClientProvider import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.functional.flatMap import com.wire.kalium.logic.functional.map @@ -74,27 +74,6 @@ internal class ProteusMessageUnpackerImpl( return proteusClientProvider.getOrError() .flatMap { wrapProteusRequest { -<<<<<<< HEAD - it.decrypt(decodedContentBytes, cryptoSessionId) - } - } - .map { PlainMessageBlob(it) } - .flatMap { plainMessageBlob -> getReadableMessageContent(plainMessageBlob, event.encryptedExternalContent) } - .onFailure { - when (it) { - is CoreFailure.Unknown -> logger.e("UnknownFailure when processing message: $it", it.rootCause) - - is ProteusFailure -> { - val loggableException = - "{ \"code\": \"${it.proteusException.code.name}\", \"intCode\": \"${it.proteusException.intCode}\"," + - " \"message\": \"${it.proteusException.message}\", " + - "\"error\": \"${it.proteusException.stackTraceToString()}\"," + - "\"senderClientId\": \"${event.senderClientId.value.obfuscateId()}\"," + - "\"senderUserId\": \"${event.senderUserId.value.obfuscateId()}\"," + - "\"cryptoClientId\": \"${cryptoSessionId.cryptoClientId.value.obfuscateId()}\"," + - "\"cryptoUserId\": \"${cryptoSessionId.userId.value.obfuscateId()}\"}" - logger.e("ProteusFailure when processing message detail: $loggableException") -======= it.decrypt(decodedContentBytes, cryptoSessionId) { val plainMessageBlob = PlainMessageBlob(it) getReadableMessageContent(plainMessageBlob, event.encryptedExternalContent).map { readableContent -> @@ -107,7 +86,6 @@ internal class ProteusMessageUnpackerImpl( ) handleMessage(appMessage) } ->>>>>>> 987b78283d (fix(proteus): prevent missing messages by using transactions [WPB-10873] (#2992)) } } }.flatMap { it } @@ -123,13 +101,18 @@ internal class ProteusMessageUnpackerImpl( is CoreFailure.Unknown -> logger.e("UnknownFailure when processing message: $it", it.rootCause) is ProteusFailure -> { - val loggableException = - "{ \"code\": \"${it.proteusException.code.name}\", \"message\": \"${it.proteusException.message}\", " + - "\"error\": \"${it.proteusException.stackTraceToString()}\"," + - "\"senderClientId\": \"${event.senderClientId.value.obfuscateId()}\"," + - "\"senderUserId\": \"${event.senderUserId.value.obfuscateId()}\"," + - "\"cryptoClientId\": \"${cryptoSessionId.cryptoClientId.value.obfuscateId()}\"," + - "\"cryptoUserId\": \"${cryptoSessionId.userId.value.obfuscateId()}\"}" + val loggableException = """ + { + "code": "${it.proteusException.code.name}", + "intCode": "${it.proteusException.intCode}", + "message": "${it.proteusException.message}", + "error": "${it.proteusException.stackTraceToString()}", + "senderClientId": "${event.senderClientId.value.obfuscateId()}", + "senderUserId": "${event.senderUserId.value.obfuscateId()}", + "cryptoClientId": "${cryptoSessionId.cryptoClientId.value.obfuscateId()}", + "cryptoUserId": "${cryptoSessionId.userId.value.obfuscateId()}" + } + """.trimIndent() logger.e("ProteusFailure when processing message detail: $loggableException") } @@ -146,7 +129,9 @@ internal class ProteusMessageUnpackerImpl( logger.d("Solving external content '$protoContent', EncryptedData='$it'") solveExternalContentForProteusMessage(protoContent, encryptedData) } ?: run { - val rootCause = IllegalArgumentException("Null external content when processing external message instructions.") + val rootCause = IllegalArgumentException( + "Null external content when processing external message instructions." + ) Either.Left(CoreFailure.Unknown(rootCause)) } } @@ -160,7 +145,9 @@ internal class ProteusMessageUnpackerImpl( PlainMessageBlob(decryptedExternalMessage) }.map(protoContentMapper::decodeFromProtobuf).flatMap { decodedProtobuf -> if (decodedProtobuf !is ProtoContent.Readable) { - val rootCause = IllegalArgumentException("матрёшка! External message can't contain another external message inside!") + val rootCause = IllegalArgumentException( + "матрёшка! External message can't contain another external message inside!" + ) Either.Left(CoreFailure.Unknown(rootCause)) } else { Either.Right(decodedProtobuf)