Skip to content

Commit

Permalink
Merge pull request #13 from Nashatyrev/fix/add-protocol-on-fly
Browse files Browse the repository at this point in the history
Fixes for PR #299
  • Loading branch information
ianopolous authored Aug 18, 2023
2 parents 4d4198a + d20d7df commit efd43c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 4 additions & 2 deletions libp2p/src/main/kotlin/io/libp2p/core/dsl/Builders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<StreamMuxer>) -> SecureChannel
Expand Down Expand Up @@ -173,7 +174,8 @@ open class Builder {
}
}

val muxers = muxers.map { it.createMuxer(streamMultistreamProtocol, protocols.values) }
val updatableProtocols: MutableList<ProtocolBinding<Any>> = CopyOnWriteArrayList(protocols.values)
val muxers = muxers.map { it.createMuxer(streamMultistreamProtocol, updatableProtocols) }

val secureChannels = secureChannels.values.map { it(privKey, muxers) }

Expand Down Expand Up @@ -201,7 +203,7 @@ open class Builder {
networkImpl,
addressBook,
network.listen.map { Multiaddr(it) },
protocols.values,
updatableProtocols,
broadcastConnHandler,
streamVisitors
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import java.time.Duration
import java.util.concurrent.CompletableFuture

class MultistreamImpl<TController>(
initList: List<ProtocolBinding<TController>> = listOf(),
override val bindings: List<ProtocolBinding<TController>>,
val preHandler: P2PChannelHandler<*>? = null,
val postHandler: P2PChannelHandler<*>? = null,
val negotiationTimeLimit: Duration = DEFAULT_NEGOTIATION_TIME_LIMIT
) : Multistream<TController> {

override val bindings: List<ProtocolBinding<TController>> = initList

override fun initChannel(ch: P2PChannel): CompletableFuture<TController> {
return with(ch) {
preHandler?.also {
Expand Down

0 comments on commit efd43c4

Please sign in to comment.