diff --git a/.gitattributes b/.gitattributes index b657656..c521c9c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,2 @@ *.sh text=auto eol=lf -gordonmu-coio/src/test/resources/testfile.txt binary \ No newline at end of file +blachris-coio/src/test/resources/testfile.txt binary \ No newline at end of file diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 90e3a4c..4053d9f 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -9,10 +9,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 17 - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle @@ -21,4 +21,4 @@ jobs: if: ${{ failure() }} with: name: Test Results - path: gordonmu-coio/build/reports/tests/ + path: blachris-coio/build/reports/tests/ diff --git a/README.md b/README.md index ccd6798..e981b41 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -![Java CI](https://github.com/gordonmu/coio/workflows/Java%20CI/badge.svg) - [ ![Download](https://api.bintray.com/packages/gordonmu/jvm/coio/images/download.svg) ](https://bintray.com/gordonmu/jvm/coio/_latestVersion) +![Java CI](https://github.com/blachris/coio/workflows/Java%20CI/badge.svg) + [ ![Download](https://api.bintray.com/packages/blachris/jvm/coio/images/download.svg) ](https://bintray.com/blachris/jvm/coio/_latestVersion) # CoIO diff --git a/blachris-coio-tls/build.gradle b/blachris-coio-tls/build.gradle new file mode 100644 index 0000000..e7583d8 --- /dev/null +++ b/blachris-coio-tls/build.gradle @@ -0,0 +1,60 @@ +dependencies { + implementation project(":blachris-coio") + implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: "$kotlin_version" + implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: "$kotlinxcoroutine_version" + implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-jdk8', version: "$kotlinxcoroutine_version" + implementation group: 'io.github.microutils', name: 'kotlin-logging', version: "$kotlinlogging_version" + implementation group: 'org.slf4j', name: 'slf4j-api', version: "$slf4j_version" + implementation group: 'io.netty', name: 'netty-buffer', version: '4.1.99.Final' + implementation group: 'io.netty', name: 'netty-handler', version: '4.1.99.Final' + implementation group: 'com.github.marianobarrios', name: 'tls-channel', version: '0.4.0' + implementation group: 'io.netty', name: 'netty-tcnative-boringssl-static', version: "$tcnative_version" + + testImplementation group: 'org.assertj', name: 'assertj-core', version: "$assertj_version" + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "$junit5_version" + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "$junit5_version" + testImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: "$log4jslf4j_version" + testImplementation group: 'io.mockk', name: 'mockk', version: "$mockk_version" + testImplementation group: 'org.awaitility', name: 'awaitility', version: "$awaitility_version" + testImplementation group: 'org.awaitility', name: 'awaitility-kotlin', version: "$awaitility_version" +} + +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + artifact sourcesJar { + archiveClassifier.set("sources") + } + artifact javadocJar { + archiveClassifier.set("javadoc") + } + groupId project.group + artifactId project.name + version project.version + pom(commonPom) + pom { + name = 'CoIO TLS Extension' + description = 'A CoIO extension to use TLS over any CoIOStream.' + url = 'https://github.com/blachris/coio' + } + } + } + repositories { + maven { + url "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2" + credentials { + if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) { + username = ossrhUsername + password = ossrhPassword + } + } + } + } +} + +if (project.hasProperty('signing.keyId') && project.hasProperty('signing.password') && project.hasProperty('signing.secretKeyRingFile')) { + signing { + sign publishing.publications.mavenJava + } +} diff --git a/gordonmu-coio-tls/openssl_commands.md b/blachris-coio-tls/openssl_commands.md similarity index 100% rename from gordonmu-coio-tls/openssl_commands.md rename to blachris-coio-tls/openssl_commands.md diff --git a/gordonmu-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/CoIOTls.kt b/blachris-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/CoIOTls.kt similarity index 92% rename from gordonmu-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/CoIOTls.kt rename to blachris-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/CoIOTls.kt index 726bbe9..4d22a36 100644 --- a/gordonmu-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/CoIOTls.kt +++ b/blachris-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/CoIOTls.kt @@ -1,6 +1,6 @@ -package com.github.gordonmu.coio.tls +package com.github.blachris.coio.tls -import com.github.gordonmu.coio.CoIOStream +import com.github.blachris.coio.CoIOStream import io.netty.buffer.ByteBufAllocator import io.netty.handler.ssl.SslContext import io.netty.handler.ssl.SslContextBuilder @@ -40,7 +40,7 @@ fun CoIOStream.wrapTlsServer(keyCertChain: List, * @param trustedCerts a stream over a sequence of PEM encoded certificates */ fun CoIOStream.wrapTlsClient(serverName: String, - trustedCerts: InputStream): CoIOStream = wrapTlsClient(serverName, com.github.gordonmu.coio.tls.loadX509Certificates(trustedCerts)) + trustedCerts: InputStream): CoIOStream = wrapTlsClient(serverName, com.github.blachris.coio.tls.loadX509Certificates(trustedCerts)) fun CoIOStream.wrapTlsClient(serverName: String, trustedCerts: List): CoIOStream { @@ -55,5 +55,5 @@ fun CoIOStream.wrapTlsClient(serverName: String, } fun CoIOStream.wrapTls(sslEngine: SSLEngine): CoIOStream { - return com.github.gordonmu.coio.tls.TlsChannelAdapter(sslEngine, this) + return com.github.blachris.coio.tls.TlsChannelAdapter(sslEngine, this) } \ No newline at end of file diff --git a/gordonmu-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/TlsChannelAdapter.kt b/blachris-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/TlsChannelAdapter.kt similarity index 98% rename from gordonmu-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/TlsChannelAdapter.kt rename to blachris-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/TlsChannelAdapter.kt index 60793b5..a340c7f 100644 --- a/gordonmu-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/TlsChannelAdapter.kt +++ b/blachris-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/TlsChannelAdapter.kt @@ -1,6 +1,6 @@ -package com.github.gordonmu.coio.tls +package com.github.blachris.coio.tls -import com.github.gordonmu.coio.* +import com.github.blachris.coio.* import kotlinx.coroutines.delay import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock diff --git a/gordonmu-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/TlsUtils.kt b/blachris-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/TlsUtils.kt similarity index 98% rename from gordonmu-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/TlsUtils.kt rename to blachris-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/TlsUtils.kt index 2f8b40c..58156a5 100644 --- a/gordonmu-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/TlsUtils.kt +++ b/blachris-coio-tls/src/main/kotlin/com/github/gordonmu/coio/tls/TlsUtils.kt @@ -1,4 +1,4 @@ -package com.github.gordonmu.coio.tls +package com.github.blachris.coio.tls import java.io.ByteArrayOutputStream import java.io.IOException diff --git a/gordonmu-coio-tls/src/test/kotlin/NettySSLEngineTests.java b/blachris-coio-tls/src/test/kotlin/NettySSLEngineTests.java similarity index 89% rename from gordonmu-coio-tls/src/test/kotlin/NettySSLEngineTests.java rename to blachris-coio-tls/src/test/kotlin/NettySSLEngineTests.java index c7b11c0..60a379e 100644 --- a/gordonmu-coio-tls/src/test/kotlin/NettySSLEngineTests.java +++ b/blachris-coio-tls/src/test/kotlin/NettySSLEngineTests.java @@ -19,8 +19,8 @@ public class NettySSLEngineTests { - private TrustManagerFactory dummyTrustManagerFacotory = new SimpleTrustManagerFactory() { - private TrustManager[] trustManagers = new TrustManager[]{new DummyTrustManager()}; + private final TrustManagerFactory dummyTrustManagerFacotory = new SimpleTrustManagerFactory() { + private final TrustManager[] trustManagers = new TrustManager[]{new DummyTrustManager()}; @Override protected void engineInit(KeyStore keyStore) throws Exception { @@ -45,12 +45,10 @@ public void nettySSLEngineInitializationTest() throws IOException { .build(); SSLEngine sslEngine = ctx.newEngine(ByteBufAllocator.DEFAULT, "test", 0); - ClientTlsChannel chan = ClientTlsChannel.newBuilder(new DummyByteChannel(), sslEngine) + try (ClientTlsChannel chan = ClientTlsChannel.newBuilder(new DummyByteChannel(), sslEngine) .withEncryptedBufferAllocator(new HeapBufferAllocator()) - .build(); - - try { - chan.handshake(); + .build()) { + chan.handshake(); } catch (NeedsWriteException es) { // test passed, expected exception } diff --git a/gordonmu-coio-tls/src/test/kotlin/TlsStreamTests.kt b/blachris-coio-tls/src/test/kotlin/TlsStreamTests.kt similarity index 90% rename from gordonmu-coio-tls/src/test/kotlin/TlsStreamTests.kt rename to blachris-coio-tls/src/test/kotlin/TlsStreamTests.kt index fc3193d..878442c 100644 --- a/gordonmu-coio-tls/src/test/kotlin/TlsStreamTests.kt +++ b/blachris-coio-tls/src/test/kotlin/TlsStreamTests.kt @@ -1,7 +1,7 @@ -import com.github.gordonmu.coio.CoIOMemoryStream -import com.github.gordonmu.coio.tls.wrapTlsClient -import com.github.gordonmu.coio.tls.wrapTlsServer -import com.github.gordonmu.coio.writeFully +import com.github.blachris.coio.CoIOMemoryStream +import com.github.blachris.coio.tls.wrapTlsClient +import com.github.blachris.coio.tls.wrapTlsServer +import com.github.blachris.coio.writeFully import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout @@ -26,8 +26,8 @@ class TlsStreamTests { withTimeout(10000) { val serverStream = memStream.front.wrapTlsServer( - clz.getResourceAsStream("testserver-cert.pem"), - clz.getResourceAsStream("testserver-key_pkcs8.pem")) + clz.getResourceAsStream("testserver-cert.pem")!!, + clz.getResourceAsStream("testserver-key_pkcs8.pem")!!) val clientStream = memStream.back.wrapTlsClient("testserver", SequenceInputStream( clz.getResourceAsStream("testroot-cert.pem"), diff --git a/gordonmu-coio-tls/src/test/resources/log4j2.xml b/blachris-coio-tls/src/test/resources/log4j2.xml similarity index 100% rename from gordonmu-coio-tls/src/test/resources/log4j2.xml rename to blachris-coio-tls/src/test/resources/log4j2.xml diff --git a/gordonmu-coio-tls/src/test/resources/testroot-cert.pem b/blachris-coio-tls/src/test/resources/testroot-cert.pem similarity index 100% rename from gordonmu-coio-tls/src/test/resources/testroot-cert.pem rename to blachris-coio-tls/src/test/resources/testroot-cert.pem diff --git a/gordonmu-coio-tls/src/test/resources/testroot-key.pem b/blachris-coio-tls/src/test/resources/testroot-key.pem similarity index 100% rename from gordonmu-coio-tls/src/test/resources/testroot-key.pem rename to blachris-coio-tls/src/test/resources/testroot-key.pem diff --git a/gordonmu-coio-tls/src/test/resources/testroot-key_pkcs8.pem b/blachris-coio-tls/src/test/resources/testroot-key_pkcs8.pem similarity index 100% rename from gordonmu-coio-tls/src/test/resources/testroot-key_pkcs8.pem rename to blachris-coio-tls/src/test/resources/testroot-key_pkcs8.pem diff --git a/gordonmu-coio-tls/src/test/resources/testserver-cert.pem b/blachris-coio-tls/src/test/resources/testserver-cert.pem similarity index 100% rename from gordonmu-coio-tls/src/test/resources/testserver-cert.pem rename to blachris-coio-tls/src/test/resources/testserver-cert.pem diff --git a/gordonmu-coio-tls/src/test/resources/testserver-key.pem b/blachris-coio-tls/src/test/resources/testserver-key.pem similarity index 100% rename from gordonmu-coio-tls/src/test/resources/testserver-key.pem rename to blachris-coio-tls/src/test/resources/testserver-key.pem diff --git a/gordonmu-coio-tls/src/test/resources/testserver-key_pkcs8.pem b/blachris-coio-tls/src/test/resources/testserver-key_pkcs8.pem similarity index 100% rename from gordonmu-coio-tls/src/test/resources/testserver-key_pkcs8.pem rename to blachris-coio-tls/src/test/resources/testserver-key_pkcs8.pem diff --git a/blachris-coio/build.gradle b/blachris-coio/build.gradle new file mode 100644 index 0000000..7d3d505 --- /dev/null +++ b/blachris-coio/build.gradle @@ -0,0 +1,57 @@ +dependencies { + implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: "$kotlin_version" + implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: "$kotlinxcoroutine_version" + implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-jdk8', version: "$kotlinxcoroutine_version" + implementation group: 'io.github.microutils', name: 'kotlin-logging', version: "$kotlinlogging_version" + implementation group: 'org.slf4j', name: 'slf4j-api', version: "$slf4j_version" + + testImplementation group: 'org.assertj', name: 'assertj-core', version: "$assertj_version" + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "$junit5_version" + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "$junit5_version" + testImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: "$log4jslf4j_version" + testImplementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-test', version: "$kotlinxcoroutine_version" + testImplementation group: 'io.mockk', name: 'mockk', version: "$mockk_version" + testImplementation group: 'org.awaitility', name: 'awaitility', version: "$awaitility_version" + testImplementation group: 'org.awaitility', name: 'awaitility-kotlin', version: "$awaitility_version" +} + +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + artifact sourcesJar { + archiveClassifier.set("sources") + } + artifact javadocJar { + archiveClassifier.set("javadoc") + } + groupId project.group + artifactId project.name + version project.version + pom(commonPom) + pom { + name = 'Kotlin Coroutine IO Library' + description = 'A library for a simple coroutine IO API, wrapping efficient non-blocking Java IO libs for easy use.' + url = 'https://github.com/blachris/coio' + } + } + } + repositories { + maven { + url "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2" + credentials { + if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) { + username = ossrhUsername + password = ossrhPassword + } + } + } + } +} + +if (project.hasProperty('signing.keyId') && project.hasProperty('signing.password') && project.hasProperty('signing.secretKeyRingFile')) { + signing { + sign publishing.publications.mavenJava + } +} + diff --git a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/ByteBufferUtils.kt b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/ByteBufferUtils.kt similarity index 93% rename from gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/ByteBufferUtils.kt rename to blachris-coio/src/main/kotlin/com/github/gordonmu/coio/ByteBufferUtils.kt index f969382..b3c0d50 100644 --- a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/ByteBufferUtils.kt +++ b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/ByteBufferUtils.kt @@ -1,4 +1,4 @@ -package com.github.gordonmu.coio +package com.github.blachris.coio import java.nio.ByteBuffer @@ -27,7 +27,7 @@ inline fun ByteBuffer.withRemainingAtMost(maxRemaining: Long, block: ByteBuf } /** - * Same as [put] but never fails because it only puts as much bytes from [src] as possible into this. + * Same as [ByteBuffer.put] but never fails because it only puts as many bytes from [src] as possible into this. */ fun ByteBuffer.putPossible(src: ByteBuffer) { src.withRemainingAtMost(src.remaining()) { diff --git a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIO.kt b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIO.kt similarity index 99% rename from gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIO.kt rename to blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIO.kt index 19558af..e5f5fb7 100644 --- a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIO.kt +++ b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIO.kt @@ -1,4 +1,4 @@ -package com.github.gordonmu.coio +package com.github.blachris.coio import java.io.IOException import java.net.SocketAddress diff --git a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOChannel.kt b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOChannel.kt similarity index 96% rename from gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOChannel.kt rename to blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOChannel.kt index 9f06b70..2be0c99 100644 --- a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOChannel.kt +++ b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOChannel.kt @@ -1,4 +1,4 @@ -package com.github.gordonmu.coio +package com.github.blachris.coio import kotlinx.coroutines.channels.Channel import java.nio.ByteBuffer diff --git a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOFile.kt b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOFile.kt similarity index 98% rename from gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOFile.kt rename to blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOFile.kt index ec7d86c..ea4f4eb 100644 --- a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOFile.kt +++ b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOFile.kt @@ -1,4 +1,4 @@ -package com.github.gordonmu.coio +package com.github.blachris.coio import java.nio.ByteBuffer import java.nio.channels.AsynchronousFileChannel diff --git a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOMemoryStream.kt b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOMemoryStream.kt similarity index 96% rename from gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOMemoryStream.kt rename to blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOMemoryStream.kt index 22a9f35..f5a17af 100644 --- a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOMemoryStream.kt +++ b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOMemoryStream.kt @@ -1,4 +1,4 @@ -package com.github.gordonmu.coio +package com.github.blachris.coio class CoIOMemoryStream(channelCapacity: Int = 8) : AutoCloseable { val frontToBackChannel = CoIOChannel(channelCapacity) diff --git a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOSelector.kt b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOSelector.kt similarity index 98% rename from gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOSelector.kt rename to blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOSelector.kt index be075d9..ce1ea18 100644 --- a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOSelector.kt +++ b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOSelector.kt @@ -1,4 +1,4 @@ -package com.github.gordonmu.coio +package com.github.blachris.coio import java.nio.channels.ClosedSelectorException import java.nio.channels.SelectableChannel diff --git a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOTcp.kt b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOTcp.kt similarity index 97% rename from gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOTcp.kt rename to blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOTcp.kt index ac02177..b032871 100644 --- a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOTcp.kt +++ b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOTcp.kt @@ -1,9 +1,9 @@ -package com.github.gordonmu.coio +package com.github.blachris.coio import kotlinx.coroutines.CancellableContinuation import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.ReceiveChannel -import kotlinx.coroutines.channels.sendBlocking +import kotlinx.coroutines.runBlocking import kotlinx.coroutines.suspendCancellableCoroutine import mu.KotlinLogging import java.io.IOException @@ -18,13 +18,13 @@ private val logger = KotlinLogging.logger {} object CoIOTcp { /** - * Opens a TCP connection client to a remote host and returns a [CoIORemoteStream]. + * Opens a TCP connection client to a remote host and returns a [RemoteCoIOStream]. */ suspend fun connect(host: String, remotePort: Int): RemoteCoIOStream = CoIO.DEFAULT_COIOSELECTOR.connectTcp(InetSocketAddress(host, remotePort)) /** - * Opens a TCP connection client to a remote host and returns a [CoIORemoteStream]. + * Opens a TCP connection client to a remote host and returns a [RemoteCoIOStream]. */ suspend fun connect(address: InetSocketAddress): RemoteCoIOStream = CoIO.DEFAULT_COIOSELECTOR.connectTcp(address) @@ -70,7 +70,9 @@ fun CoIOSelector.listenTcp(socketAddress: SocketAddress): ReceiveChannel val handler = NioChannelHandler(channel.remoteAddress, channel, channel) registerChannel(channel, SelectionKey.OP_READ or SelectionKey.OP_WRITE, handler) - handlerChannel.sendBlocking(handler) + runBlocking { + handlerChannel.send(handler) + } } registerChannel(serverChannel, SelectionKey.OP_ACCEPT, serverHandler) handlerChannel.invokeOnClose { serverHandler.close() } diff --git a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOUdp.kt b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOUdp.kt similarity index 99% rename from gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOUdp.kt rename to blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOUdp.kt index c5a3718..3279b5e 100644 --- a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOUdp.kt +++ b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIOUdp.kt @@ -1,4 +1,4 @@ -package com.github.gordonmu.coio +package com.github.blachris.coio import kotlinx.coroutines.CancellableContinuation import kotlinx.coroutines.suspendCancellableCoroutine diff --git a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIStreamAdapter.kt b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIStreamAdapter.kt similarity index 98% rename from gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIStreamAdapter.kt rename to blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIStreamAdapter.kt index f70e686..65bbe72 100644 --- a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/CoIStreamAdapter.kt +++ b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/CoIStreamAdapter.kt @@ -1,4 +1,4 @@ -package com.github.gordonmu.coio +package com.github.blachris.coio import kotlinx.coroutines.runBlocking import java.io.IOException diff --git a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/FileCache.kt b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/FileCache.kt similarity index 99% rename from gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/FileCache.kt rename to blachris-coio/src/main/kotlin/com/github/gordonmu/coio/FileCache.kt index 415b38d..c9ed796 100644 --- a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/FileCache.kt +++ b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/FileCache.kt @@ -1,4 +1,4 @@ -package com.github.gordonmu.coio +package com.github.blachris.coio import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock diff --git a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/PathTreeMap.kt b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/PathTreeMap.kt similarity index 99% rename from gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/PathTreeMap.kt rename to blachris-coio/src/main/kotlin/com/github/gordonmu/coio/PathTreeMap.kt index eefb917..2e1d2b4 100644 --- a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/PathTreeMap.kt +++ b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/PathTreeMap.kt @@ -1,4 +1,4 @@ -package com.github.gordonmu.coio +package com.github.blachris.coio import java.util.* diff --git a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/PushbackCoInputStream.kt b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/PushbackCoInputStream.kt similarity index 97% rename from gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/PushbackCoInputStream.kt rename to blachris-coio/src/main/kotlin/com/github/gordonmu/coio/PushbackCoInputStream.kt index 1d979a0..145e69e 100644 --- a/gordonmu-coio/src/main/kotlin/com/github/gordonmu/coio/PushbackCoInputStream.kt +++ b/blachris-coio/src/main/kotlin/com/github/gordonmu/coio/PushbackCoInputStream.kt @@ -1,4 +1,4 @@ -package com.github.gordonmu.coio +package com.github.blachris.coio import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow @@ -129,7 +129,7 @@ class PushbackCoIPort(private val inputPort: CoIPort) : CoIPort { private class ByteBufferSequenceStream(buffers: Collection) : InputStream() { // invariant: all buffers have remaining bytes - private val seq = LinkedList(buffers) + private val seq = LinkedList(buffers) override fun read(): Int { if (seq.isEmpty()) @@ -153,7 +153,7 @@ private class ByteBufferSequenceStream(buffers: Collection) : InputS } } -fun CoIPort.readSeparated(separator: Byte = '\n'.toByte()): Flow = flow { +fun CoIPort.readSeparated(separator: Byte = '\n'.code.toByte()): Flow = flow { val pbport = PushbackCoIPort(this@readSeparated) val res = LinkedList() while (true) { diff --git a/gordonmu-coio/src/test/kotlin/FileTests.kt b/blachris-coio/src/test/kotlin/FileTests.kt similarity index 97% rename from gordonmu-coio/src/test/kotlin/FileTests.kt rename to blachris-coio/src/test/kotlin/FileTests.kt index 7d27e27..52244ba 100644 --- a/gordonmu-coio/src/test/kotlin/FileTests.kt +++ b/blachris-coio/src/test/kotlin/FileTests.kt @@ -1,4 +1,4 @@ -import com.github.gordonmu.coio.* +import com.github.blachris.coio.* import kotlinx.coroutines.flow.count import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat @@ -110,7 +110,7 @@ class FileTests { } assertThat(fc.filesCount).isEqualTo(1) assertThat(fc.bytesCount).isEqualTo(testFileSize) - val h1 = fc.get("xyz", 1000000) { f -> + val h1 = fc.get("xyz", 1000000) { _ -> fail("should not regenerate cached file") } assertThat(fc.filesCount).isEqualTo(1) diff --git a/gordonmu-coio/src/test/kotlin/NioTestServer.kt b/blachris-coio/src/test/kotlin/NioTestServer.kt similarity index 95% rename from gordonmu-coio/src/test/kotlin/NioTestServer.kt rename to blachris-coio/src/test/kotlin/NioTestServer.kt index 423aa68..77ca0d1 100644 --- a/gordonmu-coio/src/test/kotlin/NioTestServer.kt +++ b/blachris-coio/src/test/kotlin/NioTestServer.kt @@ -1,4 +1,4 @@ -import com.github.gordonmu.coio.CoIOTcp +import com.github.blachris.coio.CoIOTcp import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import java.nio.ByteBuffer diff --git a/gordonmu-coio/src/test/kotlin/PathTreeMapTests.kt b/blachris-coio/src/test/kotlin/PathTreeMapTests.kt similarity index 98% rename from gordonmu-coio/src/test/kotlin/PathTreeMapTests.kt rename to blachris-coio/src/test/kotlin/PathTreeMapTests.kt index a789421..fc680ed 100644 --- a/gordonmu-coio/src/test/kotlin/PathTreeMapTests.kt +++ b/blachris-coio/src/test/kotlin/PathTreeMapTests.kt @@ -1,5 +1,5 @@ -import com.github.gordonmu.coio.PathTreeMap -import com.github.gordonmu.coio.subTreeValues +import com.github.blachris.coio.PathTreeMap +import com.github.blachris.coio.subTreeValues import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.* diff --git a/gordonmu-coio/src/test/kotlin/ServerClientTests.kt b/blachris-coio/src/test/kotlin/ServerClientTests.kt similarity index 94% rename from gordonmu-coio/src/test/kotlin/ServerClientTests.kt rename to blachris-coio/src/test/kotlin/ServerClientTests.kt index e69f3c2..c95403e 100644 --- a/gordonmu-coio/src/test/kotlin/ServerClientTests.kt +++ b/blachris-coio/src/test/kotlin/ServerClientTests.kt @@ -1,7 +1,7 @@ -import com.github.gordonmu.coio.CoIOTcp -import com.github.gordonmu.coio.RemoteCoIOStream -import com.github.gordonmu.coio.readFully -import com.github.gordonmu.coio.writeFully +import com.github.blachris.coio.CoIOTcp +import com.github.blachris.coio.RemoteCoIOStream +import com.github.blachris.coio.readFully +import com.github.blachris.coio.writeFully import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout diff --git a/gordonmu-coio/src/test/kotlin/UdpTests.kt b/blachris-coio/src/test/kotlin/UdpTests.kt similarity index 61% rename from gordonmu-coio/src/test/kotlin/UdpTests.kt rename to blachris-coio/src/test/kotlin/UdpTests.kt index c843659..b55b282 100644 --- a/gordonmu-coio/src/test/kotlin/UdpTests.kt +++ b/blachris-coio/src/test/kotlin/UdpTests.kt @@ -1,20 +1,23 @@ -import com.github.gordonmu.coio.CoIOUdp +import com.github.blachris.coio.CoIOUdp import kotlinx.coroutines.* +import kotlinx.coroutines.test.runTest import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import java.nio.ByteBuffer +import kotlin.time.DurationUnit +import kotlin.time.toDuration @TestInstance(TestInstance.Lifecycle.PER_CLASS) class UdpTests { @Test - fun `connectUdp`() { + fun connectUdp() = runTest(timeout = 5000.toDuration(DurationUnit.MILLISECONDS)) { val pointA = CoIOUdp.connect("localhost", 12000, 12001) val pointB = CoIOUdp.connect("localhost", 12001, 12000) - val j1 = GlobalScope.launch { + val j1 = launch { val buf = ByteBuffer.allocate(1024) pointA.write(buf) assertThat(buf.position()).isEqualTo(1024) @@ -23,7 +26,7 @@ class UdpTests { assertThat(buf.position()).isEqualTo(1024) } - val j2 = GlobalScope.launch { + val j2 = launch { val buf = ByteBuffer.allocate(1024) pointB.read(buf) assertThat(buf.position()).isEqualTo(1024) @@ -32,20 +35,16 @@ class UdpTests { assertThat(buf.position()).isEqualTo(1024) } - runBlocking { - withTimeout(5000) { - j1.join() - j2.join() - } - } + j1.join() + j2.join() } @Test @Disabled - fun test() { + fun test() = runTest { val server = CoIOUdp.open(6678) - GlobalScope.launch { + launch { val buf = ByteBuffer.allocate(1024) while (true) { buf.clear() @@ -56,31 +55,27 @@ class UdpTests { } } - runBlocking { - val client = CoIOUdp.connect("localhost", 6678) - - launch { - val buf = ByteBuffer.allocate(1024) - client.read(buf) - println("read ${buf.position()}") - } - - delay(500) + val client = CoIOUdp.connect("localhost", 6678) + launch { val buf = ByteBuffer.allocate(1024) - client.write(buf) - println("written ${buf.position()}") + client.read(buf) + println("read ${buf.position()}") + } - delay(2000) - buf.clear() - client.write(buf) - println("written ${buf.position()}") + delay(500) + val buf = ByteBuffer.allocate(1024) + client.write(buf) + println("written ${buf.position()}") - while (true) { - delay(1000) - } - } + delay(2000) + buf.clear() + client.write(buf) + println("written ${buf.position()}") + while (true) { + delay(1000) + } } } \ No newline at end of file diff --git a/gordonmu-coio/src/test/resources/log4j2.xml b/blachris-coio/src/test/resources/log4j2.xml similarity index 100% rename from gordonmu-coio/src/test/resources/log4j2.xml rename to blachris-coio/src/test/resources/log4j2.xml diff --git a/gordonmu-coio/src/test/resources/testfile.txt b/blachris-coio/src/test/resources/testfile.txt similarity index 100% rename from gordonmu-coio/src/test/resources/testfile.txt rename to blachris-coio/src/test/resources/testfile.txt diff --git a/build.gradle b/build.gradle index 4fd52be..b2e796d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,18 @@ apply plugin: 'idea' -apply plugin: 'maven' +apply plugin: 'maven-publish' buildscript { - ext.kotlin_version = '1.4.20' - ext.kotlinxcoroutine_version = '1.4.2' + ext.kotlin_version = '1.8.22' + ext.kotlinxcoroutine_version = '1.7.3' ext.kotlinlogging_version = '1.8.3' - ext.protobufgradle_version = '0.8.13' + ext.protobufgradle_version = '0.9.4' ext.grpc_version = '1.31.1' - ext.tcnative_version = '2.0.34.Final' + ext.tcnative_version = '2.0.48.Final' ext.jackson_version = '2.9.8' ext.protoc_version = '3.10.0' ext.kroto_version = '0.6.1' - ext.slf4j_version = '1.7.30' - ext.log4jslf4j_version = '2.13.3' + ext.slf4j_version = '1.7.36' + ext.log4jslf4j_version = '2.20.0' ext.junit5_version = '5.6.2' ext.mockk_version = '1.10.0' ext.assertj_version = '3.17.2' @@ -42,17 +42,28 @@ buildscript { } } -ext.pomConfig = { - licenses { - license { - name "The Apache Software License, Version 2.0" - url "http://www.apache.org/licenses/LICENSE-2.0.txt" - distribution "repo" +ext { + commonPom = { + licenses { + license { + name = "The Apache Software License, Version 2.0" + url = "http://www.apache.org/licenses/LICENSE-2.0.txt" + } + } + + scm { + connection = 'scm:git:https://github.com/blachris/coio.git' + developerConnection = 'scm:git:https://github.com/blachris/coio.git' + url = 'https://github.com/blachris/coio' } - } - scm { - url "https://github.com/gordonmu/coio.git" + developers { + developer { + id = 'blachris' + name = 'Gordon Mu' + email = '70778512+blachris@users.noreply.github.com' + } + } } } @@ -61,9 +72,10 @@ allprojects { apply plugin: 'java' apply plugin: 'kotlin' apply plugin: 'maven-publish' + apply plugin: 'signing' - group 'io.github.gordonmu' - version = '0.8.0' + group 'io.github.blachris' + version = '0.9.0' if (!project.hasProperty("release")) { version += '-SNAPSHOT' } diff --git a/gordonmu-coio-tls/build.gradle b/gordonmu-coio-tls/build.gradle deleted file mode 100644 index fdcf55f..0000000 --- a/gordonmu-coio-tls/build.gradle +++ /dev/null @@ -1,100 +0,0 @@ -apply plugin: 'maven' -apply plugin: 'signing' - -dependencies { - implementation project(":gordonmu-coio") - implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: "$kotlin_version" - implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: "$kotlinxcoroutine_version" - implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-jdk8', version: "$kotlinxcoroutine_version" - implementation group: 'io.github.microutils', name: 'kotlin-logging', version: "$kotlinlogging_version" - implementation group: 'org.slf4j', name: 'slf4j-api', version: "$slf4j_version" - implementation group: 'io.netty', name: 'netty-buffer', version: '4.1.52.Final' - implementation group: 'io.netty', name: 'netty-handler', version: '4.1.52.Final' - implementation group: 'com.github.marianobarrios', name: 'tls-channel', version: '0.4.0' - runtime group: 'io.netty', name: 'netty-tcnative-boringssl-static', version: "$tcnative_version" - - testImplementation group: 'org.assertj', name: 'assertj-core', version: "$assertj_version" - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "$junit5_version" - testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "$junit5_version" - testRuntime group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: "$log4jslf4j_version" - testImplementation group: 'io.mockk', name: 'mockk', version: "$mockk_version" - testImplementation group: 'org.awaitility', name: 'awaitility', version: "$awaitility_version" - testImplementation group: 'org.awaitility', name: 'awaitility-kotlin', version: "$awaitility_version" -} - -publishing { - publications { - maven(MavenPublication) { - from components.java - artifact sourcesJar { - classifier "sources" - } - artifact javadocJar { - classifier "javadoc" - } - groupId project.group - artifactId project.name - version project.version - pom.withXml { - def root = asNode() - root.appendNode('description', 'A CoIO extension to use TLS over any CoIOStream.') - root.appendNode('name', 'CoIO TLS Extension') - root.appendNode('url', 'https://github.com/gordonmu/coio') - root.children().last() + pomConfig - } - } - } -} - -if (project.hasProperty('signing.keyId') && project.hasProperty('signing.password') && project.hasProperty('signing.secretKeyRingFile')) { - signing { - sign configurations.archives - } -} - -if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) { - uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - repository(url: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - - snapshotRepository(url: "https://s01.oss.sonatype.org/content/repositories/snapshots/") { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - - pom.project { - name project.name - packaging 'jar' - // optionally artifactId can be defined here - description 'A CoIO extension to use TLS over any CoIOStream.' - url 'https://github.com/gordonmu/coio' - - scm { - connection 'scm:git:https://github.com/gordonmu/coio.git' - developerConnection 'scm:git:https://github.com/gordonmu/coio.git' - url 'https://github.com/gordonmu/coio' - } - - licenses { - license { - name 'The Apache License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - } - } - - developers { - developer { - id 'gordonmu' - name 'Gordon Mu' - email '70778512+gordonmu@users.noreply.github.com' - } - } - } - } - } - } -} diff --git a/gordonmu-coio/build.gradle b/gordonmu-coio/build.gradle deleted file mode 100644 index b9794a2..0000000 --- a/gordonmu-coio/build.gradle +++ /dev/null @@ -1,95 +0,0 @@ -apply plugin: 'maven' -apply plugin: 'signing' - -dependencies { - implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: "$kotlin_version" - implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: "$kotlinxcoroutine_version" - implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-jdk8', version: "$kotlinxcoroutine_version" - implementation group: 'io.github.microutils', name: 'kotlin-logging', version: "$kotlinlogging_version" - implementation group: 'org.slf4j', name: 'slf4j-api', version: "$slf4j_version" - - testImplementation group: 'org.assertj', name: 'assertj-core', version: "$assertj_version" - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "$junit5_version" - testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "$junit5_version" - testRuntime group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: "$log4jslf4j_version" - testImplementation group: 'io.mockk', name: 'mockk', version: "$mockk_version" - testImplementation group: 'org.awaitility', name: 'awaitility', version: "$awaitility_version" - testImplementation group: 'org.awaitility', name: 'awaitility-kotlin', version: "$awaitility_version" -} - -publishing { - publications { - maven(MavenPublication) { - from components.java - artifact sourcesJar { - classifier "sources" - } - artifact javadocJar { - classifier "javadoc" - } - groupId project.group - artifactId project.name - version project.version - pom.withXml { - def root = asNode() - root.appendNode('description', 'A library for a simple coroutine IO API, wrapping efficient non-blocking Java IO libs for easy use.') - root.appendNode('name', 'Kotlin Coroutine IO Library') - root.appendNode('url', 'https://github.com/gordonmu/coio') - root.children().last() + pomConfig - } - } - } -} - -if (project.hasProperty('signing.keyId') && project.hasProperty('signing.password') && project.hasProperty('signing.secretKeyRingFile')) { - signing { - sign configurations.archives - } -} - -if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) { - uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - repository(url: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - - snapshotRepository(url: "https://s01.oss.sonatype.org/content/repositories/snapshots/") { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - - pom.project { - name project.name - packaging 'jar' - // optionally artifactId can be defined here - description 'A library for a simple coroutine IO API, wrapping efficient non-blocking Java IO libs for easy use.' - url 'https://github.com/gordonmu/coio' - - scm { - connection 'scm:git:https://github.com/gordonmu/coio.git' - developerConnection 'scm:git:https://github.com/gordonmu/coio.git' - url 'https://github.com/gordonmu/coio' - } - - licenses { - license { - name 'The Apache License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - } - } - - developers { - developer { - id 'gordonmu' - name 'Gordon Mu' - email '70778512+gordonmu@users.noreply.github.com' - } - } - } - } - } - } -} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b28d97e..62a48dd 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index e3dbfc3..8054168 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,7 +1,7 @@ rootProject.name = 'coio' -include 'gordonmu-coio' -include 'gordonmu-coio-tls' +include 'blachris-coio' +include 'blachris-coio-tls'