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 ) diff --git a/libp2p/src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt b/libp2p/src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt index 570dd69f..8cf242f6 100644 --- a/libp2p/src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt +++ b/libp2p/src/main/kotlin/io/libp2p/multistream/MultistreamImpl.kt @@ -8,14 +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) { preHandler?.also {