core, ui: option to use web port by default for preset servers only (#5847)

* core: option to use web port by default for preset servers only

* ui

* refactor

* simplexmq
This commit is contained in:
Evgeny authored and GitHub committed 2025-04-25 11:17:27 +01:00
1 parent d53c13f8be
commit 7b11d8514a
14 files changed
+156 -94

No files matched your search

+3 -2
View File
@@ -89,6 +89,7 @@ defaultChatConfig =
-- to have a different set of servers on the receiving end and on the sending end.
-- To preserve backward compatibility receiving end should update before the sending.
shortLinkPresetServers = allPresetServers,
presetDomains = [".simplex.im", ".simplexonflux.com"],
tbqSize = 1024,
fileChunkSize = 15780, -- do not change
xftpDescrPartSize = 14000,
@@ -240,12 +241,12 @@ newChatController
randomServerCfgs name p opDomains rndSrvs =
toJustOrError name $ L.nonEmpty $ agentServerCfgs p opDomains $ concatMap (pServers p) rndSrvs
agentServers :: DB.Connection -> ChatConfig -> NonEmpty PresetOperator -> RandomAgentServers -> IO InitialAgentServers
agentServers db ChatConfig {presetServers = PresetServers {ntf, netCfg}} presetOps as = do
agentServers db ChatConfig {presetServers = PresetServers {ntf, netCfg}, presetDomains} presetOps as = do
users <- getUsers db
ops <- getUpdateServerOperators db presetOps (null users)
let opDomains = operatorDomains $ mapMaybe snd ops
(smp', xftp') <- unzip <$> mapM (getServers ops opDomains) users
pure InitialAgentServers {smp = M.fromList (optServers smp' smpServers), xftp = M.fromList (optServers xftp' xftpServers), ntf, netCfg}
pure InitialAgentServers {smp = M.fromList (optServers smp' smpServers), xftp = M.fromList (optServers xftp' xftpServers), ntf, netCfg, presetDomains}
where
optServers :: [(UserId, NonEmpty (ServerCfg p))] -> [ProtoServerWithAuth p] -> [(UserId, NonEmpty (ServerCfg p))]
optServers srvs overrides_ = case L.nonEmpty overrides_ of
+5 -3
View File
@@ -50,6 +50,7 @@ import Data.Time.Clock.System (SystemTime (..), systemToUTCTime)
import Data.Version (showVersion)
import Data.Word (Word16)
import Language.Haskell.TH (Exp, Q, runIO)
import Network.Socket (HostName)
import Numeric.Natural
import qualified Paths_simplex_chat as SC
import Simplex.Chat.AppSettings
@@ -77,7 +78,7 @@ import Simplex.Messaging.Agent.Protocol
import Simplex.Messaging.Agent.Store.Common (DBStore, withTransaction, withTransactionPriority)
import Simplex.Messaging.Agent.Store.Shared (MigrationConfirmation, UpMigration)
import qualified Simplex.Messaging.Agent.Store.DB as DB
import Simplex.Messaging.Client (HostMode (..), SMPProxyFallback (..), SMPProxyMode (..), SocksMode (..))
import Simplex.Messaging.Client (HostMode (..), SMPProxyFallback (..), SMPProxyMode (..), SMPWebPortServers (..), SocksMode (..))
import qualified Simplex.Messaging.Crypto as C
import Simplex.Messaging.Crypto.File (CryptoFile (..))
import qualified Simplex.Messaging.Crypto.File as CF
@@ -139,6 +140,7 @@ data ChatConfig = ChatConfig
confirmMigrations :: MigrationConfirmation,
presetServers :: PresetServers,
shortLinkPresetServers :: NonEmpty SMPServer,
presetDomains :: [HostName],
tbqSize :: Natural,
fileChunkSize :: Integer,
xftpDescrPartSize :: Int,
@@ -1053,7 +1055,7 @@ data SimpleNetCfg = SimpleNetCfg
requiredHostMode :: Bool,
smpProxyMode_ :: Maybe SMPProxyMode,
smpProxyFallback_ :: Maybe SMPProxyFallback,
smpWebPort :: Bool,
smpWebPortServers :: SMPWebPortServers,
tcpTimeout_ :: Maybe Int,
logTLSErrors :: Bool
}
@@ -1068,7 +1070,7 @@ defaultSimpleNetCfg =
requiredHostMode = False,
smpProxyMode_ = Nothing,
smpProxyFallback_ = Nothing,
smpWebPort = False,
smpWebPortServers = SWPPreset,
tcpTimeout_ = Nothing,
logTLSErrors = False
}
+5 -5
View File
@@ -91,7 +91,7 @@ import Simplex.Messaging.Agent.Store.Interface (execSQL)
import Simplex.Messaging.Agent.Store.Shared (upMigration)
import qualified Simplex.Messaging.Agent.Store.DB as DB
import Simplex.Messaging.Agent.Store.Interface (getCurrentMigrations)
import Simplex.Messaging.Client (NetworkConfig (..), SocksMode (SMAlways), textToHostMode)
import Simplex.Messaging.Client (NetworkConfig (..), SMPWebPortServers (..), SocksMode (SMAlways), textToHostMode)
import qualified Simplex.Messaging.Crypto as C
import Simplex.Messaging.Crypto.File (CryptoFile (..), CryptoFileArgs (..))
import qualified Simplex.Messaging.Crypto.File as CF
@@ -255,11 +255,11 @@ stopChatController ChatController {smpAgent, agentAsync = s, sndFiles, rcvFiles,
atomically $ writeTVar files M.empty
updateNetworkConfig :: NetworkConfig -> SimpleNetCfg -> NetworkConfig
updateNetworkConfig cfg SimpleNetCfg {socksProxy, socksMode, hostMode, requiredHostMode, smpProxyMode_, smpProxyFallback_, smpWebPort, tcpTimeout_, logTLSErrors} =
updateNetworkConfig cfg SimpleNetCfg {socksProxy, socksMode, hostMode, requiredHostMode, smpProxyMode_, smpProxyFallback_, smpWebPortServers, tcpTimeout_, logTLSErrors} =
let cfg1 = maybe cfg (\smpProxyMode -> cfg {smpProxyMode}) smpProxyMode_
cfg2 = maybe cfg1 (\smpProxyFallback -> cfg1 {smpProxyFallback}) smpProxyFallback_
cfg3 = maybe cfg2 (\tcpTimeout -> cfg2 {tcpTimeout, tcpConnectTimeout = (tcpTimeout * 3) `div` 2}) tcpTimeout_
in cfg3 {socksProxy, socksMode, hostMode, requiredHostMode, smpWebPort, logTLSErrors}
in cfg3 {socksProxy, socksMode, hostMode, requiredHostMode, smpWebPortServers, logTLSErrors}
useServers :: Foldable f => RandomAgentServers -> [(Text, ServerOperator)] -> f UserOperatorServers -> (NonEmpty (ServerCfg 'PSMP), NonEmpty (ServerCfg 'PXFTP))
useServers as opDomains uss =
@@ -4383,11 +4383,11 @@ chatCommandP =
requiredHostMode <- (" required-host-mode" $> True) <|> pure False
smpProxyMode_ <- optional $ " smp-proxy=" *> strP
smpProxyFallback_ <- optional $ " smp-proxy-fallback=" *> strP
smpWebPort <- (" smp-web-port" $> True) <|> pure False
smpWebPortServers <- (" smp-web-port-servers=" *> strP) <|> (" smp-web-port" $> SWPAll) <|> pure SWPPreset
t_ <- optional $ " timeout=" *> A.decimal
logTLSErrors <- " log=" *> onOffP <|> pure False
let tcpTimeout_ = (1000000 *) <$> t_
pure $ SimpleNetCfg {socksProxy, socksMode, hostMode, requiredHostMode, smpProxyMode_, smpProxyFallback_, smpWebPort, tcpTimeout_, logTLSErrors}
pure $ SimpleNetCfg {socksProxy, socksMode, hostMode, requiredHostMode, smpProxyMode_, smpProxyFallback_, smpWebPortServers, tcpTimeout_, logTLSErrors}
#if !defined(dbPostgres)
dbKeyP = nonEmptyKey <$?> strP
nonEmptyKey k@(DBEncryptionKey s) = if BA.null s then Left "empty key" else Right k
+2 -2
View File
@@ -46,7 +46,7 @@ operatorFlux =
-- so that option used for restoring links is updated earlier, for backward/forward compatibility.
allPresetServers :: NonEmpty SMPServer
allPresetServers = enabledSimplexChatSMPServers <> disabledSimplexChatSMPServers <> fluxSMPServers_
-- TODO [short links] remove, added for testing
-- added for testing, not preset in the clients
<> ["smp://8Af90NX2TTkKEJAF1RCg69P_Odg2Z-6_J6DOKUqK3rQ=@smp7.simplex.im,dbxqutskmmbkbrs7ofi7pmopeyhgi5cxbjbh4ummgmep4r6bz4cbrcid.onion"]
simplexChatSMPServers :: [NewUserServer 'PSMP]
@@ -87,7 +87,7 @@ disabledSimplexChatSMPServers =
]
fluxSMPServers :: [NewUserServer 'PSMP]
fluxSMPServers = map (presetServer' True) $ L.toList fluxSMPServers_
fluxSMPServers = map (presetServer' True) (L.toList fluxSMPServers_)
-- Please note: if any servers are removed from this list, they MUST be added to allPresetServers.
-- Otherwise previously created short links won't work.
+10 -4
View File
@@ -29,7 +29,7 @@ import Numeric.Natural (Natural)
import Options.Applicative
import Simplex.Chat.Controller (ChatLogLevel (..), SimpleNetCfg (..), updateStr, versionNumber, versionString)
import Simplex.FileTransfer.Description (mb)
import Simplex.Messaging.Client (HostMode (..), SocksMode (..), textToHostMode)
import Simplex.Messaging.Client (HostMode (..), SMPWebPortServers (..), SocksMode (..), textToHostMode)
import Simplex.Messaging.Encoding.String
import Simplex.Messaging.Parsers (parseAll)
import Simplex.Messaging.Protocol (ProtoServerWithAuth, ProtocolTypeI, SMPServerWithAuth, XFTPServerWithAuth)
@@ -153,11 +153,17 @@ coreChatOptsP appDir defaultDbName = do
<> metavar "SMP_PROXY_FALLBACK_MODE"
<> help "Allow downgrade and connect directly: no, [when IP address is] protected (default), yes"
)
smpWebPort <-
switch
smpWebPortServers <-
flag' SWPAll
( long "smp-web-port"
<> help "Use port 443 with SMP servers when not specified"
)
<|> option
strParse
( long "smp-web-port-servers"
<> help "Use port 443 with SMP servers when not specified: all, preset (default), off"
<> value SWPPreset
)
t <-
option
auto
@@ -243,7 +249,7 @@ coreChatOptsP appDir defaultDbName = do
requiredHostMode,
smpProxyMode_,
smpProxyFallback_,
smpWebPort,
smpWebPortServers,
tcpTimeout_ = Just $ useTcpTimeout socksProxy t,
logTLSErrors
},