Skip to content

Commit 40fa75e

Browse files
afrindmeta-codesync[bot]
authored andcommitted
Support multiple endpoints on MoQServer (#111)
Summary: Pull Request resolved: #111 Replace the single `endpoint_` string in `MoQServerBase` with an `unordered_set<string> endpoints_` so multiple paths can be served by one server instance. - `getEndpoint()` is replaced by `addEndpoint()` (inserts into the set) and `isAcceptedEndpoint(path)` (checks membership). - The constructor still accepts a single initial endpoint for backward compatibility. - `MoQServer` exposes `addEndpoint()` publicly, forwarding to the base. - `Handler::onHeadersComplete` now calls `isAcceptedEndpoint()` instead of comparing against a single string. Reviewed By: sharmafb Differential Revision: D95593896 fbshipit-source-id: dfaf20c77e8b00cad4dcf48d5238ae8dbeacb0dc
1 parent ae78c90 commit 40fa75e

4 files changed

Lines changed: 15 additions & 6 deletions

File tree

moxygen/MoQServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void MoQServer::Handler::onHeadersComplete(
248248
HTTPMessage resp;
249249
resp.setHTTPVersion(1, 1);
250250

251-
if (req->getPathAsStringPiece() != server_.getEndpoint()) {
251+
if (!server_.isAcceptedEndpoint(req->getPathAsStringPiece())) {
252252
XLOG(DBG0) << req->getPathAsStringPiece();
253253
req->dumpMessage(0);
254254
resp.setStatusCode(404);

moxygen/MoQServer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ class MoQServer : public MoQServerBase {
8989
folly::EventBase* evb,
9090
std::shared_ptr<const fizz::server::FizzServerContext> ctx);
9191

92+
void addEndpoint(std::string endpoint) {
93+
MoQServerBase::addEndpoint(std::move(endpoint));
94+
}
95+
9296
void setWtMoqtProtocols(std::vector<std::string> protocols) {
9397
wtMoqtProtocols_ = std::move(protocols);
9498
}

moxygen/MoQServerBase.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
namespace moxygen {
1212

13-
MoQServerBase::MoQServerBase(std::string endpoint)
14-
: endpoint_(std::move(endpoint)) {}
13+
MoQServerBase::MoQServerBase(std::string endpoint) {
14+
endpoints_.insert(std::move(endpoint));
15+
}
1516

1617
void MoQServerBase::setMLoggerFactory(std::shared_ptr<MLoggerFactory> factory) {
1718
mLoggerFactory_ = std::move(factory);

moxygen/MoQServerBase.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <moxygen/mlog/MLoggerFactory.h>
1111
#include <memory>
1212
#include <string>
13+
#include <unordered_set>
1314

1415
namespace moxygen {
1516

@@ -79,15 +80,18 @@ class MoQServerBase : public MoQSession::ServerSetupCallback {
7980
// Create a logger from the factory if one is set
8081
std::shared_ptr<MLogger> createLogger() const;
8182

82-
[[nodiscard]] const std::string& getEndpoint() const {
83-
return endpoint_;
83+
void addEndpoint(std::string endpoint) {
84+
endpoints_.insert(std::move(endpoint));
85+
}
86+
bool isAcceptedEndpoint(folly::StringPiece path) const {
87+
return endpoints_.count(std::string(path)) > 0;
8488
}
8589

8690
// AUTHORITY parameter validation methods
8791
bool isValidAuthorityFormat(const std::string& authority);
8892
bool isSupportedAuthority(const std::string& authority);
8993

90-
std::string endpoint_;
94+
std::unordered_set<std::string> endpoints_;
9195
std::shared_ptr<MLoggerFactory> mLoggerFactory_;
9296
};
9397

0 commit comments

Comments
 (0)