Skip to content

Commit 09b67d7

Browse files
Add websocket to interop client (libp2p#429)
1 parent bd921ba commit 09b67d7

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

interop-test-client/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ The first thing to be able to run the test locally is build the images of each l
1515
being tested. You need to run the following steps for each one of the implementations that you are
1616
planning to run:
1717

18-
1. Checkout the project https://github.com/libp2p.
19-
2. Navigate to test-plans/impl/<IMPL>/<VERSION>; where <IMPL> is the implementation that you want to
18+
1. Checkout the project https://github.com/libp2p/test-plans.
19+
2. Navigate to transport-interop/impl/<IMPL>/<VERSION>; where <IMPL> is the implementation that you want to
2020
build (e.g. `jvm`) and <VERSION> is what version you want (e.g. `v1.2`).
2121
3. Once in the specific version folder run `make` to build the image. This will create a
2222
`image.json` file with the hash of the Docker image built.

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ import io.libp2p.security.noise.NoiseXXSecureChannel
2121
import io.libp2p.security.tls.TlsSecureChannel.Companion.ECDSA
2222
import io.libp2p.transport.quic.QuicTransport
2323
import io.libp2p.transport.tcp.TcpTransport
24+
import io.libp2p.transport.ws.WsTransport
2425
import redis.clients.jedis.Jedis
2526
import java.util.concurrent.CompletableFuture
2627
import java.util.concurrent.TimeUnit
2728
import java.util.stream.Collectors
2829
import kotlin.random.Random
2930
import kotlin.system.exitProcess
3031

32+
const val TCP = "tcp"
33+
const val WS = "ws"
3134
const val QUIC_V1 = "quic-v1"
3235
private const val REDIS_KEY_LISTENER_ADDRESS = "listenerAddr"
3336

@@ -38,12 +41,19 @@ class InteropTestAgent(val params: InteropTestParams) {
3841

3942
init {
4043
val port = 10000 + Random.nextInt(50000)
41-
val isTcp = "tcp" == params.transport
42-
val ip = params.ip
43-
val protocol = if (isTcp) "tcp" else "udp"
44-
val maybeQuicSuffix = (if (isTcp) "" else "/quic-v1")
44+
val transport = params.transport
45+
val protocol = when (transport) {
46+
TCP -> TCP
47+
WS -> TCP
48+
else -> "udp"
49+
}
50+
val maybeSuffix = when (transport) {
51+
TCP -> ""
52+
WS -> "/ws"
53+
else -> "/quic-v1"
54+
}
4555
val address =
46-
Multiaddr.fromString("/ip4/$ip/$protocol/${port}$maybeQuicSuffix")
56+
Multiaddr.fromString("/ip4/${params.ip}/$protocol/${port}$maybeSuffix")
4757

4858
val privateKey = generateEd25519KeyPair().first
4959
val peerID = fromPubKey(privateKey.publicKey())
@@ -73,10 +83,10 @@ class InteropTestAgent(val params: InteropTestParams) {
7383
listenAddresses: ArrayList<String>
7484
): Host = hostJ(Builder.Defaults.None, fn = {
7585
it.identity.factory = { privateKey }
76-
if (params.transport == QUIC_V1) {
77-
it.secureTransports.add(QuicTransport::ECDSA)
78-
} else {
79-
it.transports.add(::TcpTransport)
86+
when (params.transport) {
87+
QUIC_V1 -> it.secureTransports.add(QuicTransport::ECDSA)
88+
WS -> it.transports.add(::WsTransport)
89+
else -> it.transports.add(::TcpTransport)
8090
}
8191

8292
if ("noise" == params.security) {

0 commit comments

Comments
 (0)