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

Commit

Permalink
quic: capture received connection_close details
Browse files Browse the repository at this point in the history
Fixes: #86
PR-URL: #207
Reviewed-By: #207
  • Loading branch information
jasnell authored and addaleax committed Dec 11, 2019
1 parent bfc228e commit a469bc7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/node_quic_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,7 @@ bool QuicSession::Receive(
// If processing the packet puts us into draining period, there's
// absolutely nothing left for us to do except silently close
// and destroy this QuicSession.
GetConnectionCloseInfo();
SilentClose();
return true;
} else {
Expand All @@ -1890,6 +1891,14 @@ bool QuicSession::ReceiveClientInitial(const ngtcp2_cid* dcid) {
initial_connection_close_ == NGTCP2_NO_ERROR;
}

// Captures the error code and family information from a received
// connection close frame.
void QuicSession::GetConnectionCloseInfo() {
ngtcp2_connection_close_error_code close_code;
ngtcp2_conn_get_connection_close_error_code(Connection(), &close_code);
SetLastError(QuicError(close_code));
}

bool QuicSession::ReceivePacket(
ngtcp2_path* path,
const uint8_t* data,
Expand Down
1 change: 1 addition & 0 deletions src/node_quic_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ class QuicSession : public AsyncWrap,
void ExtendMaxStreamsRemoteUni(uint64_t max_streams);
void ExtendMaxStreamsRemoteBidi(uint64_t max_streams);
int GetNewConnectionID(ngtcp2_cid* cid, uint8_t* token, size_t cidlen);
void GetConnectionCloseInfo();
void HandshakeCompleted();
void PathValidation(
const ngtcp2_path* path,
Expand Down
15 changes: 15 additions & 0 deletions src/node_quic_util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ QuicError::QuicError(
}
}

QuicError::QuicError(ngtcp2_connection_close_error_code ccec) :
code(ccec.error_code), family(QUIC_ERROR_SESSION) {
switch (ccec.type) {
case NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION:
family = QUIC_ERROR_APPLICATION;
break;
case NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT:
if (code & NGTCP2_CRYPTO_ERROR)
family = QUIC_ERROR_CRYPTO;
break;
default:
UNREACHABLE();
}
}

QuicError::QuicError(
Environment* env,
v8::Local<v8::Value> codeArg,
Expand Down
1 change: 1 addition & 0 deletions src/node_quic_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct QuicError {
inline QuicError(
int32_t family_ = QUIC_ERROR_SESSION,
uint64_t code_ = NGTCP2_NO_ERROR);
inline QuicError(ngtcp2_connection_close_error_code code);
inline QuicError(
Environment* env,
v8::Local<v8::Value> codeArg,
Expand Down

0 comments on commit a469bc7

Please sign in to comment.