Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
'src/quic/tlscontext.cc',
'src/quic/transportparams.cc',
'src/quic/quic.cc',
'src/quic/arena.h',
'src/quic/bindingdata.h',
'src/quic/cid.h',
'src/quic/data.h',
Expand Down Expand Up @@ -440,6 +441,7 @@
'test/cctest/test_node_crypto_env.cc',
],
'node_cctest_quic_sources': [
'test/cctest/test_quic_arena.cc',
'test/cctest/test_quic_cid.cc',
'test/cctest/test_quic_error.cc',
'test/cctest/test_quic_preferredaddress.cc',
Expand Down
1 change: 0 additions & 1 deletion src/async_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ namespace node {
V(QUERYWRAP) \
V(QUIC_ENDPOINT) \
V(QUIC_LOGSTREAM) \
V(QUIC_PACKET) \
V(QUIC_SESSION) \
V(QUIC_STREAM) \
V(QUIC_UDP) \
Expand Down
29 changes: 10 additions & 19 deletions src/quic/application.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if HAVE_OPENSSL && HAVE_QUIC
#include "guard.h"
#ifndef OPENSSL_NO_QUIC
#include "application.h"
#include <async_wrap-inl.h>
#include <debug_utils-inl.h>
#include <nghttp3/nghttp3.h>
Expand All @@ -10,6 +9,7 @@
#include <node_sockaddr-inl.h>
#include <uv.h>
#include <v8.h>
#include "application.h"
#include "defs.h"
#include "endpoint.h"
#include "http3.h"
Expand Down Expand Up @@ -207,12 +207,9 @@ StreamPriority Session::Application::GetStreamPriority(const Stream& stream) {
return StreamPriority::DEFAULT;
}

BaseObjectPtr<Packet> Session::Application::CreateStreamDataPacket() {
return Packet::Create(env(),
session_->endpoint(),
session_->remote_address(),
session_->max_packet_size(),
"stream data");
Packet::Ptr Session::Application::CreateStreamDataPacket() {
return session_->endpoint().CreatePacket(
session_->remote_address(), session_->max_packet_size(), "stream data");
}

void Session::Application::StreamClose(Stream* stream, QuicError&& error) {
Expand Down Expand Up @@ -264,7 +261,7 @@ void Session::Application::SendPendingData() {
// The number of packets that have been sent in this call to SendPendingData.
size_t packet_send_count = 0;

BaseObjectPtr<Packet> packet;
Packet::Ptr packet;
uint8_t* pos = nullptr;
uint8_t* begin = nullptr;

Expand All @@ -273,7 +270,7 @@ void Session::Application::SendPendingData() {
packet = CreateStreamDataPacket();
if (!packet) [[unlikely]]
return false;
pos = begin = ngtcp2_vec(*packet).base;
pos = begin = packet->data();
}
DCHECK(packet);
DCHECK_NOT_NULL(pos);
Expand All @@ -299,7 +296,6 @@ void Session::Application::SendPendingData() {
// The stream_data is the next block of data from the application stream.
if (GetStreamData(&stream_data) < 0) {
Debug(session_, "Application failed to get stream data");
packet->CancelPacket();
session_->SetLastError(QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
closed = true;
return session_->Close(CloseMethod::SILENT);
Expand Down Expand Up @@ -367,7 +363,6 @@ void Session::Application::SendPendingData() {
if (ndatalen >= 0 && !StreamCommit(&stream_data, ndatalen)) {
Debug(session_,
"Failed to commit stream data while writing packets");
packet->CancelPacket();
session_->SetLastError(
QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
closed = true;
Expand All @@ -380,7 +375,6 @@ void Session::Application::SendPendingData() {
// ngtcp2 callback failed for some reason. This would be a
// bug in our code.
Debug(session_, "Internal failure with ngtcp2 callback");
packet->CancelPacket();
session_->SetLastError(
QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
closed = true;
Expand All @@ -393,12 +387,10 @@ void Session::Application::SendPendingData() {
Debug(session_,
"Application encountered error while writing packet: %s",
ngtcp2_strerror(nwrite));
packet->CancelPacket();
session_->SetLastError(QuicError::ForNgtcp2Error(nwrite));
closed = true;
return session_->Close(CloseMethod::SILENT);
} else if (ndatalen >= 0 && !StreamCommit(&stream_data, ndatalen)) {
packet->CancelPacket();
session_->SetLastError(QuicError::ForNgtcp2Error(NGTCP2_ERR_INTERNAL));
closed = true;
return session_->Close(CloseMethod::SILENT);
Expand All @@ -416,10 +408,9 @@ void Session::Application::SendPendingData() {
if (datalen) {
Debug(session_, "Sending packet with %zu bytes", datalen);
packet->Truncate(datalen);
session_->Send(packet, path);
} else {
packet->CancelPacket();
session_->Send(std::move(packet), path);
}
// If no data, Ptr destructor releases the packet.

return;
}
Expand All @@ -429,15 +420,15 @@ void Session::Application::SendPendingData() {
size_t datalen = pos - begin;
Debug(session_, "Sending packet with %zu bytes", datalen);
packet->Truncate(datalen);
session_->Send(packet, path);
session_->Send(std::move(packet), path);

// If we have sent the maximum number of packets, we're done.
if (++packet_send_count == max_packet_count) {
return;
}

// Prepare to loop back around to prepare a new packet.
packet.reset();
// packet is already empty from the std::move above.
pos = begin = nullptr;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/quic/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Session::Application : public MemoryRetainer {
}

private:
BaseObjectPtr<Packet> CreateStreamDataPacket();
Packet::Ptr CreateStreamDataPacket();

// Write the given stream_data into the buffer.
ssize_t WriteVStream(PathStorage* path,
Expand Down
Loading
Loading