From 398dbeedea190df84df87b445a758904786ff49c Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sun, 15 Sep 2024 21:37:09 +0100 Subject: [PATCH] servers: allow multiple server ports for SMP and Ntf servers (#1319) * servers: allow multiple server ports for SMP and Ntf servers * fix --- src/Simplex/Messaging/Notifications/Server/Main.hs | 8 +++++--- src/Simplex/Messaging/Server/CLI.hs | 14 +++++++++++--- src/Simplex/Messaging/Server/Main.hs | 6 ++++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Simplex/Messaging/Notifications/Server/Main.hs b/src/Simplex/Messaging/Notifications/Server/Main.hs index 5002d2d45..f401ce225 100644 --- a/src/Simplex/Messaging/Notifications/Server/Main.hs +++ b/src/Simplex/Messaging/Notifications/Server/Main.hs @@ -86,11 +86,13 @@ ntfServerCLI cfgPath logPath = <> ("enable: " <> onOff enableStoreLog <> "\n\n") <> "log_stats: off\n\n\ \[TRANSPORT]\n\ - \# host is only used to print server address on start\n" + \# Host is only used to print server address on start.\n\ + \# You can specify multiple server ports.\n" <> ("host: " <> T.pack host <> "\n") <> ("port: " <> T.pack defaultServerPort <> "\n") - <> "log_tls_errors: off\n" - <> "websockets: off\n\n\ + <> "log_tls_errors: off\n\n\ + \# Use `websockets: 443` to run websockets server in addition to plain TLS.\n\ + \websockets: off\n\n\ \[SUBSCRIBER]\n\ \# Network configuration for notification server client.\n\ \# `host_mode` can be 'public' (default) or 'onion'.\n\ diff --git a/src/Simplex/Messaging/Server/CLI.hs b/src/Simplex/Messaging/Server/CLI.hs index 956b30816..0ae228496 100644 --- a/src/Simplex/Messaging/Server/CLI.hs +++ b/src/Simplex/Messaging/Server/CLI.hs @@ -6,6 +6,7 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeApplications #-} module Simplex.Messaging.Server.CLI where @@ -16,6 +17,7 @@ import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.Either (fromRight) import Data.Ini (Ini, lookupValue) +import Data.List ((\\)) import Data.Text (Text) import qualified Data.Text as T import Data.Text.Encoding (encodeUtf8) @@ -275,9 +277,15 @@ checkSavedFingerprint cfgPath x509cfg = do iniTransports :: Ini -> [(String, ATransport)] iniTransports ini = - let port = T.unpack $ strictIni "TRANSPORT" "port" ini - enableWebsockets = (== "on") $ strictIni "TRANSPORT" "websockets" ini - in (port, transport @TLS) : [("80", transport @WS) | enableWebsockets] + let smpPorts = ports $ strictIni "TRANSPORT" "port" ini + ws = strictIni "TRANSPORT" "websockets" ini + wsPorts + | ws == "off" = [] + | ws == "on" = ["80"] + | otherwise = ports ws \\ smpPorts + in map (,transport @TLS) smpPorts <> map (,transport @WS) wsPorts + where + ports = map T.unpack . T.splitOn "," printServerConfig :: [(ServiceName, ATransport)] -> Maybe FilePath -> IO () printServerConfig transports logFile = do diff --git a/src/Simplex/Messaging/Server/Main.hs b/src/Simplex/Messaging/Server/Main.hs index 8a1ea0a60..b9e5e861c 100644 --- a/src/Simplex/Messaging/Server/Main.hs +++ b/src/Simplex/Messaging/Server/Main.hs @@ -168,10 +168,12 @@ smpServerCLI_ generateSite serveStaticFiles cfgPath logPath = \# control_port_admin_password:\n\ \# control_port_user_password:\n\n\ \[TRANSPORT]\n\ - \# host is only used to print server address on start\n" + \# Host is only used to print server address on start.\n\ + \# You can specify multiple server ports.\n" <> ("host: " <> T.pack host <> "\n") <> ("port: " <> T.pack defaultServerPort <> "\n") - <> "log_tls_errors: off\n\ + <> "log_tls_errors: off\n\n\ + \# Use `websockets: 443` to run websockets server in addition to plain TLS.\n\ \websockets: off\n\ \# control_port: 5224\n\n\ \[PROXY]\n\