Skip to content

Commit

Permalink
Merge pull request #309 from ooni/engine-v3.22.0
Browse files Browse the repository at this point in the history
chore: upgrade to engine `v3.24.0`
  • Loading branch information
sdsantos authored Nov 27, 2024
2 parents 1f4fdd6 + 3e48080 commit 76324a1
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

Expand Down
36 changes: 23 additions & 13 deletions composeApp/src/commonMain/kotlin/org/ooni/engine/Engine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,32 @@ class Engine(
session(sessionConfig).submitMeasurement(measurement)
}.mapError { MkException(it) }

suspend fun checkIn(taskOrigin: TaskOrigin): Result<OonimkallBridge.CheckInResults, MkException> =
resultOf(backgroundContext) {
suspend fun checkIn(taskOrigin: TaskOrigin): Result<OonimkallBridge.CheckInResults, MkException> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion iosApp/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
50 changes: 25 additions & 25 deletions iosApp/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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:
Expand All @@ -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
97 changes: 45 additions & 52 deletions iosApp/iosApp/engine/IosOonimkallBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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..<size {

if info?.webConnectivity?.at(i) != nil {
let urlInfo: OonimkallURLInfo = (info?.webConnectivity?.at(i))!
if info.webConnectivity?.at(i) != nil {
let urlInfo: OonimkallURLInfo = (info.webConnectivity?.at(i))!
responseUrls.append(
OonimkallBridgeUrlInfo(
url: urlInfo.url,
Expand All @@ -87,9 +88,9 @@ class IosOonimkallBridge: OonimkallBridge {
)
}
}

return OonimkallBridgeCheckInResults(
reportId: info?.webConnectivity?.reportID,
reportId: info.webConnectivity?.reportID,
urls: responseUrls
)
} catch {
Expand All @@ -98,36 +99,24 @@ class IosOonimkallBridge: OonimkallBridge {
}

func httpDo(request: OonimkallBridgeHTTPRequest) throws -> 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 ?? ""
Expand All @@ -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())
}
}

Expand Down

0 comments on commit 76324a1

Please sign in to comment.