Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quic: always copy stateless reset token #33917

Closed
wants to merge 1 commit into from
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
15 changes: 10 additions & 5 deletions src/quic/node_quic_util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,27 @@ bool PreferredAddress::ResolvePreferredAddress(
StatelessResetToken::StatelessResetToken(
uint8_t* token,
const uint8_t* secret,
const QuicCID& cid) : token_(token) {
const QuicCID& cid) {
GenerateResetToken(token, secret, cid);
memcpy(buf_, token, sizeof(buf_));
}

StatelessResetToken::StatelessResetToken(
const uint8_t* secret,
const QuicCID& cid)
: token_(buf_) {
const QuicCID& cid) {
GenerateResetToken(buf_, secret, cid);
}

StatelessResetToken::StatelessResetToken(
const uint8_t* token) {
memcpy(buf_, token, sizeof(buf_));
}

std::string StatelessResetToken::ToString() const {
std::vector<char> dest(NGTCP2_STATELESS_RESET_TOKENLEN * 2 + 1);
dest[dest.size() - 1] = '\0';
size_t written = StringBytes::hex_encode(
reinterpret_cast<const char*>(token_),
reinterpret_cast<const char*>(buf_),
NGTCP2_STATELESS_RESET_TOKENLEN,
dest.data(),
dest.size());
Expand All @@ -313,7 +318,7 @@ size_t StatelessResetToken::Hash::operator()(
const StatelessResetToken& token) const {
size_t hash = 0;
for (size_t n = 0; n < NGTCP2_STATELESS_RESET_TOKENLEN; n++)
hash ^= std::hash<uint8_t>{}(token.token_[n]) + 0x9e3779b9 +
hash ^= std::hash<uint8_t>{}(token.buf_[n]) + 0x9e3779b9 +
(hash << 6) + (hash >> 2);
return hash;
}
Expand Down
8 changes: 3 additions & 5 deletions src/quic/node_quic_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,12 @@ class StatelessResetToken : public MemoryRetainer {
const uint8_t* secret,
const QuicCID& cid);

explicit StatelessResetToken(
const uint8_t* token)
: token_(token) {}
explicit inline StatelessResetToken(
const uint8_t* token);

inline std::string ToString() const;

const uint8_t* data() const { return token_; }
const uint8_t* data() const { return buf_; }

struct Hash {
inline size_t operator()(const StatelessResetToken& token) const;
Expand All @@ -414,7 +413,6 @@ class StatelessResetToken : public MemoryRetainer {

private:
uint8_t buf_[NGTCP2_STATELESS_RESET_TOKENLEN]{};
const uint8_t* token_;
};

template <typename T>
Expand Down