Skip to content

Commit

Permalink
Add QuicChannel.applicationProtocol()
Browse files Browse the repository at this point in the history
Motivation:

Add a method to access the application protocol that was negotated

Modifications:

Add method to access the application protocol

Result:

Be able to access the protocol
  • Loading branch information
normanmaurer committed Nov 11, 2020
1 parent de9b87a commit a0e9431
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/c/netty_quic_quiche.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ static jint netty_quic_quiche_conn_close(JNIEnv* env, jclass clazz, jlong conn,
return quiche_conn_close((quiche_conn *) conn, app == JNI_TRUE ? true : false, err, (const uint8_t *) reason, (size_t) reason_len);
}

static jbyteArray netty_quic_quiche_conn_application_proto(JNIEnv* env, jclass clazz, jlong conn) {
const uint8_t *app_proto = NULL;
size_t app_proto_len;

quiche_conn_application_proto((quiche_conn *) conn, &app_proto, &app_proto_len);
if (app_proto == NULL || app_proto_len == 0) {
return NULL;
}
jbyteArray array = (*env)->NewByteArray(env, app_proto_len);
if (array == NULL) {
return NULL;
}
(*env)->SetByteArrayRegion(env,array,0,app_proto_len, (jbyte*) app_proto);
return array;
}


static jboolean netty_quic_quiche_conn_is_established(JNIEnv* env, jclass clazz, jlong conn) {
return quiche_conn_is_established((quiche_conn *) conn) == true ? JNI_TRUE : JNI_FALSE;
}
Expand Down Expand Up @@ -429,6 +446,7 @@ static const JNINativeMethod fixed_method_table[] = {
{ "quiche_conn_stream_shutdown", "(JJIJ)I", (void *) netty_quic_quiche_conn_stream_shutdown },
{ "quiche_conn_stream_capacity", "(JJ)I", (void *) netty_quic_quiche_conn_stream_capacity },
{ "quiche_conn_stream_finished", "(JJ)Z", (void *) netty_quic_quiche_conn_stream_finished },
{ "quiche_conn_application_proto", "(J)[B", (void *) netty_quic_quiche_conn_application_proto },
{ "quiche_conn_close", "(JZJJI)I", (void *) netty_quic_quiche_conn_close },
{ "quiche_conn_is_established", "(J)Z", (void *) netty_quic_quiche_conn_is_established },
{ "quiche_conn_is_in_early_data", "(J)Z", (void *) netty_quic_quiche_conn_is_in_early_data },
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/netty/incubator/codec/quic/QuicChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ public interface QuicChannel extends Channel {
*/
Future<QuicStreamChannel> createStream(QuicStreamAddress address, ChannelHandler handler,
Promise<QuicStreamChannel> promise);

/**
* Returns the negotiated ALPN protocol or {@code null} if non has been negotiated.
*/
byte[] applicationProtocol();
}
7 changes: 7 additions & 0 deletions src/main/java/io/netty/incubator/codec/quic/Quiche.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ static native int quiche_retry(long scidAddr, int scidLen, long dcidAddr, int dc
*/
static native int quiche_conn_close(long connAddr, boolean app, long err, long reasonAddr, int reasonLen);

/**
* See
* <a href="https://github.com/cloudflare/quiche/blob/0.6.0/include/quiche.h#L301">
* quiche_conn_application_proto</a>.
*/
static native byte[] quiche_conn_application_proto(long connAddr);

/**
* See
* <a href="https://github.com/cloudflare/quiche/blob/0.6.0/include/quiche.h#L305">quiche_conn_is_established</a>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ public void run() {
return promise;
}

@Override
public byte[] applicationProtocol() {
if (isConnDestroyed()) {
return null;
}
return Quiche.quiche_conn_application_proto(connAddr);
}

@Override
public String toString() {
String traceId = this.traceId;
Expand Down

0 comments on commit a0e9431

Please sign in to comment.