From 9f84efafe27df36a73facd28eca43f1f56f8e6e4 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 18 Aug 2023 16:51:57 +0400 Subject: [PATCH 1/3] Inline bindings --- .../src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libp2p/src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt b/libp2p/src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt index 570dd69f..7c4cf164 100644 --- a/libp2p/src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt +++ b/libp2p/src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt @@ -8,13 +8,12 @@ import java.time.Duration import java.util.concurrent.CompletableFuture class MultistreamImpl( - initList: List> = listOf(), + override val bindings: List>, val preHandler: P2PChannelHandler<*>? = null, val postHandler: P2PChannelHandler<*>? = null, val negotiationTimeLimit: Duration = DEFAULT_NEGOTIATION_TIME_LIMIT ) : Multistream { - override val bindings: List> = initList override fun initChannel(ch: P2PChannel): CompletableFuture { return with(ch) { From 1a5b0753e40f6fbaf96d231e582b083bcef86bbd Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 18 Aug 2023 16:52:30 +0400 Subject: [PATCH 2/3] Make a thread-safe shared MutableList for Host and Muxers --- libp2p/src/main/kotlin/io/libp2p/core/dsl/Builders.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libp2p/src/main/kotlin/io/libp2p/core/dsl/Builders.kt b/libp2p/src/main/kotlin/io/libp2p/core/dsl/Builders.kt index 5482b5e8..67dd02fc 100644 --- a/libp2p/src/main/kotlin/io/libp2p/core/dsl/Builders.kt +++ b/libp2p/src/main/kotlin/io/libp2p/core/dsl/Builders.kt @@ -33,6 +33,7 @@ import io.libp2p.transport.tcp.TcpTransport import io.netty.channel.ChannelHandler import io.netty.handler.logging.LogLevel import io.netty.handler.logging.LoggingHandler +import java.util.concurrent.CopyOnWriteArrayList typealias TransportCtor = (ConnectionUpgrader) -> Transport typealias SecureChannelCtor = (PrivKey, List) -> SecureChannel @@ -173,7 +174,8 @@ open class Builder { } } - val muxers = muxers.map { it.createMuxer(streamMultistreamProtocol, protocols.values) } + val updatableProtocols: MutableList> = CopyOnWriteArrayList(protocols.values) + val muxers = muxers.map { it.createMuxer(streamMultistreamProtocol, updatableProtocols) } val secureChannels = secureChannels.values.map { it(privKey, muxers) } @@ -201,7 +203,7 @@ open class Builder { networkImpl, addressBook, network.listen.map { Multiaddr(it) }, - protocols.values, + updatableProtocols, broadcastConnHandler, streamVisitors ) From d20d7df92654b61c44adb014776c2409e7bf0e4d Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 18 Aug 2023 17:01:22 +0400 Subject: [PATCH 3/3] Format --- libp2p/src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/libp2p/src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt b/libp2p/src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt index 7c4cf164..8cf242f6 100644 --- a/libp2p/src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt +++ b/libp2p/src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt @@ -14,7 +14,6 @@ class MultistreamImpl( val negotiationTimeLimit: Duration = DEFAULT_NEGOTIATION_TIME_LIMIT ) : Multistream { - override fun initChannel(ch: P2PChannel): CompletableFuture { return with(ch) { preHandler?.also {