Skip to content

Commit

Permalink
upgrades and refactored package
Browse files Browse the repository at this point in the history
  • Loading branch information
blachris committed Oct 4, 2023
1 parent 4ffd5b9 commit 6c90d95
Show file tree
Hide file tree
Showing 42 changed files with 231 additions and 302 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.sh text=auto eol=lf
gordonmu-coio/src/test/resources/testfile.txt binary
blachris-coio/src/test/resources/testfile.txt binary
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,4 +21,4 @@ jobs:
if: ${{ failure() }}
with:
name: Test Results
path: gordonmu-coio/build/reports/tests/
path: blachris-coio/build/reports/tests/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
60 changes: 60 additions & 0 deletions blachris-coio-tls/build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -40,7 +40,7 @@ fun CoIOStream.wrapTlsServer(keyCertChain: List<X509Certificate>,
* @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<X509Certificate>): CoIOStream {
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.gordonmu.coio.tls
package com.github.blachris.coio.tls

import java.io.ByteArrayOutputStream
import java.io.IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"),
Expand Down
57 changes: 57 additions & 0 deletions blachris-coio/build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.gordonmu.coio
package com.github.blachris.coio

import java.nio.ByteBuffer

Expand Down Expand Up @@ -27,7 +27,7 @@ inline fun <R> 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()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.gordonmu.coio
package com.github.blachris.coio

import java.io.IOException
import java.net.SocketAddress
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.gordonmu.coio
package com.github.blachris.coio

import kotlinx.coroutines.channels.Channel
import java.nio.ByteBuffer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.gordonmu.coio
package com.github.blachris.coio

import java.nio.ByteBuffer
import java.nio.channels.AsynchronousFileChannel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.gordonmu.coio
package com.github.blachris.coio

class CoIOMemoryStream(channelCapacity: Int = 8) : AutoCloseable {
val frontToBackChannel = CoIOChannel(channelCapacity)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.gordonmu.coio
package com.github.blachris.coio

import java.nio.channels.ClosedSelectorException
import java.nio.channels.SelectableChannel
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -70,7 +70,9 @@ fun CoIOSelector.listenTcp(socketAddress: SocketAddress): ReceiveChannel<RemoteC
serverHandler.onAccept = { channel ->
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() }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.gordonmu.coio
package com.github.blachris.coio

import kotlinx.coroutines.CancellableContinuation
import kotlinx.coroutines.suspendCancellableCoroutine
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.gordonmu.coio
package com.github.blachris.coio

import kotlinx.coroutines.runBlocking
import java.io.IOException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.gordonmu.coio
package com.github.blachris.coio

import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.gordonmu.coio
package com.github.blachris.coio

import java.util.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.gordonmu.coio
package com.github.blachris.coio

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
Expand Down Expand Up @@ -129,7 +129,7 @@ class PushbackCoIPort(private val inputPort: CoIPort) : CoIPort {
private class ByteBufferSequenceStream(buffers: Collection<ByteBuffer>) : InputStream() {

// invariant: all buffers have remaining bytes
private val seq = LinkedList<ByteBuffer>(buffers)
private val seq = LinkedList(buffers)

override fun read(): Int {
if (seq.isEmpty())
Expand All @@ -153,7 +153,7 @@ private class ByteBufferSequenceStream(buffers: Collection<ByteBuffer>) : InputS
}
}

fun CoIPort.readSeparated(separator: Byte = '\n'.toByte()): Flow<InputStream> = flow {
fun CoIPort.readSeparated(separator: Byte = '\n'.code.toByte()): Flow<InputStream> = flow {
val pbport = PushbackCoIPort(this@readSeparated)
val res = LinkedList<ByteBuffer>()
while (true) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit 6c90d95

Please sign in to comment.