From f76879eb0dc287f09ae3810bd61b191f21344f78 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sat, 30 Sep 2023 13:52:56 -0400 Subject: [PATCH] feat(ui): add port mapping table (#1681) --- docs/source/about/advanced_usage.rst | 3 + src/config.cpp | 4 +- src/main.cpp | 12 ++- src_assets/common/assets/web/config.html | 94 ++++++++++++++++++++++-- 4 files changed, 105 insertions(+), 8 deletions(-) diff --git a/docs/source/about/advanced_usage.rst b/docs/source/about/advanced_usage.rst index c433a7ca..dfc86454 100644 --- a/docs/source/about/advanced_usage.rst +++ b/docs/source/about/advanced_usage.rst @@ -552,6 +552,9 @@ port **Default** ``47989`` +**Range** + ``1029-65514`` + **Example** .. code-block:: text diff --git a/src/config.cpp b/src/config.cpp index 7c738679..94657a49 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -16,6 +16,8 @@ #include "config.h" #include "main.h" +#include "nvhttp.h" +#include "rtsp.h" #include "utility.h" #include "platform/common.h" @@ -1049,7 +1051,7 @@ namespace config { bool_f(vars, "always_send_scancodes", input.always_send_scancodes); int port = sunshine.port; - int_f(vars, "port"s, port); + int_between_f(vars, "port"s, port, { 1024 + nvhttp::PORT_HTTPS, 65535 - rtsp_stream::RTSP_SETUP_PORT }); sunshine.port = (std::uint16_t) port; string_restricted_f(vars, "address_family", sunshine.address_family, { "ipv4"sv, "both"sv }); diff --git a/src/main.cpp b/src/main.cpp index c04e5dcd..a2aee13f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -836,7 +836,15 @@ write_file(const char *path, const std::string_view &contents) { */ std::uint16_t map_port(int port) { - // TODO: Ensure port is in the range of 21-65535 + // calculate the port from the config port + auto mapped_port = (std::uint16_t)((int) config::sunshine.port + port); + + // Ensure port is in the range of 1024-65535 + if (mapped_port < 1024 || mapped_port > 65535) { + BOOST_LOG(warning) << "Port out of range: "sv << mapped_port; + } + // TODO: Ensure port is not already in use by another application - return (std::uint16_t)((int) config::sunshine.port + port); + + return mapped_port; } diff --git a/src_assets/common/assets/web/config.html b/src_assets/common/assets/web/config.html index d85004cd..d2a8f4c3 100644 --- a/src_assets/common/assets/web/config.html +++ b/src_assets/common/assets/web/config.html @@ -72,6 +72,7 @@ id="origin_web_ui_allowed" class="form-select" v-model="config.origin_web_ui_allowed" + @change="forceUpdate" > @@ -80,6 +81,10 @@
| Protocol | +Port | +Note | +
|---|---|---|
| TCP | +{{+effectivePort - 5}} | ++ |
| TCP | +{{+effectivePort}} | +
+
+ Use this port to connect with Moonlight.
+
+ |
+
| TCP | +{{+effectivePort + 1}} | +Web UI | +
| TCP | +{{+effectivePort + 21}} | ++ |
| UDP | +{{+effectivePort + 9}} - {{+effectivePort + 11}} | ++ |