diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 871db1a..f69b165 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: check: name: Check - runs-on: macos-latest + runs-on: macos-14-large steps: - name: Check out uses: actions/checkout@v2 diff --git a/build.gradle.kts b/build.gradle.kts index 9eb0203..6e73bf0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,33 +1,34 @@ import org.jetbrains.dokka.Platform plugins { - id("com.android.library") version "7.2.2" + id("com.android.library") version "7.4.2" kotlin("multiplatform") version Versions.kotlin - id("org.jetbrains.dokka") version Versions.kotlin + id("org.jetbrains.dokka") version Versions.dokka `maven-publish` } buildscript { dependencies { - classpath("org.jetbrains.dokka:dokka-gradle-plugin:${Versions.kotlin}") + classpath("org.jetbrains.dokka:dokka-gradle-plugin:${Versions.dokka}") } } group = "fr.acinq.tor" -version = "0.2.0" +version = "0.3.0-SNAPSHOT" repositories { + maven("https://oss.sonatype.org/content/repositories/snapshots") google() mavenCentral() } android { + namespace = "fr.acinq.tor.library" compileSdk = 33 ndkVersion = Versions.ndk sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") defaultConfig { minSdk = 21 - targetSdk = 33 testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } externalNativeBuild { @@ -43,17 +44,26 @@ android { kotlin { explicitApi() - android { + androidTarget { publishLibraryVariants("release") compilations.all { kotlinOptions.jvmTarget = "1.8" } } - ios { + iosX64 { compilations["main"].cinterops.create("tor_in_thread") { + val platform = "IosX64" includeDirs.headerFilterOnly("$rootDir/native/tor_in_thread") - tasks[interopProcessingTaskName].dependsOn(":native:buildTor_in_thread${target!!.name.capitalize()}") + tasks[interopProcessingTaskName].dependsOn(":native:buildTor_in_thread${platform.capitalize()}") + } + } + + iosArm64 { + compilations["main"].cinterops.create("tor_in_thread") { + val platform = "IosArm64" + includeDirs.headerFilterOnly("$rootDir/native/tor_in_thread") + tasks[interopProcessingTaskName].dependsOn(":native:buildTor_in_thread${platform.capitalize()}") } } @@ -78,18 +88,15 @@ kotlin { implementation("fr.acinq.secp256k1:secp256k1-kmp-jni-android:${Versions.secp256k1}") } } - val androidTest by getting { + val androidUnitTest by getting { dependencies { implementation(kotlin("test-junit")) implementation("junit:junit:4.13.2") - implementation("androidx.test.ext:junit:1.1.4") - implementation("androidx.test.espresso:espresso-core:3.5.0") + implementation("androidx.test.ext:junit:1.1.5") + implementation("androidx.test.espresso:espresso-core:3.5.1") } } - val iosMain by getting - val iosTest by getting - all { languageSettings.optIn("kotlin.RequiresOptIn") } @@ -138,6 +145,7 @@ afterEvaluate { Platform.js -> "js" Platform.native -> "native" Platform.common -> "common" + Platform.wasm -> "wasm" } displayName.set(platformName) perPackageOption { diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index cd535cf..a11de5e 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -1,6 +1,7 @@ object Versions { - const val kotlin = "1.6.21" + const val kotlin = "1.9.22" + const val dokka = "1.9.10" const val ndk = "21.3.6528147" - const val ktor = "2.0.3" - const val secp256k1 = "0.7.0" + const val ktor = "2.3.7" + const val secp256k1 = "0.13.0" } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index dad6518..d32fbdd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,6 @@ kotlin.code.style=official android.useAndroidX=true kotlin.mpp.enableCInteropCommonization=true -kotlin.native.binary.memoryModel=experimental kotlin.mpp.stability.nowarn=true org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 669386b..5116c5b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionSha256Sum=f6b8596b10cce501591e92f229816aa4046424f3b24d771751b06779d58c8ec4 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/native/ios/libevent.sh b/native/ios/libevent.sh index 4a9e19f..3def3e2 100755 --- a/native/ios/libevent.sh +++ b/native/ios/libevent.sh @@ -50,7 +50,7 @@ export LDFLAGS="${HOST_FLAGS}" ./configure \ --host="${CHOST}" \ --prefix="${PREFIX}" \ - --enable-static --disable-shared \ + --enable-static --disable-shared --disable-openssl\ --enable-gcc-hardening --disable-samples \ cross_compiling="yes" ac_cv_func_clock_gettime="no" diff --git a/src/androidMain/AndroidManifest.xml b/src/androidMain/AndroidManifest.xml index 20c89a9..19d2638 100644 --- a/src/androidMain/AndroidManifest.xml +++ b/src/androidMain/AndroidManifest.xml @@ -1,4 +1,4 @@ - + diff --git a/src/androidTest/kotlin/fr/acinq/tor/TorAndroidTests.kt b/src/androidUnitTest/kotlin/fr/acinq/tor/TorAndroidTests.kt similarity index 100% rename from src/androidTest/kotlin/fr/acinq/tor/TorAndroidTests.kt rename to src/androidUnitTest/kotlin/fr/acinq/tor/TorAndroidTests.kt diff --git a/src/androidTest/kotlin/fr/acinq/tor/utilsAndroid.kt b/src/androidUnitTest/kotlin/fr/acinq/tor/utilsAndroid.kt similarity index 100% rename from src/androidTest/kotlin/fr/acinq/tor/utilsAndroid.kt rename to src/androidUnitTest/kotlin/fr/acinq/tor/utilsAndroid.kt diff --git a/src/commonTest/kotlin/fr/acinq/tor/TorTest.kt b/src/commonTest/kotlin/fr/acinq/tor/TorTest.kt index 5f44dce..2c933cd 100644 --- a/src/commonTest/kotlin/fr/acinq/tor/TorTest.kt +++ b/src/commonTest/kotlin/fr/acinq/tor/TorTest.kt @@ -3,11 +3,8 @@ package fr.acinq.tor import fr.acinq.tor.socks.socks5Handshake import io.ktor.network.selector.* import io.ktor.network.sockets.* -import io.ktor.network.tls.* import io.ktor.utils.io.* import io.ktor.utils.io.core.* -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.first @@ -15,6 +12,7 @@ import kotlinx.coroutines.runBlocking import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNull +import kotlin.test.assertTrue class TorTest { @@ -58,7 +56,8 @@ class TorTest { ) tor.start(this) - + tor.state.first { it == TorState.RUNNING } + tor.info.filterNotNull().first { it.networkLiveness == "up" } try { SelectorManager().use { selectorManager -> aSocket(selectorManager).tcp().connect(Tor.SOCKS_ADDRESS, Tor.SOCKS_PORT).use { socket -> @@ -69,7 +68,7 @@ class TorTest { connection.output.flush() val line = connection.input.readUTF8Line() - assertEquals("HTTP/1.0 200 OK", line) + assertTrue { line.equals("HTTP/1.0 200 OK") || line.equals("HTTP/1.0 302 Found") } } } } finally { diff --git a/src/iosMain/kotlin/fr/acinq/tor/torInThreadIos.kt b/src/iosMain/kotlin/fr/acinq/tor/torInThreadIos.kt index 3092e71..47fd1c3 100644 --- a/src/iosMain/kotlin/fr/acinq/tor/torInThreadIos.kt +++ b/src/iosMain/kotlin/fr/acinq/tor/torInThreadIos.kt @@ -2,15 +2,18 @@ package fr.acinq.tor import fr.acinq.tor.in_thread.tor_in_thread_get_is_running import fr.acinq.tor.in_thread.tor_in_thread_start +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.memScoped import kotlinx.cinterop.toCStringArray +@OptIn(ExperimentalForeignApi::class) internal actual fun startTorInThread(args: Array) { memScoped { tor_in_thread_start(args.size, args.toCStringArray(this)) } } +@OptIn(ExperimentalForeignApi::class) internal actual fun isTorInThreadRunning(): Boolean = tor_in_thread_get_is_running() != 0 diff --git a/src/iosMain/kotlin/fr/acinq/tor/utils/platformIos.kt b/src/iosMain/kotlin/fr/acinq/tor/utils/platformIos.kt index 9ec9299..e21606e 100644 --- a/src/iosMain/kotlin/fr/acinq/tor/utils/platformIos.kt +++ b/src/iosMain/kotlin/fr/acinq/tor/utils/platformIos.kt @@ -8,6 +8,7 @@ import platform.Foundation.* import platform.posix.* +@OptIn(ExperimentalForeignApi::class) internal actual suspend fun fileContent(path: String): ByteArray? { val file = fopen(path, "r") ?: return null fseek(file, 0.convert(), SEEK_END) @@ -23,6 +24,7 @@ internal actual suspend fun deleteFile(path: String) { remove(path) } +@OptIn(ExperimentalForeignApi::class) internal actual fun hmacSha256(key: ByteArray, message: ByteArray): ByteArray { val result = ByteArray(CC_SHA256_DIGEST_LENGTH) result.usePinned { pinnedResult ->