Skip to content

Commit

Permalink
Add new trackRequestParams to MoQFramer
Browse files Browse the repository at this point in the history
Summary: Adds MAX_CACHE_DURATION and DELIVERY_TIMEOUT. Doesn't do anything with them yet

Reviewed By: yuandagits

Differential Revision: D63562040

fbshipit-source-id: 2e50501de3f1ae8f1304f00bbd0b11b2bed9ef5b
  • Loading branch information
DanielFay22 authored and facebook-github-bot committed Oct 1, 2024
1 parent b86bc00 commit f723a30
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 39 deletions.
76 changes: 51 additions & 25 deletions moxygen/MoQFramer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,33 @@ folly::Expected<folly::Unit, ErrorCode> parseTrackRequestParams(
size_t numParams,
std::vector<TrackRequestParameter>& params) {
for (auto i = 0u; i < numParams; i++) {
TrackRequestParameter p;
auto key = quic::decodeQuicInteger(cursor, length);
if (!key) {
return folly::makeUnexpected(ErrorCode::PARSE_UNDERFLOW);
}
length -= key->second;
auto res = parseFixedString(cursor, length);
if (!res) {
return folly::makeUnexpected(res.error());
p.key = key->first;
if (p.key == folly::to_underlying(TrackRequestParamKey::AUTHORIZATION)) {
auto res = parseFixedString(cursor, length);
if (!res) {
return folly::makeUnexpected(res.error());
}
p.asString = std::move(res.value());
} else {
auto res = quic::decodeQuicInteger(cursor, length);
if (!res) {
return folly::makeUnexpected(ErrorCode::PARSE_UNDERFLOW);
}
length -= res->second;
res = quic::decodeQuicInteger(cursor, res->first);
if (!res) {
return folly::makeUnexpected(ErrorCode::PARSE_UNDERFLOW);
}
length -= res->second;
p.asUint64 = res->first;
}
params.emplace_back(
TrackRequestParameter({key->first, std::move(res.value())}));
params.emplace_back(std::move(p));
}
return folly::unit;
}
Expand Down Expand Up @@ -828,6 +844,32 @@ void writeFullTrackName(
writeFixedString(writeBuf, fullTrackName.trackName, size, error);
}

void writeTrackRequestParams(
folly::IOBufQueue& writeBuf,
const std::vector<TrackRequestParameter>& params,
size_t& size,
bool& error) noexcept {
writeVarint(writeBuf, params.size(), size, error);
for (auto& param : params) {
writeVarint(writeBuf, param.key, size, error);
switch (param.key) {
case folly::to_underlying(TrackRequestParamKey::AUTHORIZATION):
writeFixedString(writeBuf, param.asString, size, error);
break;
case folly::to_underlying(TrackRequestParamKey::DELIVERY_TIMEOUT):
case folly::to_underlying(TrackRequestParamKey::MAX_CACHE_DURATION):
auto res = quic::getQuicIntegerSize(param.asUint64);
if (!res) {
error = true;
return;
}
writeVarint(writeBuf, res.value(), size, error);
writeVarint(writeBuf, param.asUint64, size, error);
break;
}
}
}

WriteResult writeClientSetup(
folly::IOBufQueue& writeBuf,
const ClientSetup& clientSetup) noexcept {
Expand Down Expand Up @@ -1000,11 +1042,7 @@ WriteResult writeSubscribeRequest(
writeVarint(writeBuf, subscribeRequest.end->group, size, error);
writeVarint(writeBuf, subscribeRequest.end->object, size, error);
}
writeVarint(writeBuf, subscribeRequest.params.size(), size, error);
for (auto& param : subscribeRequest.params) {
writeVarint(writeBuf, param.key, size, error);
writeFixedString(writeBuf, param.value, size, error);
}
writeTrackRequestParams(writeBuf, subscribeRequest.params, size, error);
writeSize(sizePtr, size, error);
if (error) {
return folly::makeUnexpected(quic::TransportErrorCode::INTERNAL_ERROR);
Expand All @@ -1025,11 +1063,7 @@ WriteResult writeSubscribeUpdate(
writeVarint(writeBuf, update.end.object, size, error);
writeBuf.append(&update.priority, 1);
size += 1;
writeVarint(writeBuf, update.params.size(), size, error);
for (auto& param : update.params) {
writeVarint(writeBuf, param.key, size, error);
writeFixedString(writeBuf, param.value, size, error);
}
writeTrackRequestParams(writeBuf, update.params, size, error);
writeSize(sizePtr, size, error);
if (error) {
return folly::makeUnexpected(quic::TransportErrorCode::INTERNAL_ERROR);
Expand All @@ -1055,11 +1089,7 @@ WriteResult writeSubscribeOk(
} else {
writeVarint(writeBuf, 0, size, error); // content exists
}
writeVarint(writeBuf, subscribeOk.params.size(), size, error);
for (auto& param : subscribeOk.params) {
writeVarint(writeBuf, param.key, size, error);
writeFixedString(writeBuf, param.value, size, error);
}
writeTrackRequestParams(writeBuf, subscribeOk.params, size, error);
writeSize(sizePtr, size, error);
if (error) {
return folly::makeUnexpected(quic::TransportErrorCode::INTERNAL_ERROR);
Expand Down Expand Up @@ -1129,11 +1159,7 @@ WriteResult writeAnnounce(
bool error = false;
auto sizePtr = writeFrameHeader(writeBuf, FrameType::ANNOUNCE, error);
writeTrackNamespace(writeBuf, announce.trackNamespace, size, error);
writeVarint(writeBuf, announce.params.size(), size, error);
for (auto& param : announce.params) {
writeVarint(writeBuf, param.key, size, error);
writeFixedString(writeBuf, param.value, size, error);
}
writeTrackRequestParams(writeBuf, announce.params, size, error);
writeSize(sizePtr, size, error);
if (error) {
return folly::makeUnexpected(quic::TransportErrorCode::INTERNAL_ERROR);
Expand Down
14 changes: 7 additions & 7 deletions moxygen/MoQFramer.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,23 @@ enum class SetupKey : uint64_t { ROLE = 0, PATH = 1 };

enum class Role : uint8_t { PUBLISHER = 1, SUBSCRIBER = 2, PUB_AND_SUB = 3 };

struct SetupParameter {
struct Parameter {
uint64_t key;
std::string asString;
uint64_t asUint64;
};

struct SetupParameter : public Parameter {};
struct TrackRequestParameter : public Parameter {};

constexpr uint64_t kVersionDraft01 = 0xff000001;
constexpr uint64_t kVersionDraft02 = 0xff000002;
constexpr uint64_t kVersionDraft03 = 0xff000003;
constexpr uint64_t kVersionDraft04 = 0xff000004;
constexpr uint64_t kVersionDraft05 = 0xff000005;
constexpr uint64_t kVersionDraft06 = 0xff000006;
constexpr uint64_t kVersionDraft06_exp =
0xff060002; // Draft 6 in progress version
0xff060003; // Draft 6 in progress version
constexpr uint64_t kVersionDraftCurrent = kVersionDraft06_exp;

struct ClientSetup {
Expand Down Expand Up @@ -177,11 +180,8 @@ folly::Expected<ObjectHeader, ErrorCode> parseMultiObjectHeader(

enum class TrackRequestParamKey : uint64_t {
AUTHORIZATION = 2,
};

struct TrackRequestParameter {
uint64_t key;
std::string value;
DELIVERY_TIMEOUT = 3,
MAX_CACHE_DURATION = 4,
};

enum class LocationType : uint8_t {
Expand Down
2 changes: 1 addition & 1 deletion moxygen/samples/chat/MoQChatServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MoQChatServer : MoQServer {
std::string username;
for (const auto& p : subReq.params) {
if (p.key == folly::to_underlying(TrackRequestParamKey::AUTHORIZATION)) {
username = p.value;
username = p.asString;
break;
}
}
Expand Down
33 changes: 27 additions & 6 deletions moxygen/test/TestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ std::unique_ptr<folly::IOBuf> writeAllControlMessages() {
folly::none,
folly::none,
{{folly::to_underlying(TrackRequestParamKey::AUTHORIZATION),
"binky"}}}));
"binky",
0},
{folly::to_underlying(TrackRequestParamKey::DELIVERY_TIMEOUT),
"",
1000},
{folly::to_underlying(TrackRequestParamKey::MAX_CACHE_DURATION),
"",
3600000}}}));
res = writeSubscribeUpdate(
writeBuf,
SubscribeUpdate(
Expand All @@ -53,17 +60,24 @@ std::unique_ptr<folly::IOBuf> writeAllControlMessages() {
{3, 4},
255,
{{folly::to_underlying(TrackRequestParamKey::AUTHORIZATION),
"binky"}}}));
"binky",
0},
{folly::to_underlying(TrackRequestParamKey::DELIVERY_TIMEOUT),
"",
1000},
{folly::to_underlying(TrackRequestParamKey::MAX_CACHE_DURATION),
"",
3600000}}}));
res = writeSubscribeOk(
writeBuf,
SubscribeOk(
{0,
std::chrono::milliseconds(0),
GroupOrder::OldestFirst,
AbsoluteLocation{2, 5},
// AUTHORIZATION is not valid here, but MAX_CACHE_DURATION is pending
{{folly::to_underlying(TrackRequestParamKey::AUTHORIZATION),
"binky"}}}));
{{folly::to_underlying(TrackRequestParamKey::MAX_CACHE_DURATION),
"",
3600000}}}));
res = writeSubscribeError(
writeBuf, SubscribeError({0, 404, "not found", folly::none}));
res = writeUnsubscribe(
Expand All @@ -87,7 +101,14 @@ std::unique_ptr<folly::IOBuf> writeAllControlMessages() {
Announce(
{TrackNamespace({"hello"}),
{{folly::to_underlying(TrackRequestParamKey::AUTHORIZATION),
"binky"}}}));
"binky",
0},
{folly::to_underlying(TrackRequestParamKey::DELIVERY_TIMEOUT),
"",
1000},
{folly::to_underlying(TrackRequestParamKey::MAX_CACHE_DURATION),
"",
3600000}}}));
res = writeAnnounceOk(writeBuf, AnnounceOk({TrackNamespace({"hello"})}));
res = writeAnnounceError(
writeBuf,
Expand Down

0 comments on commit f723a30

Please sign in to comment.