1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-11-09 10:00:57 +03:00

Store tokens in new token frames as IoBuf and hexlify when including in qlogger

Summary:
As title. This changes the NewTokenFrame (for writing) to hold the toke as an IOBuf instead of a string. This makes it consistent with the read side.

In the same change, the qlogger now hexlifies this buffer when writing the token to the qlog.

Reviewed By: hanidamlaj, mjoras

Differential Revision: D46955172

fbshipit-source-id: 8f5f575ad2f0a4ec3b4c01cb67defa1f4425cd74
This commit is contained in:
Joseph Beshay
2023-06-27 13:12:10 -07:00
committed by Facebook GitHub Bot
parent e40013d568
commit c3ea605df1
5 changed files with 16 additions and 17 deletions

View File

@@ -747,7 +747,7 @@ size_t writeSimpleFrame(
QuicInteger intFrameType(static_cast<uint8_t>(FrameType::NEW_TOKEN)); QuicInteger intFrameType(static_cast<uint8_t>(FrameType::NEW_TOKEN));
auto& token = newTokenFrame->token; auto& token = newTokenFrame->token;
QuicInteger tokenLength(token.size()); QuicInteger tokenLength(token->computeChainDataLength());
auto newTokenFrameLength = intFrameType.getSize() + auto newTokenFrameLength = intFrameType.getSize() +
/*encoding token length*/ tokenLength.getSize() + /*encoding token length*/ tokenLength.getSize() +
tokenLength.getValue(); tokenLength.getValue();
@@ -755,7 +755,7 @@ size_t writeSimpleFrame(
if (packetSpaceCheck(spaceLeft, newTokenFrameLength)) { if (packetSpaceCheck(spaceLeft, newTokenFrameLength)) {
builder.write(intFrameType); builder.write(intFrameType);
builder.write(tokenLength); builder.write(tokenLength);
builder.push((uint8_t*)token.data(), tokenLength.getValue()); builder.insert(token->clone());
builder.appendFrame(QuicSimpleFrame(*newTokenFrame)); builder.appendFrame(QuicSimpleFrame(*newTokenFrame));
return newTokenFrameLength; return newTokenFrameLength;
} }

View File

@@ -369,18 +369,19 @@ struct WriteCryptoFrame {
}; };
struct NewTokenFrame { struct NewTokenFrame {
std::string token; Buf token;
explicit NewTokenFrame(std::string tokenIn) { explicit NewTokenFrame(Buf tokenIn) : token(std::move(tokenIn)) {}
token = std::move(tokenIn);
}
NewTokenFrame(const NewTokenFrame& other) { NewTokenFrame(const NewTokenFrame& other) {
token = other.token; if (other.token) {
token = other.token->clone();
}
} }
bool operator==(const NewTokenFrame& rhs) const { bool operator==(const NewTokenFrame& rhs) const {
return token == rhs.token; folly::IOBufEqualTo eq;
return eq(token, rhs.token);
} }
}; };

View File

@@ -73,8 +73,9 @@ void addQuicSimpleFrameToEvent(
} }
case quic::QuicSimpleFrame::Type::NewTokenFrame: { case quic::QuicSimpleFrame::Type::NewTokenFrame: {
const quic::NewTokenFrame& frame = *simpleFrame.asNewTokenFrame(); const quic::NewTokenFrame& frame = *simpleFrame.asNewTokenFrame();
auto tokenHexStr = folly::hexlify(frame.token->coalesce());
event->frames.push_back( event->frames.push_back(
std::make_unique<quic::NewTokenFrameLog>(frame.token)); std::make_unique<quic::NewTokenFrameLog>(tokenHexStr));
break; break;
} }
} }

View File

@@ -464,10 +464,7 @@ void updateHandshakeState(QuicServerConnectionState& conn) {
auto encryptedToken = generator.encryptToken(token); auto encryptedToken = generator.encryptToken(token);
CHECK(encryptedToken.has_value()); CHECK(encryptedToken.has_value());
std::string encryptedTokenStr = sendSimpleFrame(conn, NewTokenFrame(std::move(encryptedToken.value())));
encryptedToken.value()->moveToFbString().toStdString();
sendSimpleFrame(conn, NewTokenFrame(std::move(encryptedTokenStr)));
QUIC_STATS(conn.statsCallback, onNewTokenIssued); QUIC_STATS(conn.statsCallback, onNewTokenIssued);
conn.sentNewTokenFrame = true; conn.sentNewTokenFrame = true;

View File

@@ -3561,7 +3561,7 @@ TEST_F(
server->getConn().supportedVersions[0]); server->getConn().supportedVersions[0]);
RegularQuicPacketBuilder builder( RegularQuicPacketBuilder builder(
kDefaultUDPSendPacketLen, std::move(header), /*largestAcked=*/0); kDefaultUDPSendPacketLen, std::move(header), /*largestAcked=*/0);
writeSimpleFrame(NewTokenFrame("token!"), builder); writeSimpleFrame(NewTokenFrame(IOBuf::copyBuffer("token!")), builder);
// add some data // add some data
auto data = IOBuf::copyBuffer("hello!"); auto data = IOBuf::copyBuffer("hello!");
@@ -4143,9 +4143,9 @@ TEST_F(QuicUnencryptedServerTransportTest, TestSendHandshakeDoneNewTokenFrame) {
auto clientReadNewTokenFrame = clientParsedFrame->asReadNewTokenFrame(); auto clientReadNewTokenFrame = clientParsedFrame->asReadNewTokenFrame();
auto serverToken = serverWriteNewTokenFrame.second[0]->token; auto serverToken =
auto clientToken = serverWriteNewTokenFrame.second[0]->token->to<std::string>();
clientReadNewTokenFrame->token->moveToFbString().toStdString(); auto clientToken = clientReadNewTokenFrame->token->to<std::string>();
EXPECT_EQ(clientToken, serverToken); EXPECT_EQ(clientToken, serverToken);
loopForWrites(); loopForWrites();