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

Commit

Permalink
quic: additional suggested updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Dec 4, 2019
1 parent 58a1cd2 commit 89cad7e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
29 changes: 13 additions & 16 deletions src/node_quic_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void QuicSessionListener::OnOCSP(const std::string& ocsp) {
void QuicSessionListener::OnStreamHeaders(
int64_t stream_id,
int kind,
std::vector<std::unique_ptr<QuicHeader>>* headers) {
const std::vector<std::unique_ptr<QuicHeader>>& headers) {
if (previous_listener_ != nullptr)
previous_listener_->OnStreamHeaders(stream_id, kind, headers);
}
Expand Down Expand Up @@ -375,29 +375,25 @@ void JSQuicSessionListener::OnCert(const char* server_name) {
void JSQuicSessionListener::OnStreamHeaders(
int64_t stream_id,
int kind,
std::vector<std::unique_ptr<QuicHeader>>* headers) {
const std::vector<std::unique_ptr<QuicHeader>>& headers) {
Environment* env = Session()->env();
HandleScope scope(env->isolate());
Context::Scope context_scope(env->context());
std::vector<Local<Value>> head;
for (const auto& header : *headers) {
MaybeStackBuffer<Local<Value>, 16> head(headers.size());
size_t n = 0;
for (const auto& header : headers) {
// name and value should never be empty here, and if
// they are, there's an actual bug so go ahead and crash
Local<Value> pair[] = {
header->GetName(Session()->Application()).ToLocalChecked(),
header->GetValue(Session()->Application()).ToLocalChecked()
};
head.push_back(Array::New(env->isolate(), pair, arraysize(pair)));
head[n++] = Array::New(env->isolate(), pair, arraysize(pair));
}
Local<Value> argv[] = {
Number::New(env->isolate(), static_cast<double>(stream_id)),
Array::New(
env->isolate(),
head.data(),
head.size()),
Integer::New(
env->isolate(),
kind)
Array::New(env->isolate(), head.out(), n),
Integer::New(env->isolate(), kind)
};
BaseObjectPtr<QuicSession> ptr(Session());
Session()->MakeCallback(
Expand Down Expand Up @@ -641,16 +637,17 @@ void JSQuicSessionListener::OnVersionNegotiation(
Local<Context> context = env->context();
Context::Scope context_scope(context);

std::vector<Local<Value>> versions;
MaybeStackBuffer<Local<Value>, 4> versions(vcnt);
for (size_t n = 0; n < vcnt; n++)
versions.push_back(Integer::New(env->isolate(), vers[n]));
versions[n] = Integer::New(env->isolate(), vers[n]);


Local<Value> supported =
Integer::New(env->isolate(), supported_version);

Local<Value> argv[] = {
Integer::New(env->isolate(), NGTCP2_PROTO_VER),
Array::New(env->isolate(), versions.data(), vcnt),
Array::New(env->isolate(), versions.out(), vcnt),
Array::New(env->isolate(), &supported, 1)
};

Expand Down Expand Up @@ -1110,7 +1107,7 @@ void QuicCryptoContext::WriteHandshake(
void QuicApplication::StreamHeaders(
int64_t stream_id,
int kind,
std::vector<std::unique_ptr<QuicHeader>>* headers) {
const std::vector<std::unique_ptr<QuicHeader>>& headers) {
Session()->Listener()->OnStreamHeaders(stream_id, kind, headers);
}

Expand Down
6 changes: 3 additions & 3 deletions src/node_quic_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class QuicSessionListener {
virtual void OnStreamHeaders(
int64_t stream_id,
int kind,
std::vector<std::unique_ptr<QuicHeader>>* headers);
const std::vector<std::unique_ptr<QuicHeader>>& headers);
virtual void OnStreamClose(
int64_t stream_id,
uint64_t app_error_code);
Expand Down Expand Up @@ -256,7 +256,7 @@ class JSQuicSessionListener : public QuicSessionListener {
void OnStreamHeaders(
int64_t stream_id,
int kind,
std::vector<std::unique_ptr<QuicHeader>>* headers) override;
const std::vector<std::unique_ptr<QuicHeader>>& headers) override;
void OnStreamClose(
int64_t stream_id,
uint64_t app_error_code) override;
Expand Down Expand Up @@ -470,7 +470,7 @@ class QuicApplication : public MemoryRetainer {
virtual void StreamHeaders(
int64_t stream_id,
int kind,
std::vector<std::unique_ptr<QuicHeader>>* headers);
const std::vector<std::unique_ptr<QuicHeader>>& headers);
virtual void StreamClose(
int64_t stream_id,
uint64_t app_error_code);
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 @@ -400,7 +400,7 @@ void QuicStream::EndHeaders() {
// Upon completion of a block of headers, convert the
// vector of Header objects into an array of name+value
// pairs, then call the on_stream_headers function.
Session()->Application()->StreamHeaders(GetID(), headers_kind_, &headers_);
Session()->Application()->StreamHeaders(GetID(), headers_kind_, headers_);
headers_.clear();
}

Expand Down

0 comments on commit 89cad7e

Please sign in to comment.