Skip to content

Commit

Permalink
Add clone() method to codec builders
Browse files Browse the repository at this point in the history
Motivation:

It is useful to be able to clone the codec builder.

Modifications:

Add clone method for both codec builders

Result:

Fixes #150
  • Loading branch information
normanmaurer committed Feb 2, 2021
1 parent e79636e commit 59797be
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ public QuicClientCodecBuilder() {
super(false);
}

private QuicClientCodecBuilder(QuicCodecBuilder<QuicClientCodecBuilder> builder) {
super(builder);
}

@Override
public QuicClientCodecBuilder clone() {
return new QuicClientCodecBuilder(this);
}

@Override
protected ChannelHandler build(QuicheConfig config,
Function<QuicChannel, ? extends QuicSslEngine> sslEngineProvider,
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/io/netty/incubator/codec/quic/QuicCodecBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,35 @@ public abstract class QuicCodecBuilder<B extends QuicCodecBuilder<B>> {
private QuicCongestionControlAlgorithm congestionControlAlgorithm;
private int localConnIdLength = Quiche.QUICHE_MAX_CONN_ID_LEN;
private Function<QuicChannel, ? extends QuicSslEngine> sslEngineProvider;

QuicCodecBuilder(boolean server) {
Quic.ensureAvailability();
this.server = server;
}

QuicCodecBuilder(QuicCodecBuilder<B> 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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down

0 comments on commit 59797be

Please sign in to comment.