release 0.2.4

This commit is contained in:
Sergey Chernov 2024-08-01 02:36:37 +02:00
parent 1f7e7f88fa
commit 03bc727750
14 changed files with 172 additions and 41 deletions

View File

@ -0,0 +1,6 @@
<component name="ArtifactManager">
<artifact type="jar" name="kiloparsec-js-0.1.2-SNAPSHOT">
<output-path>$PROJECT_DIR$/build/libs</output-path>
<root id="archive" name="kiloparsec-js-0.1.2-SNAPSHOT.jar" />
</artifact>
</component>

View File

@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="kiloparsec-js-0.2.2-SNAPSHOT">
<output-path>$PROJECT_DIR$/build/libs</output-path>
<root id="archive" name="kiloparsec-js-0.2.2-SNAPSHOT.jar">
<element id="module-output" name="kiloparsec.jsMain" />
</root>
</artifact>
</component>

8
.idea/artifacts/kiloparsec_js_0_2_3.xml generated Normal file
View File

@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="kiloparsec-js-0.2.3">
<output-path>$PROJECT_DIR$/build/libs</output-path>
<root id="archive" name="kiloparsec-js-0.2.3.jar">
<element id="module-output" name="kiloparsec.jsMain" />
</root>
</artifact>
</component>

View File

@ -0,0 +1,6 @@
<component name="ArtifactManager">
<artifact type="jar" name="kiloparsec-jvm-0.1.2-SNAPSHOT">
<output-path>$PROJECT_DIR$/build/libs</output-path>
<root id="archive" name="kiloparsec-jvm-0.1.2-SNAPSHOT.jar" />
</artifact>
</component>

View File

@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="kiloparsec-jvm-0.2.2-SNAPSHOT">
<output-path>$PROJECT_DIR$/build/libs</output-path>
<root id="archive" name="kiloparsec-jvm-0.2.2-SNAPSHOT.jar">
<element id="module-output" name="kiloparsec.jvmMain" />
</root>
</artifact>
</component>

View File

@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="kiloparsec-jvm-0.2.3">
<output-path>$PROJECT_DIR$/build/libs</output-path>
<root id="archive" name="kiloparsec-jvm-0.2.3.jar">
<element id="module-output" name="kiloparsec.jvmMain" />
</root>
</artifact>
</component>

5
.idea/misc.xml generated
View File

@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" /> <file type="web" url="file://$PROJECT_DIR$" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK" /> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17 (5)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project> </project>

View File

@ -6,7 +6,7 @@ plugins {
} }
group = "net.sergeych" group = "net.sergeych"
version = "0.2.2-SNAPSHOT" version = "0.2.4"
repositories { repositories {
mavenCentral() mavenCentral()
@ -17,13 +17,8 @@ repositories {
kotlin { kotlin {
jvm() jvm()
js(IR) { js {
browser { browser {
// commonWebpackConfig {
// cssSupport {
// enabled.set(true)
// }
// }
} }
} }
// val hostOs = System.getProperty("os.name") // val hostOs = System.getProperty("os.name")
@ -39,16 +34,15 @@ kotlin {
// else -> throw GradleException("Host OS is not supported in Kotlin/Native.") // else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
// } // }
// macosArm64() macosArm64()
// iosX64() iosX64()
// iosArm64() iosArm64()
// iosSimulatorArm64() iosSimulatorArm64()
linuxX64() linuxX64()
linuxArm64() linuxArm64()
// macosX64() macosX64()
val ktor_version = "2.3.12"
val ktor_version = "2.3.6"
sourceSets { sourceSets {
all { all {
@ -64,17 +58,20 @@ kotlin {
// api("com.ionspin.kotlin:bignum:0.3.9") // api("com.ionspin.kotlin:bignum:0.3.9")
api("io.ktor:ktor-client-core:$ktor_version") api("io.ktor:ktor-client-core:$ktor_version")
api("net.sergeych:crypto2:0.4.2")
// api("net.sergeych:mp_bintools:0.1.1")
// api("net.sergeych:mp_stools:1.4.7")
api("net.sergeych:crypto2:0.4.1-SNAPSHOT")
} }
} }
// val ktorSocketMain by creating {
// dependsOn(commonMain)
// dependencies {
// implementation("io.ktor:ktor-network:$ktor_version")
// }
// }
val commonTest by getting { val commonTest by getting {
dependencies { dependencies {
implementation(kotlin("test")) implementation(kotlin("test"))
implementation("org.slf4j:slf4j-simple:2.0.9") implementation("org.slf4j:slf4j-simple:2.0.9")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1")
} }
} }
val jvmMain by getting { val jvmMain by getting {
@ -85,6 +82,7 @@ kotlin {
implementation("io.ktor:ktor-server-netty:$ktor_version") implementation("io.ktor:ktor-server-netty:$ktor_version")
api("io.ktor:ktor-client-cio:$ktor_version") api("io.ktor:ktor-client-cio:$ktor_version")
} }
// dependsOn(ktorSocketMain)
} }
val jvmTest by getting val jvmTest by getting
val jsMain by getting { val jsMain by getting {
@ -93,12 +91,10 @@ kotlin {
} }
} }
val jsTest by getting val jsTest by getting
// val nativeMain by getting {
// dependencies { // for (pm in listOf(linuxMain, macosMain, iosMain, mingwMain))
// implementation("io.ktor:ktor-client-cio:$ktor_version") // pm { dependsOn(ktorSocketMain) }
// }
// }
// val nativeTest by getting
} }
publishing { publishing {

View File

@ -0,0 +1,37 @@
package net.sergeych.kiloparsec
import io.ktor.utils.io.*
object AsyncVarint {
suspend fun encodeUnsigned(value: ULong, output: ByteWriteChannel) {
var rest = value
do {
val x = (rest and 127u).toInt()
rest = rest shr 7
if (rest > 0u)
output.writeByte(x or 0x80)
else
output.writeByte(x)
} while (rest > 0u)
}
suspend fun decodeUnsigned(source: ByteReadChannel): ULong {
var result: ULong = 0u
var count = 0
while (true) {
val x = source.readUByte().toInt()
result = result or ((x and 0x7F).toULong() shl count)
if ((x and 0x80) == 0)
break
count += 7
}
return result
}
}
suspend fun ByteReadChannel.readUByte(): UByte = this.readByte().toUByte()
suspend fun ByteWriteChannel.writeByte(byte: Int) {
this.writeByte(byte.toByte())
}

View File

@ -1,7 +1,7 @@
package net.sergeych.kiloparsec package net.sergeych.kiloparsec
/** /**
* The local interface to provice functions, register errors for Kiloparsec users. Use it * The local interface to provide functions, register errors for Kiloparsec users. Use it
* with [KiloClient], [KiloClientConnection], [KiloServerConnection], etc. * with [KiloClient], [KiloClientConnection], [KiloServerConnection], etc.
* *
* BAse implementation registers relevant exceptions. * BAse implementation registers relevant exceptions.

View File

@ -22,12 +22,14 @@ actual fun acceptTcpDevice(port: Int): Flow<InetTransportDevice> {
} }
} }
while (true) { while (true) {
println("0 --- $port")
val connectedSocket = suspendCancellableCoroutine { continuation -> val connectedSocket = suspendCancellableCoroutine { continuation ->
continuation.invokeOnCancellation { continuation.invokeOnCancellation {
socket.close() socket.close()
} }
socket.accept(continuation, ContinuationHandler()) socket.accept(continuation, ContinuationHandler())
} }
println("1 ---")
emit(asyncSocketToDevice(connectedSocket)) emit(asyncSocketToDevice(connectedSocket))
} }
} }

View File

@ -100,16 +100,9 @@ class ClientTest {
on(cmdCheckConnected) { connectedCalled } on(cmdCheckConnected) { connectedCalled }
on(cmdClose) { on(cmdClose) {
throw LocalInterface.BreakConnectionException() throw LocalInterface.BreakConnectionException()
// if( closeCounter < 2 ) {
// println("-------------------------- call close!")
// throw RemoteInterface.ClosedException()
// }
// else {
// println("close counter $closeCounter, ignoring")
// }
} }
} }
// val server = setupWebsoketServer()
val ns: NettyApplicationEngine = embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = { val ns: NettyApplicationEngine = embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = {
setupWebsocketServer(serverInterface) { Session() } setupWebsocketServer(serverInterface) { Session() }
}).start(wait = false) }).start(wait = false)

View File

@ -10,6 +10,7 @@ import net.sergeych.kiloparsec.adapter.toNetworkAddress
import net.sergeych.kiloparsec.decodeFromUByteArray import net.sergeych.kiloparsec.decodeFromUByteArray
import net.sergeych.kiloparsec.encodeToUByteArray import net.sergeych.kiloparsec.encodeToUByteArray
import net.sergeych.mp_logger.Log import net.sergeych.mp_logger.Log
import net.sergeych.mp_logger.LogTag
import net.sergeych.synctools.ProtectedOp import net.sergeych.synctools.ProtectedOp
import net.sergeych.synctools.invoke import net.sergeych.synctools.invoke
import kotlin.test.Test import kotlin.test.Test
@ -43,8 +44,11 @@ class NetworkTest {
val op = ProtectedOp() val op = ProtectedOp()
var pills = setOf<String>() var pills = setOf<String>()
val j = launch { val j = launch {
println("serf")
serverFlow.collect { device -> serverFlow.collect { device ->
println("serf 0")
launch { launch {
println("serf 1")
device.output.send("Hello, world!".encodeToUByteArray()) device.output.send("Hello, world!".encodeToUByteArray())
device.output.send("Great".encodeToUByteArray()) device.output.send("Great".encodeToUByteArray())
while (true) { while (true) {
@ -63,13 +67,22 @@ class NetworkTest {
} }
yield() yield()
run { run {
val s = connectTcpDevice("127.0.1.1:17171".toNetworkAddress()) try {
assertEquals("Hello, world!", s.input.receive().decodeFromUByteArray()) println("pre-con")
assertEquals("Great", s.input.receive().decodeFromUByteArray()) val s = connectTcpDevice("127.0.1.1:17171".toNetworkAddress())
s.output.send("Goodbye".encodeToUByteArray()) println("2")
s.output.send("die1".encodeToUByteArray()) assertEquals("Hello, world!", s.input.receive().decodeFromUByteArray())
s.close() assertEquals("Great", s.input.receive().decodeFromUByteArray())
s.output.send("Goodbye".encodeToUByteArray())
s.output.send("die1".encodeToUByteArray())
s.close()
}
catch(t: Throwable) {
t.printStackTrace()
throw t
}
} }
println("pre-con2")
val s1 = connectTcpDevice("127.0.1.1:17171".toNetworkAddress()) val s1 = connectTcpDevice("127.0.1.1:17171".toNetworkAddress())
assertEquals("Hello, world!", s1.input.receive().decodeFromUByteArray()) assertEquals("Hello, world!", s1.input.receive().decodeFromUByteArray())
assertEquals("Great", s1.input.receive().decodeFromUByteArray()) assertEquals("Great", s1.input.receive().decodeFromUByteArray())

View File

@ -0,0 +1,43 @@
package net.sergeych.kiloparsec.adapter
import io.ktor.network.selector.*
import io.ktor.network.sockets.*
import io.ktor.util.network.*
import io.ktor.utils.io.*
import io.ktor.utils.io.core.*
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import net.sergeych.kiloparsec.AsyncVarint
import net.sergeych.mp_logger.LogTag
import kotlin.io.use
//class SocketNetworkAddress(override val host: String, override val port: Int) : NetworkAddress
//
//actual fun NetworkAddress(host: String, port: Int): NetworkAddress = SocketNetworkAddress(host, port)
//
//fun acceptTcpSocketDevice(port: Int): Flow<InetTransportDevice> {
// val selectorManager = SelectorManager(Dispatchers.IO)
// val serverSocket = aSocket(selectorManager).tcp().bind("127.0.0.1", port)
// val log = LogTag("TCPS${}")
// return flow {
// serverSocket.accept().use { sock ->
// val closed = CompletableDeferred<Boolean>()
// val scope = coroutineScope {
// val networkAddress = sock.remoteAddress.toJavaAddress().let { NetworkAddress(it.hostname, it.port) }
// val inputBlocks = Channel<UByteArray>(4096)
// sock.launch {
// val sockInput = sock.openReadChannel()
// while (isActive && sock.isActive) {
// try {
// val size = AsyncVarint.decodeUnsigned(sockInput)
// } catch (e: Exception) {
//
// }
// }
// }
// }
// }
// }
//}