diff --git a/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt b/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt index f568dfab6..3bc19da32 100644 --- a/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt +++ b/composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt @@ -49,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 3e0a1638f..fd86a5af4 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/engine/Engine.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/engine/Engine.kt @@ -85,22 +85,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 99624984a..7a8e2d23d 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 250dd1b14..dff97e4dd 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/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3249c1f61..e2f4d6048 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 2e032086e..8e9e141c0 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 74e7870fc..e6910a286 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 diff --git a/iosApp/iosApp/engine/IosOonimkallBridge.swift b/iosApp/iosApp/engine/IosOonimkallBridge.swift index 3c101686c..0b5668d8c 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 ?? "" @@ -136,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()) } }