Skip to content

Commit

Permalink
H3 priorities are no more
Browse files Browse the repository at this point in the history
Summary:
quicwg/base-drafts#2922
quicwg/base-drafts#2924

Reviewed By: mjoras

Differential Revision: D17835762

fbshipit-source-id: b972d08a117de0661b8dce288ac34227ddcd2b2e
  • Loading branch information
lnicco authored and facebook-github-bot committed Oct 10, 2019
1 parent e2d6281 commit bc5f1f7
Show file tree
Hide file tree
Showing 16 changed files with 2 additions and 534 deletions.
16 changes: 0 additions & 16 deletions proxygen/lib/http/codec/HQControlCodec.cpp
Expand Up @@ -60,13 +60,6 @@ ParseResult HQControlCodec::checkFrameAllowed(FrameType type) {
return folly::none;
}

ParseResult HQControlCodec::parsePriority(Cursor& cursor,
const FrameHeader& header) {
PriorityUpdate outPriority;
auto res = hq::parsePriority(cursor, header, outPriority);
return res;
}

ParseResult HQControlCodec::parseCancelPush(Cursor& cursor,
const FrameHeader& header) {
PushId outPushId;
Expand All @@ -91,11 +84,6 @@ ParseResult HQControlCodec::parseSettings(Cursor& cursor,
case hq::SettingId::MAX_HEADER_LIST_SIZE:
case hq::SettingId::QPACK_BLOCKED_STREAMS:
break;
case hq::SettingId::NUM_PLACEHOLDERS:
if (transportDirection_ == TransportDirection::DOWNSTREAM) {
return HTTP3::ErrorCode::HTTP_WRONG_SETTING_DIRECTION;
}
break;
default:
continue; // ignore unknown settings
}
Expand Down Expand Up @@ -161,10 +149,6 @@ size_t HQControlCodec::generateSettings(folly::IOBufQueue& writeBuf) {
case hq::SettingId::MAX_HEADER_LIST_SIZE:
case hq::SettingId::QPACK_BLOCKED_STREAMS:
break;
case hq::SettingId::NUM_PLACEHOLDERS:
CHECK_NE(setting.value, 0);
CHECK_EQ(transportDirection_, TransportDirection::DOWNSTREAM);
break;
}
settings.emplace_back(*id, (SettingValue)setting.value);
}
Expand Down
2 changes: 0 additions & 2 deletions proxygen/lib/http/codec/HQControlCodec.h
Expand Up @@ -126,8 +126,6 @@ class HQControlCodec

protected:
ParseResult checkFrameAllowed(FrameType type) override;
ParseResult parsePriority(folly::io::Cursor& cursor,
const FrameHeader& header) override;
ParseResult parseCancelPush(folly::io::Cursor& cursor,
const FrameHeader& header) override;
ParseResult parseSettings(folly::io::Cursor& cursor,
Expand Down
2 changes: 0 additions & 2 deletions proxygen/lib/http/codec/HQFramedCodec.cpp
Expand Up @@ -29,8 +29,6 @@ ParseResult HQFramedCodec::parseFrame(Cursor& cursor) {
return parseData(cursor, curHeader_);
case hq::FrameType::HEADERS:
return parseHeaders(cursor, curHeader_);
case hq::FrameType::PRIORITY:
return parsePriority(cursor, curHeader_);
case hq::FrameType::CANCEL_PUSH:
return parseCancelPush(cursor, curHeader_);
case hq::FrameType::SETTINGS:
Expand Down
6 changes: 0 additions & 6 deletions proxygen/lib/http/codec/HQFramedCodec.h
Expand Up @@ -305,12 +305,6 @@ class HQFramedCodec : public HTTPCodec {
folly::assume_unreachable();
}

virtual ParseResult parsePriority(folly::io::Cursor& /*cursor*/,
const FrameHeader& /*header*/) {
LOG(FATAL) << __func__ << " not supported on this codec";
folly::assume_unreachable();
}

virtual ParseResult parseCancelPush(folly::io::Cursor& /*cursor*/,
const FrameHeader& /*header*/) {
LOG(FATAL) << __func__ << " not supported on this codec";
Expand Down
113 changes: 0 additions & 113 deletions proxygen/lib/http/codec/HQFramer.cpp
Expand Up @@ -63,79 +63,6 @@ ParseResult parseHeaders(folly::io::Cursor& cursor,
return folly::none;
}

uint8_t encodePriorityFlags(PriorityUpdate priority) {
uint8_t flags = 0x00;
flags |= (priority.prioritizedType << PRIORITIZED_TYPE_POS);
flags |= (priority.dependencyType << DEPENDENCY_TYPE_POS);
if (priority.exclusive) {
flags |= PRIORITY_EXCLUSIVE_MASK;
}
return flags;
}

bool decodePriorityFlags(uint8_t flags, PriorityUpdate& outPriority) {
outPriority.prioritizedType = static_cast<PriorityElementType>(
(flags & (0x03 << PRIORITIZED_TYPE_POS)) >> PRIORITIZED_TYPE_POS);
outPriority.dependencyType = static_cast<PriorityElementType>(
(flags & (0x03 << DEPENDENCY_TYPE_POS)) >> DEPENDENCY_TYPE_POS);
outPriority.exclusive = (flags & PRIORITY_EXCLUSIVE_MASK);
uint8_t empty = flags & (0x07 << PRIORITY_EMPTY_POS);
if (empty != 0) {
return false;
}
return true;
}

ParseResult parsePriority(folly::io::Cursor& cursor,
const FrameHeader& header,
PriorityUpdate& outPriority) noexcept {
DCHECK_LE(header.length, cursor.totalLength());
folly::IOBuf buf;
auto frameLength = header.length;

if (!cursor.canAdvance(sizeof(uint8_t))) {
return HTTP3::ErrorCode::HTTP_MALFORMED_FRAME_PRIORITY;
}

uint8_t flags = cursor.readBE<uint8_t>();
frameLength -= sizeof(uint8_t);
bool res = decodePriorityFlags(flags, outPriority);
if (!res) {
return HTTP3::ErrorCode::HTTP_MALFORMED_FRAME_PRIORITY;
}

// A PRIORITY frame that prioritizes the root of the tree is not allowed
if (outPriority.prioritizedType == PriorityElementType::TREE_ROOT) {
return HTTP3::ErrorCode::HTTP_MALFORMED_FRAME_PRIORITY;
}

auto prioritizedElementId = quic::decodeQuicInteger(cursor, frameLength);
if (!prioritizedElementId) {
return HTTP3::ErrorCode::HTTP_MALFORMED_FRAME_PRIORITY;
}
outPriority.prioritizedElementId = prioritizedElementId->first;
frameLength -= prioritizedElementId->second;

if (outPriority.dependencyType != PriorityElementType::TREE_ROOT) {
auto elementDependencyId = quic::decodeQuicInteger(cursor, frameLength);
if (!elementDependencyId) {
return HTTP3::ErrorCode::HTTP_MALFORMED_FRAME_PRIORITY;
}
outPriority.elementDependencyId = elementDependencyId->first;
frameLength -= elementDependencyId->second;
}

if (!cursor.canAdvance(sizeof(uint8_t))) {
return HTTP3::ErrorCode::HTTP_MALFORMED_FRAME_PRIORITY;
}
outPriority.weight = cursor.readBE<uint8_t>();
frameLength -= sizeof(uint8_t);
if (frameLength != 0) {
return HTTP3::ErrorCode::HTTP_MALFORMED_FRAME_PRIORITY;
}
return folly::none;
}

ParseResult parseCancelPush(folly::io::Cursor& cursor,
const FrameHeader& header,
PushId& outPushId) noexcept {
Expand Down Expand Up @@ -174,7 +101,6 @@ decodeSettingValue(folly::io::Cursor& cursor,
// unknown ones
switch (settingId) {
case SettingId::HEADER_TABLE_SIZE:
case SettingId::NUM_PLACEHOLDERS:
case SettingId::MAX_HEADER_LIST_SIZE:
case SettingId::QPACK_BLOCKED_STREAMS:
return value;
Expand Down Expand Up @@ -317,43 +243,6 @@ WriteResult writeHeaders(IOBufQueue& queue,
return writeSimpleFrame(queue, FrameType::HEADERS, std::move(data));
}

WriteResult writePriority(IOBufQueue& queue, PriorityUpdate priority) noexcept {
uint8_t flags = encodePriorityFlags(priority);

auto prioritizedElementIdSize =
quic::getQuicIntegerSize(priority.prioritizedElementId);
if (prioritizedElementIdSize.hasError()) {
return prioritizedElementIdSize;
}


size_t payloadSize = *prioritizedElementIdSize +
2 * sizeof(uint8_t);

if (priority.dependencyType != PriorityElementType::TREE_ROOT) {
auto elementDependencyIdSize =
quic::getQuicIntegerSize(priority.elementDependencyId);
if (elementDependencyIdSize.hasError()) {
return elementDependencyIdSize;
}
payloadSize += *elementDependencyIdSize;
}

const auto headerSize =
writeFrameHeader(queue, FrameType::PRIORITY, payloadSize);
if (headerSize.hasError()) {
return headerSize;
}
QueueAppender appender(&queue, payloadSize);
appender.writeBE<uint8_t>(flags);
quic::encodeQuicInteger(priority.prioritizedElementId, appender);
if (priority.dependencyType != PriorityElementType::TREE_ROOT) {
quic::encodeQuicInteger(priority.elementDependencyId, appender);
}
appender.writeBE<uint8_t>(priority.weight);
return *headerSize + payloadSize;
}

WriteResult writeCancelPush(folly::IOBufQueue& writeBuf,
PushId pushId) noexcept {
DCHECK(pushId & kPushIdMask);
Expand Down Expand Up @@ -452,8 +341,6 @@ const char* getFrameTypeString(FrameType type) {
return "DATA";
case FrameType::HEADERS:
return "HEADERS";
case FrameType::PRIORITY:
return "PRIORITY";
case FrameType::CANCEL_PUSH:
return "CANCEL_PUSH";
case FrameType::SETTINGS:
Expand Down
80 changes: 0 additions & 80 deletions proxygen/lib/http/codec/HQFramer.h
Expand Up @@ -53,7 +53,6 @@ using WriteResult = folly::Expected<size_t, quic::TransportErrorCode>;
enum class FrameType : uint64_t {
DATA = 0x00,
HEADERS = 0x01,
PRIORITY = 0x02,
CANCEL_PUSH = 0x03,
SETTINGS = 0x04,
PUSH_PROMISE = 0x05,
Expand All @@ -69,60 +68,10 @@ struct FrameHeader {
uint64_t length;
};

enum PriorityElementType {
REQUEST_STREAM = 0x00,
PUSH_STREAM = 0x01,
PLACEHOLDER = 0x02,
TREE_ROOT = 0x03,
};

// The first byte in a Priority Frame has multiple fields
const uint8_t PRIORITIZED_TYPE_POS = 6;
const uint8_t DEPENDENCY_TYPE_POS = 4;
const uint8_t PRIORITY_EMPTY_POS = 1;
const uint8_t PRIORITY_EXCLUSIVE_MASK = 0x01;

struct PriorityUpdate {
PriorityUpdate(PriorityElementType pt,
PriorityElementType dt,
bool ex,
uint64_t pe,
uint64_t ed,
uint8_t wt)
: prioritizedType(pt),
dependencyType(dt),
prioritizedElementId(pe),
elementDependencyId(ed),
weight(wt),
exclusive(ex) {
}

PriorityUpdate()
: prioritizedType(PriorityElementType::REQUEST_STREAM),
dependencyType(PriorityElementType::TREE_ROOT),
prioritizedElementId(0),
elementDependencyId(0),
weight(0),
exclusive(false) {
}

PriorityElementType prioritizedType;
PriorityElementType dependencyType;
// the prioritized element ID can be a stream ID, a push ID or a placeholder
// ID, based on prioritized Type
uint64_t prioritizedElementId;
// the element dependency ID can be a stream ID, a push ID or a placeholder
// ID, based on dependency Type
uint64_t elementDependencyId;
uint8_t weight;
bool exclusive;
};

enum class SettingId : uint64_t {
HEADER_TABLE_SIZE = 0x01,
MAX_HEADER_LIST_SIZE = 0x06,
QPACK_BLOCKED_STREAMS = 0x07,
NUM_PLACEHOLDERS = 0x09,
};

using SettingValue = uint64_t;
Expand Down Expand Up @@ -165,23 +114,6 @@ ParseResult parseHeaders(folly::io::Cursor& cursor,
const FrameHeader& header,
std::unique_ptr<folly::IOBuf>& outBuf) noexcept;

/**
* This function parses the section of the PRIORITY frame after the common
* frame header. It pulls header.length bytes from the cursor, so it is the
* caller's responsibility to ensure there is enough data available.
* It fetches priority information both from the frame payload and from the
* frame header.
*
* @param cursor The cursor to pull data from.
* @param header The frame header for the frame being parsed.
* @param outPriority On success, filled with the priority information
* from this frame.
* @return folly::none for successful parse or the quic application error code.
*/
ParseResult parsePriority(folly::io::Cursor& cursor,
const FrameHeader& header,
PriorityUpdate& outPriority) noexcept;

/**
* This function parses the section of the CANCEL_PUSH frame after the common
* frame header. It pulls header.length bytes from the cursor, so it is the
Expand Down Expand Up @@ -307,18 +239,6 @@ WriteResult writeUnframedBytes(folly::IOBufQueue& writeBuf,
WriteResult writeHeaders(folly::IOBufQueue& writeBuf,
std::unique_ptr<folly::IOBuf> data) noexcept;

/**
* Generate an entire PRIORITY frame, including the common frame header.
*
* @param writeBuf The output queue to write to. It may grow or add
* underlying buffers inside this function.
* @param priority The priority depedency information to update the stream with.
* @return The number of bytes written to writeBuf if successful, a quic error
* otherwise
*/
WriteResult writePriority(folly::IOBufQueue& writeBuf,
PriorityUpdate priority) noexcept;

/**
* Generate an entire CANCEL_PUSH frame, including the common frame
* header.
Expand Down
1 change: 0 additions & 1 deletion proxygen/lib/http/codec/HQStreamCodec.cpp
Expand Up @@ -53,7 +53,6 @@ ParseResult HQStreamCodec::checkFrameAllowed(FrameType type) {
case hq::FrameType::SETTINGS:
case hq::FrameType::GOAWAY:
case hq::FrameType::MAX_PUSH_ID:
case hq::FrameType::PRIORITY:
case hq::FrameType::CANCEL_PUSH:
return HTTP3::ErrorCode::HTTP_WRONG_STREAM;
case hq::FrameType::PUSH_PROMISE:
Expand Down
4 changes: 0 additions & 4 deletions proxygen/lib/http/codec/HQUtils.cpp
Expand Up @@ -138,8 +138,6 @@ folly::Optional<hq::SettingId> httpToHqSettingsId(proxygen::SettingsId id) {
return hq::SettingId::HEADER_TABLE_SIZE;
case proxygen::SettingsId::MAX_HEADER_LIST_SIZE:
return hq::SettingId::MAX_HEADER_LIST_SIZE;
case proxygen::SettingsId::_HQ_NUM_PLACEHOLDERS:
return hq::SettingId::NUM_PLACEHOLDERS;
case proxygen::SettingsId::_HQ_QPACK_BLOCKED_STREAMS:
return hq::SettingId::QPACK_BLOCKED_STREAMS;
default:
Expand All @@ -152,8 +150,6 @@ folly::Optional<proxygen::SettingsId> hqToHttpSettingsId(hq::SettingId id) {
switch (id) {
case hq::SettingId::HEADER_TABLE_SIZE:
return proxygen::SettingsId::HEADER_TABLE_SIZE;
case hq::SettingId::NUM_PLACEHOLDERS:
return proxygen::SettingsId::_HQ_NUM_PLACEHOLDERS;
case hq::SettingId::MAX_HEADER_LIST_SIZE:
return proxygen::SettingsId::MAX_HEADER_LIST_SIZE;
case hq::SettingId::QPACK_BLOCKED_STREAMS:
Expand Down
1 change: 0 additions & 1 deletion proxygen/lib/http/codec/SPDYConstants.cpp
Expand Up @@ -114,7 +114,6 @@ folly::Optional<proxygen::spdy::SettingsId> httpToSpdySettingsId(
case proxygen::SettingsId::THRIFT_CHANNEL_ID_DEPRECATED:
case proxygen::SettingsId::THRIFT_CHANNEL_ID:
return folly::none;
case proxygen::SettingsId::_HQ_NUM_PLACEHOLDERS:
case proxygen::SettingsId::_HQ_QPACK_BLOCKED_STREAMS:
case proxygen::SettingsId::SETTINGS_HTTP_CERT_AUTH:
return folly::none;
Expand Down
1 change: 0 additions & 1 deletion proxygen/lib/http/codec/SettingsId.h
Expand Up @@ -52,7 +52,6 @@ enum class SettingsId : uint64_t {
//_HQ_HEADER_TABLE_SIZE = HQ_SETTINGS_MASK | 1, -- use HEADER_TABLE_SIZE
//_HQ_MAX_HEADER_LIST_SIZE = HQ_SETTINGS_MASK | 6, -- use MAX_HEADER_LIST_SIZE
_HQ_QPACK_BLOCKED_STREAMS = HQ_SETTINGS_MASK | 7,
_HQ_NUM_PLACEHOLDERS = HQ_SETTINGS_MASK | 8,
};

using SettingPair = std::pair<SettingsId, uint32_t>;
Expand Down

0 comments on commit bc5f1f7

Please sign in to comment.