From 59797bef8ac941255627c3f6b589402c7ed9b3be Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 2 Feb 2021 18:45:58 +0100 Subject: [PATCH] Add clone() method to codec builders Motivation: It is useful to be able to clone the codec builder. Modifications: Add clone method for both codec builders Result: Fixes https://github.com/netty/netty-incubator-codec-quic/issues/150 --- .../codec/quic/QuicClientCodecBuilder.java | 9 ++++++ .../codec/quic/QuicCodecBuilder.java | 31 +++++++++++++++++++ .../codec/quic/QuicServerCodecBuilder.java | 17 ++++++++++ 3 files changed, 57 insertions(+) diff --git a/src/main/java/io/netty/incubator/codec/quic/QuicClientCodecBuilder.java b/src/main/java/io/netty/incubator/codec/quic/QuicClientCodecBuilder.java index c8904160..deecad03 100644 --- a/src/main/java/io/netty/incubator/codec/quic/QuicClientCodecBuilder.java +++ b/src/main/java/io/netty/incubator/codec/quic/QuicClientCodecBuilder.java @@ -32,6 +32,15 @@ public QuicClientCodecBuilder() { super(false); } + private QuicClientCodecBuilder(QuicCodecBuilder builder) { + super(builder); + } + + @Override + public QuicClientCodecBuilder clone() { + return new QuicClientCodecBuilder(this); + } + @Override protected ChannelHandler build(QuicheConfig config, Function sslEngineProvider, diff --git a/src/main/java/io/netty/incubator/codec/quic/QuicCodecBuilder.java b/src/main/java/io/netty/incubator/codec/quic/QuicCodecBuilder.java index 5650e29f..0cba53f0 100644 --- a/src/main/java/io/netty/incubator/codec/quic/QuicCodecBuilder.java +++ b/src/main/java/io/netty/incubator/codec/quic/QuicCodecBuilder.java @@ -49,11 +49,35 @@ public abstract class QuicCodecBuilder> { private QuicCongestionControlAlgorithm congestionControlAlgorithm; private int localConnIdLength = Quiche.QUICHE_MAX_CONN_ID_LEN; private Function sslEngineProvider; + QuicCodecBuilder(boolean server) { Quic.ensureAvailability(); this.server = server; } + QuicCodecBuilder(QuicCodecBuilder builder) { + Quic.ensureAvailability(); + this.server = builder.server; + this.grease = builder.grease; + this.earlyData = builder.earlyData; + this.maxIdleTimeout = builder.maxIdleTimeout; + this.maxRecvUdpPayloadSize = builder.maxRecvUdpPayloadSize; + this.maxSendUdpPayloadSize = builder.maxSendUdpPayloadSize; + this.initialMaxData = builder.initialMaxData; + this.initialMaxStreamDataBidiLocal = builder.initialMaxStreamDataBidiLocal; + this.initialMaxStreamDataBidiRemote = builder.initialMaxStreamDataBidiRemote; + this.initialMaxStreamDataUni = builder.initialMaxStreamDataUni; + this.initialMaxStreamsBidi = builder.initialMaxStreamsBidi; + this.initialMaxStreamsUni = builder.initialMaxStreamsUni; + this.ackDelayExponent = builder.ackDelayExponent; + this.maxAckDelay = builder.maxAckDelay; + this.disableActiveMigration = builder.disableActiveMigration; + this.enableHystart = builder.enableHystart; + this.congestionControlAlgorithm = builder.congestionControlAlgorithm; + this.localConnIdLength = builder.localConnIdLength; + this.sslEngineProvider = builder.sslEngineProvider; + } + /** * Returns itself. * @@ -390,6 +414,13 @@ public final ChannelHandler build() { } } + /** + * Clone the builder + * + * @return the new instance that is a clone if this instance. + */ + public abstract B clone(); + /** * Builds the QUIC codec. * diff --git a/src/main/java/io/netty/incubator/codec/quic/QuicServerCodecBuilder.java b/src/main/java/io/netty/incubator/codec/quic/QuicServerCodecBuilder.java index d0b3de96..81468ab0 100644 --- a/src/main/java/io/netty/incubator/codec/quic/QuicServerCodecBuilder.java +++ b/src/main/java/io/netty/incubator/codec/quic/QuicServerCodecBuilder.java @@ -48,6 +48,23 @@ public QuicServerCodecBuilder() { super(true); } + private QuicServerCodecBuilder(QuicServerCodecBuilder builder) { + super(builder); + options.putAll(builder.options); + attrs.putAll(builder.attrs); + streamOptions.putAll(builder.streamOptions); + streamAttrs.putAll(builder.streamAttrs); + handler = builder.handler; + streamHandler = builder.streamHandler; + connectionIdAddressGenerator = builder.connectionIdAddressGenerator; + tokenHandler = builder.tokenHandler; + } + + @Override + public QuicServerCodecBuilder clone() { + return new QuicServerCodecBuilder(this); + } + /** * Allow to specify a {@link ChannelOption} which is used for the {@link QuicChannel} instances once they got * created. Use a value of {@code null} to remove a previous set {@link ChannelOption}.