Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
quic: additional suggested updates
  • Loading branch information
jasnell committed Dec 4, 2019
commit 04dd27dabf26e85057a2382ef585dda12336731f
29 changes: 13 additions & 16 deletions src/node_quic_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,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 @@ -376,29 +376,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 @@ -643,16 +639,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 @@ -1115,7 +1112,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 @@ -482,7 +482,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