-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMain.cpp
More file actions
102 lines (97 loc) · 3.52 KB
/
Main.cpp
File metadata and controls
102 lines (97 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "CollabVm.capnp.h"
#include "Guacamole.capnp.h"
#include <capnp/any.h>
#include <capnp/blob.h>
#include <capnp/common.h>
#include <capnp/dynamic.h>
#include <capnp/layout.h>
#include <capnp/schema.h>
#include "GuacamoleClient.hpp"
#include <argon2.h>
#include <openssl/opensslv.h>
#include <sqlite3.h>
#include <cstdint>
#include <clipp.h>
#include <iostream>
#include <sqlite_modern_cpp.h>
#include <string>
#include <algorithm>
#include <thread>
#include <rfb/rfbconfig.h>
#include <freerdp/freerdp.h>
#include <cairo/cairo.h>
#include "CollabVmServer.hpp"
#include "WebSocketServer.hpp"
int main(int argc, char* argv[]) {
using namespace clipp;
using namespace std::string_literals;
auto host = "localhost"s;
// Use half the cores so the remaining can be used by
// the hypervisor and Guacamole client threads
const auto cores = std::thread::hardware_concurrency();
auto threads = std::max(cores / 2, 1u);
auto port = 0u;
auto root = "./web-app/"s;
auto auto_start_vms = true;
auto invalid_arguments = std::vector<std::string>();
enum {
start,
help,
version
} mode = start;
const auto cli_arguments = (
(option("--host", "-l") & value("address", host))
.doc("ip or host to listen on (default: localhost)"),
(option("--threads", "-t") & integer("number", threads))
.doc("the number of threads the server will use (default: "
+ std::to_string(threads) + " - half the number of cores)"),
(option("--port", "-p") & integer("number", port))
.doc("the port to listen on (default: random)"),
(option("--root", "-r") & value("path", root))
.doc("the root directory to serve files from (default: '" + root + "')"),
option("--cert", "-c") // TODO: use this argument
.doc("path to PEM certificate to use for SSL/TLS"),
option("--no-autostart", "-n").set(auto_start_vms, false)
.doc("don't automatically start any VMs"),
option("--version", "-v").set(mode, version)
.doc("show version and dependencies"),
option("--help", "-h").set(mode, help)
.doc("show this help message"),
any_other(invalid_arguments)
);
if (!parse(argc, argv, cli_arguments)
|| !invalid_arguments.empty()
|| mode == help) {
std::for_each(
invalid_arguments.begin(),
invalid_arguments.end(),
[](const auto& arg)
{
std::cout << "invalid argument '" << arg << "'\n";
});
std::cout << usage_lines(cli_arguments, "collab-vm-server") << '\n'
<< documentation(cli_arguments) << std::endl;
return 0;
}
if (mode == version) {
std::cout << "collab-vm-server " BOOST_STRINGIZE(PROJECT_VERSION) "\n\n"
"Third-Party Libraries:\n"
"Argon2 " << ARGON2_VERSION_NUMBER << "\n"
"Boost " << BOOST_VERSION / 100000 << '.'
<< BOOST_VERSION / 100 % 1000 << '.'
<< BOOST_VERSION % 100 << "\n"
"cairo " << cairo_version_string() << "\n"
"Cap'n Proto " BOOST_STRINGIZE(CAPNP_VERSION_STR) "\n"
"FreeRDP " << freerdp_get_version_string() << "\n"
"Guacamole (patched)" "\n"
LIBVNCSERVER_PACKAGE_STRING "\n"
"sqlite modern cpp " << MODERN_SQLITE_VERSION / 1000000 << '.'
<< MODERN_SQLITE_VERSION / 1000 % 1000 << '.'
<< MODERN_SQLITE_VERSION / 1000 % 1000 << "\n"
"OpenSSL " OPENSSL_VERSION_TEXT "\n"
"SQLite3 " SQLITE_VERSION "\n" << std::endl;
return 0;
}
using Server = CollabVm::Server::CollabVmServer<CollabVm::Server::WebServer>;
Server(root).Start(threads, host, port, auto_start_vms);
}