From 66bffec02005c6649a72721acf6ff63d58c05f4c Mon Sep 17 00:00:00 2001 From: Felix Hilgers Date: Fri, 7 Mar 2025 13:31:24 +0000 Subject: [PATCH 1/4] fix: runOnce after processSyncResponse --- .../trixnity/clientserverapi/client/SyncApiClient.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/trixnity-clientserverapi/trixnity-clientserverapi-client/src/commonMain/kotlin/net/folivo/trixnity/clientserverapi/client/SyncApiClient.kt b/trixnity-clientserverapi/trixnity-clientserverapi-client/src/commonMain/kotlin/net/folivo/trixnity/clientserverapi/client/SyncApiClient.kt index 341dce9fb..6264f0140 100644 --- a/trixnity-clientserverapi/trixnity-clientserverapi-client/src/commonMain/kotlin/net/folivo/trixnity/clientserverapi/client/SyncApiClient.kt +++ b/trixnity-clientserverapi/trixnity-clientserverapi-client/src/commonMain/kotlin/net/folivo/trixnity/clientserverapi/client/SyncApiClient.kt @@ -306,18 +306,18 @@ class SyncApiClientImpl( } log.info { "received sync response after about $measuredSyncDuration with token $batchToken" } - val result = runOnce(response) - + var result = CompletableDeferred() withTransaction { val measuredProcessDuration = measureTime { processSyncResponse(response) } log.info { "processed sync response in about $measuredProcessDuration with token $batchToken" } + result.complete(runOnce(response)) setBatchToken(response.nextBatch) } _currentSyncState.value = RUNNING - return result + return result.await() } private suspend fun processSyncResponse(response: Sync.Response) { @@ -372,4 +372,4 @@ class SyncApiClientImpl( } private suspend fun measureTime(block: suspend () -> Unit): Duration = measureTime(block).second -} \ No newline at end of file +} -- GitLab From e6084c188d5f119248e842e6824a0efc4d7dd430 Mon Sep 17 00:00:00 2001 From: Felix Hilgers Date: Mon, 10 Mar 2025 13:52:44 +0000 Subject: [PATCH 2/4] fix: too many olm inbound session --- .../net/folivo/trixnity/crypto/olm/OlmEncryptionService.kt | 7 +++++-- .../folivo/trixnity/crypto/olm/OlmEncryptionServiceTest.kt | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/trixnity-crypto/src/commonMain/kotlin/net/folivo/trixnity/crypto/olm/OlmEncryptionService.kt b/trixnity-crypto/src/commonMain/kotlin/net/folivo/trixnity/crypto/olm/OlmEncryptionService.kt index fc1e953e3..a310d84f3 100644 --- a/trixnity-crypto/src/commonMain/kotlin/net/folivo/trixnity/crypto/olm/OlmEncryptionService.kt +++ b/trixnity-crypto/src/commonMain/kotlin/net/folivo/trixnity/crypto/olm/OlmEncryptionService.kt @@ -454,8 +454,11 @@ class OlmEncryptionServiceImpl( return (storedSessions?.size ?: 0) >= 3 && storedSessions ?.sortedByDescending { it.createdAt } ?.takeLast(3) - ?.map { it.createdAt.plus(1, DateTimeUnit.HOUR) <= now } - ?.all { true } == true + ?.map { + check(it.createdAt <= now) + it.createdAt.plus(1, DateTimeUnit.HOUR) >= now + } + ?.all { it } == true } private fun hasCreatedTooManyOlmOutboundSessions(storedSessions: Set?): Boolean { diff --git a/trixnity-crypto/src/commonTest/kotlin/net/folivo/trixnity/crypto/olm/OlmEncryptionServiceTest.kt b/trixnity-crypto/src/commonTest/kotlin/net/folivo/trixnity/crypto/olm/OlmEncryptionServiceTest.kt index 83846c987..7d6d7bb5b 100644 --- a/trixnity-crypto/src/commonTest/kotlin/net/folivo/trixnity/crypto/olm/OlmEncryptionServiceTest.kt +++ b/trixnity-crypto/src/commonTest/kotlin/net/folivo/trixnity/crypto/olm/OlmEncryptionServiceTest.kt @@ -324,8 +324,8 @@ private val body: ShouldSpec.() -> Unit = { StoredOlmSession( bobCurveKey.value, pseudoSessionId.toString(), - Clock.System.now(), - Clock.System.now(), + clockMock.now(), + clockMock.now(), aliceSession.pickle("") ) } -- GitLab From fce82e9df9a17e061f28ef91fa0277bf5a47d71a Mon Sep 17 00:00:00 2001 From: Felix Hilgers Date: Mon, 10 Mar 2025 14:07:45 +0000 Subject: [PATCH 3/4] Revert "fix: runOnce after processSyncResponse" This reverts commit 66bffec02005c6649a72721acf6ff63d58c05f4c. --- .../trixnity/clientserverapi/client/SyncApiClient.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/trixnity-clientserverapi/trixnity-clientserverapi-client/src/commonMain/kotlin/net/folivo/trixnity/clientserverapi/client/SyncApiClient.kt b/trixnity-clientserverapi/trixnity-clientserverapi-client/src/commonMain/kotlin/net/folivo/trixnity/clientserverapi/client/SyncApiClient.kt index 6cbbbd583..28e315f42 100644 --- a/trixnity-clientserverapi/trixnity-clientserverapi-client/src/commonMain/kotlin/net/folivo/trixnity/clientserverapi/client/SyncApiClient.kt +++ b/trixnity-clientserverapi/trixnity-clientserverapi-client/src/commonMain/kotlin/net/folivo/trixnity/clientserverapi/client/SyncApiClient.kt @@ -306,18 +306,18 @@ class SyncApiClientImpl( } log.info { "received sync response after about $measuredSyncDuration with token $batchToken" } - var result = CompletableDeferred() + val result = runOnce(response) + withTransaction { val measuredProcessDuration = measureTime { processSyncResponse(response) } log.info { "processed sync response in about $measuredProcessDuration with token $batchToken" } - result.complete(runOnce(response)) setBatchToken(response.nextBatch) } _currentSyncState.value = RUNNING - return result.await() + return result } private suspend fun processSyncResponse(response: Sync.Response) { @@ -372,4 +372,4 @@ class SyncApiClientImpl( } private suspend fun measureTime(block: suspend () -> Unit): Duration = measureTime(block).second -} +} \ No newline at end of file -- GitLab From 5aa840944638a2682ae0da6200450ae5e4f11b3e Mon Sep 17 00:00:00 2001 From: Felix Hilgers Date: Mon, 10 Mar 2025 14:09:41 +0000 Subject: [PATCH 4/4] chore: changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 382ad00e6..3164b966c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fix check for too many olm inbound sessions + ### Security ## 4.13.2 -- GitLab