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

Commit

Permalink
quic: linting fixups
Browse files Browse the repository at this point in the history
PR-URL: #31
  • Loading branch information
jasnell committed Aug 19, 2019
1 parent 8b5549a commit 63545c5
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 48 deletions.
5 changes: 5 additions & 0 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,11 @@ compiled with ICU support.

A given value is out of the accepted range.

<a id="ERR_QUIC_ERROR"></a>
### ERR_QUIC_ERROR

TBD

<a id="ERR_QUICCLIENTSESSION_FAILED"></a>
### ERR_QUICCLIENTSESSION_FAILED

Expand Down
38 changes: 19 additions & 19 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,25 @@ E('ERR_OUT_OF_RANGE',
msg += ` It must be ${range}. Received ${received}`;
return msg;
}, RangeError);
E('ERR_QUICCLIENTSESSION_FAILED',
'Failed to create a new QuicClientSession: %s', Error);
E('ERR_QUICCLIENTSESSION_FAILED_SETSOCKET',
'Failed to set the QuicSocket: %d', Error);
E('ERR_QUICSESSION_DESTROYED',
'Cannot call %s after a QuicSession has been destroyed', Error);
E('ERR_QUICSESSION_INVALID_DCID', 'Invalid DCID value: %s', Error);
E('ERR_QUICSESSION_UNABLE_TO_MIGRATE',
'The QuicClientSession is currently unable to be migrated to a ' +
'different QuicSocket',
Error);
E('ERR_QUICSOCKET_CLOSING',
'Cannot call %s while a QuicSocket is closing', Error);
E('ERR_QUICSOCKET_DESTROYED',
'Cannot call %s after a QuicSocket has been destroyed', Error);
E('ERR_QUICSOCKET_LISTENING',
'This QuicSocket is already listening', Error);
E('ERR_QUICSOCKET_UNBOUND',
'Cannot call %s before a QuicSocket has been bound', Error);
E('ERR_QUIC_ERROR', function(code, family) {
const {
constants: {
Expand All @@ -1126,25 +1145,6 @@ E('ERR_QUIC_ERROR', function(code, family) {
}
return `QUIC session closed with ${familyType} error code ${code}`;
}, Error);
E('ERR_QUICCLIENTSESSION_FAILED',
'Failed to create a new QuicClientSession: %s', Error);
E('ERR_QUICCLIENTSESSION_FAILED_SETSOCKET',
'Failed to set the QuicSocket: %d', Error);
E('ERR_QUICSESSION_DESTROYED',
'Cannot call %s after a QuicSession has been destroyed', Error);
E('ERR_QUICSESSION_INVALID_DCID', 'Invalid DCID value: %s', Error);
E('ERR_QUICSESSION_UNABLE_TO_MIGRATE',
'The QuicClientSession is currently unable to be migrated to a ' +
'different QuicSocket',
Error);
E('ERR_QUICSOCKET_CLOSING',
'Cannot call %s while a QuicSocket is closing', Error);
E('ERR_QUICSOCKET_DESTROYED',
'Cannot call %s after a QuicSocket has been destroyed', Error);
E('ERR_QUICSOCKET_LISTENING',
'This QuicSocket is already listening', Error);
E('ERR_QUICSOCKET_UNBOUND',
'Cannot call %s before a QuicSocket has been bound', Error);
E('ERR_QUIC_TLS13_REQUIRED', 'QUIC requires TLS version 1.3', Error);
E('ERR_REQUIRE_ESM', 'Must use import to load ES Module: %s', Error);
E('ERR_SCRIPT_EXECUTION_INTERRUPTED',
Expand Down
28 changes: 15 additions & 13 deletions lib/internal/quic/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
assertCrypto();

const { Error } = primordials;
const { Buffer } = require('buffer');
const { isArrayBufferView } = require('internal/util/types');
const {
getAllowUnauthorized,
Expand Down Expand Up @@ -61,6 +62,7 @@ const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_CALLBACK,
ERR_QUIC_ERROR,
ERR_QUICSESSION_DESTROYED,
ERR_QUICSOCKET_CLOSING,
ERR_QUICSOCKET_DESTROYED,
Expand Down Expand Up @@ -526,8 +528,8 @@ function onRemoveListener(event) {
this[kHandle].state[IDX_QUIC_SESSION_STATE_CLIENT_HELLO_ENABLED] = 0;
break;
case 'OCSPRequest':
this[kHandle].state[IDX_QUIC_SESSION_STATE_CERT_ENABLED] = 0;
break;
this[kHandle].state[IDX_QUIC_SESSION_STATE_CERT_ENABLED] = 0;
break;
}
}

Expand Down Expand Up @@ -1147,7 +1149,7 @@ class QuicSession extends EventEmitter {

if (typeof error === 'number' ||
(error != null &&
typeof error === 'Object' &&
typeof error === 'object' &&
!(error instanceof Error))) {
const {
closeCode,
Expand Down Expand Up @@ -1276,7 +1278,7 @@ class QuicServerSession extends QuicSession {
}

[kClientHello](alpn, servername, ciphers, callback) {
this.emit(
this.emit(
'clientHello',
alpn,
servername,
Expand Down Expand Up @@ -1374,8 +1376,10 @@ class QuicClientSession extends QuicSession {
this.#preferredAddressPolicy = preferredAddressPolicy;
this.#remoteTransportParams = remoteTransportParams;
this.#requestOCSP = requestOCSP;
this.#secureContext = createSecureContext(sc_options,
initSecureContextClient);
this.#secureContext =
createSecureContext(
sc_options,
initSecureContextClient);
this.#sessionTicket = sessionTicket;
this.#transportParams =
validateTransportParams(
Expand Down Expand Up @@ -1553,14 +1557,12 @@ class QuicStream extends Duplex {
// Close the writable side
this.end();
}
} else if (this.serverInitiated) {
// Close the writable side
this.end();
} else {
if (this.serverInitiated) {
// Close the writable side
this.end();
} else {
this.push(null);
this.read();
}
this.push(null);
this.read();
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/quic/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const {
IDX_QUIC_SESSION_MAX_PACKET_SIZE_DEFAULT,
MAX_RETRYTOKEN_EXPIRATION,
MIN_RETRYTOKEN_EXPIRATION,
NGTCP2_NO_ERROR,
NGTCP2_DEFAULT_MAX_ACK_DELAY,
NGTCP2_MAX_CIDLEN,
NGTCP2_MIN_CIDLEN,
Expand Down Expand Up @@ -92,7 +93,7 @@ function validateCloseCode(code) {
closeCode = code;
closeFamily = QUIC_ERROR_APPLICATION;
} else {
throw new ERR_INVALID_ARG_TYPE('code', ['number', 'Object'], code)
throw new ERR_INVALID_ARG_TYPE('code', ['number', 'Object'], code);
}
return {
closeCode,
Expand Down
6 changes: 3 additions & 3 deletions src/node_quic_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ inline void MessageCB(
}
}

inline std::string ToHex(const uint8_t *s, size_t len) {
inline std::string ToHex(const uint8_t* s, size_t len) {
static constexpr char LOWER_XDIGITS[] = "0123456789abcdef";
std::string res;
res.resize(len * 2);
Expand All @@ -909,9 +909,9 @@ inline std::string ToHex(const uint8_t *s, size_t len) {
}

inline void LogSecret(
SSL *ssl,
SSL* ssl,
int name,
const unsigned char *secret,
const unsigned char* secret,
size_t secretlen) {
if (auto keylog_cb = SSL_CTX_get_keylog_callback(SSL_get_SSL_CTX(ssl))) {
unsigned char crandom[32];
Expand Down
10 changes: 4 additions & 6 deletions src/node_quic_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ using crypto::SecureContext;

using v8::Array;
using v8::ArrayBufferView;
using v8::Boolean;
using v8::Context;
using v8::Float64Array;
using v8::Function;
Expand Down Expand Up @@ -1822,9 +1821,9 @@ int QuicSession::TLSHandshake() {
CHECK(!IsDestroyed());
Debug(this, "TLS handshake %s", initial_ ? "starting" : "continuing");

if (initial_)
if (initial_) {
session_stats_.handshake_start_at = uv_hrtime();
else {
} else {
// TODO(@jasnell): Check handshake_continue_at to guard against slow
// handshake attack
}
Expand Down Expand Up @@ -2091,7 +2090,6 @@ int QuicServerSession::OnClientHello() {
arraysize(argv), argv);

OPENSSL_free(exts);
//return 0;
return client_hello_cb_running_ ? -1 : 0;
}

Expand Down Expand Up @@ -3036,9 +3034,9 @@ int QuicClientSession::OnTLSStatus() {
int len = SSL_get_tlsext_status_ocsp_resp(ssl(), &resp);
Debug(this, "An OCSP Response of %d bytes has been received.", len);
Local<Value> arg;
if (resp == nullptr)
if (resp == nullptr) {
arg = Undefined(env()->isolate());
else {
} else {
arg = Buffer::Copy(env(), reinterpret_cast<const char*>(resp), len)
.ToLocalChecked();
}
Expand Down
10 changes: 6 additions & 4 deletions src/node_quic_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,12 @@ void QuicSocketListen(const FunctionCallbackInfo<Value>& args) {
alpn += *val;
}

bool reject_unauthorized = args[5]->IsTrue();
bool request_cert = args[6]->IsTrue();

socket->Listen(sc, preferred_address, alpn, reject_unauthorized, request_cert);
socket->Listen(
sc,
preferred_address,
alpn,
args[5]->IsTrue(), // reject_unauthorized
args[6]->IsTrue()); // request_cert
}

void QuicSocketReceiveStart(const FunctionCallbackInfo<Value>& args) {
Expand Down
2 changes: 1 addition & 1 deletion src/node_quic_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void QuicStream::ReceiveData(int fin, const uint8_t* data, size_t datalen) {
inbound_consumed_data_while_paused_ += avail;
else
session_->ExtendStreamOffset(this, avail);
};
}

// When fin != 0, we've received that last chunk of data for this
// stream, indicating that the stream is no longer readable.
Expand Down
6 changes: 5 additions & 1 deletion test/parallel/test-quic-client-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ server.on('session', common.mustCall((session) => {
// TODO(@jasnell): Using setImmediate here causes the test
// to fail, but it shouldn't. Investigate why.
process.nextTick(() => {
// The first argument is a potential error
// The second is an optional new SecureContext
// The third is the ocsp response.
// All arguments are optional
cb(null, null, Buffer.from('hello'));
});
}));
}));

session.on('keylog', common.mustCall((line) => {
assert(kKeylogs.shift().test(line));
Expand Down

0 comments on commit 63545c5

Please sign in to comment.