Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 7d5277f

Browse files
committed
quic: capture received connection_close details
Fixes: #86
1 parent 16932e3 commit 7d5277f

4 files changed

+26
-0
lines changed

src/node_quic_session.cc

+9
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,7 @@ bool QuicSession::Receive(
18681868
// If processing the packet puts us into draining period, there's
18691869
// absolutely nothing left for us to do except silently close
18701870
// and destroy this QuicSession.
1871+
GetConnectionCloseInfo();
18711872
SilentClose();
18721873
return true;
18731874
} else {
@@ -1893,6 +1894,14 @@ bool QuicSession::ReceiveClientInitial(const ngtcp2_cid* dcid) {
18931894
initial_connection_close_ == NGTCP2_NO_ERROR;
18941895
}
18951896

1897+
// Captures the error code and family information from a received
1898+
// connection close frame.
1899+
void QuicSession::GetConnectionCloseInfo() {
1900+
ngtcp2_connection_close_error_code close_code;
1901+
ngtcp2_conn_get_connection_close_error_code(Connection(), &close_code);
1902+
SetLastError(QuicError(close_code));
1903+
}
1904+
18961905
bool QuicSession::ReceivePacket(
18971906
ngtcp2_path* path,
18981907
const uint8_t* data,

src/node_quic_session.h

+1
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ class QuicSession : public AsyncWrap,
925925
void ExtendMaxStreamsRemoteUni(uint64_t max_streams);
926926
void ExtendMaxStreamsRemoteBidi(uint64_t max_streams);
927927
int GetNewConnectionID(ngtcp2_cid* cid, uint8_t* token, size_t cidlen);
928+
void GetConnectionCloseInfo();
928929
void HandshakeCompleted();
929930
void PathValidation(
930931
const ngtcp2_path* path,

src/node_quic_util-inl.h

+15
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,21 @@ QuicError::QuicError(
185185
}
186186
}
187187

188+
QuicError::QuicError(ngtcp2_connection_close_error_code ccec) :
189+
code(ccec.error_code), family(QUIC_ERROR_SESSION) {
190+
switch (ccec.type) {
191+
case NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION:
192+
family = QUIC_ERROR_APPLICATION;
193+
break;
194+
case NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT:
195+
if (code & NGTCP2_CRYPTO_ERROR)
196+
family = QUIC_ERROR_CRYPTO;
197+
break;
198+
default:
199+
UNREACHABLE();
200+
}
201+
}
202+
188203
QuicError::QuicError(
189204
Environment* env,
190205
v8::Local<v8::Value> codeArg,

src/node_quic_util.h

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct QuicError {
8585
inline QuicError(
8686
int32_t family_ = QUIC_ERROR_SESSION,
8787
uint64_t code_ = NGTCP2_NO_ERROR);
88+
inline QuicError(ngtcp2_connection_close_error_code code);
8889
inline QuicError(
8990
Environment* env,
9091
v8::Local<v8::Value> codeArg,

0 commit comments

Comments
 (0)