From ed1f11c3dccc3df99aafb600209ccd16e84db946 Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Tue, 26 Nov 2024 12:53:09 +0100 Subject: [PATCH 1/4] chore: upgrade engine to `v3.22.0` --- gradle/libs.versions.toml | 2 +- iosApp/Podfile | 2 +- iosApp/Podfile.lock | 50 +++++++++++++++++++-------------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3249c1f6..e2f4d604 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ androidx-datastore-core-okio = { group = "androidx.datastore", name = "datastore androidx-datastore-preferences-core = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "dataStoreVersion" } # Engine -android-oonimkall = { module = "org.ooni:oonimkall", version = "2024.08.08-091959" } +android-oonimkall = { module = "org.ooni:oonimkall", version = "2024.11.26-053000" } # Logging kermit = { module = "co.touchlab:kermit", version = "2.0.4" } diff --git a/iosApp/Podfile b/iosApp/Podfile index 2e032086..8e9e141c 100644 --- a/iosApp/Podfile +++ b/iosApp/Podfile @@ -2,7 +2,7 @@ platform :ios, '14.0' use_frameworks! def shared_pods - ooni_version = "v3.22.0" + ooni_version = "v3.24.0" ooni_pods_location = "https://github.com/ooni/probe-cli/releases/download/#{ooni_version}" pod 'composeApp', :path => '../composeApp' diff --git a/iosApp/Podfile.lock b/iosApp/Podfile.lock index 74e7870f..e6910a28 100644 --- a/iosApp/Podfile.lock +++ b/iosApp/Podfile.lock @@ -1,12 +1,12 @@ PODS: - composeApp (1.0): - Sentry (~> 8.38.0) - - libcrypto (2024.05.22-093305) - - libevent (2024.05.22-093305) - - libssl (2024.05.22-093305) - - libtor (2024.05.22-093305) - - libz (2024.05.22-093305) - - oonimkall (2024.05.22-093305) + - libcrypto (2024.11.26-053946) + - libevent (2024.11.26-053946) + - libssl (2024.11.26-053946) + - libtor (2024.11.26-053946) + - libz (2024.11.26-053946) + - oonimkall (2024.11.26-053946) - Sentry (8.38.0): - Sentry/Core (= 8.38.0) - Sentry/Core (8.38.0) @@ -16,12 +16,12 @@ PODS: DEPENDENCIES: - composeApp (from `../composeApp`) - - libcrypto (from `https://github.com/ooni/probe-cli/releases/download/v3.22.0/libcrypto.podspec`) - - libevent (from `https://github.com/ooni/probe-cli/releases/download/v3.22.0/libevent.podspec`) - - libssl (from `https://github.com/ooni/probe-cli/releases/download/v3.22.0/libssl.podspec`) - - libtor (from `https://github.com/ooni/probe-cli/releases/download/v3.22.0/libtor.podspec`) - - libz (from `https://github.com/ooni/probe-cli/releases/download/v3.22.0/libz.podspec`) - - oonimkall (from `https://github.com/ooni/probe-cli/releases/download/v3.22.0/oonimkall.podspec`) + - libcrypto (from `https://github.com/ooni/probe-cli/releases/download/v3.24.0/libcrypto.podspec`) + - libevent (from `https://github.com/ooni/probe-cli/releases/download/v3.24.0/libevent.podspec`) + - libssl (from `https://github.com/ooni/probe-cli/releases/download/v3.24.0/libssl.podspec`) + - libtor (from `https://github.com/ooni/probe-cli/releases/download/v3.24.0/libtor.podspec`) + - libz (from `https://github.com/ooni/probe-cli/releases/download/v3.24.0/libz.podspec`) + - oonimkall (from `https://github.com/ooni/probe-cli/releases/download/v3.24.0/oonimkall.podspec`) - sqlite3 (~> 3.42.0) SPEC REPOS: @@ -33,29 +33,29 @@ EXTERNAL SOURCES: composeApp: :path: "../composeApp" libcrypto: - :podspec: https://github.com/ooni/probe-cli/releases/download/v3.22.0/libcrypto.podspec + :podspec: https://github.com/ooni/probe-cli/releases/download/v3.24.0/libcrypto.podspec libevent: - :podspec: https://github.com/ooni/probe-cli/releases/download/v3.22.0/libevent.podspec + :podspec: https://github.com/ooni/probe-cli/releases/download/v3.24.0/libevent.podspec libssl: - :podspec: https://github.com/ooni/probe-cli/releases/download/v3.22.0/libssl.podspec + :podspec: https://github.com/ooni/probe-cli/releases/download/v3.24.0/libssl.podspec libtor: - :podspec: https://github.com/ooni/probe-cli/releases/download/v3.22.0/libtor.podspec + :podspec: https://github.com/ooni/probe-cli/releases/download/v3.24.0/libtor.podspec libz: - :podspec: https://github.com/ooni/probe-cli/releases/download/v3.22.0/libz.podspec + :podspec: https://github.com/ooni/probe-cli/releases/download/v3.24.0/libz.podspec oonimkall: - :podspec: https://github.com/ooni/probe-cli/releases/download/v3.22.0/oonimkall.podspec + :podspec: https://github.com/ooni/probe-cli/releases/download/v3.24.0/oonimkall.podspec SPEC CHECKSUMS: composeApp: 675ce506dcd05e76ecb4fdd0f73a10d4af635af1 - libcrypto: 1bb58600c586e28688f5578f4675f5ffa46c8eaf - libevent: 5c8502ca5cc38be31bb510ddade0f238bcc5f0dc - libssl: 170bebcaf567a0285e91a8850b9686137d07c3e1 - libtor: c72b23da6a5d2e16173149784f11cf66156c35be - libz: 83658eb2a0db785623ffdf9ce13407e6b8b5c8f9 - oonimkall: 9768ce9dad18265d45d2ea972c84fb0bd5237cc3 + libcrypto: 7fb50209305641e986f6b1a1e4680ec4d71602e3 + libevent: b9f2a7f3b682f7a072f4d21edf360052d3a591dc + libssl: 115acb9ff8f7d20f437ff8e112f1d21f210dad94 + libtor: efd4a639943c12a239094c2927891578cb4c7fcc + libz: 8e83c9433082438bce962f836f845d835f26b850 + oonimkall: 935a4263650a75bef0d8b487f7d349094b4c2b73 Sentry: 205813e7e758b53df157cedb8c55b31a14300645 sqlite3: f163dbbb7aa3339ad8fc622782c2d9d7b72f7e9c -PODFILE CHECKSUM: 7ccceb3a8043e0a52e0aaf77c23a4e93dbe689e7 +PODFILE CHECKSUM: 59b6c2ae5c19ca87fa0a3f359deffa5e78551529 COCOAPODS: 1.16.2 From f50313658c1a3af0e3699b476a43b163d0ce0172 Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Tue, 26 Nov 2024 12:59:50 +0100 Subject: [PATCH 2/4] call session close --- .../kotlin/org/ooni/engine/AndroidOonimkallBridge.kt | 3 +++ iosApp/iosApp/engine/IosOonimkallBridge.swift | 1 + 2 files changed, 4 insertions(+) diff --git a/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt b/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt index f568dfab..b28d86f0 100644 --- a/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt +++ b/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt @@ -38,6 +38,9 @@ class AndroidOonimkallBridge : OonimkallBridge { override fun checkIn(config: OonimkallBridge.CheckInConfig): OonimkallBridge.CheckInResults { val context = session.newContextWithTimeout(CONTEXT_TIMEOUT) val info = session.checkIn(context, config.toMk()) + runCatching { + session.close() + } return OonimkallBridge.CheckInResults( reportId = info.webConnectivity?.reportID, urls = info.webConnectivity.getUrlInfos(), diff --git a/iosApp/iosApp/engine/IosOonimkallBridge.swift b/iosApp/iosApp/engine/IosOonimkallBridge.swift index 3c101686..4f5f5455 100644 --- a/iosApp/iosApp/engine/IosOonimkallBridge.swift +++ b/iosApp/iosApp/engine/IosOonimkallBridge.swift @@ -88,6 +88,7 @@ class IosOonimkallBridge: OonimkallBridge { } } + try ses?.close() return OonimkallBridgeCheckInResults( reportId: info?.webConnectivity?.reportID, urls: responseUrls From 5e01945ae276d7cc2d81d442679970e99b04004e Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Tue, 26 Nov 2024 18:14:26 +0100 Subject: [PATCH 3/4] chore: add logger --- .../kotlin/org/ooni/engine/AndroidOonimkallBridge.kt | 2 ++ iosApp/iosApp/engine/IosOonimkallBridge.swift | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt b/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt index b28d86f0..19afcad8 100644 --- a/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt +++ b/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt @@ -40,6 +40,8 @@ class AndroidOonimkallBridge : OonimkallBridge { val info = session.checkIn(context, config.toMk()) runCatching { session.close() + }.onFailure { + co.touchlab.kermit.Logger.w(it) { "Failed to close session" } } return OonimkallBridge.CheckInResults( reportId = info.webConnectivity?.reportID, diff --git a/iosApp/iosApp/engine/IosOonimkallBridge.swift b/iosApp/iosApp/engine/IosOonimkallBridge.swift index 4f5f5455..0e4d9b1a 100644 --- a/iosApp/iosApp/engine/IosOonimkallBridge.swift +++ b/iosApp/iosApp/engine/IosOonimkallBridge.swift @@ -88,7 +88,9 @@ class IosOonimkallBridge: OonimkallBridge { } } - try ses?.close() + do { + try ses?.close() + } catch {} return OonimkallBridgeCheckInResults( reportId: info?.webConnectivity?.reportID, urls: responseUrls From 3e4808072ab66184868578145a899648b130d022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Santos?= Date: Tue, 26 Nov 2024 17:46:40 +0000 Subject: [PATCH 4/4] Delegate session close to the engine --- .../org/ooni/engine/AndroidOonimkallBridge.kt | 9 +- .../kotlin/org/ooni/engine/Engine.kt | 36 ++++--- .../kotlin/org/ooni/engine/OonimkallBridge.kt | 4 + .../org/ooni/engine/TestOonimkallBridge.kt | 2 + .../ooni/probe/domain/OrganizationSettings.kt | 2 +- iosApp/iosApp/engine/IosOonimkallBridge.swift | 100 ++++++++---------- 6 files changed, 79 insertions(+), 74 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt b/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt index 19afcad8..3bc19da3 100644 --- a/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt +++ b/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt @@ -38,11 +38,6 @@ class AndroidOonimkallBridge : OonimkallBridge { override fun checkIn(config: OonimkallBridge.CheckInConfig): OonimkallBridge.CheckInResults { val context = session.newContextWithTimeout(CONTEXT_TIMEOUT) val info = session.checkIn(context, config.toMk()) - runCatching { - session.close() - }.onFailure { - co.touchlab.kermit.Logger.w(it) { "Failed to close session" } - } return OonimkallBridge.CheckInResults( reportId = info.webConnectivity?.reportID, urls = info.webConnectivity.getUrlInfos(), @@ -54,6 +49,10 @@ class AndroidOonimkallBridge : OonimkallBridge { val response = session.httpDo(context, request.toMk()) return OonimkallBridge.HTTPResponse(body = response.body) } + + override fun close() { + session.close() + } } } diff --git a/composeApp/src/commonMain/kotlin/org/ooni/engine/Engine.kt b/composeApp/src/commonMain/kotlin/org/ooni/engine/Engine.kt index f06299af..09cf70b5 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/engine/Engine.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/engine/Engine.kt @@ -81,22 +81,32 @@ class Engine( session(sessionConfig).submitMeasurement(measurement) }.mapError { MkException(it) } - suspend fun checkIn(taskOrigin: TaskOrigin): Result = - resultOf(backgroundContext) { + suspend fun checkIn(taskOrigin: TaskOrigin): Result { + return resultOf(backgroundContext) { val preferences = getEnginePreferences() val sessionConfig = buildSessionConfig(taskOrigin, preferences) - session(sessionConfig).checkIn( - OonimkallBridge.CheckInConfig( - charging = isBatteryCharging(), - onWiFi = networkTypeFinder() == NetworkType.Wifi, - platform = platformInfo.platform.value, - runType = taskOrigin.value, - softwareName = sessionConfig.softwareName, - softwareVersion = sessionConfig.softwareVersion, - webConnectivityCategories = preferences.enabledWebCategories, - ), - ) + val session = session(sessionConfig) + try { + session.checkIn( + OonimkallBridge.CheckInConfig( + charging = isBatteryCharging(), + onWiFi = networkTypeFinder() == NetworkType.Wifi, + platform = platformInfo.platform.value, + runType = taskOrigin.value, + softwareName = sessionConfig.softwareName, + softwareVersion = sessionConfig.softwareVersion, + webConnectivityCategories = preferences.enabledWebCategories, + ), + ) + } finally { + try { + session.close() + } catch (e: Exception) { + Logger.w("Error closing session", e) + } + } }.mapError { MkException(it) } + } suspend fun httpDo( method: String, diff --git a/composeApp/src/commonMain/kotlin/org/ooni/engine/OonimkallBridge.kt b/composeApp/src/commonMain/kotlin/org/ooni/engine/OonimkallBridge.kt index 99624984..7a8e2d23 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/engine/OonimkallBridge.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/engine/OonimkallBridge.kt @@ -45,6 +45,10 @@ interface OonimkallBridge { @Throws(Exception::class) fun httpDo(request: HTTPRequest): HTTPResponse + + // Needs to be called after `checkIn` + @Throws(Exception::class) + fun close() } data class SubmitMeasurementResults( diff --git a/composeApp/src/commonTest/kotlin/org/ooni/engine/TestOonimkallBridge.kt b/composeApp/src/commonTest/kotlin/org/ooni/engine/TestOonimkallBridge.kt index 250dd1b1..dff97e4d 100644 --- a/composeApp/src/commonTest/kotlin/org/ooni/engine/TestOonimkallBridge.kt +++ b/composeApp/src/commonTest/kotlin/org/ooni/engine/TestOonimkallBridge.kt @@ -46,5 +46,7 @@ class TestOonimkallBridge : OonimkallBridge { override fun checkIn(config: OonimkallBridge.CheckInConfig): OonimkallBridge.CheckInResults = checkInMock!!(config) override fun httpDo(request: OonimkallBridge.HTTPRequest): OonimkallBridge.HTTPResponse = httpDoMock!!(request) + + override fun close() {} } } diff --git a/composeApp/src/dwMain/kotlin/org/ooni/probe/domain/OrganizationSettings.kt b/composeApp/src/dwMain/kotlin/org/ooni/probe/domain/OrganizationSettings.kt index 05538846..98fb257b 100644 --- a/composeApp/src/dwMain/kotlin/org/ooni/probe/domain/OrganizationSettings.kt +++ b/composeApp/src/dwMain/kotlin/org/ooni/probe/domain/OrganizationSettings.kt @@ -11,6 +11,6 @@ fun webConnectivityPreferences( return emptyList() } -fun preferenceDefaults(): List> { +fun preferenceDefaults(): List> { return emptyList() } diff --git a/iosApp/iosApp/engine/IosOonimkallBridge.swift b/iosApp/iosApp/engine/IosOonimkallBridge.swift index 0e4d9b1a..0b5668d8 100644 --- a/iosApp/iosApp/engine/IosOonimkallBridge.swift +++ b/iosApp/iosApp/engine/IosOonimkallBridge.swift @@ -33,51 +33,52 @@ class IosOonimkallBridge: OonimkallBridge { } func doNewSession(sessionConfig: OonimkallBridgeSessionConfig) throws -> OonimkallBridgeSession { - class IosSession: OonimkallBridgeSession { - private let sessionConfig: OonimkallSessionConfig + func error(_ message: String, code: Int = 0, domain: String = "IosOonimkallBridge", function: String = #function, file: String = #file, line: Int = #line) -> NSError { - init(sessionConfig: OonimkallSessionConfig) { - self.sessionConfig = sessionConfig - } + let functionKey = "\(domain).function" + let fileKey = "\(domain).file" + let lineKey = "\(domain).line" - func error(_ message: String, code: Int = 0, domain: String = "IosOonimkallBridge", function: String = #function, file: String = #file, line: Int = #line) -> NSError { + let error = NSError(domain: domain, code: code, userInfo: [ + message: message, + functionKey: function, + fileKey: file, + lineKey: line + ]) - let functionKey = "\(domain).function" - let fileKey = "\(domain).file" - let lineKey = "\(domain).line" + return error + } - let error = NSError(domain: domain, code: code, userInfo: [ - message: message, - functionKey: function, - fileKey: file, - lineKey: line - ]) + class IosSession: OonimkallBridgeSession { + private let session: OonimkallSession - return error + init(sessionConfig: OonimkallSessionConfig) throws { + var sessionError: NSError? + guard let session = OonimkallNewSession(sessionConfig, &sessionError) else { + throw error("Unable to create session") + } + // throw error if any + if sessionError != nil { + throw sessionError! + } + self.session = session } func checkIn(config: OonimkallBridgeCheckInConfig) throws -> OonimkallBridgeCheckInResults { - var error: NSError? - let ses = OonimkallNewSession(sessionConfig, &error) - // throw error if any - if error != nil { - throw error! - } - guard let context = ses?.newContext(withTimeout: CONTEXT_TIMEOUT) else { - throw self.error("Unable to create context") + guard let context = session.newContext(withTimeout: CONTEXT_TIMEOUT) else { + throw error("Unable to create context") } do { - let info = try ses?.check(in: context, config: config.toMk()) - - + let info = try session.check(in: context, config: config.toMk()) + var responseUrls = [OonimkallBridgeUrlInfo]() - let size = info?.webConnectivity?.size() ?? 0 + let size = info.webConnectivity?.size() ?? 0 for i in 0.. OonimkallBridgeHTTPResponse { - var error: NSError? - let ses = OonimkallNewSession(sessionConfig, &error) - // throw error if any - if error != nil { - throw error! - } - guard let context = ses?.newContext(withTimeout: CONTEXT_TIMEOUT) else { - throw self.error("Unable to create context") + guard let context = session.newContext(withTimeout: CONTEXT_TIMEOUT) else { + throw error("Unable to create context") } do { - let response = try ses?.httpDo(context, jreq: request.toMk()) - return OonimkallBridgeHTTPResponse(body: response?.body) + let response = try session.httpDo(context, jreq: request.toMk()) + return OonimkallBridgeHTTPResponse(body: response.body) } catch { throw error } } func submitMeasurement(measurement: String) throws -> OonimkallBridgeSubmitMeasurementResults { - var error: NSError? - let ses = OonimkallNewSession(sessionConfig, &error) - // throw error if any - if error != nil { - throw error! - } - guard let context = ses?.newContext(withTimeout: CONTEXT_TIMEOUT) else { - throw self.error("Unable to create context") + guard let context = session.newContext(withTimeout: CONTEXT_TIMEOUT) else { + throw error("Unable to create context") } do { - let result: OonimkallSubmitMeasurementResults? = try ses?.submit(context, measurement: measurement) + let result: OonimkallSubmitMeasurementResults? = try session.submit(context, measurement: measurement) return OonimkallBridgeSubmitMeasurementResults( updatedMeasurement: result?.updatedMeasurement, updatedReportId: result?.updatedReportID ?? "" @@ -139,9 +125,13 @@ class IosOonimkallBridge: OonimkallBridge { throw error } } + + func close() throws { + try session.close() + } } - return IosSession(sessionConfig: sessionConfig.toMk()) + return try IosSession(sessionConfig: sessionConfig.toMk()) } }