Skip to content

Commit 3b50e1f

Browse files
authored
ntf server: only use SOCKS proxy for servers without public address (#1314)
1 parent 7c25b3b commit 3b50e1f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/Simplex/Messaging/Notifications/Server/Main.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import qualified Data.Text as T
1616
import qualified Data.Text.IO as T
1717
import Network.Socket (HostName)
1818
import Options.Applicative
19-
import Simplex.Messaging.Client (NetworkConfig (..), ProtocolClientConfig (..), SocksMode (..), defaultNetworkConfig)
19+
import Simplex.Messaging.Client (HostMode (..), NetworkConfig (..), ProtocolClientConfig (..), SocksMode (..), defaultNetworkConfig)
2020
import Simplex.Messaging.Client.Agent (SMPClientAgentConfig (..), defaultSMPClientAgentConfig)
2121
import qualified Simplex.Messaging.Crypto as C
2222
import Simplex.Messaging.Notifications.Server (runNtfServer)
@@ -26,6 +26,7 @@ import Simplex.Messaging.Notifications.Transport (supportedNTFHandshakes, suppor
2626
import Simplex.Messaging.Protocol (ProtoServerWithAuth (..), pattern NtfServer)
2727
import Simplex.Messaging.Server.CLI
2828
import Simplex.Messaging.Server.Expiration
29+
import Simplex.Messaging.Server.Main (textToHostMode)
2930
import Simplex.Messaging.Transport (simplexMQVersion)
3031
import Simplex.Messaging.Transport.Client (TransportHost (..))
3132
import Simplex.Messaging.Transport.Server (TransportServerConfig (..), defaultTransportServerConfig)
@@ -92,6 +93,10 @@ ntfServerCLI cfgPath logPath =
9293
<> "websockets: off\n\n\
9394
\[SUBSCRIBER]\n\
9495
\# Network configuration for notification server client.\n\
96+
\# `host_mode` can be 'public' (default) or 'onion'.\n\
97+
\# It defines prefferred hostname for destination servers with multiple hostnames.\n\
98+
\# host_mode: public\n\
99+
\# required_host_mode: off\n\n\
95100
\# SOCKS proxy port for subscribing to SMP servers.\n\
96101
\# You may need a separate instance of SOCKS proxy for incoming single-hop requests.\n\
97102
\# socks_proxy: localhost:9050\n\n\
@@ -134,6 +139,8 @@ ntfServerCLI cfgPath logPath =
134139
defaultNetworkConfig
135140
{ socksProxy = either error id <$!> strDecodeIni "SUBSCRIBER" "socks_proxy" ini,
136141
socksMode = maybe SMOnion (either error id) $! strDecodeIni "SUBSCRIBER" "socks_mode" ini,
142+
hostMode = either (const HMPublic) textToHostMode $ lookupValue "SUBSCRIBER" "host_mode" ini,
143+
requiredHostMode = fromMaybe False $ iniOnOff "SUBSCRIBER" "required_host_mode" ini,
137144
smpPingInterval = 60_000_000 -- 1 minutes
138145
}
139146
},

src/Simplex/Messaging/Server/Main.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,6 @@ smpServerCLI_ generateSite serveStaticFiles cfgPath logPath =
318318
serverClientConcurrency = readIniDefault defaultProxyClientConcurrency "PROXY" "client_concurrency" ini,
319319
information = serverPublicInfo ini
320320
}
321-
textToHostMode :: Text -> HostMode
322-
textToHostMode = \case
323-
"public" -> HMPublic
324-
"onion" -> HMOnionViaSocks
325-
s -> error . T.unpack $ "Invalid host_mode: " <> s
326321
textToOwnServers :: Text -> [ByteString]
327322
textToOwnServers = map encodeUtf8 . T.words
328323

@@ -346,6 +341,12 @@ smpServerCLI_ generateSite serveStaticFiles cfgPath logPath =
346341
where
347342
isOnion = \case THOnionHost _ -> True; _ -> False
348343

344+
textToHostMode :: Text -> HostMode
345+
textToHostMode = \case
346+
"public" -> HMPublic
347+
"onion" -> HMOnionViaSocks
348+
s -> error . T.unpack $ "Invalid host_mode: " <> s
349+
349350
data EmbeddedWebParams = EmbeddedWebParams
350351
{ webStaticPath :: FilePath,
351352
webHttpPort :: Maybe Int,

0 commit comments

Comments
 (0)