-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93cf5e6
commit c81243e
Showing
15 changed files
with
352 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,38 @@ | ||
/* Copyright (c) 2015-2024, EPFL/Blue Brain Project | ||
/* Copyright (c) 2015-2024 EPFL/Blue Brain Project | ||
* All rights reserved. Do not distribute without permission. | ||
* Responsible Author: Cyrille Favreau <[email protected]> | ||
* | ||
* Responsible Author: [email protected] | ||
* | ||
* This file is part of Brayns <https://github.com/BlueBrain/Brayns> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* This library is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License version 3.0 as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* This library is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this library; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#include <iostream> | ||
|
||
#include <brayns/core/Launcher.h> | ||
#include <brayns/core/Version.h> | ||
#include <brayns/core/cli/CommandLine.h> | ||
#include <brayns/core/utils/Logger.h> | ||
|
||
using namespace brayns::experimental; | ||
using brayns::createConsoleLogger; | ||
using brayns::getCopyright; | ||
|
||
namespace brayns::experimental | ||
{ | ||
struct Settings | ||
{ | ||
bool help = false; | ||
bool version = false; | ||
std::string host; | ||
std::uint16_t port = 0; | ||
std::size_t maxClient = 0; | ||
std::size_t maxFrameSize = 0; | ||
bool sslEnabled = false; | ||
// SslSettings ssl = {}; | ||
}; | ||
|
||
template<> | ||
struct ArgvSettingsReflector<Settings> | ||
{ | ||
static auto reflect() | ||
{ | ||
auto builder = ArgvBuilder<Settings>(); | ||
builder.description(getCopyright()); | ||
builder.option("help", [](auto &settings) { return &settings.help; }) | ||
.description("Display this help message") | ||
.defaultValue(false); | ||
builder.option("version", [](auto &settings) { return &settings.version; }) | ||
.description("Display brayns copyright with version") | ||
.defaultValue(false); | ||
builder.option("host", [](auto &settings) { return &settings.host; }) | ||
.description("Websocket server hostname, use 0.0.0.0 to allow any host to connect") | ||
.defaultValue("localhost"); | ||
builder.option("port", [](auto &settings) { return &settings.port; }) | ||
.description("Websocket server port") | ||
.defaultValue(5000); | ||
builder.option("max-client", [](auto &settings) { return &settings.maxClient; }) | ||
.description("Maximum number of simultaneously connected clients") | ||
.defaultValue(2); | ||
builder.option("max-frame-size", [](auto &settings) { return &settings.maxFrameSize; }) | ||
.description("Maximum frame size the websocket server accepts") | ||
.defaultValue(std::numeric_limits<int>::max()); | ||
builder.option("ssl", [](auto &settings) { return &settings.sslEnabled; }) | ||
.description("Enable SSL for websocket server, requires a certificate and a private key") | ||
.defaultValue(false); | ||
/*builder.option("private-key-file", [](auto &settings) { return &settings.ssl.privateKeyFile; }) | ||
.description("SSL private key used by the websocket server") | ||
.defaultValue(""); | ||
builder.option("certificate-file", [](auto &settings) { return &settings.ssl.certificateFile; }) | ||
.description("SSL certificate the websocket server will provide to clients") | ||
.defaultValue(""); | ||
builder.option("ca-location", [](auto &settings) { return &settings.ssl.caLocation; }) | ||
.description("Path to a certificate file to use as certification authority or a CA directory") | ||
.defaultValue(""); | ||
builder.option("private-key-passphrase", [](auto &settings) { return &settings.ssl.privateKeyPassphrase; }) | ||
.description("Passphrase for the private key if encrypted") | ||
.defaultValue("");*/ | ||
return builder.build(); | ||
} | ||
}; | ||
} | ||
|
||
int main(int argc, const char **argv) | ||
{ | ||
auto logger = createConsoleLogger("Brayns"); | ||
|
||
try | ||
{ | ||
auto settings = parseArgvAs<Settings>(argc, argv); | ||
auto settings = parseArgvAs<ServiceSettings>(argc, argv); | ||
|
||
if (settings.version) | ||
{ | ||
|
@@ -103,18 +42,19 @@ int main(int argc, const char **argv) | |
|
||
if (settings.help) | ||
{ | ||
std::cout << getArgvHelp<Settings>() << '\n'; | ||
std::cout << getArgvHelp<ServiceSettings>() << '\n'; | ||
return 0; | ||
} | ||
|
||
runService(settings); | ||
} | ||
catch (const std::exception &e) | ||
{ | ||
logger.fatal("Fatal error: '{}'.", e.what()); | ||
return 1; | ||
std::cout << "Fatal error: " << e.what() << ".\n"; | ||
} | ||
catch (...) | ||
{ | ||
logger.fatal("Unknown fatal error."); | ||
std::cout << "Unknown fatal error."; | ||
return 1; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* Copyright (c) 2015-2024 EPFL/Blue Brain Project | ||
* All rights reserved. Do not distribute without permission. | ||
* | ||
* Responsible Author: [email protected] | ||
* | ||
* This file is part of Brayns <https://github.com/BlueBrain/Brayns> | ||
* | ||
* This library is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License version 3.0 as published | ||
* by the Free Software Foundation. | ||
* | ||
* This library is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this library; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#include "Launcher.h" | ||
|
||
#include <brayns/core/service/Service.h> | ||
#include <brayns/core/utils/Logger.h> | ||
|
||
namespace brayns::experimental | ||
{ | ||
void runService(const ServiceSettings &settings) | ||
{ | ||
auto level = brayns::EnumInfo::getValue<LogLevel>(settings.logLevel); | ||
|
||
auto logger = createConsoleLogger("brayns"); | ||
logger.setLevel(level); | ||
|
||
auto ssl = std::optional<SslSettings>(); | ||
|
||
if (settings.ssl) | ||
{ | ||
ssl = SslSettings{ | ||
.privateKeyFile = settings.privateKeyFile, | ||
.certificateFile = settings.certificateFile, | ||
.caLocation = settings.caLocation, | ||
.privateKeyPassphrase = settings.privateKeyPassphrase, | ||
}; | ||
} | ||
|
||
auto server = WebSocketServerSettings{ | ||
.host = settings.host, | ||
.port = settings.port, | ||
.maxThreadCount = settings.maxThreadCount, | ||
.maxQueueSize = settings.maxQueueSize, | ||
.maxFrameSize = settings.maxFrameSize, | ||
.ssl = std::move(ssl), | ||
}; | ||
|
||
auto endpoints = EndpointRegistry({}); | ||
|
||
auto tasks = TaskManager(); | ||
|
||
auto context = std::make_unique<ServiceContext>(ServiceContext{ | ||
.logger = std::move(logger), | ||
.server = std::move(server), | ||
.endpoints = std::move(endpoints), | ||
.tasks = std::move(tasks), | ||
}); | ||
|
||
auto service = Service(std::move(context)); | ||
|
||
service.run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* Copyright (c) 2015-2024 EPFL/Blue Brain Project | ||
* All rights reserved. Do not distribute without permission. | ||
* | ||
* Responsible Author: [email protected] | ||
* | ||
* This file is part of Brayns <https://github.com/BlueBrain/Brayns> | ||
* | ||
* This library is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License version 3.0 as published | ||
* by the Free Software Foundation. | ||
* | ||
* This library is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this library; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <brayns/core/Version.h> | ||
#include <brayns/core/cli/CommandLine.h> | ||
|
||
namespace brayns::experimental | ||
{ | ||
struct ServiceSettings | ||
{ | ||
bool help; | ||
bool version; | ||
std::string logLevel; | ||
std::string host; | ||
std::uint16_t port; | ||
std::size_t maxThreadCount; | ||
std::size_t maxQueueSize; | ||
std::size_t maxFrameSize; | ||
bool ssl; | ||
std::string privateKeyFile; | ||
std::string certificateFile; | ||
std::string caLocation; | ||
std::string privateKeyPassphrase; | ||
}; | ||
|
||
template<> | ||
struct ArgvSettingsReflector<ServiceSettings> | ||
{ | ||
static auto reflect() | ||
{ | ||
auto builder = ArgvBuilder<ServiceSettings>(); | ||
|
||
builder.description(getCopyright()); | ||
|
||
builder.option("help", [](auto &settings) { return &settings.help; }) | ||
.description("Display this help message and exit") | ||
.defaultValue(false); | ||
|
||
builder.option("version", [](auto &settings) { return &settings.version; }) | ||
.description("Display brayns copyright with version and exit") | ||
.defaultValue(false); | ||
|
||
builder.option("log-level", [](auto &settings) { return &settings.logLevel; }) | ||
.description("Log level among [trace, debug, info, warn, error, fatal]") | ||
.defaultValue("info"); | ||
|
||
builder.option("host", [](auto &settings) { return &settings.host; }) | ||
.description("Websocket server hostname, use 0.0.0.0 to allow any host to connect") | ||
.defaultValue("localhost"); | ||
builder.option("port", [](auto &settings) { return &settings.port; }) | ||
.description("Websocket server port") | ||
.defaultValue(5000); | ||
builder.option("max-thread-count", [](auto &settings) { return &settings.maxThreadCount; }) | ||
.description("Maximum number of threads for the websocket server") | ||
.defaultValue(2); | ||
builder.option("max-queue-size", [](auto &settings) { return &settings.maxQueueSize; }) | ||
.description("Maximum number of queued connections before they are rejected") | ||
.defaultValue(64); | ||
builder.option("max-frame-size", [](auto &settings) { return &settings.maxFrameSize; }) | ||
.description("Maximum frame size the websocket server accepts") | ||
.defaultValue(std::numeric_limits<int>::max()); | ||
|
||
builder.option("ssl", [](auto &settings) { return &settings.ssl; }) | ||
.description("Enable SSL for websocket server, requires a certificate and a private key") | ||
.defaultValue(false); | ||
|
||
builder.option("private-key-file", [](auto &settings) { return &settings.privateKeyFile; }) | ||
.description("SSL private key used by the websocket server") | ||
.defaultValue(""); | ||
builder.option("certificate-file", [](auto &settings) { return &settings.certificateFile; }) | ||
.description("SSL certificate the websocket server will provide to clients") | ||
.defaultValue(""); | ||
builder.option("ca-location", [](auto &settings) { return &settings.caLocation; }) | ||
.description("Path to an additional certification authority (file or directory)") | ||
.defaultValue(""); | ||
builder.option("private-key-passphrase", [](auto &settings) { return &settings.privateKeyPassphrase; }) | ||
.description("Passphrase for the private key if encrypted") | ||
.defaultValue(""); | ||
|
||
return builder.build(); | ||
} | ||
}; | ||
|
||
void runService(const ServiceSettings &settings); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.