Skip to content

Commit

Permalink
chore: solve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorhugods committed Sep 18, 2024
1 parent 33fc71d commit e617029
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<CryptoSessionId>): Map<CryptoSessionId, ByteArray> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ 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
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
Expand Down Expand Up @@ -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 ->
Expand All @@ -107,7 +86,6 @@ internal class ProteusMessageUnpackerImpl(
)
handleMessage(appMessage)
}
>>>>>>> 987b78283d (fix(proteus): prevent missing messages by using transactions [WPB-10873] (#2992))
}
}
}.flatMap { it }
Expand All @@ -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")
}

Expand All @@ -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))
}
}
Expand All @@ -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)
Expand Down

0 comments on commit e617029

Please sign in to comment.