GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allow to set destination connection id when creating a client side Qu… · netty/netty@81d6b47

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-classes-quic/src/main/java/io/netty/handler/codec/quic
    • QuicChannelBootstrap.java
    • Quiche.java
    • QuicheNativeStaticallyReferencedJniMethods.java
    • QuicheQuicChannel.java
  • codec-native-quic
    • pom.xml
    • src/main/c
      • netty_quic_quiche.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicChannelBootstrap.java‎

Copy file name to clipboardExpand all lines: codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicChannelBootstrap.java
+32-4Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public final class QuicChannelBootstrap {
5050

5151
private SocketAddress local;
5252
private SocketAddress remote;
53-
private QuicConnectionAddress connectionAddress = QuicConnectionAddress.EPHEMERAL;
53+
private QuicConnectionAddress localAddress = QuicConnectionAddress.EPHEMERAL;
54+
private QuicConnectionAddress remoteAddress = QuicConnectionAddress.EPHEMERAL;
5455
private ChannelHandler handler;
5556
private ChannelHandler streamHandler;
5657

@@ -178,9 +179,35 @@ public QuicChannelBootstrap remoteAddress(SocketAddress remote) {
178179
*
179180
* @param connectionAddress the {@link QuicConnectionAddress} to use.
180181
* @return this instance.
182+
* @deprecated use {@link #localConnectionAddress(QuicConnectionAddress)}.
181183
*/
184+
@Deprecated
182185
public QuicChannelBootstrap connectionAddress(QuicConnectionAddress connectionAddress) {
183-
this.connectionAddress = ObjectUtil.checkNotNull(connectionAddress, "connectionAddress");
186+
this.localAddress = ObjectUtil.checkNotNull(connectionAddress, "connectionAddress");
187+
return this;
188+
}
189+
190+
/**
191+
* Set the {@link QuicConnectionAddress} to use. If none is specified a random address is generated on your
192+
* behalf.
193+
*
194+
* @param localConnectionAddress the {@link QuicConnectionAddress} to use.
195+
* @return this instance.
196+
*/
197+
public QuicChannelBootstrap localConnectionAddress(QuicConnectionAddress localConnectionAddress) {
198+
this.localAddress = ObjectUtil.checkNotNull(localConnectionAddress, "localConnectionAddress");
199+
return this;
200+
}
201+
202+
/**
203+
* Set the {@link QuicConnectionAddress} to use. If none is specified a random address is generated on your
204+
* behalf.
205+
*
206+
* @param remoteConnectionAddress the {@link QuicConnectionAddress} to use.
207+
* @return this instance.
208+
*/
209+
public QuicChannelBootstrap remoteConnectionAddress(QuicConnectionAddress remoteConnectionAddress) {
210+
this.remoteAddress = ObjectUtil.checkNotNull(remoteConnectionAddress, "remoteConnectionAddress");
184211
return this;
185212
}
186213

@@ -220,7 +247,8 @@ public Future<QuicChannel> connect(Promise<QuicChannel> promise) {
220247
throw new IllegalStateException("remote not set");
221248
}
222249

223-
final QuicConnectionAddress address = connectionAddress;
250+
final QuicConnectionAddress localaddress = localAddress;
251+
final QuicConnectionAddress remoteaddress = remoteAddress;
224252
QuicChannel channel = QuicheQuicChannel.forClient(parent, (InetSocketAddress) local,
225253
(InetSocketAddress) remote,
226254
streamHandler, Quic.toOptionsArray(streamOptions), Quic.toAttributesArray(streamAttrs));
@@ -232,7 +260,7 @@ public Future<QuicChannel> connect(Promise<QuicChannel> promise) {
232260
if (cause != null) {
233261
promise.setFailure(cause);
234262
} else {
235-
channel.connect(address).addListener(f -> {
263+
channel.connect(remoteaddress, localaddress).addListener(f -> {
236264
Throwable error = f.cause();
237265
if (error != null) {
238266
promise.setFailure(error);
Collapse file

‎codec-classes-quic/src/main/java/io/netty/handler/codec/quic/Quiche.java‎

Copy file name to clipboardExpand all lines: codec-classes-quic/src/main/java/io/netty/handler/codec/quic/Quiche.java
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ private static void loadNativeLibrary() {
279279
static final int QUICHE_ERR_CRYPTO_BUFFER_EXCEEDED =
280280
QuicheNativeStaticallyReferencedJniMethods.quiche_err_crypto_buffer_exceeded();
281281

282+
static final int QUICHE_ERR_INVALID_DCID_INITIALIZATION =
283+
QuicheNativeStaticallyReferencedJniMethods.quiche_err_invalid_dcid_initialization();
284+
282285
/**
283286
* See <a href="https://github.com/cloudflare/quiche/blob/0.6.0/include/quiche.h#L176">
284287
* QUICHE_CC_RENO</a>.
@@ -340,6 +343,11 @@ static native long quiche_conn_new_with_tls(long scidAddr, int scidLen, long odc
340343
long peerAddr, int peerLen,
341344
long configAddr, long ssl, boolean isServer);
342345

346+
static native long quiche_conn_new_with_tls_and_client_dcid(long scidAddr, int scidLen, long odcidAddr,
347+
int odcidLen, long localAddr, int localLen,
348+
long peerAddr, int peerLen,
349+
long configAddr, long ssl);
350+
343351
/**
344352
* See <a href="https://github.com/cloudflare/quiche/blob/master/include/quiche.h#L248">
345353
* quiche_conn_set_qlog_path</a>.
@@ -903,6 +911,8 @@ static long getPrimitiveValue(ByteBuffer memory, int offset, int valueType) {
903911
new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_STREAM_STOPPED"));
904912
ERROR_MAPPINGS.put(QUICHE_ERR_OUT_OF_IDENTIFIERS,
905913
new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_OUT_OF_IDENTIFIERS"));
914+
ERROR_MAPPINGS.put(QUICHE_ERR_INVALID_DCID_INITIALIZATION, new QuicTransportErrorHolder(
915+
QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_INVALID_DCID_INITIALIZATION"));
906916
}
907917

908918
static Exception convertToException(int result) {
Collapse file

‎codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicheNativeStaticallyReferencedJniMethods.java‎

Copy file name to clipboardExpand all lines: codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicheNativeStaticallyReferencedJniMethods.java
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ final class QuicheNativeStaticallyReferencedJniMethods {
4242
static native int quiche_err_out_of_identifiers();
4343
static native int quiche_err_key_update();
4444
static native int quiche_err_crypto_buffer_exceeded();
45+
static native int quiche_err_invalid_dcid_initialization();
4546
static native int quiche_cc_reno();
4647
static native int quiche_cc_cubic();
4748
static native int quiche_cc_bbr();
Collapse file

‎codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicheQuicChannel.java‎

Copy file name to clipboardExpand all lines: codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicheQuicChannel.java
+44-16Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ public void operationComplete(ChannelFuture future) {
145145
private ByteBuf outErrorCodeBuffer;
146146
private ChannelPromise connectPromise;
147147
private ScheduledFuture<?> connectTimeoutFuture;
148-
private QuicConnectionAddress connectAddress;
148+
private QuicConnectionAddress connectLocalAddress;
149+
private QuicConnectionAddress connectRemoteAddress;
149150
private CloseData closeData;
150151
private QuicConnectionCloseEvent connectionCloseEvent;
151152
private QuicConnectionStats statsAtClose;
@@ -338,17 +339,19 @@ void connectNow(Function<QuicChannel, ? extends QuicSslEngine> engineProvider, E
338339
this.sslTaskExecutor = sslTaskExecutor;
339340
this.freeTask = freeTask;
340341

341-
QuicConnectionAddress address = this.connectAddress;
342+
QuicConnectionAddress connectLocalAddress = this.connectLocalAddress;
342343

343-
if (address == QuicConnectionAddress.EPHEMERAL) {
344-
address = QuicConnectionAddress.random(localConnIdLength);
344+
if (connectLocalAddress == QuicConnectionAddress.EPHEMERAL) {
345+
connectLocalAddress = QuicConnectionAddress.random(localConnIdLength);
345346
}
346-
ByteBuffer connectId = address.id();
347-
if (connectId.remaining() != localConnIdLength) {
347+
ByteBuffer localConnectId = connectLocalAddress.id();
348+
if (localConnectId.remaining() != localConnIdLength) {
348349
failConnectPromiseAndThrow(new IllegalArgumentException("connectionAddress has length "
349-
+ connectId.remaining()
350+
+ localConnectId.remaining()
350351
+ " instead of " + localConnIdLength));
351352
}
353+
QuicConnectionAddress connectRemoteAddress = this.connectRemoteAddress;
354+
352355
QuicSslEngine engine = engineProvider.apply(this);
353356
if (!(engine instanceof QuicheQuicSslEngine)) {
354357
failConnectPromiseAndThrow(new IllegalArgumentException("QuicSslEngine is not of type "
@@ -359,16 +362,37 @@ void connectNow(Function<QuicChannel, ? extends QuicSslEngine> engineProvider, E
359362
failConnectPromiseAndThrow(new IllegalArgumentException("QuicSslEngine is not create in client mode"));
360363
}
361364
QuicheQuicSslEngine quicheEngine = (QuicheQuicSslEngine) engine;
362-
ByteBuf idBuffer = alloc().directBuffer(connectId.remaining()).writeBytes(connectId.duplicate());
365+
ByteBuf localIdBuffer = alloc().directBuffer(localConnectId.remaining()).writeBytes(localConnectId.duplicate());
366+
ByteBuf remoteIdBuffer;
367+
if (connectRemoteAddress != QuicConnectionAddress.EPHEMERAL) {
368+
ByteBuffer remoteId = connectRemoteAddress.id();
369+
remoteIdBuffer = alloc().directBuffer(remoteId.remaining()).writeBytes(remoteId.duplicate());
370+
} else {
371+
remoteIdBuffer = null;
372+
}
363373
try {
364374
int fromSockaddrLen = SockaddrIn.setAddress(fromSockaddrMemory, local);
365375
int toSockaddrLen = SockaddrIn.setAddress(toSockaddrMemory, remote);
366-
QuicheQuicConnection connection = quicheEngine.createConnection(ssl ->
367-
Quiche.quiche_conn_new_with_tls(Quiche.readerMemoryAddress(idBuffer),
368-
idBuffer.readableBytes(), -1, -1,
376+
QuicheQuicConnection connection = quicheEngine.createConnection(ssl -> {
377+
long localIdMemoryAddress = Quiche.readerMemoryAddress(localIdBuffer);
378+
int localIdLength = localIdBuffer.readableBytes();
379+
380+
final long remoteIdMemoryAddress;
381+
final int remoteIdLength;
382+
if (remoteIdBuffer == null) {
383+
return Quiche.quiche_conn_new_with_tls(localIdMemoryAddress, localIdLength,
384+
-1, -1,
369385
Quiche.memoryAddressWithPosition(fromSockaddrMemory), fromSockaddrLen,
370386
Quiche.memoryAddressWithPosition(toSockaddrMemory), toSockaddrLen,
371-
configAddr, ssl, false));
387+
configAddr, ssl, false);
388+
} else {
389+
return Quiche.quiche_conn_new_with_tls_and_client_dcid(localIdMemoryAddress, localIdLength,
390+
Quiche.readerMemoryAddress(remoteIdBuffer), remoteIdBuffer.readableBytes(),
391+
Quiche.memoryAddressWithPosition(fromSockaddrMemory), fromSockaddrLen,
392+
Quiche.memoryAddressWithPosition(toSockaddrMemory), toSockaddrLen,
393+
configAddr, ssl);
394+
}
395+
});
372396
if (connection == null) {
373397
failConnectPromiseAndThrow(new ConnectException());
374398
return;
@@ -383,9 +407,12 @@ void connectNow(Function<QuicChannel, ? extends QuicSslEngine> engineProvider, E
383407
}
384408
}
385409
this.supportsDatagram = supportsDatagram;
386-
sourceConnectionIds.add(connectId);
410+
sourceConnectionIds.add(localConnectId);
387411
} finally {
388-
idBuffer.release();
412+
localIdBuffer.release();
413+
if (remoteIdBuffer != null) {
414+
remoteIdBuffer.release();
415+
}
389416
}
390417
}
391418

@@ -1543,7 +1570,8 @@ public void connect(SocketAddress remote, SocketAddress local, ChannelPromise ch
15431570
return;
15441571
}
15451572

1546-
connectAddress = (QuicConnectionAddress) remote;
1573+
connectLocalAddress = (QuicConnectionAddress) local;
1574+
connectRemoteAddress = (QuicConnectionAddress) remote;
15471575
connectPromise = channelPromise;
15481576

15491577
// Schedule connect timeout.
@@ -1553,7 +1581,7 @@ public void connect(SocketAddress remote, SocketAddress local, ChannelPromise ch
15531581
ChannelPromise connectPromise = QuicheQuicChannel.this.connectPromise;
15541582
if (connectPromise != null && !connectPromise.isDone()
15551583
&& connectPromise.tryFailure(new ConnectTimeoutException(
1556-
"connection timed out: " + remote))) {
1584+
"connection timed out: " + local + " -> " + remote))) {
15571585
close(voidPromise());
15581586
}
15591587
}, connectTimeoutMillis, TimeUnit.MILLISECONDS);
Collapse file

‎codec-native-quic/pom.xml‎

Copy file name to clipboardExpand all lines: codec-native-quic/pom.xml
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<quicheHomeIncludeDir>${quicheHomeDir}/quiche/include</quicheHomeIncludeDir>
6161
<quicheRepository>https://github.com/cloudflare/quiche</quicheRepository>
6262
<quicheBranch>master</quicheBranch>
63-
<quicheCommitSha>c9d3e85f0f2acda30acbe186033bf534faeba7f3</quicheCommitSha>
63+
<quicheCommitSha>4f347477006bf7f928335d28f05056013f70b87e</quicheCommitSha>
6464
<generatedSourcesDir>${project.build.directory}/generated-sources</generatedSourcesDir>
6565
<templateDir>${project.build.directory}/template</templateDir>
6666
<cargoTarget />
@@ -820,7 +820,7 @@
820820
<equals arg1="${platform}" arg2="android" />
821821
<then>
822822
<exec executable="cargo" failonerror="true" dir="${quicheSourceDir}" resolveexecutable="true">
823-
<arg line="ndk ${cargoTarget} --platform ${androidNdkVersion} -- build -p quiche --features &quot;ffi qlog&quot; --release" />
823+
<arg line="ndk ${cargoTarget} --platform ${androidNdkVersion} -- build -p quiche --features &quot;ffi qlog custom-client-dcid&quot; --release" />
824824
<env key="CFLAGS" value="${extraCflags}" />
825825
<env key="CXXFLAGS" value="${extraCxxflags}" />
826826
<env key="QUICHE_BSSL_PATH" value="${boringsslHomeDir}/" />
@@ -831,7 +831,7 @@
831831
<equals arg1="${os.detected.name}" arg2="windows" />
832832
<then>
833833
<exec executable="cargo" failonerror="true" dir="${quicheSourceDir}" resolveexecutable="true">
834-
<arg line="build -p quiche --features &quot;ffi qlog&quot; --release" />
834+
<arg line="build -p quiche --features &quot;ffi qlog custom-client-dcid&quot; --release" />
835835
<arg value="${cargoTarget}" />
836836
<!-- See https://github.com/cloudflare/quiche/blob/0.7.0/src/build.rs#L73 -->
837837
<env key="DEBUG" value="true" />
@@ -843,7 +843,7 @@
843843
<equals arg1="${crossCompile}" arg2="linux" />
844844
<then>
845845
<exec executable="cargo" failonerror="true" dir="${quicheSourceDir}" resolveexecutable="true">
846-
<arg line="build -p quiche --features &quot;ffi qlog&quot; --release" />
846+
<arg line="build -p quiche --features &quot;ffi qlog custom-client-dcid&quot; --release" />
847847
<arg value="${cargoTarget}" />
848848
<env key="QUICHE_BSSL_PATH" value="${boringsslHomeDir}/" />
849849
<!-- Lets enable frame-pointers so we can profile better -->
@@ -856,7 +856,7 @@
856856
<equals arg1="${crossCompile}" arg2="mac" />
857857
<then>
858858
<exec executable="cargo" failonerror="true" dir="${quicheSourceDir}" resolveexecutable="true">
859-
<arg line="build -p quiche --features &quot;ffi qlog&quot; --release" />
859+
<arg line="build -p quiche --features &quot;ffi qlog custom-client-dcid&quot; --release" />
860860
<env key="CFLAGS" value="${extraCflags}" />
861861
<env key="CXXFLAGS" value="${extraCxxflags}" />
862862
<arg value="${cargoTarget}" />
@@ -869,7 +869,7 @@
869869
</elseif>
870870
<else>
871871
<exec executable="cargo" failonerror="true" dir="${quicheSourceDir}" resolveexecutable="true">
872-
<arg line="build -p quiche --features &quot;ffi qlog&quot; --release" />
872+
<arg line="build -p quiche --features &quot;ffi qlog custom-client-dcid&quot; --release" />
873873
<env key="CFLAGS" value="${extraCflags}" />
874874
<env key="CXXFLAGS" value="${extraCxxflags}" />
875875
<env key="QUICHE_BSSL_PATH" value="${boringsslHomeDir}/" />
Collapse file

‎codec-native-quic/src/main/c/netty_quic_quiche.c‎

Copy file name to clipboardExpand all lines: codec-native-quic/src/main/c/netty_quic_quiche.c
+25-1Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ static jint netty_quiche_err_crypto_buffer_exceeded(JNIEnv* env, jclass clazz) {
311311
return QUICHE_ERR_CRYPTO_BUFFER_EXCEEDED;
312312
}
313313

314+
static jint netty_quiche_err_invalid_dcid_initialization(JNIEnv* env, jclass clazz) {
315+
return QUICHE_ERR_INVALID_DCID_INITIALIZATION;
316+
}
317+
314318
static jint netty_quiche_cc_reno(JNIEnv* env, jclass clazz) {
315319
return QUICHE_CC_RENO;
316320
}
@@ -320,7 +324,7 @@ static jint netty_quiche_cc_cubic(JNIEnv* env, jclass clazz) {
320324
}
321325

322326
static jint netty_quiche_cc_bbr(JNIEnv* env, jclass clazz) {
323-
return QUICHE_CC_BBR;
327+
return QUICHE_CC_BBR2_GCONGESTION;
324328
}
325329

326330
static jint netty_quiche_path_event_type_new(JNIEnv* env, jclass clazz) {
@@ -402,6 +406,24 @@ static jlong netty_quiche_conn_new_with_tls(JNIEnv* env, jclass clazz, jlong sci
402406
return (jlong) conn;
403407
}
404408

409+
static jlong netty_quiche_conn_new_with_tls_and_client_dcid(JNIEnv* env, jclass clazz, jlong scid, jint scid_len, jlong odcid, jint odcid_len, jlong local, jint local_len, jlong peer, jint peer_len, jlong config, jlong ssl) {
410+
const uint8_t * odcid_pointer = NULL;
411+
if (odcid_len != -1) {
412+
odcid_pointer = (const uint8_t *) odcid;
413+
}
414+
const struct sockaddr *local_pointer = (const struct sockaddr*) local;
415+
const struct sockaddr *peer_pointer = (const struct sockaddr*) peer;
416+
quiche_conn *conn = quiche_conn_new_with_tls_and_client_dcid((const uint8_t *) scid, (size_t) scid_len,
417+
odcid_pointer, (size_t) odcid_len,
418+
local_pointer, (socklen_t) local_len,
419+
peer_pointer, (socklen_t) peer_len,
420+
(quiche_config *) config, (void*) ssl);
421+
if (conn == NULL) {
422+
return -1;
423+
}
424+
return (jlong) conn;
425+
}
426+
405427
static jbyteArray to_byte_array(JNIEnv* env, const uint8_t* bytes, size_t len) {
406428
if (bytes == NULL || len == 0) {
407429
return NULL;
@@ -1155,6 +1177,7 @@ static const JNINativeMethod statically_referenced_fixed_method_table[] = {
11551177
{ "quiche_err_out_of_identifiers", "()I", (void *) netty_quiche_err_out_of_identifiers },
11561178
{ "quiche_err_key_update", "()I", (void *) netty_quiche_err_key_update },
11571179
{ "quiche_err_crypto_buffer_exceeded", "()I", (void *) netty_quiche_err_crypto_buffer_exceeded },
1180+
{ "quiche_err_invalid_dcid_initialization", "()I", (void *) netty_quiche_err_invalid_dcid_initialization },
11581181
{ "quiche_cc_reno", "()I", (void *) netty_quiche_cc_reno },
11591182
{ "quiche_cc_cubic", "()I", (void *) netty_quiche_cc_cubic },
11601183
{ "quiche_cc_bbr", "()I", (void *) netty_quiche_cc_bbr },
@@ -1178,6 +1201,7 @@ static const JNINativeMethod fixed_method_table[] = {
11781201
{ "quiche_conn_source_id", "(J)[B", (void *) netty_quiche_conn_source_id },
11791202
{ "quiche_conn_destination_id", "(J)[B", (void *) netty_quiche_conn_destination_id },
11801203
{ "quiche_conn_new_with_tls", "(JIJIJIJIJJZ)J", (void *) netty_quiche_conn_new_with_tls },
1204+
{ "quiche_conn_new_with_tls_and_client_dcid", "(JIJIJIJIJJ)J", (void *) netty_quiche_conn_new_with_tls_and_client_dcid },
11811205
{ "quiche_conn_recv", "(JJIJ)I", (void *) netty_quiche_conn_recv },
11821206
{ "quiche_conn_send", "(JJIJ)I", (void *) netty_quiche_conn_send },
11831207
{ "quiche_conn_free", "(J)V", (void *) netty_quiche_conn_free },

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.