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 — Fine-grained Quiche exception (#44) · chrisvest/netty@47dbc63

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/main/java/io/netty/incubator/codec/quic
    • QuicError.java
    • Quiche.java
    • QuicheException.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/main/java/io/netty/incubator/codec/quic/QuicError.java‎

Copy file name to clipboard
+75Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2020 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
package io.netty.incubator.codec.quic;
17+
18+
import io.netty.util.collection.IntObjectHashMap;
19+
import io.netty.util.collection.IntObjectMap;
20+
21+
/**
22+
* All QUIC error codes identified by Quiche.
23+
* See <a href="https://github.com/cloudflare/quiche/blob/0.6.0/src/lib.rs#L335-L380">Error</a>
24+
*/
25+
public enum QuicError {
26+
UNKNOWN_VERSION(Quiche.QUICHE_ERR_UNKNOWN_VERSION, "QUICHE_ERR_UNKNOWN_VERSION"),
27+
INVALID_FRAME(Quiche.QUICHE_ERR_INVALID_FRAME, "QUICHE_ERR_INVALID_FRAME"),
28+
INVALID_PACKET(Quiche.QUICHE_ERR_INVALID_PACKET, "QUICHE_ERR_INVALID_PACKET"),
29+
INVALID_STATE(Quiche.QUICHE_ERR_INVALID_STATE, "QUICHE_ERR_INVALID_STATE"),
30+
INVALID_STREAM_STATE(Quiche.QUICHE_ERR_INVALID_STREAM_STATE, "QUICHE_ERR_INVALID_STREAM_STATE"),
31+
INVALID_TRANSPORT_PARAM(Quiche.QUICHE_ERR_INVALID_TRANSPORT_PARAM, "QUICHE_ERR_INVALID_TRANSPORT_PARAM"),
32+
CRYPTO_FAIL(Quiche.QUICHE_ERR_CRYPTO_FAIL, "QUICHE_ERR_CRYPTO_FAIL"),
33+
TLS_FAIL(Quiche.QUICHE_ERR_TLS_FAIL, "QUICHE_ERR_TLS_FAIL"),
34+
FLOW_CONTROL(Quiche.QUICHE_ERR_FLOW_CONTROL, "QUICHE_ERR_FLOW_CONTROL"),
35+
STREAM_LIMIT(Quiche.QUICHE_ERR_STREAM_LIMIT, "QUICHE_ERR_STREAM_LIMIT"),
36+
FINAL_SIZE(Quiche.QUICHE_ERR_FINAL_SIZE, "QUICHE_ERR_FINAL_SIZE"),
37+
CONGESTION_CONTROL(Quiche.QUICHE_ERR_CONGESTION_CONTROL, "QUICHE_ERR_CONGESTION_CONTROL");
38+
39+
private static final IntObjectMap<QuicError> ERROR_MAP = new IntObjectHashMap<>();
40+
41+
static {
42+
for (QuicError errorCode : QuicError.values()) {
43+
ERROR_MAP.put(errorCode.code(), errorCode);
44+
}
45+
}
46+
47+
private final int code;
48+
private final String message;
49+
50+
QuicError(int code, String message) {
51+
this.code = code;
52+
this.message = message;
53+
}
54+
55+
final int code() {
56+
return code;
57+
}
58+
59+
final String message() {
60+
return message;
61+
}
62+
63+
@Override
64+
public final String toString() {
65+
return String.format("QuicError{code=%d, message=%s}", code, message);
66+
}
67+
68+
static QuicError valueOf(int code) {
69+
final QuicError errorCode = ERROR_MAP.get(code);
70+
if (errorCode == null) {
71+
throw new IllegalArgumentException("unknown " + QuicError.class.getSimpleName() + " code: " + code);
72+
}
73+
return errorCode;
74+
}
75+
}
Collapse file

‎src/main/java/io/netty/incubator/codec/quic/Quiche.java‎

Copy file name to clipboardExpand all lines: src/main/java/io/netty/incubator/codec/quic/Quiche.java
+8-24Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@
2828

2929
import javax.net.ssl.SSLException;
3030
import javax.net.ssl.SSLHandshakeException;
31-
import java.io.IOException;
3231

3332
final class Quiche {
3433
private static final InternalLogger logger = InternalLoggerFactory.getInstance(Quiche.class);
35-
private static final IntObjectMap<String> ERROR_MAP = new IntObjectHashMap<>();
3634
private static final boolean DEBUG_LOGGING_ENABLED = logger.isDebugEnabled();
3735

3836
static {
@@ -512,36 +510,22 @@ static native int quiche_retry(long scidAddr, int scidLen, long dcidAddr, int dc
512510
*/
513511
private static native void quiche_enable_debug_logging(QuicheLogger logger);
514512

515-
static {
516-
ERROR_MAP.put(QUICHE_ERR_DONE, "QUICHE_ERR_DONE");
517-
ERROR_MAP.put(QUICHE_ERR_BUFFER_TOO_SHORT, "QUICHE_ERR_BUFFER_TOO_SHORT");
518-
ERROR_MAP.put(QUICHE_ERR_UNKNOWN_VERSION, "QUICHE_ERR_UNKNOWN_VERSION");
519-
ERROR_MAP.put(QUICHE_ERR_INVALID_FRAME, "QUICHE_ERR_INVALID_FRAME");
520-
ERROR_MAP.put(QUICHE_ERR_INVALID_PACKET, "QUICHE_ERR_INVALID_PACKET");
521-
ERROR_MAP.put(QUICHE_ERR_INVALID_STATE, "QUICHE_ERR_INVALID_STATE");
522-
ERROR_MAP.put(QUICHE_ERR_INVALID_STREAM_STATE, "QUICHE_ERR_INVALID_STREAM_STATE");
523-
ERROR_MAP.put(QUICHE_ERR_INVALID_TRANSPORT_PARAM, "QUICHE_ERR_INVALID_TRANSPORT_PARAM");
524-
ERROR_MAP.put(QUICHE_ERR_CRYPTO_FAIL, "QUICHE_ERR_CRYPTO_FAIL");
525-
ERROR_MAP.put(QUICHE_ERR_TLS_FAIL, "QUICHE_ERR_TLS_FAIL");
526-
ERROR_MAP.put(QUICHE_ERR_FLOW_CONTROL, "QUICHE_ERR_FLOW_CONTROL");
527-
ERROR_MAP.put(QUICHE_ERR_STREAM_LIMIT, "QUICHE_ERR_STREAM_LIMIT");
528-
ERROR_MAP.put(QUICHE_ERR_FINAL_SIZE, "QUICHE_ERR_FINAL_SIZE");
529-
ERROR_MAP.put(QUICHE_ERR_CONGESTION_CONTROL, "QUICHE_ERR_CONGESTION_CONTROL");
530-
}
531-
532513
static String errorAsString(int err) {
533-
return ERROR_MAP.get(err);
514+
return QuicError.valueOf(err).message();
534515
}
535516

536517
static Exception newException(int err) {
537-
String errStr = errorAsString(err);
518+
final QuicError error = QuicError.valueOf(err);
519+
final QuicheException reason = new QuicheException(error);
538520
if (err == QUICHE_ERR_TLS_FAIL) {
539-
return new SSLHandshakeException(errStr);
521+
final SSLHandshakeException sslExc = new SSLHandshakeException(error.message());
522+
sslExc.initCause(reason);
523+
return sslExc;
540524
}
541525
if (err == QUICHE_ERR_CRYPTO_FAIL) {
542-
return new SSLException(errStr);
526+
return new SSLException(error.message(), reason);
543527
}
544-
return new IOException(errStr);
528+
return reason;
545529
}
546530

547531
static boolean throwIfError(int res) throws Exception {
Collapse file

‎src/main/java/io/netty/incubator/codec/quic/QuicheException.java‎

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2020 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
package io.netty.incubator.codec.quic;
17+
18+
import java.io.IOException;
19+
20+
public final class QuicheException extends IOException {
21+
22+
private final QuicError error;
23+
24+
QuicheException(QuicError error) {
25+
super(error.message());
26+
this.error = error;
27+
}
28+
29+
public QuicError error() {
30+
return error;
31+
}
32+
}

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.