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

Commit

Permalink
quic: use ngtcp2_path_storage and ngtcp2_path structs
Browse files Browse the repository at this point in the history
PR-URL: #207
Reviewed-By: #207
  • Loading branch information
jasnell authored and addaleax committed Dec 11, 2019
1 parent 166ece1 commit be206cf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
12 changes: 6 additions & 6 deletions src/node_quic_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ bool QuicSession::ReceiveClientInitial(const ngtcp2_cid* dcid) {
}

bool QuicSession::ReceivePacket(
QuicPath* path,
ngtcp2_path* path,
const uint8_t* data,
ssize_t nread) {
DCHECK(!Ngtcp2CallbackScope::InNgtcp2CallbackScope(this));
Expand All @@ -1555,7 +1555,7 @@ bool QuicSession::ReceivePacket(

uint64_t now = uv_hrtime();
session_stats_.session_received_at = now;
int err = ngtcp2_conn_read_pkt(Connection(), **path, data, nread, now);
int err = ngtcp2_conn_read_pkt(Connection(), path, data, nread, now);
if (err < 0) {
switch (err) {
case NGTCP2_ERR_DRAINING:
Expand Down Expand Up @@ -1787,7 +1787,7 @@ bool QuicSession::SelectPreferredAddress(

bool QuicSession::SendPacket(
MallocedBuffer<uint8_t> buf,
QuicPathStorage* path) {
ngtcp2_path_storage* path) {
sendbuf_.Push(std::move(buf));
// TODO(@jasnell): Update the local endpoint also?
remote_address_.Update(&path->path.remote);
Expand Down Expand Up @@ -1991,7 +1991,7 @@ bool QuicSession::SetSocket(QuicSocket* socket, bool nat_rebinding) {
QuicPath path(local_address, &remote_address_);
if (ngtcp2_conn_initiate_migration(
Connection(),
*path,
&path,
uv_hrtime()) != 0) {
return false;
}
Expand Down Expand Up @@ -2421,7 +2421,7 @@ void QuicSession::InitServer(
&conn,
dcid,
&scid_,
*path,
&path,
version,
&callbacks[crypto_context_->Side()],
**config,
Expand Down Expand Up @@ -2545,7 +2545,7 @@ bool QuicSession::InitClient(
&conn,
&dcid,
&scid_,
*path,
&path,
NGTCP2_PROTO_VER,
&callbacks[crypto_context_->Side()],
*config,
Expand Down
5 changes: 3 additions & 2 deletions src/node_quic_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ class QuicSession : public AsyncWrap,

QuicStream* CreateStream(int64_t id);
QuicStream* FindStream(int64_t id);

inline bool HasStream(int64_t id);

inline QuicError GetLastError() const;
Expand Down Expand Up @@ -659,7 +660,7 @@ class QuicSession : public AsyncWrap,
// Causes pending QuicStream data to be serialized and sent
bool SendStreamData(QuicStream* stream);

bool SendPacket(MallocedBuffer<uint8_t> buf, QuicPathStorage* path);
bool SendPacket(MallocedBuffer<uint8_t> buf, ngtcp2_path_storage* path);

inline uint64_t GetMaxDataLeft();

Expand Down Expand Up @@ -847,7 +848,7 @@ class QuicSession : public AsyncWrap,
const ngtcp2_path* path,
ngtcp2_path_validation_result res);
bool ReceiveClientInitial(const ngtcp2_cid* dcid);
bool ReceivePacket(QuicPath* path, const uint8_t* data, ssize_t nread);
bool ReceivePacket(ngtcp2_path* path, const uint8_t* data, ssize_t nread);
bool ReceiveRetry();
void RemoveConnectionID(const ngtcp2_cid* cid);
void ScheduleRetransmit();
Expand Down
4 changes: 2 additions & 2 deletions src/node_quic_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void QuicSocket::SendInitialConnectionClose(
&conn,
*dcid,
&scid,
*path,
&path,
version,
&callbacks,
&settings,
Expand All @@ -429,7 +429,7 @@ void QuicSocket::SendInitialConnectionClose(
ssize_t nwrite =
ngtcp2_conn_write_connection_close(
conn,
*path,
&path,
reinterpret_cast<uint8_t*>(buf.data),
NGTCP2_MAX_PKTLEN_IPV6,
error_code,
Expand Down
23 changes: 7 additions & 16 deletions src/node_quic_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,28 +302,19 @@ class SocketAddress {
sockaddr_storage address_;
};

class QuicPath {
public:
struct QuicPath : public ngtcp2_path {
QuicPath(
SocketAddress* local,
SocketAddress* remote) :
path_({ local->ToAddr(), remote->ToAddr() }) {}

ngtcp2_path* operator*() { return &path_; }

private:
ngtcp2_path path_;
SocketAddress* remote) {
ngtcp2_addr_init(&this->local, **local, local->Size(), nullptr);
ngtcp2_addr_init(&this->remote, **remote, remote->Size(), nullptr);
}
};

struct QuicPathStorage {
struct QuicPathStorage : public ngtcp2_path_storage {
QuicPathStorage() {
path.local.addr = local_addrbuf.data();
path.remote.addr = remote_addrbuf.data();
ngtcp2_path_storage_zero(this);
}

ngtcp2_path path;
std::array<uint8_t, sizeof(sockaddr_storage)> local_addrbuf;
std::array<uint8_t, sizeof(sockaddr_storage)> remote_addrbuf;
};

// Simple wrapper for ngtcp2_cid that handles hex encoding
Expand Down

0 comments on commit be206cf

Please sign in to comment.