Skip to content

Commit 8104b86

Browse files
Add quic to interop client (#425)
1 parent 8aa477d commit 8104b86

File tree

5 files changed

+36
-31
lines changed

5 files changed

+36
-31
lines changed

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM openjdk:11-jdk AS build
2+
COPY . /jvm-libp2p
3+
WORKDIR /jvm-libp2p
4+
RUN ./gradlew build -x test --no-daemon
5+
6+
FROM openjdk:11-jdk
7+
WORKDIR /jvm-libp2p
8+
COPY --from=build /jvm-libp2p/interop-test-client/build/distributions/interop-test-client*.tar .
9+
RUN tar -xf interop-test-client*.tar && rm interop-test-client*.tar
10+
11+
ENTRYPOINT ["/jvm-libp2p/interop-test-client-develop/bin/interop-test-client"]
12+
EXPOSE 4001
Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
1+
import org.jetbrains.kotlin.cli.jvm.compiler.findMainClass
2+
13
plugins {
2-
id("java")
3-
id("com.bmuschko.docker-java-application") version "9.4.0"
4+
id("application")
5+
id("kotlin")
6+
}
7+
8+
application {
9+
mainClass = "io.libp2p.interop.InteropTestAgentKt"
410
}
511

612
dependencies {
713
implementation(project(":libp2p"))
814
implementation("redis.clients:jedis:6.1.0")
915
runtimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl")
1016
}
11-
12-
docker {
13-
javaApplication {
14-
baseImage.set("openjdk:11-jdk")
15-
ports.set(listOf(4041))
16-
}
17-
}
18-
19-
val composeFileSpec: CopySpec = copySpec {
20-
from("src/test/resources")
21-
include("compose.yaml")
22-
}
23-
24-
val copyAssets = tasks.register<Copy>("copyAssets") {
25-
into(layout.buildDirectory.dir("docker"))
26-
with(composeFileSpec)
27-
}
28-
29-
tasks.dockerCreateDockerfile {
30-
dependsOn(copyAssets)
31-
}

interop-test-client/src/main/kotlin/io/libp2p/interop/InteropTestAgent.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import java.util.stream.Collectors
2828
import kotlin.random.Random
2929
import kotlin.system.exitProcess
3030

31+
const val QUIC_V1 = "quic-v1"
3132
private const val REDIS_KEY_LISTENER_ADDRESS = "listenerAddr"
3233

3334
class InteropTestAgent(val params: InteropTestParams) {
@@ -59,7 +60,7 @@ class InteropTestAgent(val params: InteropTestParams) {
5960
.thenCompose { startJedisConnection() }
6061
.thenCompose { jedis ->
6162
if (params.isDialer) {
62-
startDialer(jedis, node)
63+
startDialer(jedis, node, advertisedAddress)
6364
} else {
6465
startListener(jedis, advertisedAddress)
6566
}
@@ -72,7 +73,7 @@ class InteropTestAgent(val params: InteropTestParams) {
7273
listenAddresses: ArrayList<String>
7374
): Host = hostJ(Builder.Defaults.None, fn = {
7475
it.identity.factory = { privateKey }
75-
if (params.transport == "quic-v1") {
76+
if (params.transport == QUIC_V1) {
7677
it.secureTransports.add(QuicTransport::ECDSA)
7778
} else {
7879
it.transports.add(::TcpTransport)
@@ -135,9 +136,13 @@ class InteropTestAgent(val params: InteropTestParams) {
135136
/*
136137
Start dialer and try to connect with a listener
137138
*/
138-
private fun startDialer(jedis: Jedis, node: Host): CompletableFuture<Void> {
139+
private fun startDialer(
140+
jedis: Jedis,
141+
node: Host,
142+
advertisedAddress: Multiaddr
143+
): CompletableFuture<Void> {
139144
return CompletableFuture.supplyAsync {
140-
printDiagnosticsLog("Starting dialer")
145+
printDiagnosticsLog("Starting dialer with advertisedAddress: $advertisedAddress")
141146

142147
val listenerAddresses =
143148
jedis.blpop(params.testTimeoutInSeconds, REDIS_KEY_LISTENER_ADDRESS)
@@ -175,7 +180,7 @@ class InteropTestAgent(val params: InteropTestParams) {
175180
advertisedAddress: Multiaddr
176181
): CompletableFuture<Void> {
177182
return CompletableFuture.supplyAsync {
178-
println("Starting listener with advertisedAddress: $advertisedAddress")
183+
printDiagnosticsLog("Starting listener with advertisedAddress: $advertisedAddress")
179184

180185
jedis.rpush(REDIS_KEY_LISTENER_ADDRESS, advertisedAddress.toString())
181186

@@ -222,7 +227,6 @@ private fun printDiagnosticsLog(msg: String) {
222227
System.err.println(msg)
223228
}
224229

225-
@SuppressWarnings("unused")
226230
fun main() {
227231
try {
228232
val params = InteropTestParams.Builder().fromEnvironmentVariables().build()

interop-test-client/src/main/kotlin/io/libp2p/interop/InteropTestParams.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ class InteropTestParams(
3535
fun build(): InteropTestParams {
3636
checkNonEmptyParam("transport", transport)
3737
checkNonEmptyParam("muxer", muxer)
38-
checkNonEmptyParam("security", security)
39-
checkNonEmptyParam("redis_addr", security)
38+
if (transport != QUIC_V1) {
39+
checkNonEmptyParam("security", security)
40+
}
41+
checkNonEmptyParam("redis_addr", redisAddress)
4042

4143
if (ip == null || ip!!.isBlank()) {
4244
ip = "0.0.0.0"

interop-test-client/src/test/resources/compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ services:
2424
depends_on:
2525
redis:
2626
condition: service_started
27+
listener:
28+
condition: service_started
2729
redis:
2830
image: "redis:7-alpine"
2931
ports:

0 commit comments

Comments
 (0)