1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-08 09:42:06 +03:00

Introduce a Cursor typealias

Summary: See title

Reviewed By: kvtsoy

Differential Revision: D73474979

fbshipit-source-id: 7048d75e79e619917b226bfc2b90bcd2248e44eb
This commit is contained in:
Aman Sharma
2025-04-23 10:07:20 -07:00
committed by Facebook GitHub Bot
parent 302b9599cf
commit a934b46f49
30 changed files with 193 additions and 202 deletions

View File

@@ -8,6 +8,7 @@
#pragma once #pragma once
#include <folly/chrono/Clock.h> #include <folly/chrono/Clock.h>
#include <folly/io/Cursor.h>
#include <folly/io/IOBuf.h> #include <folly/io/IOBuf.h>
#include <quic/common/third-party/enum.h> #include <quic/common/third-party/enum.h>
#include <sys/types.h> #include <sys/types.h>
@@ -41,6 +42,7 @@ using Buf = folly::IOBuf; // Used when we're not wrapping the buffer in an
// std::unique_ptr // std::unique_ptr
using BufPtr = std::unique_ptr<Buf>; using BufPtr = std::unique_ptr<Buf>;
using BufEq = folly::IOBufEqualTo; using BufEq = folly::IOBufEqualTo;
using Cursor = folly::io::Cursor;
using Clock = std::chrono::steady_clock; using Clock = std::chrono::steady_clock;
using TimePoint = std::chrono::time_point<Clock>; using TimePoint = std::chrono::time_point<Clock>;
using DurationRep = std::chrono::microseconds::rep; using DurationRep = std::chrono::microseconds::rep;

View File

@@ -369,7 +369,7 @@ void QuicStreamAsyncTransport::handleRead() {
readCb_->readBufferAvailable(std::move(readData->first)); readCb_->readBufferAvailable(std::move(readData->first));
} else { } else {
size_t readLen = readData->first->computeChainDataLength(); size_t readLen = readData->first->computeChainDataLength();
folly::io::Cursor c(readData->first.get()); Cursor c(readData->first.get());
CHECK_NOTNULL(buf); CHECK_NOTNULL(buf);
c.pull(buf, readLen); c.pull(buf, readLen);
readCb_->readDataAvailable(readLen); readCb_->readDataAvailable(readLen);

View File

@@ -398,7 +398,7 @@ iobufChainBasedBuildScheduleEncrypt(
auto bodyLen = packet->body.computeChainDataLength(); auto bodyLen = packet->body.computeChainDataLength();
auto unencrypted = BufHelpers::createCombined( auto unencrypted = BufHelpers::createCombined(
headerLen + bodyLen + aead.getCipherOverhead()); headerLen + bodyLen + aead.getCipherOverhead());
auto bodyCursor = folly::io::Cursor(&packet->body); auto bodyCursor = Cursor(&packet->body);
bodyCursor.pull(unencrypted->writableData() + headerLen, bodyLen); bodyCursor.pull(unencrypted->writableData() + headerLen, bodyLen);
unencrypted->advance(headerLen); unencrypted->advance(headerLen);
unencrypted->append(bodyLen); unencrypted->append(bodyLen);
@@ -406,7 +406,7 @@ iobufChainBasedBuildScheduleEncrypt(
aead.inplaceEncrypt(std::move(unencrypted), &packet->header, packetNum); aead.inplaceEncrypt(std::move(unencrypted), &packet->header, packetNum);
DCHECK(packetBuf->headroom() == headerLen); DCHECK(packetBuf->headroom() == headerLen);
packetBuf->clear(); packetBuf->clear();
auto headerCursor = folly::io::Cursor(&packet->header); auto headerCursor = Cursor(&packet->header);
headerCursor.pull(packetBuf->writableData(), headerLen); headerCursor.pull(packetBuf->writableData(), headerLen);
packetBuf->append(headerLen + bodyLen + aead.getCipherOverhead()); packetBuf->append(headerLen + bodyLen + aead.getCipherOverhead());

View File

@@ -104,14 +104,14 @@ BufPtr encodeDatagramFrame(BufQueue data) {
return buf; return buf;
} }
std::pair<BufPtr, uint32_t> decodeDatagramFrame(folly::io::Cursor& cursor) { std::pair<BufPtr, uint32_t> decodeDatagramFrame(Cursor& cursor) {
BufPtr outData; BufPtr outData;
auto len = cursor.readBE<uint32_t>(); auto len = cursor.readBE<uint32_t>();
cursor.clone(outData, len); cursor.clone(outData, len);
return std::make_pair(std::move(outData), len); return std::make_pair(std::move(outData), len);
} }
std::pair<BufPtr, uint64_t> decodeDataBuffer(folly::io::Cursor& cursor) { std::pair<BufPtr, uint64_t> decodeDataBuffer(Cursor& cursor) {
BufPtr outData; BufPtr outData;
auto len = cursor.readBE<uint32_t>(); auto len = cursor.readBE<uint32_t>();
cursor.clone(outData, len); cursor.clone(outData, len);
@@ -119,8 +119,7 @@ std::pair<BufPtr, uint64_t> decodeDataBuffer(folly::io::Cursor& cursor) {
return std::make_pair(std::move(outData), offset); return std::make_pair(std::move(outData), offset);
} }
std::pair<StreamId, StreamBuffer> decodeStreamBuffer( std::pair<StreamId, StreamBuffer> decodeStreamBuffer(Cursor& cursor) {
folly::io::Cursor& cursor) {
auto streamId = cursor.readBE<StreamId>(); auto streamId = cursor.readBE<StreamId>();
auto dataBuffer = decodeDataBuffer(cursor); auto dataBuffer = decodeDataBuffer(cursor);
bool eof = (bool)cursor.readBE<uint8_t>(); bool eof = (bool)cursor.readBE<uint8_t>();
@@ -135,7 +134,7 @@ struct StreamGroupIdBuf {
StreamBuffer buf; StreamBuffer buf;
}; };
StreamGroupIdBuf decodeStreamGroupBuffer(folly::io::Cursor& cursor) { StreamGroupIdBuf decodeStreamGroupBuffer(Cursor& cursor) {
auto streamId = cursor.readBE<StreamId>(); auto streamId = cursor.readBE<StreamId>();
auto groupId = cursor.readBE<StreamGroupId>(); auto groupId = cursor.readBE<StreamGroupId>();
auto dataBuffer = decodeDataBuffer(cursor); auto dataBuffer = decodeDataBuffer(cursor);
@@ -146,12 +145,12 @@ StreamGroupIdBuf decodeStreamGroupBuffer(folly::io::Cursor& cursor) {
StreamBuffer(std::move(dataBuffer.first), dataBuffer.second, eof)}; StreamBuffer(std::move(dataBuffer.first), dataBuffer.second, eof)};
} }
StreamBuffer decodeCryptoBuffer(folly::io::Cursor& cursor) { StreamBuffer decodeCryptoBuffer(Cursor& cursor) {
auto dataBuffer = decodeDataBuffer(cursor); auto dataBuffer = decodeDataBuffer(cursor);
return StreamBuffer(std::move(dataBuffer.first), dataBuffer.second, false); return StreamBuffer(std::move(dataBuffer.first), dataBuffer.second, false);
} }
MaxStreamsFrame decodeMaxStreamsFrame(folly::io::Cursor& cursor) { MaxStreamsFrame decodeMaxStreamsFrame(Cursor& cursor) {
bool isBidi = cursor.readBE<uint8_t>(); bool isBidi = cursor.readBE<uint8_t>();
auto maxStreams = cursor.readBE<uint64_t>(); auto maxStreams = cursor.readBE<uint64_t>();
return MaxStreamsFrame(maxStreams, isBidi); return MaxStreamsFrame(maxStreams, isBidi);
@@ -291,7 +290,7 @@ class TestQuicTransport
if (udpPacket.buf.empty()) { if (udpPacket.buf.empty()) {
return folly::unit; return folly::unit;
} }
folly::io::Cursor cursor(udpPacket.buf.front()); Cursor cursor(udpPacket.buf.front());
while (!cursor.isAtEnd()) { while (!cursor.isAtEnd()) {
// create server chosen connId with processId = 0 and workerId = 0 // create server chosen connId with processId = 0 and workerId = 0
ServerConnectionIdParams params(0, 0, 0); ServerConnectionIdParams params(0, 0, 0);

View File

@@ -44,8 +44,7 @@ folly::Expected<quic::PacketNum, quic::QuicError> nextAckedPacketLen(
namespace quic { namespace quic {
folly::Expected<PaddingFrame, QuicError> decodePaddingFrame( folly::Expected<PaddingFrame, QuicError> decodePaddingFrame(Cursor& cursor) {
folly::io::Cursor& cursor) {
// we might have multiple padding frames in sequence in the common case. // we might have multiple padding frames in sequence in the common case.
// Let's consume all the padding and return 1 padding frame for everything. // Let's consume all the padding and return 1 padding frame for everything.
static_assert( static_assert(
@@ -68,12 +67,11 @@ folly::Expected<PaddingFrame, QuicError> decodePaddingFrame(
return PaddingFrame(); return PaddingFrame();
} }
folly::Expected<PingFrame, QuicError> decodePingFrame(folly::io::Cursor&) { folly::Expected<PingFrame, QuicError> decodePingFrame(Cursor&) {
return PingFrame(); return PingFrame();
} }
folly::Expected<QuicFrame, QuicError> decodeKnobFrame( folly::Expected<QuicFrame, QuicError> decodeKnobFrame(Cursor& cursor) {
folly::io::Cursor& cursor) {
auto knobSpace = decodeQuicInteger(cursor); auto knobSpace = decodeQuicInteger(cursor);
if (!knobSpace) { if (!knobSpace) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -96,7 +94,7 @@ folly::Expected<QuicFrame, QuicError> decodeKnobFrame(
} }
folly::Expected<QuicSimpleFrame, QuicError> decodeAckFrequencyFrame( folly::Expected<QuicSimpleFrame, QuicError> decodeAckFrequencyFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
auto sequenceNumber = decodeQuicInteger(cursor); auto sequenceNumber = decodeQuicInteger(cursor);
if (!sequenceNumber) { if (!sequenceNumber) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -129,8 +127,7 @@ folly::Expected<QuicSimpleFrame, QuicError> decodeAckFrequencyFrame(
return QuicSimpleFrame(frame); return QuicSimpleFrame(frame);
} }
folly::Expected<ImmediateAckFrame, QuicError> decodeImmediateAckFrame( folly::Expected<ImmediateAckFrame, QuicError> decodeImmediateAckFrame(Cursor&) {
folly::io::Cursor&) {
return ImmediateAckFrame(); return ImmediateAckFrame();
} }
@@ -162,7 +159,7 @@ folly::Expected<uint64_t, QuicError> convertEncodedDurationToMicroseconds(
} }
folly::Expected<ReadAckFrame, QuicError> decodeAckFrame( folly::Expected<ReadAckFrame, QuicError> decodeAckFrame(
folly::io::Cursor& cursor, Cursor& cursor,
const PacketHeader& header, const PacketHeader& header,
const CodecParameters& params, const CodecParameters& params,
FrameType frameType) { FrameType frameType) {
@@ -252,7 +249,7 @@ folly::Expected<ReadAckFrame, QuicError> decodeAckFrame(
static folly::Expected<folly::Unit, QuicError> decodeReceiveTimestampsInAck( static folly::Expected<folly::Unit, QuicError> decodeReceiveTimestampsInAck(
ReadAckFrame& frame, ReadAckFrame& frame,
folly::io::Cursor& cursor, Cursor& cursor,
const CodecParameters& params) { const CodecParameters& params) {
auto latestRecvdPacketNum = decodeQuicInteger(cursor); auto latestRecvdPacketNum = decodeQuicInteger(cursor);
if (!latestRecvdPacketNum) { if (!latestRecvdPacketNum) {
@@ -322,7 +319,7 @@ static folly::Expected<folly::Unit, QuicError> decodeReceiveTimestampsInAck(
static folly::Expected<folly::Unit, QuicError> decodeEcnCountsInAck( static folly::Expected<folly::Unit, QuicError> decodeEcnCountsInAck(
ReadAckFrame& frame, ReadAckFrame& frame,
folly::io::Cursor& cursor) { Cursor& cursor) {
auto ect_0 = decodeQuicInteger(cursor); auto ect_0 = decodeQuicInteger(cursor);
auto ect_1 = decodeQuicInteger(cursor); auto ect_1 = decodeQuicInteger(cursor);
auto ce = decodeQuicInteger(cursor); auto ce = decodeQuicInteger(cursor);
@@ -337,7 +334,7 @@ static folly::Expected<folly::Unit, QuicError> decodeEcnCountsInAck(
} }
folly::Expected<ReadAckFrame, QuicError> decodeAckExtendedFrame( folly::Expected<ReadAckFrame, QuicError> decodeAckExtendedFrame(
folly::io::Cursor& cursor, Cursor& cursor,
const PacketHeader& header, const PacketHeader& header,
const CodecParameters& params) { const CodecParameters& params) {
ReadAckFrame frame; ReadAckFrame frame;
@@ -379,7 +376,7 @@ folly::Expected<ReadAckFrame, QuicError> decodeAckExtendedFrame(
} }
folly::Expected<QuicFrame, QuicError> decodeAckFrameWithReceivedTimestamps( folly::Expected<QuicFrame, QuicError> decodeAckFrameWithReceivedTimestamps(
folly::io::Cursor& cursor, Cursor& cursor,
const PacketHeader& header, const PacketHeader& header,
const CodecParameters& params, const CodecParameters& params,
FrameType frameType) { FrameType frameType) {
@@ -401,7 +398,7 @@ folly::Expected<QuicFrame, QuicError> decodeAckFrameWithReceivedTimestamps(
} }
folly::Expected<QuicFrame, QuicError> decodeAckFrameWithECN( folly::Expected<QuicFrame, QuicError> decodeAckFrameWithECN(
folly::io::Cursor& cursor, Cursor& cursor,
const PacketHeader& header, const PacketHeader& header,
const CodecParameters& params) { const CodecParameters& params) {
ReadAckFrame readAckFrame; ReadAckFrame readAckFrame;
@@ -422,7 +419,7 @@ folly::Expected<QuicFrame, QuicError> decodeAckFrameWithECN(
} }
folly::Expected<RstStreamFrame, QuicError> decodeRstStreamFrame( folly::Expected<RstStreamFrame, QuicError> decodeRstStreamFrame(
folly::io::Cursor& cursor, Cursor& cursor,
bool reliable) { bool reliable) {
auto streamId = decodeQuicInteger(cursor); auto streamId = decodeQuicInteger(cursor);
if (!streamId) { if (!streamId) {
@@ -467,7 +464,7 @@ folly::Expected<RstStreamFrame, QuicError> decodeRstStreamFrame(
} }
folly::Expected<StopSendingFrame, QuicError> decodeStopSendingFrame( folly::Expected<StopSendingFrame, QuicError> decodeStopSendingFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
auto streamId = decodeQuicInteger(cursor); auto streamId = decodeQuicInteger(cursor);
if (!streamId) { if (!streamId) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -485,8 +482,7 @@ folly::Expected<StopSendingFrame, QuicError> decodeStopSendingFrame(
return StopSendingFrame(folly::to<StreamId>(streamId->first), errorCode); return StopSendingFrame(folly::to<StreamId>(streamId->first), errorCode);
} }
folly::Expected<ReadCryptoFrame, QuicError> decodeCryptoFrame( folly::Expected<ReadCryptoFrame, QuicError> decodeCryptoFrame(Cursor& cursor) {
folly::io::Cursor& cursor) {
auto optionalOffset = decodeQuicInteger(cursor); auto optionalOffset = decodeQuicInteger(cursor);
if (!optionalOffset) { if (!optionalOffset) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -516,7 +512,7 @@ folly::Expected<ReadCryptoFrame, QuicError> decodeCryptoFrame(
} }
folly::Expected<ReadNewTokenFrame, QuicError> decodeNewTokenFrame( folly::Expected<ReadNewTokenFrame, QuicError> decodeNewTokenFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
auto tokenLength = decodeQuicInteger(cursor); auto tokenLength = decodeQuicInteger(cursor);
if (!tokenLength) { if (!tokenLength) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -542,7 +538,7 @@ folly::Expected<ReadStreamFrame, QuicError> decodeStreamFrame(
BufQueue& queue, BufQueue& queue,
StreamTypeField frameTypeField, StreamTypeField frameTypeField,
bool isGroupFrame) { bool isGroupFrame) {
folly::io::Cursor cursor(queue.front()); Cursor cursor(queue.front());
auto streamId = decodeQuicInteger(cursor); auto streamId = decodeQuicInteger(cursor);
if (!streamId) { if (!streamId) {
@@ -621,8 +617,7 @@ folly::Expected<ReadStreamFrame, QuicError> decodeStreamFrame(
groupId); groupId);
} }
folly::Expected<MaxDataFrame, QuicError> decodeMaxDataFrame( folly::Expected<MaxDataFrame, QuicError> decodeMaxDataFrame(Cursor& cursor) {
folly::io::Cursor& cursor) {
auto maximumData = decodeQuicInteger(cursor); auto maximumData = decodeQuicInteger(cursor);
if (!maximumData) { if (!maximumData) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -632,7 +627,7 @@ folly::Expected<MaxDataFrame, QuicError> decodeMaxDataFrame(
} }
folly::Expected<MaxStreamDataFrame, QuicError> decodeMaxStreamDataFrame( folly::Expected<MaxStreamDataFrame, QuicError> decodeMaxStreamDataFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
auto streamId = decodeQuicInteger(cursor); auto streamId = decodeQuicInteger(cursor);
if (!streamId) { if (!streamId) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -648,7 +643,7 @@ folly::Expected<MaxStreamDataFrame, QuicError> decodeMaxStreamDataFrame(
} }
folly::Expected<MaxStreamsFrame, QuicError> decodeBiDiMaxStreamsFrame( folly::Expected<MaxStreamsFrame, QuicError> decodeBiDiMaxStreamsFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
auto streamCount = decodeQuicInteger(cursor); auto streamCount = decodeQuicInteger(cursor);
if (!streamCount || streamCount->first > kMaxMaxStreams) { if (!streamCount || streamCount->first > kMaxMaxStreams) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -659,7 +654,7 @@ folly::Expected<MaxStreamsFrame, QuicError> decodeBiDiMaxStreamsFrame(
} }
folly::Expected<MaxStreamsFrame, QuicError> decodeUniMaxStreamsFrame( folly::Expected<MaxStreamsFrame, QuicError> decodeUniMaxStreamsFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
auto streamCount = decodeQuicInteger(cursor); auto streamCount = decodeQuicInteger(cursor);
if (!streamCount || streamCount->first > kMaxMaxStreams) { if (!streamCount || streamCount->first > kMaxMaxStreams) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -670,7 +665,7 @@ folly::Expected<MaxStreamsFrame, QuicError> decodeUniMaxStreamsFrame(
} }
folly::Expected<DataBlockedFrame, QuicError> decodeDataBlockedFrame( folly::Expected<DataBlockedFrame, QuicError> decodeDataBlockedFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
auto dataLimit = decodeQuicInteger(cursor); auto dataLimit = decodeQuicInteger(cursor);
if (!dataLimit) { if (!dataLimit) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -680,7 +675,7 @@ folly::Expected<DataBlockedFrame, QuicError> decodeDataBlockedFrame(
} }
folly::Expected<StreamDataBlockedFrame, QuicError> decodeStreamDataBlockedFrame( folly::Expected<StreamDataBlockedFrame, QuicError> decodeStreamDataBlockedFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
auto streamId = decodeQuicInteger(cursor); auto streamId = decodeQuicInteger(cursor);
if (!streamId) { if (!streamId) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -696,7 +691,7 @@ folly::Expected<StreamDataBlockedFrame, QuicError> decodeStreamDataBlockedFrame(
} }
folly::Expected<StreamsBlockedFrame, QuicError> decodeBiDiStreamsBlockedFrame( folly::Expected<StreamsBlockedFrame, QuicError> decodeBiDiStreamsBlockedFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
auto streamId = decodeQuicInteger(cursor); auto streamId = decodeQuicInteger(cursor);
if (!streamId) { if (!streamId) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -708,7 +703,7 @@ folly::Expected<StreamsBlockedFrame, QuicError> decodeBiDiStreamsBlockedFrame(
} }
folly::Expected<StreamsBlockedFrame, QuicError> decodeUniStreamsBlockedFrame( folly::Expected<StreamsBlockedFrame, QuicError> decodeUniStreamsBlockedFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
auto streamId = decodeQuicInteger(cursor); auto streamId = decodeQuicInteger(cursor);
if (!streamId) { if (!streamId) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -720,7 +715,7 @@ folly::Expected<StreamsBlockedFrame, QuicError> decodeUniStreamsBlockedFrame(
} }
folly::Expected<NewConnectionIdFrame, QuicError> decodeNewConnectionIdFrame( folly::Expected<NewConnectionIdFrame, QuicError> decodeNewConnectionIdFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
auto sequenceNumber = decodeQuicInteger(cursor); auto sequenceNumber = decodeQuicInteger(cursor);
if (!sequenceNumber) { if (!sequenceNumber) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -766,7 +761,7 @@ folly::Expected<NewConnectionIdFrame, QuicError> decodeNewConnectionIdFrame(
} }
folly::Expected<RetireConnectionIdFrame, QuicError> folly::Expected<RetireConnectionIdFrame, QuicError>
decodeRetireConnectionIdFrame(folly::io::Cursor& cursor) { decodeRetireConnectionIdFrame(Cursor& cursor) {
auto sequenceNum = decodeQuicInteger(cursor); auto sequenceNum = decodeQuicInteger(cursor);
if (!sequenceNum) { if (!sequenceNum) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -776,7 +771,7 @@ decodeRetireConnectionIdFrame(folly::io::Cursor& cursor) {
} }
folly::Expected<PathChallengeFrame, QuicError> decodePathChallengeFrame( folly::Expected<PathChallengeFrame, QuicError> decodePathChallengeFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
if (!cursor.canAdvance(sizeof(uint64_t))) { if (!cursor.canAdvance(sizeof(uint64_t))) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
quic::TransportErrorCode::FRAME_ENCODING_ERROR, quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -787,7 +782,7 @@ folly::Expected<PathChallengeFrame, QuicError> decodePathChallengeFrame(
} }
folly::Expected<PathResponseFrame, QuicError> decodePathResponseFrame( folly::Expected<PathResponseFrame, QuicError> decodePathResponseFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
if (!cursor.canAdvance(sizeof(uint64_t))) { if (!cursor.canAdvance(sizeof(uint64_t))) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
quic::TransportErrorCode::FRAME_ENCODING_ERROR, quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -798,7 +793,7 @@ folly::Expected<PathResponseFrame, QuicError> decodePathResponseFrame(
} }
folly::Expected<ConnectionCloseFrame, QuicError> decodeConnectionCloseFrame( folly::Expected<ConnectionCloseFrame, QuicError> decodeConnectionCloseFrame(
folly::io::Cursor& cursor) { Cursor& cursor) {
TransportErrorCode errorCode{}; TransportErrorCode errorCode{};
auto varCode = decodeQuicInteger(cursor); auto varCode = decodeQuicInteger(cursor);
if (!varCode) { if (!varCode) {
@@ -836,7 +831,7 @@ folly::Expected<ConnectionCloseFrame, QuicError> decodeConnectionCloseFrame(
} }
folly::Expected<ConnectionCloseFrame, QuicError> decodeApplicationClose( folly::Expected<ConnectionCloseFrame, QuicError> decodeApplicationClose(
folly::io::Cursor& cursor) { Cursor& cursor) {
ApplicationErrorCode errorCode{}; ApplicationErrorCode errorCode{};
auto varCode = decodeQuicInteger(cursor); auto varCode = decodeQuicInteger(cursor);
if (!varCode) { if (!varCode) {
@@ -866,7 +861,7 @@ folly::Expected<ConnectionCloseFrame, QuicError> decodeApplicationClose(
} }
folly::Expected<HandshakeDoneFrame, QuicError> decodeHandshakeDoneFrame( folly::Expected<HandshakeDoneFrame, QuicError> decodeHandshakeDoneFrame(
folly::io::Cursor& /*cursor*/) { Cursor& /*cursor*/) {
return HandshakeDoneFrame(); return HandshakeDoneFrame();
} }
@@ -876,7 +871,7 @@ folly::Expected<HandshakeDoneFrame, QuicError> decodeHandshakeDoneFrame(
* associated data. * associated data.
*/ */
folly::Expected<uint64_t, TransportErrorCode> parsePlaintextRetryOrNewToken( folly::Expected<uint64_t, TransportErrorCode> parsePlaintextRetryOrNewToken(
folly::io::Cursor& cursor) { Cursor& cursor) {
// Read in the timestamp // Read in the timestamp
if (!cursor.canAdvance(sizeof(uint64_t))) { if (!cursor.canAdvance(sizeof(uint64_t))) {
return folly::makeUnexpected(TransportErrorCode::INVALID_TOKEN); return folly::makeUnexpected(TransportErrorCode::INVALID_TOKEN);
@@ -889,7 +884,7 @@ folly::Expected<uint64_t, TransportErrorCode> parsePlaintextRetryOrNewToken(
folly::Expected<DatagramFrame, QuicError> decodeDatagramFrame( folly::Expected<DatagramFrame, QuicError> decodeDatagramFrame(
BufQueue& queue, BufQueue& queue,
bool hasLen) { bool hasLen) {
folly::io::Cursor cursor(queue.front()); Cursor cursor(queue.front());
size_t length = cursor.length(); size_t length = cursor.length();
if (hasLen) { if (hasLen) {
auto decodeLength = decodeQuicInteger(cursor); auto decodeLength = decodeQuicInteger(cursor);
@@ -911,7 +906,7 @@ folly::Expected<QuicFrame, QuicError> parseFrame(
BufQueue& queue, BufQueue& queue,
const PacketHeader& header, const PacketHeader& header,
const CodecParameters& params) { const CodecParameters& params) {
folly::io::Cursor cursor(queue.front()); Cursor cursor(queue.front());
auto frameTypeInt = decodeQuicInteger(cursor); auto frameTypeInt = decodeQuicInteger(cursor);
if (!frameTypeInt) { if (!frameTypeInt) {
return folly::makeUnexpected(QuicError( return folly::makeUnexpected(QuicError(
@@ -1238,7 +1233,7 @@ folly::Expected<RegularQuicPacket, QuicError> decodeRegularPacket(
Optional<VersionNegotiationPacket> decodeVersionNegotiation( Optional<VersionNegotiationPacket> decodeVersionNegotiation(
const ParsedLongHeaderInvariant& longHeaderInvariant, const ParsedLongHeaderInvariant& longHeaderInvariant,
folly::io::Cursor& cursor) { Cursor& cursor) {
auto cursorLength = cursor.totalLength(); auto cursorLength = cursor.totalLength();
if (cursorLength < sizeof(QuicVersionType) || if (cursorLength < sizeof(QuicVersionType) ||
@@ -1277,7 +1272,7 @@ ParsedLongHeaderInvariant::ParsedLongHeaderInvariant(
invariantLength(length) {} invariantLength(length) {}
folly::Expected<ParsedLongHeaderInvariant, TransportErrorCode> folly::Expected<ParsedLongHeaderInvariant, TransportErrorCode>
parseLongHeaderInvariant(uint8_t initialByte, folly::io::Cursor& cursor) { parseLongHeaderInvariant(uint8_t initialByte, Cursor& cursor) {
size_t initialLength = cursor.totalLength(); size_t initialLength = cursor.totalLength();
if (!cursor.canAdvance(sizeof(QuicVersionType))) { if (!cursor.canAdvance(sizeof(QuicVersionType))) {
VLOG(5) << "Not enough input bytes to read Version or connection-id"; VLOG(5) << "Not enough input bytes to read Version or connection-id";
@@ -1355,7 +1350,7 @@ std::pair<PacketNum, size_t> parsePacketNumber(
folly::Expected<ParsedLongHeaderResult, TransportErrorCode> parseLongHeader( folly::Expected<ParsedLongHeaderResult, TransportErrorCode> parseLongHeader(
uint8_t initialByte, uint8_t initialByte,
folly::io::Cursor& cursor) { Cursor& cursor) {
if (getHeaderForm(initialByte) != HeaderForm::Long) { if (getHeaderForm(initialByte) != HeaderForm::Long) {
VLOG(5) << "Bad header form bit"; VLOG(5) << "Bad header form bit";
return folly::makeUnexpected(TransportErrorCode::FRAME_ENCODING_ERROR); return folly::makeUnexpected(TransportErrorCode::FRAME_ENCODING_ERROR);
@@ -1393,7 +1388,7 @@ folly::Expected<ParsedLongHeaderResult, TransportErrorCode> parseLongHeader(
folly::Expected<ParsedLongHeader, TransportErrorCode> parseLongHeaderVariants( folly::Expected<ParsedLongHeader, TransportErrorCode> parseLongHeaderVariants(
LongHeader::Types type, LongHeader::Types type,
ParsedLongHeaderInvariant parsedLongHeaderInvariant, ParsedLongHeaderInvariant parsedLongHeaderInvariant,
folly::io::Cursor& cursor, Cursor& cursor,
QuicNodeType nodeType) { QuicNodeType nodeType) {
if (type == LongHeader::Types::Retry) { if (type == LongHeader::Types::Retry) {
// The integrity tag is kRetryIntegrityTagLen bytes in length, and the // The integrity tag is kRetryIntegrityTagLen bytes in length, and the
@@ -1472,7 +1467,7 @@ folly::Expected<ParsedLongHeader, TransportErrorCode> parseLongHeaderVariants(
folly::Expected<ShortHeaderInvariant, TransportErrorCode> folly::Expected<ShortHeaderInvariant, TransportErrorCode>
parseShortHeaderInvariants( parseShortHeaderInvariants(
uint8_t initialByte, uint8_t initialByte,
folly::io::Cursor& cursor, Cursor& cursor,
size_t dstConnIdSize) { size_t dstConnIdSize) {
if (getHeaderForm(initialByte) != HeaderForm::Short) { if (getHeaderForm(initialByte) != HeaderForm::Short) {
VLOG(5) << "Bad header form bit"; VLOG(5) << "Bad header form bit";
@@ -1492,10 +1487,8 @@ parseShortHeaderInvariants(
return ShortHeaderInvariant(std::move(connId)); return ShortHeaderInvariant(std::move(connId));
} }
folly::Expected<ShortHeader, TransportErrorCode> parseShortHeader( folly::Expected<ShortHeader, TransportErrorCode>
uint8_t initialByte, parseShortHeader(uint8_t initialByte, Cursor& cursor, size_t dstConnIdSize) {
folly::io::Cursor& cursor,
size_t dstConnIdSize) {
if (getHeaderForm(initialByte) != HeaderForm::Short) { if (getHeaderForm(initialByte) != HeaderForm::Short) {
VLOG(5) << "Bad header form bit"; VLOG(5) << "Bad header form bit";
return folly::makeUnexpected(TransportErrorCode::FRAME_ENCODING_ERROR); return folly::makeUnexpected(TransportErrorCode::FRAME_ENCODING_ERROR);

View File

@@ -60,7 +60,7 @@ struct ParsedLongHeaderInvariant {
*/ */
Optional<VersionNegotiationPacket> decodeVersionNegotiation( Optional<VersionNegotiationPacket> decodeVersionNegotiation(
const ParsedLongHeaderInvariant& longHeaderInvariant, const ParsedLongHeaderInvariant& longHeaderInvariant,
folly::io::Cursor& cursor); Cursor& cursor);
/** /**
* Decodes a single regular QUIC packet from the cursor. * Decodes a single regular QUIC packet from the cursor.
@@ -87,89 +87,89 @@ Optional<VersionNegotiationPacket> decodeVersionNegotiation(
* when decoding fails. * when decoding fails.
*/ */
[[nodiscard]] folly::Expected<PaddingFrame, QuicError> decodePaddingFrame( [[nodiscard]] folly::Expected<PaddingFrame, QuicError> decodePaddingFrame(
folly::io::Cursor& cursor); Cursor& cursor);
[[nodiscard]] folly::Expected<RstStreamFrame, QuicError> decodeRstStreamFrame( [[nodiscard]] folly::Expected<RstStreamFrame, QuicError> decodeRstStreamFrame(
folly::io::Cursor& cursor, Cursor& cursor,
bool reliable); bool reliable);
[[nodiscard]] folly::Expected<ConnectionCloseFrame, QuicError> [[nodiscard]] folly::Expected<ConnectionCloseFrame, QuicError>
decodeConnectionCloseFrame(folly::io::Cursor& cursor); decodeConnectionCloseFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<ConnectionCloseFrame, QuicError> [[nodiscard]] folly::Expected<ConnectionCloseFrame, QuicError>
decodeApplicationClose(folly::io::Cursor& cursor); decodeApplicationClose(Cursor& cursor);
[[nodiscard]] folly::Expected<MaxDataFrame, QuicError> decodeMaxDataFrame( [[nodiscard]] folly::Expected<MaxDataFrame, QuicError> decodeMaxDataFrame(
folly::io::Cursor& cursor); Cursor& cursor);
[[nodiscard]] folly::Expected<MaxStreamDataFrame, QuicError> [[nodiscard]] folly::Expected<MaxStreamDataFrame, QuicError>
decodeMaxStreamDataFrame(folly::io::Cursor& cursor); decodeMaxStreamDataFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<MaxStreamsFrame, QuicError> [[nodiscard]] folly::Expected<MaxStreamsFrame, QuicError>
decodeBiDiMaxStreamsFrame(folly::io::Cursor& cursor); decodeBiDiMaxStreamsFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<MaxStreamsFrame, QuicError> [[nodiscard]] folly::Expected<MaxStreamsFrame, QuicError>
decodeUniMaxStreamsFrame(folly::io::Cursor& cursor); decodeUniMaxStreamsFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<PingFrame, QuicError> decodePingFrame( [[nodiscard]] folly::Expected<PingFrame, QuicError> decodePingFrame(
folly::io::Cursor& cursor); Cursor& cursor);
[[nodiscard]] folly::Expected<QuicFrame, QuicError> decodeKnobFrame( [[nodiscard]] folly::Expected<QuicFrame, QuicError> decodeKnobFrame(
folly::io::Cursor& cursor); Cursor& cursor);
[[nodiscard]] folly::Expected<QuicSimpleFrame, QuicError> [[nodiscard]] folly::Expected<QuicSimpleFrame, QuicError>
decodeAckFrequencyFrame(folly::io::Cursor& cursor); decodeAckFrequencyFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<ImmediateAckFrame, QuicError> [[nodiscard]] folly::Expected<ImmediateAckFrame, QuicError>
decodeImmediateAckFrame(folly::io::Cursor& cursor); decodeImmediateAckFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<DataBlockedFrame, QuicError> [[nodiscard]] folly::Expected<DataBlockedFrame, QuicError>
decodeDataBlockedFrame(folly::io::Cursor& cursor); decodeDataBlockedFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<StreamDataBlockedFrame, QuicError> [[nodiscard]] folly::Expected<StreamDataBlockedFrame, QuicError>
decodeStreamDataBlockedFrame(folly::io::Cursor& cursor); decodeStreamDataBlockedFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<StreamsBlockedFrame, QuicError> [[nodiscard]] folly::Expected<StreamsBlockedFrame, QuicError>
decodeBiDiStreamsBlockedFrame(folly::io::Cursor& cursor); decodeBiDiStreamsBlockedFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<StreamsBlockedFrame, QuicError> [[nodiscard]] folly::Expected<StreamsBlockedFrame, QuicError>
decodeUniStreamsBlockedFrame(folly::io::Cursor& cursor); decodeUniStreamsBlockedFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<NewConnectionIdFrame, QuicError> [[nodiscard]] folly::Expected<NewConnectionIdFrame, QuicError>
decodeNewConnectionIdFrame(folly::io::Cursor& cursor); decodeNewConnectionIdFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<RetireConnectionIdFrame, QuicError> [[nodiscard]] folly::Expected<RetireConnectionIdFrame, QuicError>
decodeRetireConnectionIdFrame(folly::io::Cursor& cursor); decodeRetireConnectionIdFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<StopSendingFrame, QuicError> [[nodiscard]] folly::Expected<StopSendingFrame, QuicError>
decodeStopSendingFrame(folly::io::Cursor& cursor); decodeStopSendingFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<PathChallengeFrame, QuicError> [[nodiscard]] folly::Expected<PathChallengeFrame, QuicError>
decodePathChallengeFrame(folly::io::Cursor& cursor); decodePathChallengeFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<PathResponseFrame, QuicError> [[nodiscard]] folly::Expected<PathResponseFrame, QuicError>
decodePathResponseFrame(folly::io::Cursor& cursor); decodePathResponseFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<ReadAckFrame, QuicError> decodeAckFrame( [[nodiscard]] folly::Expected<ReadAckFrame, QuicError> decodeAckFrame(
folly::io::Cursor& cursor, Cursor& cursor,
const PacketHeader& header, const PacketHeader& header,
const CodecParameters& params, const CodecParameters& params,
FrameType frameType = FrameType::ACK); FrameType frameType = FrameType::ACK);
[[nodiscard]] folly::Expected<ReadAckFrame, QuicError> decodeAckExtendedFrame( [[nodiscard]] folly::Expected<ReadAckFrame, QuicError> decodeAckExtendedFrame(
folly::io::Cursor& cursor, Cursor& cursor,
const PacketHeader& header, const PacketHeader& header,
const CodecParameters& params); const CodecParameters& params);
[[nodiscard]] folly::Expected<QuicFrame, QuicError> [[nodiscard]] folly::Expected<QuicFrame, QuicError>
decodeAckFrameWithReceivedTimestamps( decodeAckFrameWithReceivedTimestamps(
folly::io::Cursor& cursor, Cursor& cursor,
const PacketHeader& header, const PacketHeader& header,
const CodecParameters& params, const CodecParameters& params,
FrameType frameType); FrameType frameType);
[[nodiscard]] folly::Expected<QuicFrame, QuicError> decodeAckFrameWithECN( [[nodiscard]] folly::Expected<QuicFrame, QuicError> decodeAckFrameWithECN(
folly::io::Cursor& cursor, Cursor& cursor,
const PacketHeader& header, const PacketHeader& header,
const CodecParameters& params); const CodecParameters& params);
@@ -179,16 +179,16 @@ decodeAckFrameWithReceivedTimestamps(
bool isGroupFrame = false); bool isGroupFrame = false);
[[nodiscard]] folly::Expected<ReadCryptoFrame, QuicError> decodeCryptoFrame( [[nodiscard]] folly::Expected<ReadCryptoFrame, QuicError> decodeCryptoFrame(
folly::io::Cursor& cursor); Cursor& cursor);
[[nodiscard]] folly::Expected<ReadNewTokenFrame, QuicError> decodeNewTokenFrame( [[nodiscard]] folly::Expected<ReadNewTokenFrame, QuicError> decodeNewTokenFrame(
folly::io::Cursor& cursor); Cursor& cursor);
[[nodiscard]] folly::Expected<HandshakeDoneFrame, QuicError> [[nodiscard]] folly::Expected<HandshakeDoneFrame, QuicError>
decodeHandshakeDoneFrame(folly::io::Cursor& cursor); decodeHandshakeDoneFrame(Cursor& cursor);
[[nodiscard]] folly::Expected<uint64_t, TransportErrorCode> [[nodiscard]] folly::Expected<uint64_t, TransportErrorCode>
parsePlaintextRetryOrNewToken(folly::io::Cursor& cursor); parsePlaintextRetryOrNewToken(Cursor& cursor);
[[nodiscard]] folly::Expected<DatagramFrame, QuicError> decodeDatagramFrame( [[nodiscard]] folly::Expected<DatagramFrame, QuicError> decodeDatagramFrame(
BufQueue& queue, BufQueue& queue,
@@ -201,7 +201,7 @@ parsePlaintextRetryOrNewToken(folly::io::Cursor& cursor);
* will be moved to the byte right after Source Connection ID. * will be moved to the byte right after Source Connection ID.
*/ */
[[nodiscard]] folly::Expected<ParsedLongHeaderInvariant, TransportErrorCode> [[nodiscard]] folly::Expected<ParsedLongHeaderInvariant, TransportErrorCode>
parseLongHeaderInvariant(uint8_t initalByte, folly::io::Cursor& cursor); parseLongHeaderInvariant(uint8_t initalByte, Cursor& cursor);
struct PacketLength { struct PacketLength {
// The length of the packet payload (including packet number) // The length of the packet payload (including packet number)
@@ -247,25 +247,25 @@ std::pair<PacketNum, size_t> parsePacketNumber(
// cursor: has to be point to the byte just past initialByte // cursor: has to be point to the byte just past initialByte
[[nodiscard]] folly::Expected<ParsedLongHeaderResult, TransportErrorCode> [[nodiscard]] folly::Expected<ParsedLongHeaderResult, TransportErrorCode>
parseLongHeader(uint8_t initialByte, folly::io::Cursor& cursor); parseLongHeader(uint8_t initialByte, Cursor& cursor);
// nodeType: Determine if we allow 0-len dst connection ids. // nodeType: Determine if we allow 0-len dst connection ids.
[[nodiscard]] folly::Expected<ParsedLongHeader, TransportErrorCode> [[nodiscard]] folly::Expected<ParsedLongHeader, TransportErrorCode>
parseLongHeaderVariants( parseLongHeaderVariants(
LongHeader::Types type, LongHeader::Types type,
ParsedLongHeaderInvariant longHeaderInvariant, ParsedLongHeaderInvariant longHeaderInvariant,
folly::io::Cursor& cursor, Cursor& cursor,
QuicNodeType nodeType = QuicNodeType::Server); QuicNodeType nodeType = QuicNodeType::Server);
[[nodiscard]] folly::Expected<ShortHeaderInvariant, TransportErrorCode> [[nodiscard]] folly::Expected<ShortHeaderInvariant, TransportErrorCode>
parseShortHeaderInvariants( parseShortHeaderInvariants(
uint8_t initialByte, uint8_t initialByte,
folly::io::Cursor& cursor, Cursor& cursor,
size_t dstConnIdSize = kDefaultConnectionIdSize); size_t dstConnIdSize = kDefaultConnectionIdSize);
[[nodiscard]] folly::Expected<ShortHeader, TransportErrorCode> parseShortHeader( [[nodiscard]] folly::Expected<ShortHeader, TransportErrorCode> parseShortHeader(
uint8_t initialByte, uint8_t initialByte,
folly::io::Cursor& cursor, Cursor& cursor,
size_t dstConnIdSize = kDefaultConnectionIdSize); size_t dstConnIdSize = kDefaultConnectionIdSize);
[[nodiscard]] folly::Expected<uint64_t, QuicError> [[nodiscard]] folly::Expected<uint64_t, QuicError>

View File

@@ -43,7 +43,7 @@ ConnectionId::ConnectionId(const std::vector<uint8_t>& connidIn) {
} }
} }
ConnectionId::ConnectionId(folly::io::Cursor& cursor, size_t len) { ConnectionId::ConnectionId(Cursor& cursor, size_t len) {
// Zero is special case for connids. // Zero is special case for connids.
if (len == 0) { if (len == 0) {
connidLen = 0; connidLen = 0;

View File

@@ -43,7 +43,7 @@ struct ConnectionId {
explicit ConnectionId(const std::vector<uint8_t>& connidIn); explicit ConnectionId(const std::vector<uint8_t>& connidIn);
explicit ConnectionId(folly::io::Cursor& cursor, size_t len); explicit ConnectionId(Cursor& cursor, size_t len);
bool operator==(const ConnectionId& other) const; bool operator==(const ConnectionId& other) const;
bool operator!=(const ConnectionId& other) const; bool operator!=(const ConnectionId& other) const;

View File

@@ -20,7 +20,7 @@ ParsedHeaderResult::ParsedHeaderResult(
folly::Expected<ParsedHeaderResult, TransportErrorCode> parseHeader( folly::Expected<ParsedHeaderResult, TransportErrorCode> parseHeader(
const folly::IOBuf& data) { const folly::IOBuf& data) {
folly::io::Cursor cursor(&data); Cursor cursor(&data);
if (!cursor.canAdvance(sizeof(uint8_t))) { if (!cursor.canAdvance(sizeof(uint8_t))) {
return folly::makeUnexpected(TransportErrorCode::FRAME_ENCODING_ERROR); return folly::makeUnexpected(TransportErrorCode::FRAME_ENCODING_ERROR);
} }

View File

@@ -30,7 +30,7 @@ uint8_t decodeQuicIntegerLength(uint8_t firstByte) {
} }
Optional<std::pair<uint64_t, size_t>> decodeQuicInteger( Optional<std::pair<uint64_t, size_t>> decodeQuicInteger(
folly::io::Cursor& cursor, Cursor& cursor,
uint64_t atMost) { uint64_t atMost) {
// checks // checks
if (atMost == 0 || !cursor.canAdvance(1)) { if (atMost == 0 || !cursor.canAdvance(1)) {

View File

@@ -101,7 +101,7 @@ encodeQuicInteger(uint64_t value, BufOp bufop, int outputSize) {
* read the int. It only advances the cursor in case of success. * read the int. It only advances the cursor in case of success.
*/ */
Optional<std::pair<uint64_t, size_t>> decodeQuicInteger( Optional<std::pair<uint64_t, size_t>> decodeQuicInteger(
folly::io::Cursor& cursor, Cursor& cursor,
uint64_t atMost = sizeof(uint64_t)); uint64_t atMost = sizeof(uint64_t));
/** /**

View File

@@ -198,7 +198,7 @@ void RegularQuicPacketBuilder::insert(BufPtr buf) {
void RegularQuicPacketBuilder::insert(BufPtr buf, size_t limit) { void RegularQuicPacketBuilder::insert(BufPtr buf, size_t limit) {
BufPtr streamData; BufPtr streamData;
folly::io::Cursor cursor(buf.get()); Cursor cursor(buf.get());
cursor.clone(streamData, limit); cursor.clone(streamData, limit);
// reminaingBytes_ update is taken care of inside this insert call: // reminaingBytes_ update is taken care of inside this insert call:
insert(std::move(streamData)); insert(std::move(streamData));
@@ -206,7 +206,7 @@ void RegularQuicPacketBuilder::insert(BufPtr buf, size_t limit) {
void RegularQuicPacketBuilder::insert(const BufQueue& buf, size_t limit) { void RegularQuicPacketBuilder::insert(const BufQueue& buf, size_t limit) {
BufPtr streamData; BufPtr streamData;
folly::io::Cursor cursor(buf.front()); Cursor cursor(buf.front());
cursor.clone(streamData, limit); cursor.clone(streamData, limit);
// reminaingBytes_ update is taken care of inside this insert call: // reminaingBytes_ update is taken care of inside this insert call:
insert(std::move(streamData)); insert(std::move(streamData));

View File

@@ -24,7 +24,7 @@ QuicReadCodec::QuicReadCodec(QuicNodeType nodeType) : nodeType_(nodeType) {}
Optional<VersionNegotiationPacket> QuicReadCodec::tryParsingVersionNegotiation( Optional<VersionNegotiationPacket> QuicReadCodec::tryParsingVersionNegotiation(
BufQueue& queue) { BufQueue& queue) {
folly::io::Cursor cursor(queue.front()); Cursor cursor(queue.front());
if (!cursor.canAdvance(sizeof(uint8_t))) { if (!cursor.canAdvance(sizeof(uint8_t))) {
return none; return none;
} }
@@ -47,7 +47,7 @@ Optional<VersionNegotiationPacket> QuicReadCodec::tryParsingVersionNegotiation(
} }
folly::Expected<ParsedLongHeader, TransportErrorCode> tryParseLongHeader( folly::Expected<ParsedLongHeader, TransportErrorCode> tryParseLongHeader(
folly::io::Cursor& cursor, Cursor& cursor,
QuicNodeType nodeType) { QuicNodeType nodeType) {
if (cursor.isAtEnd() || !cursor.canAdvance(sizeof(uint8_t))) { if (cursor.isAtEnd() || !cursor.canAdvance(sizeof(uint8_t))) {
return folly::makeUnexpected(TransportErrorCode::PROTOCOL_VIOLATION); return folly::makeUnexpected(TransportErrorCode::PROTOCOL_VIOLATION);
@@ -101,7 +101,7 @@ static PacketDropReason getDecryptErrorReason(ProtectionType protectionType) {
CodecResult QuicReadCodec::parseLongHeaderPacket( CodecResult QuicReadCodec::parseLongHeaderPacket(
BufQueue& queue, BufQueue& queue,
const AckStates& ackStates) { const AckStates& ackStates) {
folly::io::Cursor cursor(queue.front()); Cursor cursor(queue.front());
const uint8_t initialByte = *cursor.peekBytes().data(); const uint8_t initialByte = *cursor.peekBytes().data();
auto res = tryParseLongHeader(cursor, nodeType_); auto res = tryParseLongHeader(cursor, nodeType_);
@@ -272,7 +272,7 @@ CodecResult QuicReadCodec::tryParseShortHeaderPacket(
BufPtr data, BufPtr data,
const AckStates& ackStates, const AckStates& ackStates,
size_t dstConnIdSize, size_t dstConnIdSize,
folly::io::Cursor& cursor) { Cursor& cursor) {
// TODO: allow other connid lengths from the state. // TODO: allow other connid lengths from the state.
size_t packetNumberOffset = 1 + dstConnIdSize; size_t packetNumberOffset = 1 + dstConnIdSize;
PacketNum expectedNextPacketNum = PacketNum expectedNextPacketNum =
@@ -412,7 +412,7 @@ CodecResult QuicReadCodec::parsePacket(
return CodecResult(Nothing()); return CodecResult(Nothing());
} }
DCHECK(!queue.front()->isChained()); DCHECK(!queue.front()->isChained());
folly::io::Cursor cursor(queue.front()); Cursor cursor(queue.front());
if (!cursor.canAdvance(sizeof(uint8_t))) { if (!cursor.canAdvance(sizeof(uint8_t))) {
return CodecResult(Nothing()); return CodecResult(Nothing());
} }

View File

@@ -99,7 +99,7 @@ struct CodecResult {
* Returns an error if parsing is unsuccessful. * Returns an error if parsing is unsuccessful.
*/ */
folly::Expected<ParsedLongHeader, TransportErrorCode> tryParseLongHeader( folly::Expected<ParsedLongHeader, TransportErrorCode> tryParseLongHeader(
folly::io::Cursor& cursor, Cursor& cursor,
QuicNodeType nodeType); QuicNodeType nodeType);
class QuicReadCodec { class QuicReadCodec {
@@ -202,7 +202,7 @@ class QuicReadCodec {
BufPtr data, BufPtr data,
const AckStates& ackStates, const AckStates& ackStates,
size_t dstConnIdSize, size_t dstConnIdSize,
folly::io::Cursor& cursor); Cursor& cursor);
CodecResult parseLongHeaderPacket( CodecResult parseLongHeaderPacket(
BufQueue& queue, BufQueue& queue,
const AckStates& ackStates); const AckStates& ackStates);

View File

@@ -1072,10 +1072,8 @@ struct ShortHeader {
private: private:
ShortHeader() = delete; ShortHeader() = delete;
bool readInitialByte(uint8_t initalByte); bool readInitialByte(uint8_t initalByte);
bool readConnectionId(folly::io::Cursor& cursor); bool readConnectionId(Cursor& cursor);
bool readPacketNum( bool readPacketNum(PacketNum largestReceivedUdpPacketNum, Cursor& cursor);
PacketNum largestReceivedUdpPacketNum,
folly::io::Cursor& cursor);
private: private:
PacketNum packetSequenceNum_{0}; PacketNum packetSequenceNum_{0};

View File

@@ -294,7 +294,7 @@ TEST_F(DecodeTest, ValidAckFrame) {
numAdditionalBlocks, numAdditionalBlocks,
firstAckBlockLength, firstAckBlockLength,
ackBlocks); ackBlocks);
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
auto res = decodeAckFrame( auto res = decodeAckFrame(
cursor, cursor,
makeHeader(), makeHeader(),
@@ -325,7 +325,7 @@ TEST_F(DecodeTest, AckEcnFrame) {
false, // useRealValuesForLargestAcked false, // useRealValuesForLargestAcked
false, // useRealValuesForAckDelay false, // useRealValuesForAckDelay
true); // addEcnCounts true); // addEcnCounts
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
auto res = decodeAckFrameWithECN( auto res = decodeAckFrameWithECN(
cursor, cursor,
makeHeader(), makeHeader(),
@@ -362,7 +362,7 @@ TEST_F(DecodeTest, AckExtendedFrameWithECN) {
false, // useRealValuesForAckDelay false, // useRealValuesForAckDelay
true, // addEcnCounts true, // addEcnCounts
true); // useExtendedAck true); // useExtendedAck
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
auto ackFrameRes = decodeAckExtendedFrame( auto ackFrameRes = decodeAckExtendedFrame(
cursor, cursor,
makeHeader(), makeHeader(),
@@ -406,7 +406,7 @@ TEST_F(DecodeTest, AckExtendedFrameWithNoFeatures) {
false, // useRealValuesForAckDelay false, // useRealValuesForAckDelay
false, // addEcnCounts false, // addEcnCounts
true); // useExtendedAck true); // useExtendedAck
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
auto ackFrameRes = decodeAckExtendedFrame( auto ackFrameRes = decodeAckExtendedFrame(
cursor, cursor,
makeHeader(), makeHeader(),
@@ -444,7 +444,7 @@ TEST_F(DecodeTest, AckExtendedFrameThrowsWithUnsupportedFeatures) {
false, // useRealValuesForAckDelay false, // useRealValuesForAckDelay
true, // addEcnCounts true, // addEcnCounts
true); // useExtendedAck true); // useExtendedAck
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
// Try to decode extended ack with ECN but we only support Timestamps // Try to decode extended ack with ECN but we only support Timestamps
auto decodeResult = decodeAckExtendedFrame( auto decodeResult = decodeAckExtendedFrame(
@@ -474,7 +474,7 @@ TEST_F(DecodeTest, AckFrameLargestAckExceedsRange) {
firstAckBlockLength, firstAckBlockLength,
{}, {},
true); true);
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
auto res = decodeAckFrame( auto res = decodeAckFrame(
cursor, cursor,
makeHeader(), makeHeader(),
@@ -498,7 +498,7 @@ TEST_F(DecodeTest, AckFrameLargestAckInvalid) {
firstAckBlockLength, firstAckBlockLength,
{}, {},
true); true);
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
auto res = decodeAckFrame( auto res = decodeAckFrame(
cursor, cursor,
makeHeader(), makeHeader(),
@@ -521,7 +521,7 @@ TEST_F(DecodeTest, AckFrameDelayEncodingInvalid) {
{}, {},
false, false,
true); true);
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
auto res = decodeAckFrame( auto res = decodeAckFrame(
cursor, cursor,
makeHeader(), makeHeader(),
@@ -538,7 +538,7 @@ TEST_F(DecodeTest, AckFrameDelayExceedsRange) {
QuicInteger firstAckBlockLength(10); QuicInteger firstAckBlockLength(10);
auto result = createAckFrame( auto result = createAckFrame(
largestAcked, ackDelay, numAdditionalBlocks, firstAckBlockLength); largestAcked, ackDelay, numAdditionalBlocks, firstAckBlockLength);
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
auto res = decodeAckFrame( auto res = decodeAckFrame(
cursor, cursor,
makeHeader(), makeHeader(),
@@ -562,7 +562,7 @@ TEST_F(DecodeTest, AckFrameAdditionalBlocksUnderflow) {
numAdditionalBlocks, numAdditionalBlocks,
firstAckBlockLength, firstAckBlockLength,
ackBlocks); ackBlocks);
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
auto res = decodeAckFrame( auto res = decodeAckFrame(
cursor, cursor,
makeHeader(), makeHeader(),
@@ -588,7 +588,7 @@ TEST_F(DecodeTest, AckFrameAdditionalBlocksOverflow) {
numAdditionalBlocks, numAdditionalBlocks,
firstAckBlockLength, firstAckBlockLength,
ackBlocks); ackBlocks);
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
ASSERT_FALSE( ASSERT_FALSE(
decodeAckFrame( decodeAckFrame(
cursor, cursor,
@@ -609,7 +609,7 @@ TEST_F(DecodeTest, AckFrameMissingFields) {
auto result1 = createAckFrame( auto result1 = createAckFrame(
largestAcked, none, numAdditionalBlocks, firstAckBlockLength, ackBlocks); largestAcked, none, numAdditionalBlocks, firstAckBlockLength, ackBlocks);
folly::io::Cursor cursor1(result1.get()); Cursor cursor1(result1.get());
auto res = decodeAckFrame( auto res = decodeAckFrame(
cursor1, cursor1,
@@ -620,7 +620,7 @@ TEST_F(DecodeTest, AckFrameMissingFields) {
auto result2 = createAckFrame( auto result2 = createAckFrame(
largestAcked, ackDelay, none, firstAckBlockLength, ackBlocks); largestAcked, ackDelay, none, firstAckBlockLength, ackBlocks);
folly::io::Cursor cursor2(result2.get()); Cursor cursor2(result2.get());
res = decodeAckFrame( res = decodeAckFrame(
cursor2, cursor2,
makeHeader(), makeHeader(),
@@ -630,7 +630,7 @@ TEST_F(DecodeTest, AckFrameMissingFields) {
auto result3 = createAckFrame( auto result3 = createAckFrame(
largestAcked, ackDelay, none, firstAckBlockLength, ackBlocks); largestAcked, ackDelay, none, firstAckBlockLength, ackBlocks);
folly::io::Cursor cursor3(result3.get()); Cursor cursor3(result3.get());
res = decodeAckFrame( res = decodeAckFrame(
cursor3, cursor3,
makeHeader(), makeHeader(),
@@ -640,7 +640,7 @@ TEST_F(DecodeTest, AckFrameMissingFields) {
auto result4 = createAckFrame( auto result4 = createAckFrame(
largestAcked, ackDelay, numAdditionalBlocks, none, ackBlocks); largestAcked, ackDelay, numAdditionalBlocks, none, ackBlocks);
folly::io::Cursor cursor4(result4.get()); Cursor cursor4(result4.get());
res = decodeAckFrame( res = decodeAckFrame(
cursor4, cursor4,
makeHeader(), makeHeader(),
@@ -650,7 +650,7 @@ TEST_F(DecodeTest, AckFrameMissingFields) {
auto result5 = createAckFrame( auto result5 = createAckFrame(
largestAcked, ackDelay, numAdditionalBlocks, firstAckBlockLength, {}); largestAcked, ackDelay, numAdditionalBlocks, firstAckBlockLength, {});
folly::io::Cursor cursor5(result5.get()); Cursor cursor5(result5.get());
res = decodeAckFrame( res = decodeAckFrame(
cursor5, cursor5,
makeHeader(), makeHeader(),
@@ -667,7 +667,7 @@ TEST_F(DecodeTest, AckFrameFirstBlockLengthInvalid) {
auto result = createAckFrame( auto result = createAckFrame(
largestAcked, ackDelay, numAdditionalBlocks, firstAckBlockLength); largestAcked, ackDelay, numAdditionalBlocks, firstAckBlockLength);
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
auto res = decodeAckFrame( auto res = decodeAckFrame(
cursor, cursor,
makeHeader(), makeHeader(),
@@ -692,7 +692,7 @@ TEST_F(DecodeTest, AckFrameBlockLengthInvalid) {
numAdditionalBlocks, numAdditionalBlocks,
firstAckBlockLength, firstAckBlockLength,
ackBlocks); ackBlocks);
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
auto res = decodeAckFrame( auto res = decodeAckFrame(
cursor, cursor,
makeHeader(), makeHeader(),
@@ -717,7 +717,7 @@ TEST_F(DecodeTest, AckFrameBlockGapInvalid) {
numAdditionalBlocks, numAdditionalBlocks,
firstAckBlockLength, firstAckBlockLength,
ackBlocks); ackBlocks);
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
auto res = decodeAckFrame( auto res = decodeAckFrame(
cursor, cursor,
makeHeader(), makeHeader(),
@@ -743,7 +743,7 @@ TEST_F(DecodeTest, AckFrameBlockLengthZero) {
numAdditionalBlocks, numAdditionalBlocks,
firstAckBlockLength, firstAckBlockLength,
ackBlocks); ackBlocks);
folly::io::Cursor cursor(result.get()); Cursor cursor(result.get());
auto res = decodeAckFrame( auto res = decodeAckFrame(
cursor, cursor,
@@ -863,12 +863,12 @@ std::unique_ptr<folly::IOBuf> CreateMaxStreamsIdFrame(
void MaxStreamsIdCheckSuccess(StreamId maxStreamsId) { void MaxStreamsIdCheckSuccess(StreamId maxStreamsId) {
std::unique_ptr<folly::IOBuf> buf = CreateMaxStreamsIdFrame(maxStreamsId); std::unique_ptr<folly::IOBuf> buf = CreateMaxStreamsIdFrame(maxStreamsId);
folly::io::Cursor cursorBiDi(buf.get()); Cursor cursorBiDi(buf.get());
auto maxStreamsBiDiFrameRes = decodeBiDiMaxStreamsFrame(cursorBiDi); auto maxStreamsBiDiFrameRes = decodeBiDiMaxStreamsFrame(cursorBiDi);
ASSERT_TRUE(maxStreamsBiDiFrameRes.hasValue()); ASSERT_TRUE(maxStreamsBiDiFrameRes.hasValue());
EXPECT_EQ(maxStreamsBiDiFrameRes->maxStreams, maxStreamsId); EXPECT_EQ(maxStreamsBiDiFrameRes->maxStreams, maxStreamsId);
folly::io::Cursor cursorUni(buf.get()); Cursor cursorUni(buf.get());
auto maxStreamsUniFrameRes = decodeUniMaxStreamsFrame(cursorUni); auto maxStreamsUniFrameRes = decodeUniMaxStreamsFrame(cursorUni);
ASSERT_TRUE(maxStreamsUniFrameRes.hasValue()); ASSERT_TRUE(maxStreamsUniFrameRes.hasValue());
EXPECT_EQ(maxStreamsUniFrameRes->maxStreams, maxStreamsId); EXPECT_EQ(maxStreamsUniFrameRes->maxStreams, maxStreamsId);
@@ -878,12 +878,12 @@ void MaxStreamsIdCheckSuccess(StreamId maxStreamsId) {
void MaxStreamsIdCheckInvalid(StreamId maxStreamsId) { void MaxStreamsIdCheckInvalid(StreamId maxStreamsId) {
std::unique_ptr<folly::IOBuf> buf = CreateMaxStreamsIdFrame(maxStreamsId); std::unique_ptr<folly::IOBuf> buf = CreateMaxStreamsIdFrame(maxStreamsId);
folly::io::Cursor cursorBiDi(buf.get()); Cursor cursorBiDi(buf.get());
auto bidiResult = decodeBiDiMaxStreamsFrame(cursorBiDi); auto bidiResult = decodeBiDiMaxStreamsFrame(cursorBiDi);
EXPECT_TRUE(bidiResult.hasError()); EXPECT_TRUE(bidiResult.hasError());
EXPECT_EQ(bidiResult.error().code, TransportErrorCode::FRAME_ENCODING_ERROR); EXPECT_EQ(bidiResult.error().code, TransportErrorCode::FRAME_ENCODING_ERROR);
folly::io::Cursor cursorUni(buf.get()); Cursor cursorUni(buf.get());
auto uniResult = decodeUniMaxStreamsFrame(cursorUni); auto uniResult = decodeUniMaxStreamsFrame(cursorUni);
EXPECT_TRUE(uniResult.hasError()); EXPECT_TRUE(uniResult.hasError());
EXPECT_EQ(uniResult.error().code, TransportErrorCode::FRAME_ENCODING_ERROR); EXPECT_EQ(uniResult.error().code, TransportErrorCode::FRAME_ENCODING_ERROR);
@@ -904,7 +904,7 @@ TEST_F(DecodeTest, CryptoDecodeSuccess) {
QuicInteger length(1); QuicInteger length(1);
auto cryptoFrame = auto cryptoFrame =
createCryptoFrame(offset, length, folly::IOBuf::copyBuffer("a")); createCryptoFrame(offset, length, folly::IOBuf::copyBuffer("a"));
folly::io::Cursor cursor(cryptoFrame.get()); Cursor cursor(cryptoFrame.get());
auto decodedFrame = decodeCryptoFrame(cursor); auto decodedFrame = decodeCryptoFrame(cursor);
EXPECT_EQ(decodedFrame->offset, 10); EXPECT_EQ(decodedFrame->offset, 10);
EXPECT_EQ(decodedFrame->data->computeChainDataLength(), 1); EXPECT_EQ(decodedFrame->data->computeChainDataLength(), 1);
@@ -914,7 +914,7 @@ TEST_F(DecodeTest, CryptoOffsetNotPresent) {
QuicInteger length(1); QuicInteger length(1);
auto cryptoFrame = auto cryptoFrame =
createCryptoFrame(none, length, folly::IOBuf::copyBuffer("a")); createCryptoFrame(none, length, folly::IOBuf::copyBuffer("a"));
folly::io::Cursor cursor(cryptoFrame.get()); Cursor cursor(cryptoFrame.get());
auto result = decodeCryptoFrame(cursor); auto result = decodeCryptoFrame(cursor);
EXPECT_TRUE(result.hasError()); EXPECT_TRUE(result.hasError());
EXPECT_EQ(result.error().code, TransportErrorCode::FRAME_ENCODING_ERROR); EXPECT_EQ(result.error().code, TransportErrorCode::FRAME_ENCODING_ERROR);
@@ -923,7 +923,7 @@ TEST_F(DecodeTest, CryptoOffsetNotPresent) {
TEST_F(DecodeTest, CryptoLengthNotPresent) { TEST_F(DecodeTest, CryptoLengthNotPresent) {
QuicInteger offset(0); QuicInteger offset(0);
auto cryptoFrame = createCryptoFrame(offset, none, nullptr); auto cryptoFrame = createCryptoFrame(offset, none, nullptr);
folly::io::Cursor cursor(cryptoFrame.get()); Cursor cursor(cryptoFrame.get());
auto result = decodeCryptoFrame(cursor); auto result = decodeCryptoFrame(cursor);
EXPECT_TRUE(result.hasError()); EXPECT_TRUE(result.hasError());
EXPECT_EQ(result.error().code, TransportErrorCode::FRAME_ENCODING_ERROR); EXPECT_EQ(result.error().code, TransportErrorCode::FRAME_ENCODING_ERROR);
@@ -934,7 +934,7 @@ TEST_F(DecodeTest, CryptoIncorrectDataLength) {
QuicInteger length(10); QuicInteger length(10);
auto cryptoFrame = auto cryptoFrame =
createCryptoFrame(offset, length, folly::IOBuf::copyBuffer("a")); createCryptoFrame(offset, length, folly::IOBuf::copyBuffer("a"));
folly::io::Cursor cursor(cryptoFrame.get()); Cursor cursor(cryptoFrame.get());
auto result = decodeCryptoFrame(cursor); auto result = decodeCryptoFrame(cursor);
EXPECT_TRUE(result.hasError()); EXPECT_TRUE(result.hasError());
EXPECT_EQ(result.error().code, TransportErrorCode::FRAME_ENCODING_ERROR); EXPECT_EQ(result.error().code, TransportErrorCode::FRAME_ENCODING_ERROR);
@@ -945,14 +945,14 @@ TEST_F(DecodeTest, PaddingFrameTest) {
buf->append(1); buf->append(1);
memset(buf->writableData(), 0, 1); memset(buf->writableData(), 0, 1);
folly::io::Cursor cursor(buf.get()); Cursor cursor(buf.get());
ASSERT_FALSE(decodePaddingFrame(cursor).hasError()); ASSERT_FALSE(decodePaddingFrame(cursor).hasError());
} }
TEST_F(DecodeTest, PaddingFrameNoBytesTest) { TEST_F(DecodeTest, PaddingFrameNoBytesTest) {
auto buf = folly::IOBuf::create(sizeof(UnderlyingFrameType)); auto buf = folly::IOBuf::create(sizeof(UnderlyingFrameType));
folly::io::Cursor cursor(buf.get()); Cursor cursor(buf.get());
ASSERT_FALSE(decodePaddingFrame(cursor).hasError()); ASSERT_FALSE(decodePaddingFrame(cursor).hasError());
} }
@@ -964,7 +964,7 @@ TEST_F(DecodeTest, DecodeMultiplePaddingInterleavedTest) {
// something which is not padding // something which is not padding
memset(buf->writableData() + 10, 5, 1); memset(buf->writableData() + 10, 5, 1);
folly::io::Cursor cursor(buf.get()); Cursor cursor(buf.get());
ASSERT_FALSE(decodePaddingFrame(cursor).hasError()); ASSERT_FALSE(decodePaddingFrame(cursor).hasError());
// If we encountered an interleaved frame, leave the whole thing // If we encountered an interleaved frame, leave the whole thing
// as is // as is
@@ -976,7 +976,7 @@ TEST_F(DecodeTest, DecodeMultiplePaddingTest) {
buf->append(10); buf->append(10);
memset(buf->writableData(), 0, 10); memset(buf->writableData(), 0, 10);
folly::io::Cursor cursor(buf.get()); Cursor cursor(buf.get());
ASSERT_FALSE(decodePaddingFrame(cursor).hasError()); ASSERT_FALSE(decodePaddingFrame(cursor).hasError());
EXPECT_EQ(cursor.totalLength(), 0); EXPECT_EQ(cursor.totalLength(), 0);
} }
@@ -1000,14 +1000,14 @@ TEST_F(DecodeTest, NewTokenDecodeSuccess) {
QuicInteger length(1); QuicInteger length(1);
auto newTokenFrame = auto newTokenFrame =
createNewTokenFrame(length, folly::IOBuf::copyBuffer("a")); createNewTokenFrame(length, folly::IOBuf::copyBuffer("a"));
folly::io::Cursor cursor(newTokenFrame.get()); Cursor cursor(newTokenFrame.get());
auto decodedFrame = decodeNewTokenFrame(cursor); auto decodedFrame = decodeNewTokenFrame(cursor);
EXPECT_EQ(decodedFrame->token->computeChainDataLength(), 1); EXPECT_EQ(decodedFrame->token->computeChainDataLength(), 1);
} }
TEST_F(DecodeTest, NewTokenLengthNotPresent) { TEST_F(DecodeTest, NewTokenLengthNotPresent) {
auto newTokenFrame = createNewTokenFrame(none, folly::IOBuf::copyBuffer("a")); auto newTokenFrame = createNewTokenFrame(none, folly::IOBuf::copyBuffer("a"));
folly::io::Cursor cursor(newTokenFrame.get()); Cursor cursor(newTokenFrame.get());
auto result = decodeNewTokenFrame(cursor); auto result = decodeNewTokenFrame(cursor);
EXPECT_TRUE(result.hasError()); EXPECT_TRUE(result.hasError());
EXPECT_EQ(result.error().code, TransportErrorCode::FRAME_ENCODING_ERROR); EXPECT_EQ(result.error().code, TransportErrorCode::FRAME_ENCODING_ERROR);
@@ -1017,7 +1017,7 @@ TEST_F(DecodeTest, NewTokenIncorrectDataLength) {
QuicInteger length(10); QuicInteger length(10);
auto newTokenFrame = auto newTokenFrame =
createNewTokenFrame(length, folly::IOBuf::copyBuffer("a")); createNewTokenFrame(length, folly::IOBuf::copyBuffer("a"));
folly::io::Cursor cursor(newTokenFrame.get()); Cursor cursor(newTokenFrame.get());
auto result = decodeNewTokenFrame(cursor); auto result = decodeNewTokenFrame(cursor);
EXPECT_TRUE(result.hasError()); EXPECT_TRUE(result.hasError());
EXPECT_EQ(result.error().code, TransportErrorCode::FRAME_ENCODING_ERROR); EXPECT_EQ(result.error().code, TransportErrorCode::FRAME_ENCODING_ERROR);
@@ -1033,7 +1033,7 @@ TEST_F(DecodeTest, ParsePlaintextNewToken) {
NewToken newToken(clientIp, timestampInMs); NewToken newToken(clientIp, timestampInMs);
BufPtr plaintextNewToken = newToken.getPlaintextToken(); BufPtr plaintextNewToken = newToken.getPlaintextToken();
folly::io::Cursor cursor(plaintextNewToken.get()); Cursor cursor(plaintextNewToken.get());
auto parseResult = parsePlaintextRetryOrNewToken(cursor); auto parseResult = parsePlaintextRetryOrNewToken(cursor);
@@ -1054,7 +1054,7 @@ TEST_F(DecodeTest, ParsePlaintextRetryToken) {
RetryToken retryToken(odcid, clientIp, clientPort, timestampInMs); RetryToken retryToken(odcid, clientIp, clientPort, timestampInMs);
BufPtr plaintextRetryToken = retryToken.getPlaintextToken(); BufPtr plaintextRetryToken = retryToken.getPlaintextToken();
folly::io::Cursor cursor(plaintextRetryToken.get()); Cursor cursor(plaintextRetryToken.get());
/** /**
* Now we continue with the parsing logic here. * Now we continue with the parsing logic here.
@@ -1107,7 +1107,7 @@ TEST_F(DecodeTest, AckFrequencyFrameDecodeValid) {
sequenceNumber, packetTolerance, maxAckDelay, reorderThreshold); sequenceNumber, packetTolerance, maxAckDelay, reorderThreshold);
ASSERT_NE(ackFrequencyFrame, nullptr); ASSERT_NE(ackFrequencyFrame, nullptr);
folly::io::Cursor cursor(ackFrequencyFrame.get()); Cursor cursor(ackFrequencyFrame.get());
auto res = decodeAckFrequencyFrame(cursor); auto res = decodeAckFrequencyFrame(cursor);
EXPECT_TRUE(res.hasValue()); EXPECT_TRUE(res.hasValue());
auto decodedFrame = *res->asAckFrequencyFrame(); auto decodedFrame = *res->asAckFrequencyFrame();
@@ -1125,7 +1125,7 @@ TEST_F(DecodeTest, AckFrequencyFrameDecodeInvalidReserved) {
sequenceNumber, packetTolerance, maxAckDelay, none); sequenceNumber, packetTolerance, maxAckDelay, none);
ASSERT_NE(ackFrequencyFrame, nullptr); ASSERT_NE(ackFrequencyFrame, nullptr);
folly::io::Cursor cursor(ackFrequencyFrame.get()); Cursor cursor(ackFrequencyFrame.get());
auto res = decodeAckFrequencyFrame(cursor); auto res = decodeAckFrequencyFrame(cursor);
EXPECT_TRUE(res.hasError()); EXPECT_TRUE(res.hasError());
EXPECT_EQ(res.error().code, TransportErrorCode::FRAME_ENCODING_ERROR); EXPECT_EQ(res.error().code, TransportErrorCode::FRAME_ENCODING_ERROR);

View File

@@ -16,7 +16,7 @@ namespace quic::test {
TEST(ConnectionIdTest, TestConnidLen) { TEST(ConnectionIdTest, TestConnidLen) {
std::string out = folly::unhexlify("ffaabbee00"); std::string out = folly::unhexlify("ffaabbee00");
folly::IOBuf buf = folly::IOBuf::wrapBufferAsValue(out.data(), out.size()); folly::IOBuf buf = folly::IOBuf::wrapBufferAsValue(out.data(), out.size());
folly::io::Cursor cursor(&buf); Cursor cursor(&buf);
ConnectionId connid(cursor, out.size()); ConnectionId connid(cursor, out.size());
EXPECT_EQ(static_cast<size_t>(connid.size()), out.size()); EXPECT_EQ(static_cast<size_t>(connid.size()), out.size());
for (size_t i = 0; i < connid.size(); ++i) { for (size_t i = 0; i < connid.size(); ++i) {
@@ -29,7 +29,7 @@ TEST(ConnectionIdTest, TestConnidLen) {
TEST(ConnectionIdTest, TestZeroLenConnid) { TEST(ConnectionIdTest, TestZeroLenConnid) {
std::string out; std::string out;
folly::IOBuf buf = folly::IOBuf::wrapBufferAsValue(out.data(), out.size()); folly::IOBuf buf = folly::IOBuf::wrapBufferAsValue(out.data(), out.size());
folly::io::Cursor cursor(&buf); Cursor cursor(&buf);
ConnectionId connid(cursor, out.size()); ConnectionId connid(cursor, out.size());
EXPECT_EQ(static_cast<size_t>(connid.size()), out.size()); EXPECT_EQ(static_cast<size_t>(connid.size()), out.size());
} }

View File

@@ -38,7 +38,7 @@ TEST_P(QuicIntegerDecodeTest, DecodeTrim) {
wrappedEncoded->trimEnd(std::min( wrappedEncoded->trimEnd(std::min(
(unsigned long)(wrappedEncoded->computeChainDataLength()), (unsigned long)(wrappedEncoded->computeChainDataLength()),
(unsigned long)(GetParam().encodedLength - atMost))); (unsigned long)(GetParam().encodedLength - atMost)));
folly::io::Cursor cursor(wrappedEncoded.get()); Cursor cursor(wrappedEncoded.get());
auto originalLength = cursor.length(); auto originalLength = cursor.length();
auto decodedValue = decodeQuicInteger(cursor); auto decodedValue = decodeQuicInteger(cursor);
if (GetParam().error || atMost != GetParam().encodedLength) { if (GetParam().error || atMost != GetParam().encodedLength) {
@@ -57,7 +57,7 @@ TEST_P(QuicIntegerDecodeTest, DecodeAtMost) {
auto wrappedEncoded = IOBuf::copyBuffer(encodedBytes); auto wrappedEncoded = IOBuf::copyBuffer(encodedBytes);
for (int atMost = 0; atMost <= GetParam().encodedLength; atMost++) { for (int atMost = 0; atMost <= GetParam().encodedLength; atMost++) {
folly::io::Cursor cursor(wrappedEncoded.get()); Cursor cursor(wrappedEncoded.get());
auto originalLength = cursor.length(); auto originalLength = cursor.length();
auto decodedValue = decodeQuicInteger(cursor, atMost); auto decodedValue = decodeQuicInteger(cursor, atMost);
if (GetParam().error || atMost != GetParam().encodedLength) { if (GetParam().error || atMost != GetParam().encodedLength) {

View File

@@ -622,8 +622,8 @@ TEST_F(QuicPacketBuilderTest, PseudoRetryPacket) {
BufPtr expectedIntegrityTag = folly::IOBuf::copyBuffer( BufPtr expectedIntegrityTag = folly::IOBuf::copyBuffer(
"\xd1\x69\x26\xd8\x1f\x6f\x9c\xa2\x95\x3a\x8a\xa4\x57\x5e\x1e\x49"); "\xd1\x69\x26\xd8\x1f\x6f\x9c\xa2\x95\x3a\x8a\xa4\x57\x5e\x1e\x49");
folly::io::Cursor cursorActual(integrityTag.get()); Cursor cursorActual(integrityTag.get());
folly::io::Cursor cursorExpected(expectedIntegrityTag.get()); Cursor cursorExpected(expectedIntegrityTag.get());
EXPECT_TRUE(folly::IOBufEqualTo()(*expectedIntegrityTag, *integrityTag)); EXPECT_TRUE(folly::IOBufEqualTo()(*expectedIntegrityTag, *integrityTag));
} }
@@ -685,7 +685,7 @@ TEST_F(QuicPacketBuilderTest, RetryPacketValid) {
EXPECT_EQ(retryPacket->computeChainDataLength(), expectedPacketLen); EXPECT_EQ(retryPacket->computeChainDataLength(), expectedPacketLen);
// initial byte // initial byte
folly::io::Cursor cursor(retryPacket.get()); Cursor cursor(retryPacket.get());
auto initialByte = cursor.readBE<uint8_t>(); auto initialByte = cursor.readBE<uint8_t>();
EXPECT_EQ(initialByte & 0xf0, 0xf0); EXPECT_EQ(initialByte & 0xf0, 0xf0);

View File

@@ -723,7 +723,7 @@ TEST_F(QuicReadCodecTest, TestInitialPacketExtractToken) {
auto packetQueue = auto packetQueue =
bufToQueue(packetToBufCleartext(packet, *aead, *headerCipher, packetNum)); bufToQueue(packetToBufCleartext(packet, *aead, *headerCipher, packetNum));
folly::io::Cursor cursor(packetQueue.front()); Cursor cursor(packetQueue.front());
auto res = tryParseLongHeader(cursor, QuicNodeType::Client); auto res = tryParseLongHeader(cursor, QuicNodeType::Client);
EXPECT_FALSE(res.hasError()); EXPECT_FALSE(res.hasError());
auto parsedLongHeader = std::move(res.value()); auto parsedLongHeader = std::move(res.value());

View File

@@ -124,7 +124,7 @@ void setupCommonExpects(MockQuicPacketBuilder& pktBuilder) {
.WillRepeatedly(WithArgs<0, 1>(Invoke([&](BufPtr& buf, size_t limit) { .WillRepeatedly(WithArgs<0, 1>(Invoke([&](BufPtr& buf, size_t limit) {
pktBuilder.remaining_ -= limit; pktBuilder.remaining_ -= limit;
std::unique_ptr<folly::IOBuf> cloneBuf; std::unique_ptr<folly::IOBuf> cloneBuf;
folly::io::Cursor cursor(buf.get()); Cursor cursor(buf.get());
cursor.clone(cloneBuf, limit); cursor.clone(cloneBuf, limit);
pktBuilder.appender_.insert(std::move(cloneBuf)); pktBuilder.appender_.insert(std::move(cloneBuf));
}))); })));
@@ -147,7 +147,7 @@ void setupCommonExpects(MockQuicPacketBuilder& pktBuilder) {
WithArgs<0, 1>(Invoke([&](const BufQueue& buf, size_t limit) { WithArgs<0, 1>(Invoke([&](const BufQueue& buf, size_t limit) {
pktBuilder.remaining_ -= limit; pktBuilder.remaining_ -= limit;
std::unique_ptr<folly::IOBuf> cloneBuf; std::unique_ptr<folly::IOBuf> cloneBuf;
folly::io::Cursor cursor(buf.front()); Cursor cursor(buf.front());
cursor.clone(cloneBuf, limit); cursor.clone(cloneBuf, limit);
pktBuilder.appender_.insert(std::move(cloneBuf)); pktBuilder.appender_.insert(std::move(cloneBuf));
}))); })));
@@ -883,7 +883,7 @@ TEST_F(QuicWriteCodecTest, WriteFinToEmptyPacket) {
EXPECT_TRUE(folly::IOBufEqualTo()(inputBuf, outputBuf)); EXPECT_TRUE(folly::IOBufEqualTo()(inputBuf, outputBuf));
auto wireBuf = std::move(builtOut.second); auto wireBuf = std::move(builtOut.second);
folly::io::Cursor cursor(wireBuf.get()); Cursor cursor(wireBuf.get());
BufQueue queue; BufQueue queue;
queue.append(wireBuf->clone()); queue.append(wireBuf->clone());
auto decodedFrame = quic::parseFrame( auto decodedFrame = quic::parseFrame(
@@ -1582,7 +1582,7 @@ TEST_P(QuicWriteCodecTest, WriteExponentInLongHeaderPacket) {
EXPECT_TRUE(ackFrameWriteResult.hasValue()); EXPECT_TRUE(ackFrameWriteResult.hasValue());
auto builtOut = std::move(pktBuilder).buildLongHeaderPacket(); auto builtOut = std::move(pktBuilder).buildLongHeaderPacket();
auto wireBuf = std::move(builtOut.second); auto wireBuf = std::move(builtOut.second);
folly::io::Cursor cursor(wireBuf.get()); Cursor cursor(wireBuf.get());
BufQueue queue; BufQueue queue;
queue.append(wireBuf->clone()); queue.append(wireBuf->clone());
auto decodedFrameResult = quic::parseFrame( auto decodedFrameResult = quic::parseFrame(
@@ -2182,7 +2182,7 @@ TEST_F(QuicWriteCodecTest, WriteMaxStreamId) {
EXPECT_EQ(i, resultMaxStreamIdFrame.maxStreams); EXPECT_EQ(i, resultMaxStreamIdFrame.maxStreams);
auto wireBuf = std::move(builtOut.second); auto wireBuf = std::move(builtOut.second);
folly::io::Cursor cursor(wireBuf.get()); Cursor cursor(wireBuf.get());
BufQueue queue; BufQueue queue;
queue.append(wireBuf->clone()); queue.append(wireBuf->clone());
QuicFrame decodedFrame = parseQuicFrame(queue); QuicFrame decodedFrame = parseQuicFrame(queue);

View File

@@ -24,7 +24,7 @@ std::pair<uint8_t, BufPtr> encodeShortHeader(const ShortHeader& header) {
CHECK(!builder.encodePacketHeader().hasError()); CHECK(!builder.encodePacketHeader().hasError());
auto packet = std::move(builder).buildPacket(); auto packet = std::move(builder).buildPacket();
BufPtr out; BufPtr out;
folly::io::Cursor cursor(&packet.header); Cursor cursor(&packet.header);
auto initialByte = cursor.readBE<uint8_t>(); auto initialByte = cursor.readBE<uint8_t>();
cursor.clone(out, cursor.totalLength()); cursor.clone(out, cursor.totalLength());
return std::make_pair(initialByte, std::move(out)); return std::make_pair(initialByte, std::move(out));
@@ -63,7 +63,7 @@ folly::Expected<ParsedLongHeaderResult, TransportErrorCode> makeLongHeader(
0 /* largestAcked */); 0 /* largestAcked */);
CHECK(!builder.encodePacketHeader().hasError()); CHECK(!builder.encodePacketHeader().hasError());
auto packet = packetToBuf(std::move(builder).buildPacket()); auto packet = packetToBuf(std::move(builder).buildPacket());
folly::io::Cursor cursor(packet.get()); Cursor cursor(packet.get());
uint8_t initialByte = cursor.readBE<uint8_t>(); uint8_t initialByte = cursor.readBE<uint8_t>();
return parseLongHeader(initialByte, cursor); return parseLongHeader(initialByte, cursor);
} }
@@ -95,7 +95,7 @@ TEST_F(TypesTest, LongHeaderEmptyInput) {
uint8_t versionNegotiation = LongHeader::kPacketTypeMask; uint8_t versionNegotiation = LongHeader::kPacketTypeMask;
auto buf = folly::IOBuf::create(0); auto buf = folly::IOBuf::create(0);
buf->append(0); buf->append(0);
folly::io::Cursor cursor(buf.get()); Cursor cursor(buf.get());
EXPECT_FALSE(parseLongHeader(versionNegotiation, cursor).hasValue()); EXPECT_FALSE(parseLongHeader(versionNegotiation, cursor).hasValue());
} }
@@ -114,7 +114,7 @@ TEST_F(TypesTest, LongHeaderSmallInput) {
wcursor.writeBE<uint8_t>(2); wcursor.writeBE<uint8_t>(2);
wcursor.writeBE<uint8_t>(3); wcursor.writeBE<uint8_t>(3);
folly::io::Cursor cursor(buf.get()); Cursor cursor(buf.get());
EXPECT_FALSE(parseLongHeader(clientCleartext, cursor).hasValue()); EXPECT_FALSE(parseLongHeader(clientCleartext, cursor).hasValue());
} }
@@ -131,7 +131,7 @@ TEST_F(TypesTest, LongHeaderInvalid) {
wcursor.writeBE<uint32_t>(1234); wcursor.writeBE<uint32_t>(1234);
wcursor.writeBE<QuicVersionType>(static_cast<QuicVersionType>(version)); wcursor.writeBE<QuicVersionType>(static_cast<QuicVersionType>(version));
folly::io::Cursor cursor(buf.get()); Cursor cursor(buf.get());
EXPECT_FALSE(parseLongHeader(badInitialValue, cursor).hasValue()); EXPECT_FALSE(parseLongHeader(badInitialValue, cursor).hasValue());
} }
@@ -140,7 +140,7 @@ TEST_F(TypesTest, ShortHeader) {
auto connId = getTestConnectionId(); auto connId = getTestConnectionId();
ShortHeader testHeader1(ProtectionType::KeyPhaseZero, connId, packetNum); ShortHeader testHeader1(ProtectionType::KeyPhaseZero, connId, packetNum);
auto result1 = encodeShortHeader(testHeader1); auto result1 = encodeShortHeader(testHeader1);
folly::io::Cursor cursor1(result1.second.get()); Cursor cursor1(result1.second.get());
auto shortHeader1 = *parseShortHeader(result1.first, cursor1); auto shortHeader1 = *parseShortHeader(result1.first, cursor1);
EXPECT_EQ(ProtectionType::KeyPhaseZero, shortHeader1.getProtectionType()); EXPECT_EQ(ProtectionType::KeyPhaseZero, shortHeader1.getProtectionType());
EXPECT_EQ(connId, shortHeader1.getConnectionId()); EXPECT_EQ(connId, shortHeader1.getConnectionId());
@@ -148,7 +148,7 @@ TEST_F(TypesTest, ShortHeader) {
// Empty buffer // Empty buffer
auto buf4 = folly::IOBuf::create(0); auto buf4 = folly::IOBuf::create(0);
buf4->append(0); buf4->append(0);
folly::io::Cursor cursor4(buf4.get()); Cursor cursor4(buf4.get());
EXPECT_FALSE(parseShortHeader(0x01, cursor4).hasValue()); EXPECT_FALSE(parseShortHeader(0x01, cursor4).hasValue());
} }
@@ -165,7 +165,7 @@ TEST_F(TypesTest, ShortHeaderGetConnectionIdTest) {
ShortHeader testHeader(ProtectionType::KeyPhaseZero, connId, packetNum); ShortHeader testHeader(ProtectionType::KeyPhaseZero, connId, packetNum);
auto result = encodeShortHeader(testHeader); auto result = encodeShortHeader(testHeader);
folly::io::Cursor cursor(result.second.get()); Cursor cursor(result.second.get());
auto shortHeader = *parseShortHeader(result.first, cursor); auto shortHeader = *parseShortHeader(result.first, cursor);
EXPECT_EQ(connId, shortHeader.getConnectionId()); EXPECT_EQ(connId, shortHeader.getConnectionId());
} }

View File

@@ -374,7 +374,7 @@ TEST(BufWriterTest, BasicWrite) {
writer.writeBE(sixtyfour); writer.writeBE(sixtyfour);
testBuffer->append(writer.getBytesWritten()); testBuffer->append(writer.getBytesWritten());
folly::io::Cursor reader(testBuffer.get()); Cursor reader(testBuffer.get());
EXPECT_EQ(8, reader.template readBE<uint8_t>()); EXPECT_EQ(8, reader.template readBE<uint8_t>());
EXPECT_EQ(16, reader.template readBE<uint16_t>()); EXPECT_EQ(16, reader.template readBE<uint16_t>());
EXPECT_EQ(32, reader.template readBE<uint32_t>()); EXPECT_EQ(32, reader.template readBE<uint32_t>());
@@ -404,7 +404,7 @@ TEST(BufWriterTest, Push) {
folly::IOBuf::copyBuffer("All you're gonna see it someday"); folly::IOBuf::copyBuffer("All you're gonna see it someday");
writer.push(inputBuffer->data(), inputBuffer->computeChainDataLength()); writer.push(inputBuffer->data(), inputBuffer->computeChainDataLength());
testBuffer->append(writer.getBytesWritten()); testBuffer->append(writer.getBytesWritten());
folly::io::Cursor reader(testBuffer.get()); Cursor reader(testBuffer.get());
EXPECT_EQ( EXPECT_EQ(
"All you're gonna see it someday", "All you're gonna see it someday",
reader.readFixedString(inputBuffer->computeChainDataLength())); reader.readFixedString(inputBuffer->computeChainDataLength()));
@@ -418,7 +418,7 @@ TEST(BufWriterTest, InsertSingle) {
auto len = inputBuffer->computeChainDataLength(); auto len = inputBuffer->computeChainDataLength();
writer.insert(inputBuffer.get()); writer.insert(inputBuffer.get());
testBuffer->append(writer.getBytesWritten()); testBuffer->append(writer.getBytesWritten());
folly::io::Cursor reader(testBuffer.get()); Cursor reader(testBuffer.get());
EXPECT_EQ(inputBuffer->to<string>(), reader.readFixedString(len)); EXPECT_EQ(inputBuffer->to<string>(), reader.readFixedString(len));
} }
@@ -434,7 +434,7 @@ TEST(BufWriterTest, InsertChain) {
auto len = inputBuffer->computeChainDataLength(); auto len = inputBuffer->computeChainDataLength();
writer.insert(inputBuffer.get()); writer.insert(inputBuffer.get());
testBuffer->append(writer.getBytesWritten()); testBuffer->append(writer.getBytesWritten());
folly::io::Cursor reader(testBuffer.get()); Cursor reader(testBuffer.get());
EXPECT_EQ( EXPECT_EQ(
"Cause I lost you and now what am i to do?" "Cause I lost you and now what am i to do?"
" Can't believe that we are through." " Can't believe that we are through."
@@ -454,7 +454,7 @@ TEST(BufWriterTest, BackFill) {
bufWriter.backFill( bufWriter.backFill(
(uint8_t*)testInput3.data(), testInput3.size(), testInput1.size()); (uint8_t*)testInput3.data(), testInput3.size(), testInput1.size());
testBuffer->append(bufWriter.getBytesWritten()); testBuffer->append(bufWriter.getBytesWritten());
folly::io::Cursor reader(testBuffer.get()); Cursor reader(testBuffer.get());
EXPECT_EQ( EXPECT_EQ(
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
reader.readFixedString( reader.readFixedString(
@@ -468,7 +468,7 @@ TEST(BufWriterTest, BufQueueCopy) {
BufWriter bufWriter(outputBuffer->writableTail(), 200); BufWriter bufWriter(outputBuffer->writableTail(), 200);
bufWriter.insert(queue.front(), queue.chainLength()); bufWriter.insert(queue.front(), queue.chainLength());
outputBuffer->append(bufWriter.getBytesWritten()); outputBuffer->append(bufWriter.getBytesWritten());
folly::io::Cursor reader(outputBuffer.get()); Cursor reader(outputBuffer.get());
EXPECT_EQ( EXPECT_EQ(
"I feel like I'm drowning", reader.readFixedString(queue.chainLength())); "I feel like I'm drowning", reader.readFixedString(queue.chainLength()));
} }
@@ -480,7 +480,7 @@ TEST(BufWriterTest, BufQueueCopyPartial) {
BufWriter bufWriter(outputBuffer->writableTail(), 200); BufWriter bufWriter(outputBuffer->writableTail(), 200);
bufWriter.insert(queue.front(), 6); bufWriter.insert(queue.front(), 6);
outputBuffer->append(bufWriter.getBytesWritten()); outputBuffer->append(bufWriter.getBytesWritten());
folly::io::Cursor reader(outputBuffer.get()); Cursor reader(outputBuffer.get());
EXPECT_EQ( EXPECT_EQ(
"I feel", reader.readFixedString(outputBuffer->computeChainDataLength())); "I feel", reader.readFixedString(outputBuffer->computeChainDataLength()));
} }
@@ -493,7 +493,7 @@ TEST(BufWriterTest, BufQueueChainCopy) {
BufWriter bufWriter(outputBuffer->writableTail(), 1000); BufWriter bufWriter(outputBuffer->writableTail(), 1000);
bufWriter.insert(queue.front(), queue.chainLength()); bufWriter.insert(queue.front(), queue.chainLength());
outputBuffer->append(bufWriter.getBytesWritten()); outputBuffer->append(bufWriter.getBytesWritten());
folly::io::Cursor reader(outputBuffer.get()); Cursor reader(outputBuffer.get());
EXPECT_EQ( EXPECT_EQ(
"I'm a hotpot. You mere are hotpot soup base.", "I'm a hotpot. You mere are hotpot soup base.",
reader.readFixedString(queue.chainLength())); reader.readFixedString(queue.chainLength()));
@@ -509,7 +509,7 @@ TEST(BufWriterTest, BufQueueChainCopyPartial) {
BufWriter bufWriter(outputBuffer->writableTail(), 1000); BufWriter bufWriter(outputBuffer->writableTail(), 1000);
bufWriter.insert(queue.front(), testStr1.size() + 10); bufWriter.insert(queue.front(), testStr1.size() + 10);
outputBuffer->append(bufWriter.getBytesWritten()); outputBuffer->append(bufWriter.getBytesWritten());
folly::io::Cursor reader(outputBuffer.get()); Cursor reader(outputBuffer.get());
EXPECT_EQ( EXPECT_EQ(
folly::to<std::string>(testStr1, "That you l"), folly::to<std::string>(testStr1, "That you l"),
reader.readFixedString(testStr1.size() + 10)); reader.readFixedString(testStr1.size() + 10));
@@ -528,7 +528,7 @@ TEST(BufWriterTest, BufQueueChainCopyTooLargeLimit) {
bufWriter.insert( bufWriter.insert(
queue.front(), (testStr1.size() + testStr2.size() + testStr3.size()) * 5); queue.front(), (testStr1.size() + testStr2.size() + testStr3.size()) * 5);
outputBuffer->append(bufWriter.getBytesWritten()); outputBuffer->append(bufWriter.getBytesWritten());
folly::io::Cursor reader(outputBuffer.get()); Cursor reader(outputBuffer.get());
EXPECT_EQ( EXPECT_EQ(
"I see trees of green. " "I see trees of green. "
"Red rose too. " "Red rose too. "
@@ -549,7 +549,7 @@ TEST(BufWriterTest, TwoWriters) {
auto inputBuffer2 = folly::IOBuf::copyBuffer(" Saint"); auto inputBuffer2 = folly::IOBuf::copyBuffer(" Saint");
bufWriter2.insert(inputBuffer2.get()); bufWriter2.insert(inputBuffer2.get());
outputBuffer->append(bufWriter2.getBytesWritten()); outputBuffer->append(bufWriter2.getBytesWritten());
folly::io::Cursor reader(outputBuffer.get()); Cursor reader(outputBuffer.get());
EXPECT_EQ(15, outputBuffer->length()); EXPECT_EQ(15, outputBuffer->length());
EXPECT_EQ("Destroyer Saint", reader.readFixedString(outputBuffer->length())); EXPECT_EQ("Destroyer Saint", reader.readFixedString(outputBuffer->length()));
} }
@@ -563,7 +563,7 @@ TEST(BufWriterTest, InsertSingleByteChainedRange) {
ChainedByteRangeHead cbrh(inputBuffer); ChainedByteRangeHead cbrh(inputBuffer);
writer.insert(&cbrh); writer.insert(&cbrh);
testBuffer->append(writer.getBytesWritten()); testBuffer->append(writer.getBytesWritten());
folly::io::Cursor reader(testBuffer.get()); Cursor reader(testBuffer.get());
EXPECT_EQ( EXPECT_EQ(
inputBuffer->computeChainDataLength(), inputBuffer->computeChainDataLength(),
testBuffer->computeChainDataLength()); testBuffer->computeChainDataLength());
@@ -576,7 +576,7 @@ TEST(BufWriterTest, InsertZeroLen) {
auto inputBuffer = folly::IOBuf::copyBuffer(""); auto inputBuffer = folly::IOBuf::copyBuffer("");
ChainedByteRangeHead cbrh(inputBuffer); ChainedByteRangeHead cbrh(inputBuffer);
writer.insert(&cbrh); writer.insert(&cbrh);
folly::io::Cursor reader(testBuffer.get()); Cursor reader(testBuffer.get());
EXPECT_EQ(testBuffer->computeChainDataLength(), 0); EXPECT_EQ(testBuffer->computeChainDataLength(), 0);
} }
@@ -588,7 +588,7 @@ TEST(BufWriterTest, InsertSingleByteChainedRangeWithLimit) {
ChainedByteRangeHead cbrh(inputBuffer); ChainedByteRangeHead cbrh(inputBuffer);
writer.insert(&cbrh, 10); writer.insert(&cbrh, 10);
testBuffer->append(writer.getBytesWritten()); testBuffer->append(writer.getBytesWritten());
folly::io::Cursor reader(testBuffer.get()); Cursor reader(testBuffer.get());
EXPECT_EQ(testBuffer->computeChainDataLength(), 10); EXPECT_EQ(testBuffer->computeChainDataLength(), 10);
EXPECT_EQ("Steady on ", reader.readFixedString(10)); EXPECT_EQ("Steady on ", reader.readFixedString(10));
} }
@@ -606,7 +606,7 @@ TEST(BufWriterTest, InsertChainByteChainedRange) {
ChainedByteRangeHead cbrh(inputBuffer); ChainedByteRangeHead cbrh(inputBuffer);
writer.insert(&cbrh); writer.insert(&cbrh);
testBuffer->append(writer.getBytesWritten()); testBuffer->append(writer.getBytesWritten());
folly::io::Cursor reader(testBuffer.get()); Cursor reader(testBuffer.get());
EXPECT_EQ(testBuffer->computeChainDataLength(), len); EXPECT_EQ(testBuffer->computeChainDataLength(), len);
EXPECT_EQ( EXPECT_EQ(
"Cause I lost you and now what am i to do?" "Cause I lost you and now what am i to do?"

View File

@@ -66,7 +66,7 @@ inline void removeDuplicateParams(std::vector<TransportParameter>& params) {
inline void decodeVarintParams( inline void decodeVarintParams(
std::vector<TransportParameter>& parameters, std::vector<TransportParameter>& parameters,
folly::io::Cursor& cursor) { Cursor& cursor) {
while (!cursor.isAtEnd()) { while (!cursor.isAtEnd()) {
auto id = decodeQuicInteger(cursor); auto id = decodeQuicInteger(cursor);
if (!id) { if (!id) {
@@ -126,7 +126,7 @@ inline quic::Optional<quic::ClientTransportParameters> getClientExtension(
return quic::none; return quic::none;
} }
quic::ClientTransportParameters parameters; quic::ClientTransportParameters parameters;
folly::io::Cursor cursor(it->extension_data.get()); quic::Cursor cursor(it->extension_data.get());
decodeVarintParams(parameters.parameters, cursor); decodeVarintParams(parameters.parameters, cursor);
return parameters; return parameters;
} }
@@ -140,7 +140,7 @@ inline quic::Optional<quic::ServerTransportParameters> getServerExtension(
return quic::none; return quic::none;
} }
quic::ServerTransportParameters parameters; quic::ServerTransportParameters parameters;
folly::io::Cursor cursor(it->extension_data.get()); quic::Cursor cursor(it->extension_data.get());
decodeVarintParams(parameters.parameters, cursor); decodeVarintParams(parameters.parameters, cursor);
return parameters; return parameters;
} }
@@ -154,7 +154,7 @@ inline quic::Optional<quic::TicketTransportParameters> getTicketExtension(
return quic::none; return quic::none;
} }
quic::TicketTransportParameters parameters; quic::TicketTransportParameters parameters;
folly::io::Cursor cursor(it->extension_data.get()); quic::Cursor cursor(it->extension_data.get());
decodeVarintParams(parameters.parameters, cursor); decodeVarintParams(parameters.parameters, cursor);
return parameters; return parameters;
} }

View File

@@ -19,7 +19,7 @@ Optional<uint64_t> getIntegerParameter(
if (it == parameters.end()) { if (it == parameters.end()) {
return none; return none;
} }
auto parameterCursor = folly::io::Cursor(it->value.get()); auto parameterCursor = Cursor(it->value.get());
auto parameter = decodeQuicInteger(parameterCursor); auto parameter = decodeQuicInteger(parameterCursor);
if (!parameter) { if (!parameter) {
throw QuicTransportException( throw QuicTransportException(
@@ -39,7 +39,7 @@ Optional<ConnectionId> getConnIdParameter(
} }
auto value = it->value->clone(); auto value = it->value->clone();
folly::io::Cursor cursor(value.get()); Cursor cursor(value.get());
// Constructor may throw an exception if the input is invalid. // Constructor may throw an exception if the input is invalid.
return ConnectionId(cursor, value->length()); return ConnectionId(cursor, value->length());

View File

@@ -186,7 +186,7 @@ void TakeoverPacketHandler::processForwardedPacket(
// First we decode the actual client and time from the packet // First we decode the actual client and time from the packet
// and send it to the worker_ to handle it properly // and send it to the worker_ to handle it properly
folly::io::Cursor cursor(data.get()); Cursor cursor(data.get());
if (!cursor.canAdvance(sizeof(TakeoverProtocolVersion))) { if (!cursor.canAdvance(sizeof(TakeoverProtocolVersion))) {
VLOG(4) << "Cannot read takeover protocol version. Dropping."; VLOG(4) << "Cannot read takeover protocol version. Dropping.";
return; return;

View File

@@ -443,7 +443,7 @@ void QuicServerWorker::handleNetworkData(
try { try {
// check error conditions for packet drop & early return // check error conditions for packet drop & early return
folly::io::Cursor cursor(udpPacket.buf.front()); Cursor cursor(udpPacket.buf.front());
if (shutdown_) { if (shutdown_) {
VLOG(4) << "Packet received after shutdown, dropping"; VLOG(4) << "Packet received after shutdown, dropping";
packetDropReason = PacketDropReason::SERVER_SHUTDOWN; packetDropReason = PacketDropReason::SERVER_SHUTDOWN;
@@ -945,7 +945,7 @@ void QuicServerWorker::dispatchPacketData(
// If there is a token present, decrypt it (could be either a retry // If there is a token present, decrypt it (could be either a retry
// token or a new token) // token or a new token)
folly::io::Cursor cursor(networkData.getPackets().front().buf.front()); Cursor cursor(networkData.getPackets().front().buf.front());
auto maybeEncryptedToken = maybeGetEncryptedToken(cursor); auto maybeEncryptedToken = maybeGetEncryptedToken(cursor);
bool hasTokenSecret = transportSettings_.retryTokenSecret.hasValue(); bool hasTokenSecret = transportSettings_.retryTokenSecret.hasValue();
@@ -1032,8 +1032,7 @@ void QuicServerWorker::sendResetPacket(
QUIC_STATS(statsCallback_, onStatelessReset); QUIC_STATS(statsCallback_, onStatelessReset);
} }
Optional<std::string> QuicServerWorker::maybeGetEncryptedToken( Optional<std::string> QuicServerWorker::maybeGetEncryptedToken(Cursor& cursor) {
folly::io::Cursor& cursor) {
// Move cursor to the byte right after the initial byte // Move cursor to the byte right after the initial byte
if (!cursor.canAdvance(1)) { if (!cursor.canAdvance(1)) {
return none; return none;
@@ -1146,7 +1145,7 @@ void QuicServerWorker::sendRetryPacket(
FizzRetryIntegrityTagGenerator fizzRetryIntegrityTagGenerator; FizzRetryIntegrityTagGenerator fizzRetryIntegrityTagGenerator;
auto integrityTagBuf = fizzRetryIntegrityTagGenerator.getRetryIntegrityTag( auto integrityTagBuf = fizzRetryIntegrityTagGenerator.getRetryIntegrityTag(
QuicVersion::MVFST_INVALID, pseudoRetryPacketBuf.get()); QuicVersion::MVFST_INVALID, pseudoRetryPacketBuf.get());
folly::io::Cursor cursor{integrityTagBuf.get()}; Cursor cursor{integrityTagBuf.get()};
RetryPacket::IntegrityTagType integrityTag = {0}; RetryPacket::IntegrityTagType integrityTag = {0};
cursor.pull(integrityTag.data(), integrityTag.size()); cursor.pull(integrityTag.data(), integrityTag.size());

View File

@@ -540,7 +540,7 @@ class QuicServerWorker : public FollyAsyncUDPSocketAlias::ReadCallback,
/** /**
* Tries to get the encrypted retry token from a client initial packet * Tries to get the encrypted retry token from a client initial packet
*/ */
Optional<std::string> maybeGetEncryptedToken(folly::io::Cursor& cursor); Optional<std::string> maybeGetEncryptedToken(Cursor& cursor);
bool validRetryToken( bool validRetryToken(
std::string& encryptedToken, std::string& encryptedToken,

View File

@@ -826,7 +826,7 @@ folly::Expected<folly::Unit, QuicError> onServerReadDataFromOpen(
bool firstPacketFromPeer = false; bool firstPacketFromPeer = false;
if (!conn.readCodec) { if (!conn.readCodec) {
firstPacketFromPeer = true; firstPacketFromPeer = true;
folly::io::Cursor cursor(readData.udpPacket.buf.front()); Cursor cursor(readData.udpPacket.buf.front());
auto initialByte = cursor.readBE<uint8_t>(); auto initialByte = cursor.readBE<uint8_t>();
auto parsedLongHeader = parseLongHeaderInvariant(initialByte, cursor); auto parsedLongHeader = parseLongHeaderInvariant(initialByte, cursor);
if (!parsedLongHeader) { if (!parsedLongHeader) {

View File

@@ -1910,7 +1910,7 @@ void QuicServerWorkerTakeoverTest::testPacketForwarding(
// the writtenData contains actual client address + time of ack + data // the writtenData contains actual client address + time of ack + data
EXPECT_FALSE(eq(*data, *writtenData)); EXPECT_FALSE(eq(*data, *writtenData));
// extract and verify the encoded client address // extract and verify the encoded client address
folly::io::Cursor cursor(writtenData.get()); Cursor cursor(writtenData.get());
uint32_t protocotVersion = (cursor.readBE<uint32_t>()); uint32_t protocotVersion = (cursor.readBE<uint32_t>());
EXPECT_EQ(protocotVersion, 0x0000001); EXPECT_EQ(protocotVersion, 0x0000001);
uint16_t addrLen = (cursor.readBE<uint16_t>()); uint16_t addrLen = (cursor.readBE<uint16_t>());