Skip to content
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: add quic/streams.h/cc placeholder
  • Loading branch information
jasnell committed May 27, 2023
commit 1bcc297cd89f5fdf8526efa70355897848be4907
61 changes: 61 additions & 0 deletions src/quic/streams.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "streams.h"

#include <async_wrap-inl.h>
#include <base_object-inl.h>
#include <env-inl.h>
#include <memory_tracker-inl.h>
#include <node_bob-inl.h>
#include <node_sockaddr-inl.h>
#include "session.h"

namespace node {
namespace quic {

Stream::Stream(BaseObjectPtr<Session> session, v8::Local<v8::Object> obj)
: AsyncWrap(session->env(), obj, AsyncWrap::PROVIDER_QUIC_STREAM) {
MakeWeak();
}

Stream* Stream::From(void* stream_user_data) {
DCHECK_NOT_NULL(stream_user_data);
return static_cast<Stream*>(stream_user_data);
}

BaseObjectPtr<Stream> Stream::Create(Session* session, int64_t id) {
return BaseObjectPtr<Stream>();
}

int64_t Stream::id() const {
return 0;
}
Side Stream::origin() const {
return Side::CLIENT;
}
Direction Stream::direction() const {
return Direction::BIDIRECTIONAL;
}

bool Stream::is_destroyed() const {
return false;
}
bool Stream::is_eos() const {
return false;
}

void Stream::Acknowledge(size_t datalen) {}
void Stream::Blocked() {}
void Stream::Commit(size_t datalen) {}
void Stream::End() {}
void Stream::Destroy(QuicError error) {}

void Stream::ReceiveData(const uint8_t* data,
size_t len,
ReceiveDataFlags flags) {}
void Stream::ReceiveStopSending(QuicError error) {}
void Stream::ReceiveStreamReset(uint64_t final_size, QuicError error) {}

void Stream::Schedule(Stream::Queue* queue) {}
void Stream::Unschedule() {}

} // namespace quic
} // namespace node
82 changes: 82 additions & 0 deletions src/quic/streams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#pragma once

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC

#include <async_wrap.h>
#include <base_object.h>
#include <env.h>
#include <node_bob.h>
#include "bindingdata.h"
#include "data.h"

namespace node {
namespace quic {

class Session;

using Ngtcp2Source = bob::SourceImpl<ngtcp2_vec>;

// TODO(@jasnell): This is currently a placeholder for the actual definition.
class Stream : public AsyncWrap, public Ngtcp2Source {
public:
static Stream* From(void* stream_user_data);

static BaseObjectPtr<Stream> Create(Session* session, int64_t id);

Stream(BaseObjectPtr<Session> session, v8::Local<v8::Object> obj);

int64_t id() const;
Side origin() const;
Direction direction() const;

bool is_destroyed() const;
bool is_eos() const;

void Acknowledge(size_t datalen);
void Blocked();
void Commit(size_t datalen);
void End();
void Destroy(QuicError error);

struct ReceiveDataFlags final {
// Identifies the final chunk of data that the peer will send for the
// stream.
bool fin = false;
// Indicates that this chunk of data was received in a 0RTT packet before
// the TLS handshake completed, suggesting that is is not as secure and
// could be replayed by an attacker.
bool early = false;
};

void ReceiveData(const uint8_t* data, size_t len, ReceiveDataFlags flags);
void ReceiveStopSending(QuicError error);
void ReceiveStreamReset(uint64_t final_size, QuicError error);

SET_NO_MEMORY_INFO()
SET_MEMORY_INFO_NAME(Stream)
SET_SELF_SIZE(Stream)

ListNode<Stream> stream_queue_;

public:
// The Queue/Schedule/Unschedule here are part of the mechanism used to
// determine which streams have data to send on the session. When a stream
// potentially has data available, it will be scheduled in the Queue. Then,
// when the Session::Application starts sending pending data, it will check
// the queue to see if there are streams waiting. If there are, it will grab
// one and check to see if there is data to send. When a stream does not have
// data to send (such as when it is initially created or is using an async
// source that is still waiting for data to be pushed) it will not appear in
// the queue.
using Queue = ListHead<Stream, &Stream::stream_queue_>;

void Schedule(Queue* queue);
void Unschedule();
};

} // namespace quic
} // namespace node

#endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS