From 3ef564ccdaa1659ff04305d76ee33756e47cd1e0 Mon Sep 17 00:00:00 2001 From: Luca Kellermann Date: Fri, 11 Oct 2024 00:49:26 +0200 Subject: [PATCH 1/4] Update Dokka to 2.0.0-Beta (#985) --- .github/workflows/docs-ci.yml | 4 +- build.gradle.kts | 11 +++++- buildSrc/src/main/kotlin/Documentation.kt | 39 +++++++++++++------ .../src/main/kotlin/kord-module.gradle.kts | 10 ++--- .../kord-multiplatform-module.gradle.kts | 19 +++++---- .../main/kotlin/kord-publishing.gradle.kts | 2 +- core/build.gradle.kts | 6 --- gradle.properties | 9 ++++- gradle/libs.versions.toml | 4 +- ksp-annotations/build.gradle.kts | 4 +- 10 files changed, 66 insertions(+), 42 deletions(-) diff --git a/.github/workflows/docs-ci.yml b/.github/workflows/docs-ci.yml index 7db9fe35624..82f8b56600d 100644 --- a/.github/workflows/docs-ci.yml +++ b/.github/workflows/docs-ci.yml @@ -27,11 +27,11 @@ jobs: - name: Set up Gradle uses: gradle/actions/setup-gradle@v4 - name: Build docs with Gradle - run: ./gradlew --stacktrace --info dokkaHtmlMultiModule + run: ./gradlew --stacktrace --info :dokkaGeneratePublicationHtml - name: Deploy docs to GitHub Pages uses: JamesIves/github-pages-deploy-action@v4 with: - folder: build/dokka/htmlMultiModule + folder: build/dokka/html branch: gh-pages git-config-name: GitHub Actions git-config-email: actions@github.com diff --git a/build.gradle.kts b/build.gradle.kts index 0ad64bff26f..52f11df7127 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - org.jetbrains.dokka // for dokkaHtmlMultiModule task + org.jetbrains.dokka // for dokkaGeneratePublicationHtml task } repositories { @@ -8,3 +8,12 @@ repositories { group = Library.group version = libraryVersion + +dependencies { + dokka(projects.common) + dokka(projects.core) + dokka(projects.coreVoice) + dokka(projects.gateway) + dokka(projects.rest) + dokka(projects.voice) +} diff --git a/buildSrc/src/main/kotlin/Documentation.kt b/buildSrc/src/main/kotlin/Documentation.kt index 4bf4b7f4922..6b3a1801d7e 100644 --- a/buildSrc/src/main/kotlin/Documentation.kt +++ b/buildSrc/src/main/kotlin/Documentation.kt @@ -1,12 +1,19 @@ +import org.gradle.api.Project import org.gradle.kotlin.dsl.assign -import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask -import java.net.URI +import org.gradle.kotlin.dsl.invoke +import org.jetbrains.dokka.gradle.DokkaExtension +import org.jetbrains.dokka.gradle.workers.ProcessIsolation -fun AbstractDokkaLeafTask.applyKordDokkaOptions() { +internal fun DokkaExtension.applyKordDokkaOptions(project: Project) { + + // Dokka runs out of memory with the default maxHeapSize when ProcessIsolation is used + (dokkaGeneratorIsolation.get() as? ProcessIsolation)?.maxHeapSize = "1g" moduleName = "kord-${project.name}" - failOnWarning = true + dokkaPublications.configureEach { + failOnWarning = true + } dokkaSourceSets.configureEach { @@ -16,17 +23,25 @@ fun AbstractDokkaLeafTask.applyKordDokkaOptions() { sourceLink { localDirectory = project.projectDir - remoteUrl = URI("https://github.com/kordlib/kord/blob/${project.commitHash}/${project.name}").toURL() + remoteUrl("https://github.com/kordlib/kord/blob/${project.commitHash}/${project.name}") remoteLineSuffix = "#L" } - externalDocumentationLink("https://kotlinlang.org/api/kotlinx.coroutines/") - externalDocumentationLink("https://kotlinlang.org/api/kotlinx.serialization/") - externalDocumentationLink( - url = "https://kotlinlang.org/api/kotlinx-datetime/", - packageListUrl = "https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/package-list", - ) - externalDocumentationLink("https://api.ktor.io/") + externalDocumentationLinks { + register("kotlinx.coroutines") { + url("https://kotlinlang.org/api/kotlinx.coroutines/") + } + register("kotlinx.serialization") { + url("https://kotlinlang.org/api/kotlinx.serialization/") + } + register("kotlinx-datetime") { + url("https://kotlinlang.org/api/kotlinx-datetime/") + packageListUrl("https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/package-list") + } + register("Ktor") { + url("https://api.ktor.io/") + } + } // don't list `TweetNaclFast` in docs perPackageOption { diff --git a/buildSrc/src/main/kotlin/kord-module.gradle.kts b/buildSrc/src/main/kotlin/kord-module.gradle.kts index 19322086bd4..37397688ec0 100644 --- a/buildSrc/src/main/kotlin/kord-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-module.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask - plugins { org.jetbrains.kotlin.jvm org.jetbrains.kotlin.plugin.serialization @@ -34,15 +32,15 @@ kotlin { } } +dokka { + applyKordDokkaOptions(project) +} + tasks { withType().configureEach { useJUnitPlatform() } - withType().configureEach { - applyKordDokkaOptions() - } - withType().configureEach { options.release = KORD_JVM_TARGET } diff --git a/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts b/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts index 5a28f04dd8c..db9f9064e8f 100644 --- a/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts @@ -1,4 +1,3 @@ -import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest @@ -71,6 +70,10 @@ kotlin { } } +dokka { + applyKordDokkaOptions(project) +} + tasks { withType().configureEach { useJUnitPlatform() @@ -80,7 +83,14 @@ tasks { environment("PROJECT_ROOT", rootProject.projectDir.absolutePath) } - for (task in listOf("compileKotlinJvm", "compileKotlinJs", "jvmSourcesJar", "jsSourcesJar")) { + for (task in listOf( + "compileKotlinJvm", + "compileKotlinJs", + "jvmSourcesJar", + "jsSourcesJar", + "dokkaGenerateModuleHtml", + "dokkaGeneratePublicationHtml", + )) { named(task) { dependsOn("kspCommonMainKotlinMetadata") } @@ -91,9 +101,4 @@ tasks { dependsOn("kspCommonMainKotlinMetadata") } } - - withType().configureEach { - applyKordDokkaOptions() - dependsOn("kspCommonMainKotlinMetadata") - } } diff --git a/buildSrc/src/main/kotlin/kord-publishing.gradle.kts b/buildSrc/src/main/kotlin/kord-publishing.gradle.kts index 89913975c14..0d3904bd282 100644 --- a/buildSrc/src/main/kotlin/kord-publishing.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-publishing.gradle.kts @@ -10,7 +10,7 @@ fun MavenPublication.registerDokkaJar() = tasks.register("${name}DokkaJar") { archiveClassifier = "javadoc" destinationDirectory = destinationDirectory.get().dir(name) - from(tasks.named("dokkaHtml")) + from(tasks.named("dokkaGeneratePublicationHtml")) } publishing { diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 2d6fbe8572c..6a9478a6873 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -37,9 +37,3 @@ apiValidation { // https://github.com/Kotlin/binary-compatibility-validator/issues/88 ignoredProjects += "live-tests" } - -tasks { - dokkaHtmlMultiModule { - enabled = false - } -} diff --git a/gradle.properties b/gradle.properties index 79197226527..460391da64d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,18 @@ # the version that is planned to be released next, snapshot versions for the 'main' branch are based on this nextPlannedVersion=0.15.0 -#dokka will run out of memory with the default meta space -org.gradle.jvmargs=-XX:MaxMetaspaceSize=1024m org.gradle.parallel=true org.gradle.warning.mode=all org.gradle.kotlin.dsl.allWarningsAsErrors=true kotlin.code.style=official +# the Kotlin daemon runs out of memory with the default maximum heap size +kotlin.daemon.jvmargs=-Xmx2g + +# https://kotlinlang.org/docs/dokka-migration.html#set-the-opt-in-flag +org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled +org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true + # https://github.com/Kotlin/kotlinx-atomicfu/issues/448 # https://youtrack.jetbrains.com/issue/KT-64109#focus=Comments-27-10064206.0-0 kotlin.suppressGradlePluginWarnings=IncorrectCompileOnlyDependencyWarning diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a26d68c9293..7e0b2b54d92 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -28,7 +28,7 @@ mockk = "1.13.12" # https://github.com/mockk/mockk kbson = "0.4.0" # https://github.com/mongodb/kbson # plugins -dokka = "1.9.20" # https://github.com/Kotlin/dokka +dokka = "2.0.0-Beta" # https://github.com/Kotlin/dokka kotlinx-atomicfu = "0.25.0" # https://github.com/Kotlin/kotlinx-atomicfu binary-compatibility-validator = "0.16.3" # https://github.com/Kotlin/binary-compatibility-validator buildconfig = "5.4.0" # https://github.com/gmazzo/gradle-buildconfig-plugin @@ -85,7 +85,7 @@ slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" } kbson = { module = "org.mongodb.kbson:kbson", version.ref = "kbson" } # actually plugins, not libraries, but used is 'buildSrc/build.gradle.kts' as implementation dependencies: -# https://docs.gradle.org/current/userguide/custom_plugins.html#applying_external_plugins_in_precompiled_script_plugins +# https://docs.gradle.org/current/userguide/implementing_gradle_plugins_precompiled.html#sec:applying_external_plugins kotlin-jvm-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } kotlin-serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" } dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" } diff --git a/ksp-annotations/build.gradle.kts b/ksp-annotations/build.gradle.kts index ab5cd1ad016..6f3e2f7d6c7 100644 --- a/ksp-annotations/build.gradle.kts +++ b/ksp-annotations/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask - plugins { `kord-internal-multiplatform-module` @@ -10,7 +8,7 @@ plugins { `kord-publishing` } -tasks.withType().configureEach { +dokka { dokkaSourceSets.configureEach { suppress = true } From 1faf96630721ddd23e7757f481d621e7d65a6b60 Mon Sep 17 00:00:00 2001 From: Luca Kellermann Date: Mon, 14 Oct 2024 15:32:39 +0200 Subject: [PATCH 2/4] Update dependencies (#986) * Gradle 8.10 -> 8.10.2 * Kotlin 2.0.20 -> 2.0.21 * Ktor 2.3.12 -> 3.0.0 * kotlinx.coroutines 1.8.1 -> 1.9.0 * kotlinx.serialization 1.7.2 -> 1.7.3 * kotlin-node 20.14.10-pre.800 -> 22.5.4-pre.818 * KSP 2.0.20-1.0.24 -> 2.0.21-1.0.25 * JUnit Jupiter 5.11.0 -> 5.11.2 * JUnit Platform 1.11.0 -> 1.11.2 * MockK 1.13.12 -> 1.13.13 * gradle-buildconfig-plugin 5.4.0 -> 5.5.0 io.ktor:ktor-client-websockets is an empty artifact, support for WebSockets is included in io.ktor:ktor-client-core, so the dependency was removed from kord-gateway. --- common/build.gradle.kts | 1 - common/src/nonJvmMain/kotlin/DiscordBitSet.kt | 23 ++++++++---- gateway/build.gradle.kts | 1 - gradle/libs.versions.toml | 23 ++++++------ gradle/wrapper/gradle-wrapper.properties | 4 +-- .../kotlin/request/KtorRequestHandler.kt | 1 - .../kotlin/request/MessageRequests.kt | 6 ++-- test-kit/build.gradle.kts | 2 +- voice/api/voice.api | 2 +- .../main/kotlin/udp/GlobalVoiceUdpSocket.kt | 35 +++++++++---------- voice/src/main/kotlin/udp/RTPPacket.kt | 19 +++++----- 11 files changed, 62 insertions(+), 55 deletions(-) diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 0c6a177a319..5098d607e20 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -23,7 +23,6 @@ kotlin { } nonJvmMain { dependencies { - implementation(libs.ktor.utils) implementation(libs.bignum) implementation(libs.stately.collections) } diff --git a/common/src/nonJvmMain/kotlin/DiscordBitSet.kt b/common/src/nonJvmMain/kotlin/DiscordBitSet.kt index c883976ebf8..f1764a24a20 100644 --- a/common/src/nonJvmMain/kotlin/DiscordBitSet.kt +++ b/common/src/nonJvmMain/kotlin/DiscordBitSet.kt @@ -2,14 +2,25 @@ package dev.kord.common import com.ionspin.kotlin.bignum.integer.BigInteger import com.ionspin.kotlin.bignum.integer.Sign -import io.ktor.utils.io.core.* -internal actual fun formatIntegerFromLittleEndianLongArray(data: LongArray) = - withBuffer(data.size * Long.SIZE_BYTES) { - // need to convert from little-endian data to big-endian expected by BigInteger - writeFully(data.reversedArray()) - BigInteger.fromByteArray(readBytes(), Sign.POSITIVE).toString() +internal actual fun formatIntegerFromLittleEndianLongArray(data: LongArray): String { + // need to convert from little-endian data to big-endian expected by BigInteger + val bytes = ByteArray(size = data.size * Long.SIZE_BYTES) + val lastIndex = data.lastIndex + for (i in 0..lastIndex) { + val offset = (lastIndex - i) * Long.SIZE_BYTES + val long = data[i] + bytes[offset] = (long ushr 56).toByte() + bytes[offset + 1] = (long ushr 48).toByte() + bytes[offset + 2] = (long ushr 40).toByte() + bytes[offset + 3] = (long ushr 32).toByte() + bytes[offset + 4] = (long ushr 24).toByte() + bytes[offset + 5] = (long ushr 16).toByte() + bytes[offset + 6] = (long ushr 8).toByte() + bytes[offset + 7] = long.toByte() } + return BigInteger.fromByteArray(bytes, Sign.POSITIVE).toString() +} internal actual fun parseNonNegativeIntegerToBigEndianByteArray(value: String): ByteArray = BigInteger .parseString(value) diff --git a/gateway/build.gradle.kts b/gateway/build.gradle.kts index 81cedadaca2..076873ffa47 100644 --- a/gateway/build.gradle.kts +++ b/gateway/build.gradle.kts @@ -10,7 +10,6 @@ kotlin { api(projects.common) api(libs.bundles.ktor.client.serialization) - api(libs.ktor.client.websockets) implementation(libs.kotlin.logging) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7e0b2b54d92..ab485a8dfde 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,10 +1,10 @@ [versions] # api dependencies -kotlin = "2.0.20" # https://github.com/JetBrains/kotlin -ktor = "2.3.12" # https://github.com/ktorio/ktor -kotlinx-coroutines = "1.8.1" # https://github.com/Kotlin/kotlinx.coroutines -kotlinx-serialization = "1.7.2" # https://github.com/Kotlin/kotlinx.serialization +kotlin = "2.0.21" # https://github.com/JetBrains/kotlin +ktor = "3.0.0" # https://github.com/ktorio/ktor +kotlinx-coroutines = "1.9.0" # https://github.com/Kotlin/kotlinx.coroutines +kotlinx-serialization = "1.7.3" # https://github.com/Kotlin/kotlinx.serialization kotlinx-datetime = "0.6.1" # https://github.com/Kotlin/kotlinx-datetime kord-cache = "0.5.4" # https://github.com/kordlib/cache @@ -12,26 +12,26 @@ kord-cache = "0.5.4" # https://github.com/kordlib/cache kotlin-logging = "7.0.0" # https://github.com/oshai/kotlin-logging kotlin-logging-old = "3.0.5" # TODO remove after dependency is removed in rest, gateway, voice and core slf4j = "2.0.16" # https://www.slf4j.org -kotlin-node = "20.14.10-pre.800" # https://github.com/JetBrains/kotlin-wrappers +kotlin-node = "22.5.4-pre.818" # https://github.com/JetBrains/kotlin-wrappers bignum = "0.3.10" # https://github.com/ionspin/kotlin-multiplatform-bignum stately = "2.1.0" # https://github.com/touchlab/Stately fastZlib = "2.0.1" # https://github.com/timotejroiko/fast-zlib # code generation -ksp = "2.0.20-1.0.24" # https://github.com/google/ksp +ksp = "2.0.21-1.0.25" # https://github.com/google/ksp kotlinpoet = "1.18.1" # https://github.com/square/kotlinpoet # tests -junit-jupiter = "5.11.0" # https://github.com/junit-team/junit5 -junit-platform = "1.11.0" -mockk = "1.13.12" # https://github.com/mockk/mockk +junit-jupiter = "5.11.2" # https://github.com/junit-team/junit5 +junit-platform = "1.11.2" +mockk = "1.13.13" # https://github.com/mockk/mockk kbson = "0.4.0" # https://github.com/mongodb/kbson # plugins dokka = "2.0.0-Beta" # https://github.com/Kotlin/dokka kotlinx-atomicfu = "0.25.0" # https://github.com/Kotlin/kotlinx-atomicfu binary-compatibility-validator = "0.16.3" # https://github.com/Kotlin/binary-compatibility-validator -buildconfig = "5.4.0" # https://github.com/gmazzo/gradle-buildconfig-plugin +buildconfig = "5.5.0" # https://github.com/gmazzo/gradle-buildconfig-plugin [libraries] @@ -46,10 +46,9 @@ ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" } ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" } ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" } -ktor-client-websockets = { module = "io.ktor:ktor-client-websockets", version.ref = "ktor" } ktor-client-mock = { module = "io.ktor:ktor-client-mock", version.ref = "ktor" } ktor-network = { module = "io.ktor:ktor-network", version.ref = "ktor" } -ktor-utils = { module = "io.ktor:ktor-utils", version.ref = "ktor" } +ktor-io = { module = "io.ktor:ktor-io", version.ref = "ktor" } # kotlinx kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2b189974c29..fb602ee2af0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=5b9c5eb3f9fc2c94abaea57d90bd78747ca117ddbbf96c859d3741181a12bf2a -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +distributionSha256Sum=31c55713e40233a8303827ceb42ca48a47267a0ad4bab9177123121e71524c26 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/rest/src/commonMain/kotlin/request/KtorRequestHandler.kt b/rest/src/commonMain/kotlin/request/KtorRequestHandler.kt index f40480c32c4..e94d947ef48 100644 --- a/rest/src/commonMain/kotlin/request/KtorRequestHandler.kt +++ b/rest/src/commonMain/kotlin/request/KtorRequestHandler.kt @@ -9,7 +9,6 @@ import io.ktor.client.* import io.ktor.client.request.* import io.ktor.client.request.forms.* import io.ktor.client.statement.* -import io.ktor.content.TextContent import io.ktor.http.* import io.ktor.http.content.* import kotlinx.datetime.Clock diff --git a/rest/src/commonTest/kotlin/request/MessageRequests.kt b/rest/src/commonTest/kotlin/request/MessageRequests.kt index 6e43c1d9dec..7c728d37cbd 100644 --- a/rest/src/commonTest/kotlin/request/MessageRequests.kt +++ b/rest/src/commonTest/kotlin/request/MessageRequests.kt @@ -8,10 +8,10 @@ import dev.kord.common.entity.Snowflake import dev.kord.common.entity.optional.Optional import dev.kord.rest.json.readFile import dev.kord.rest.service.ChannelService -import dev.kord.test.Platform import io.ktor.client.* import io.ktor.client.engine.mock.* import io.ktor.client.request.forms.* +import io.ktor.utils.io.* import kotlinx.coroutines.test.runTest import kotlinx.datetime.Clock import kotlinx.serialization.encodeToString @@ -62,10 +62,9 @@ class MessageRequests { val channelService = ChannelService(KtorRequestHandler(client = HttpClient(mockEngine), token = "")) - val fileChannel = readFile("images/kord.png") + val fileChannel = readFile("images/kord.png").counted() with(fileChannel) { - if (Platform.IS_JVM) assertFalse(isClosedForWrite) // only read lazily on jvm assertFalse(isClosedForRead) assertEquals(0L, totalBytesRead) @@ -74,7 +73,6 @@ class MessageRequests { } assertEquals(mockMessage, createdMessage) - assertTrue(isClosedForWrite) assertTrue(isClosedForRead) assertTrue(totalBytesRead > 0L) } diff --git a/test-kit/build.gradle.kts b/test-kit/build.gradle.kts index e1357aadebf..a5c13ff37e4 100644 --- a/test-kit/build.gradle.kts +++ b/test-kit/build.gradle.kts @@ -7,7 +7,7 @@ kotlin { commonMain { dependencies { api(libs.bundles.test.common) - api(libs.ktor.utils) + api(libs.ktor.io) } } jsMain { diff --git a/voice/api/voice.api b/voice/api/voice.api index 2bdd226cdc1..6680afe9661 100644 --- a/voice/api/voice.api +++ b/voice/api/voice.api @@ -1232,7 +1232,7 @@ public final class dev/kord/voice/udp/RTPPacket$Builder { } public final class dev/kord/voice/udp/RTPPacket$Companion { - public final fun fromPacket (Lio/ktor/utils/io/core/ByteReadPacket;)Ldev/kord/voice/udp/RTPPacket; + public final fun fromPacket (Lkotlinx/io/Source;)Ldev/kord/voice/udp/RTPPacket; } public final class dev/kord/voice/udp/RTPPacketKt { diff --git a/voice/src/main/kotlin/udp/GlobalVoiceUdpSocket.kt b/voice/src/main/kotlin/udp/GlobalVoiceUdpSocket.kt index d4577e45cf3..4221bbf50d0 100644 --- a/voice/src/main/kotlin/udp/GlobalVoiceUdpSocket.kt +++ b/voice/src/main/kotlin/udp/GlobalVoiceUdpSocket.kt @@ -5,12 +5,13 @@ import io.github.oshai.kotlinlogging.KotlinLogging import io.ktor.network.selector.* import io.ktor.network.sockets.* import io.ktor.utils.io.core.* -import kotlinx.coroutines.CoroutineName -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.SupervisorJob -import kotlinx.coroutines.flow.* -import kotlin.text.String +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.SharedFlow +import kotlinx.coroutines.flow.emitAll +import kotlinx.io.Sink +import kotlinx.io.readString +import kotlinx.io.readUShort private val globalVoiceSocketLogger = KotlinLogging.logger { } @@ -32,18 +33,16 @@ public object GlobalVoiceUdpSocket : VoiceUdpSocket { private val _incoming: MutableSharedFlow = MutableSharedFlow() override val incoming: SharedFlow = _incoming - private val socket = aSocket(ActorSelectorManager(socketScope.coroutineContext)).udp().bind() + private val socket = socketScope.async { + aSocket(ActorSelectorManager(socketScope.coroutineContext)).udp().bind() + } private val EMPTY_DATA = ByteArray(DISCOVERY_DATA_SIZE) init { - socket.incoming - .consumeAsFlow() - .onEach { _incoming.emit(it) } - .launchIn(socketScope) + socketScope.launch { _incoming.emitAll(socket.await().incoming) } } - @OptIn(ExperimentalUnsignedTypes::class) override suspend fun discoverIp(address: InetSocketAddress, ssrc: Int): InetSocketAddress { globalVoiceSocketLogger.trace { "discovering ip" } @@ -51,15 +50,15 @@ public object GlobalVoiceUdpSocket : VoiceUdpSocket { writeShort(REQUEST) writeShort(MESSAGE_LENGTH) writeInt(ssrc) - writeFully(EMPTY_DATA) + write(EMPTY_DATA) }) return with(receiveFrom(address).packet) { require(readShort() == RESPONSE) { "did not receive a response." } - require(readShort() == MESSAGE_LENGTH) { "expected $MESSAGE_LENGTH bytes of data."} - discardExact(4) // ssrc + require(readShort() == MESSAGE_LENGTH) { "expected $MESSAGE_LENGTH bytes of data." } + skip(byteCount = 4) // ssrc - val ip = String(readBytes(64)).trimEnd(0.toChar()) + val ip = readString(byteCount = 64).trimEnd(0.toChar()) val port = readUShort().toInt() InetSocketAddress(ip, port) @@ -67,12 +66,12 @@ public object GlobalVoiceUdpSocket : VoiceUdpSocket { } override suspend fun send(packet: Datagram) { - socket.send(packet) + socket.await().send(packet) } override suspend fun stop() { /* this doesn't stop until the end of the process */ } - private fun packet(address: SocketAddress, builder: BytePacketBuilder.() -> Unit): Datagram { + private fun packet(address: SocketAddress, builder: Sink.() -> Unit): Datagram { return Datagram(buildPacket(block = builder), address) } } diff --git a/voice/src/main/kotlin/udp/RTPPacket.kt b/voice/src/main/kotlin/udp/RTPPacket.kt index 43d734c38f7..56a89078e20 100644 --- a/voice/src/main/kotlin/udp/RTPPacket.kt +++ b/voice/src/main/kotlin/udp/RTPPacket.kt @@ -4,7 +4,10 @@ import dev.kord.voice.io.ByteArrayView import dev.kord.voice.io.MutableByteArrayCursor import dev.kord.voice.io.mutableCursor import dev.kord.voice.io.view -import io.ktor.utils.io.core.* +import kotlinx.io.Source +import kotlinx.io.readByteArray +import kotlinx.io.readUInt +import kotlinx.io.readUShort import kotlin.experimental.and internal const val RTP_HEADER_LENGTH = 12 @@ -38,8 +41,8 @@ public data class RTPPacket( public companion object { internal const val VERSION = 2 - public fun fromPacket(packet: ByteReadPacket): RTPPacket? = with(packet) base@{ - if (remaining <= 13) return@base null + public fun fromPacket(packet: Source): RTPPacket? = with(packet) base@{ + if (!request(byteCount = 14)) return@base null /* * first byte | bit table @@ -72,15 +75,15 @@ public data class RTPPacket( payloadType = this and 0x7F } - val sequence = readShort().toUShort() - val timestamp = readInt().toUInt() - val ssrc = readInt().toUInt() + val sequence = readUShort() + val timestamp = readUInt() + val ssrc = readUInt() // each csrc takes up 4 bytes, plus more data is required - if (remaining <= csrcCount * 4 + 1) return@base null + if (!request(byteCount = csrcCount * 4L + 2)) return@base null val csrcIdentifiers = UIntArray(csrcCount.toInt()) { readUInt() } - val payload = readBytes().view() + val payload = readByteArray().view() val paddingBytes = if (hasPadding) { payload[payload.viewSize - 1] } else 0 From ae8ad6ecfcfb050e90494c67a8b72438b8271aac Mon Sep 17 00:00:00 2001 From: Luca Kellermann Date: Wed, 16 Oct 2024 22:20:38 +0200 Subject: [PATCH 3/4] Add changelog for 0.15.0 [skip ci] --- CHANGELOG.md | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ebb4d3d7d1..ec3996778ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,44 @@ +# 0.15.0 + +## Additions + +* Add `User.isSelf` (by @Taubsie in #950) +* Publish snapshots to https://repo.kord.dev/snapshots (#961) +* Document deprecation cycle of deprecated declarations (#969) +* Add `UserMessageCreateBuilder.enforceNonce` (by @DRSchlaubi in #971) +* Implement Monetization (by @viztea in #932) +* Add `MemberProfileAutoModerationRule` (#974) + +## Changes + +* Bump `DeprecationLevel`s after 0.14.0 (#944) +* Update Auto Moderation builders (#979) +* Link to JDK 23 in Dokka output (#980) + +## Fixes + +* Fix deserialization of members (by @NoComment1105 in #955) +* Fix deserialization of `Heartbeat` events (#957) +* Fix `getMemberOrNull` and `getGuildMembers` caching only user data (by @Galarzaa90 in #964) +* Fix misuse of reified type parameters (#981) + +## Dependencies + +Updated in #942, #954, #958, #975, #976, and #986 (not including dependencies only needed for developing Kord) + +* Kotlin 1.9.24 -> 2.0.21 +* Ktor 2.3.11 -> 3.0.0 +* kotlinx.coroutines 1.8.1 -> 1.9.0 +* kotlinx.serialization 1.6.3 -> 1.7.3 +* kotlinx-datetime 0.6.0 -> 0.6.1 +* kord-cache 0.4.0 -> 0.5.4 +* kotlin-logging 6.0.9 -> 7.0.0 +* SLF4J 2.0.13 -> 2.0.16 +* kotlin-node 20.11.30-pre.751 -> 22.5.4-pre.818 +* kotlin-multiplatform-bignum 0.3.9 -> 0.3.10 +* Stately 2.0.7 -> 2.1.0 +* AtomicFU 0.24.0 -> 0.25.0 + # 0.14.0 ## Additions @@ -30,7 +71,7 @@ Updated in #920, #929 and #943 * kotlinx-datetime 0.5.0 -> 0.6.0 * kotlin-logging 6.0.1 -> 6.0.9 * SLF4J 2.0.9 -> 2.0.13 -* kotlin-node 18.16.12-pre.619 -> 20.11.5-pre.751 +* kotlin-node 18.16.12-pre.619 -> 20.11.30-pre.751 * kotlin-multiplatform-bignum 0.3.8 -> 0.3.9 * Stately 2.0.6 -> 2.0.7 * KSP 1.9.21-1.0.16 -> 1.9.24-1.0.20 From 8dad2e7075d9079e65d4105a87f659bef76a2662 Mon Sep 17 00:00:00 2001 From: Luca Kellermann Date: Wed, 16 Oct 2024 22:52:03 +0200 Subject: [PATCH 4/4] Bump nextPlannedVersion to 0.16.0 [skip ci] --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 460391da64d..599b3de433f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # the version that is planned to be released next, snapshot versions for the 'main' branch are based on this -nextPlannedVersion=0.15.0 +nextPlannedVersion=0.16.0 org.gradle.parallel=true org.gradle.warning.mode=all