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

Commit a469bc7

Browse files
jasnelladdaleax
authored andcommitted
quic: capture received connection_close details
Fixes: #86 PR-URL: #207 Reviewed-By: #207
1 parent bfc228e commit a469bc7

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/node_quic_session.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,7 @@ bool QuicSession::Receive(
18651865
// If processing the packet puts us into draining period, there's
18661866
// absolutely nothing left for us to do except silently close
18671867
// and destroy this QuicSession.
1868+
GetConnectionCloseInfo();
18681869
SilentClose();
18691870
return true;
18701871
} else {
@@ -1890,6 +1891,14 @@ bool QuicSession::ReceiveClientInitial(const ngtcp2_cid* dcid) {
18901891
initial_connection_close_ == NGTCP2_NO_ERROR;
18911892
}
18921893

1894+
// Captures the error code and family information from a received
1895+
// connection close frame.
1896+
void QuicSession::GetConnectionCloseInfo() {
1897+
ngtcp2_connection_close_error_code close_code;
1898+
ngtcp2_conn_get_connection_close_error_code(Connection(), &close_code);
1899+
SetLastError(QuicError(close_code));
1900+
}
1901+
18931902
bool QuicSession::ReceivePacket(
18941903
ngtcp2_path* path,
18951904
const uint8_t* data,

src/node_quic_session.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ class QuicSession : public AsyncWrap,
938938
void ExtendMaxStreamsRemoteUni(uint64_t max_streams);
939939
void ExtendMaxStreamsRemoteBidi(uint64_t max_streams);
940940
int GetNewConnectionID(ngtcp2_cid* cid, uint8_t* token, size_t cidlen);
941+
void GetConnectionCloseInfo();
941942
void HandshakeCompleted();
942943
void PathValidation(
943944
const ngtcp2_path* path,

src/node_quic_util-inl.h

Lines changed: 15 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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)