Skip to content

Commit 68eba72

Browse files
afrindclaude
andcommitted
Sync ORelay from moxygen relay (21c3597..b426e6c); add sync-relay.sh
Brings ORelay up to date with 9 upstream moxygen commits: - NamespaceSubscriberInfo struct (forward, options, namespacePublishHandle, trackNamespacePrefix) replacing bare bool in sessions map - Draft 16+ bidi stream support in publishNamespace/publishNamespaceDone - trackStatus method (forward to upstream or answer from local forwarder) - publishToSession: remove PublishRequest param - subscribeNamespace: allow empty prefix for draft 16+; store full NamespaceSubscriberInfo; draft 16+ namespace message path - subscribe/publish: setExtensions replacing setGroupOrder/delivery timeout - Remove MoQTrackProperties.h include - 523 new test lines covering all new functionality scripts/sync-relay.sh automates future syncs: copies MoQRelay.h/.cpp and MoQRelayTest.cpp from deps/moxygen, applies name/namespace transforms (MoQRelay→ORelay, namespace moxygen→openmoq::o_rly, moxygen:: qualifiers in header, using namespace moxygen in .cpp), formats, builds, and tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ee04449 commit 68eba72

4 files changed

Lines changed: 966 additions & 122 deletions

File tree

include/o_rly/ORelay.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class ORelay : public moxygen::Publisher,
6161
XLOG(INFO) << "Processing goaway uri=" << goaway.newSessionUri;
6262
}
6363

64+
folly::coro::Task<moxygen::Publisher::TrackStatusResult> trackStatus(moxygen::TrackStatus req
65+
) override;
66+
6467
std::shared_ptr<moxygen::MoQSession> findPublishNamespaceSession(const moxygen::TrackNamespace& ns
6568
);
6669

@@ -76,8 +79,8 @@ class ORelay : public moxygen::Publisher,
7679

7780
// Test accessor: check if a publish exists and return node/publish state
7881
struct PublishState {
79-
bool nodeExists{false};
80-
std::shared_ptr<moxygen::MoQSession> session{nullptr};
82+
bool nodeExists{false}; // true if tree node exists
83+
std::shared_ptr<moxygen::MoQSession> session{nullptr}; // publish session if exists
8184
};
8285
PublishState findPublishState(const moxygen::FullTrackName& ftn);
8386

@@ -123,9 +126,20 @@ class ORelay : public moxygen::Publisher,
123126

124127
// Maps a track name to a the session performing the PUBLISH
125128
folly::F14FastMap<std::string, std::shared_ptr<moxygen::MoQSession>> publishes;
126-
// Sessions with a SUBSCRIBE_NAMESPACE here, with their forward preference
127-
// Key: session, Value: forward (true = forward data, false = don't forward)
128-
folly::F14FastMap<std::shared_ptr<moxygen::MoQSession>, bool> sessions;
129+
130+
// Info stored per SUBSCRIBE_NAMESPACE subscriber
131+
struct NamespaceSubscriberInfo {
132+
bool forward{true};
133+
moxygen::SubscribeNamespaceOptions options{moxygen::SubscribeNamespaceOptions::BOTH};
134+
// Handle for sending NAMESPACE / NAMESPACE_DONE on the bidi stream
135+
// (draft 16+). Null for draft <= 15.
136+
std::shared_ptr<moxygen::Publisher::NamespacePublishHandle> namespacePublishHandle;
137+
// The namespace prefix this subscriber used for SUBSCRIBE_NAMESPACE
138+
moxygen::TrackNamespace trackNamespacePrefix;
139+
};
140+
141+
// Sessions with a SUBSCRIBE_NAMESPACE here, with their preferences
142+
folly::F14FastMap<std::shared_ptr<moxygen::MoQSession>, NamespaceSubscriberInfo> sessions;
129143
// All active PUBLISH_NAMESPACEs for this node (includes prefix sessions)
130144
folly::F14FastMap<std::shared_ptr<moxygen::MoQSession>, std::shared_ptr<PublishNamespaceHandle>>
131145
namespacesPublished;
@@ -152,7 +166,9 @@ class ORelay : public moxygen::Publisher,
152166
const moxygen::TrackNamespace& ns,
153167
bool createMissingNodes = false,
154168
MatchType matchType = MatchType::Exact,
155-
std::vector<std::pair<std::shared_ptr<moxygen::MoQSession>, bool>>* sessions = nullptr
169+
std::vector<
170+
std::pair<std::shared_ptr<moxygen::MoQSession>, NamespaceNode::NamespaceSubscriberInfo>>*
171+
sessions = nullptr
156172
);
157173

158174
struct RelaySubscription {
@@ -182,7 +198,6 @@ class ORelay : public moxygen::Publisher,
182198
folly::coro::Task<void> publishToSession(
183199
std::shared_ptr<moxygen::MoQSession> session,
184200
std::shared_ptr<moxygen::MoQForwarder> forwarder,
185-
moxygen::PublishRequest pub,
186201
bool forward
187202
);
188203

scripts/sync-relay.sh

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
#!/usr/bin/env bash
2+
#
3+
# sync-relay.sh - Sync ORelay from deps/moxygen/moxygen/relay/
4+
#
5+
# Usage: scripts/sync-relay.sh [--no-build] [--no-test]
6+
#
7+
# Transforms:
8+
# MoQRelay.h -> include/o_rly/ORelay.h
9+
# MoQRelay.cpp -> src/ORelay.cpp
10+
# test/MoQRelayTest.cpp -> tests/ORelayTest.cpp
11+
#
12+
# Name/namespace mappings applied:
13+
# class MoQRelay -> class ORelay
14+
# namespace moxygen -> namespace openmoq::o_rly
15+
# unqualified moxygen types in header get moxygen:: prefix
16+
# using namespace moxygen; added before namespace in .cpp
17+
18+
set -euo pipefail
19+
20+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
21+
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
22+
MOXYGEN_RELAY="${REPO_ROOT}/deps/moxygen/moxygen/relay"
23+
24+
NO_BUILD=false
25+
NO_TEST=false
26+
for arg in "$@"; do
27+
case "$arg" in
28+
--no-build) NO_BUILD=true ;;
29+
--no-test) NO_TEST=true ;;
30+
*) echo "Unknown argument: $arg" >&2; exit 1 ;;
31+
esac
32+
done
33+
34+
TMP_DIR="$(mktemp -d)"
35+
trap 'rm -rf "${TMP_DIR}"' EXIT
36+
37+
MOXYGEN_REV="$(git -C "${REPO_ROOT}/deps/moxygen" rev-parse --short HEAD 2>/dev/null || echo unknown)"
38+
echo "==> Syncing relay files from moxygen @ ${MOXYGEN_REV}"
39+
40+
# ─────────────────────────────────────────────────────────────────────────────
41+
# Helper: replace Meta-only Apache 2.0 copyright with combined OpenMOQ header
42+
# ─────────────────────────────────────────────────────────────────────────────
43+
replace_copyright() {
44+
local file="$1"
45+
python3 - "$file" <<'PYEOF'
46+
import re, sys
47+
path = sys.argv[1]
48+
with open(path) as f:
49+
content = f.read()
50+
new_header = """\
51+
/*
52+
* Copyright (c) Meta Platforms, Inc. and affiliates.
53+
* Originally from github.com/facebookexperimental/moxygen.
54+
* See deps/moxygen/LICENSE for the original license terms.
55+
*
56+
* Copyright (c) OpenMOQ contributors.
57+
*/"""
58+
content = re.sub(
59+
r'/\*.*?This source code is licensed under.*?\*/',
60+
new_header, content, count=1, flags=re.DOTALL)
61+
with open(path, 'w') as f:
62+
f.write(content)
63+
PYEOF
64+
}
65+
66+
# ─────────────────────────────────────────────────────────────────────────────
67+
# Helper: add moxygen:: qualifier to unqualified moxygen types
68+
#
69+
# Called only on the header, where we're now in namespace openmoq::o_rly and
70+
# moxygen types are no longer implicitly visible. Uses negative lookbehind so
71+
# already-qualified occurrences (e.g. moxygen::Publisher) are left alone.
72+
# ─────────────────────────────────────────────────────────────────────────────
73+
qualify_moxygen_types() {
74+
local file="$1"
75+
perl -pi -e '
76+
next if /^#include/;
77+
s/(?<!moxygen::)\bPublisher\b/moxygen::Publisher/g;
78+
s/(?<!moxygen::)\bSubscriber\b/moxygen::Subscriber/g;
79+
s/(?<!moxygen::)\bMoQForwarder\b/moxygen::MoQForwarder/g;
80+
s/(?<!moxygen::)\bMoQSession\b/moxygen::MoQSession/g;
81+
s/(?<!moxygen::)\bMoQCache\b/moxygen::MoQCache/g;
82+
s/(?<!moxygen::)\bTrackNamespace\b/moxygen::TrackNamespace/g;
83+
s/(?<!moxygen::)\bTrackConsumer\b/moxygen::TrackConsumer/g;
84+
s/(?<!moxygen::)\bFetchConsumer\b/moxygen::FetchConsumer/g;
85+
s/(?<!moxygen::)\bFullTrackName\b/moxygen::FullTrackName/g;
86+
s/(?<!moxygen::)\bSubscribeRequest\b/moxygen::SubscribeRequest/g;
87+
s/(?<!moxygen::)\bSubscribeNamespaceOptions\b/moxygen::SubscribeNamespaceOptions/g;
88+
s/(?<!moxygen::)\bSubscribeNamespace\b/moxygen::SubscribeNamespace/g;
89+
s/(?<!moxygen::)\bPublishNamespace\b/moxygen::PublishNamespace/g;
90+
s/(?<!moxygen::)\bPublishRequest\b/moxygen::PublishRequest/g;
91+
s/(?<!moxygen::)\bGoaway\b/moxygen::Goaway/g;
92+
s/(?<!moxygen::)\bTrackStatus\b/moxygen::TrackStatus/g;
93+
s/(?<!moxygen::)\bRequestUpdate\b/moxygen::RequestUpdate/g;
94+
s/(?<!moxygen::)\bRequestErrorCode\b/moxygen::RequestErrorCode/g;
95+
s/(?<!moxygen::)\bRequestError\b/moxygen::RequestError/g;
96+
s/(?<!moxygen::)\bRequestID\b/moxygen::RequestID/g;
97+
s/(?<!moxygen::)\bFetch\b/moxygen::Fetch/g;
98+
s/(?<!moxygen::)\bkDefaultMaxCachedTracks\b/moxygen::kDefaultMaxCachedTracks/g;
99+
s/(?<!moxygen::)\bkDefaultMaxCachedGroupsPerTrack\b/moxygen::kDefaultMaxCachedGroupsPerTrack/g;
100+
' "$file"
101+
}
102+
103+
# ─────────────────────────────────────────────────────────────────────────────
104+
# 1. MoQRelay.h → include/o_rly/ORelay.h
105+
# ─────────────────────────────────────────────────────────────────────────────
106+
process_header() {
107+
local src="${MOXYGEN_RELAY}/MoQRelay.h"
108+
local dst="${REPO_ROOT}/include/o_rly/ORelay.h"
109+
local tmp="${TMP_DIR}/ORelay.h"
110+
111+
echo " MoQRelay.h -> include/o_rly/ORelay.h"
112+
cp "$src" "$tmp"
113+
114+
replace_copyright "$tmp"
115+
116+
# Include style: "moxygen/relay/MoQRelay.h" -> <o_rly/ORelay.h>; other "..." -> <...>
117+
sed -i 's|#include "moxygen/relay/MoQRelay\.h"|#include <o_rly/ORelay.h>|g' "$tmp"
118+
sed -i 's|#include "\(moxygen/[^"]*\)"|#include <\1>|g' "$tmp"
119+
120+
# Class rename
121+
sed -i 's/\bMoQRelay\b/ORelay/g' "$tmp"
122+
123+
# Namespace
124+
sed -i 's/^namespace moxygen {$/namespace openmoq::o_rly {/' "$tmp"
125+
sed -i 's|^} // namespace moxygen$|} // namespace openmoq::o_rly|' "$tmp"
126+
127+
# Qualify unqualified moxygen types (order matters: more specific before less specific)
128+
qualify_moxygen_types "$tmp"
129+
130+
cp "$tmp" "$dst"
131+
}
132+
133+
# ─────────────────────────────────────────────────────────────────────────────
134+
# 2. MoQRelay.cpp → src/ORelay.cpp
135+
# ─────────────────────────────────────────────────────────────────────────────
136+
process_source() {
137+
local src="${MOXYGEN_RELAY}/MoQRelay.cpp"
138+
local dst="${REPO_ROOT}/src/ORelay.cpp"
139+
local tmp="${TMP_DIR}/ORelay.cpp"
140+
141+
echo " MoQRelay.cpp -> src/ORelay.cpp"
142+
cp "$src" "$tmp"
143+
144+
replace_copyright "$tmp"
145+
146+
# Include style: relay header -> ORelay.h; other "..." -> <...>
147+
sed -i 's|#include "moxygen/relay/MoQRelay\.h"|#include <o_rly/ORelay.h>|g' "$tmp"
148+
sed -i 's|#include "\(moxygen/[^"]*\)"|#include <\1>|g' "$tmp"
149+
150+
# Class/method references
151+
sed -i 's/\bMoQRelay\b/ORelay/g' "$tmp"
152+
153+
# Namespace: insert "using namespace moxygen;" before the namespace block
154+
# so types in the implementation don't need moxygen:: qualification
155+
sed -i 's/^namespace moxygen {$/using namespace moxygen;\n\nnamespace openmoq::o_rly {/' "$tmp"
156+
sed -i 's|^} // namespace moxygen$|} // namespace openmoq::o_rly|' "$tmp"
157+
158+
cp "$tmp" "$dst"
159+
}
160+
161+
# ─────────────────────────────────────────────────────────────────────────────
162+
# 3. test/MoQRelayTest.cpp → tests/ORelayTest.cpp
163+
# ─────────────────────────────────────────────────────────────────────────────
164+
process_test() {
165+
local src="${MOXYGEN_RELAY}/test/MoQRelayTest.cpp"
166+
local dst="${REPO_ROOT}/tests/ORelayTest.cpp"
167+
local tmp="${TMP_DIR}/ORelayTest.cpp"
168+
169+
echo " test/MoQRelayTest.cpp -> tests/ORelayTest.cpp"
170+
cp "$src" "$tmp"
171+
172+
replace_copyright "$tmp"
173+
174+
# Replace MoQRelay include with ORelay
175+
sed -i 's|#include <moxygen/relay/MoQRelay\.h>|#include <o_rly/ORelay.h>|g' "$tmp"
176+
177+
# Relay class under test
178+
sed -i 's/\bMoQRelay\b/ORelay/g' "$tmp"
179+
180+
# Add openmoq::o_rly namespace (and moxygen for types used at file scope).
181+
# The test lives in namespace moxygen::test, but globals defined before that
182+
# namespace block need explicit usings.
183+
sed -i 's/^using namespace testing;$/using namespace testing;\nusing namespace moxygen;\nusing namespace openmoq::o_rly;/' "$tmp"
184+
185+
cp "$tmp" "$dst"
186+
}
187+
188+
# ─────────────────────────────────────────────────────────────────────────────
189+
# Run transformations
190+
# ─────────────────────────────────────────────────────────────────────────────
191+
echo "--> Transforming files"
192+
process_header
193+
process_source
194+
process_test
195+
196+
# ─────────────────────────────────────────────────────────────────────────────
197+
# Format
198+
# ─────────────────────────────────────────────────────────────────────────────
199+
echo "--> Formatting"
200+
"${SCRIPT_DIR}/format.sh"
201+
202+
# ─────────────────────────────────────────────────────────────────────────────
203+
# Build
204+
# ─────────────────────────────────────────────────────────────────────────────
205+
if ! ${NO_BUILD}; then
206+
echo "--> Building"
207+
"${SCRIPT_DIR}/build.sh"
208+
fi
209+
210+
# ─────────────────────────────────────────────────────────────────────────────
211+
# Test
212+
# ─────────────────────────────────────────────────────────────────────────────
213+
if ! ${NO_TEST}; then
214+
echo "--> Testing"
215+
"${SCRIPT_DIR}/test.sh"
216+
fi
217+
218+
echo "==> Done"

0 commit comments

Comments
 (0)