mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-13 17:13:25 +00:00
core: support passing all network configuration to the agent (#868)
* core: support passing all network configuration to the agent * update simplexmq
This commit is contained in:
committed by
GitHub
parent
a36c367b81
commit
4ad1abcbfa
@@ -25,6 +25,7 @@ import Simplex.Chat.Store
|
||||
import Simplex.Chat.Types
|
||||
import Simplex.Chat.Util (safeDecodeUtf8)
|
||||
import Simplex.Messaging.Agent.Env.SQLite (AgentConfig (yesToMigrations))
|
||||
import Simplex.Messaging.Client (defaultNetworkConfig)
|
||||
import Simplex.Messaging.Protocol (CorrId (..))
|
||||
import System.Timeout (timeout)
|
||||
|
||||
@@ -67,8 +68,7 @@ mobileChatOpts =
|
||||
ChatOpts
|
||||
{ dbFilePrefix = undefined,
|
||||
smpServers = [],
|
||||
socksProxy = Nothing,
|
||||
tcpTimeout = 5000000,
|
||||
networkConfig = defaultNetworkConfig,
|
||||
logConnections = False,
|
||||
logAgent = False,
|
||||
chatCmd = "",
|
||||
|
||||
@@ -8,6 +8,7 @@ module Simplex.Chat.Options
|
||||
( ChatOpts (..),
|
||||
getChatOpts,
|
||||
smpServersP,
|
||||
fullNetworkConfig,
|
||||
)
|
||||
where
|
||||
|
||||
@@ -16,6 +17,7 @@ import qualified Data.ByteString.Char8 as B
|
||||
import Options.Applicative
|
||||
import Simplex.Chat.Controller (updateStr, versionStr)
|
||||
import Simplex.Messaging.Agent.Protocol (SMPServer)
|
||||
import Simplex.Messaging.Client (NetworkConfig (..), defaultNetworkConfig)
|
||||
import Simplex.Messaging.Encoding.String
|
||||
import Simplex.Messaging.Parsers (parseAll)
|
||||
import Simplex.Messaging.Transport.Client (SocksProxy, defaultSocksProxy)
|
||||
@@ -24,8 +26,7 @@ import System.FilePath (combine)
|
||||
data ChatOpts = ChatOpts
|
||||
{ dbFilePrefix :: String,
|
||||
smpServers :: [SMPServer],
|
||||
socksProxy :: Maybe SocksProxy,
|
||||
tcpTimeout :: Int,
|
||||
networkConfig :: NetworkConfig,
|
||||
logConnections :: Bool,
|
||||
logAgent :: Bool,
|
||||
chatCmd :: String,
|
||||
@@ -116,11 +117,27 @@ chatOpts appDir defaultDbFileName = do
|
||||
<> short 'm'
|
||||
<> help "Run in maintenance mode (/_start to start chat)"
|
||||
)
|
||||
pure ChatOpts {dbFilePrefix, smpServers, socksProxy, tcpTimeout = useTcpTimeout socksProxy t, logConnections, logAgent, chatCmd, chatCmdDelay, chatServerPort, maintenance}
|
||||
pure
|
||||
ChatOpts
|
||||
{ dbFilePrefix,
|
||||
smpServers,
|
||||
networkConfig = fullNetworkConfig socksProxy $ useTcpTimeout socksProxy t,
|
||||
logConnections,
|
||||
logAgent,
|
||||
chatCmd,
|
||||
chatCmdDelay,
|
||||
chatServerPort,
|
||||
maintenance
|
||||
}
|
||||
where
|
||||
useTcpTimeout p t = 1000000 * if t > 0 then t else maybe 5 (const 10) p
|
||||
defaultDbFilePath = combine appDir defaultDbFileName
|
||||
|
||||
fullNetworkConfig :: Maybe SocksProxy -> Int -> NetworkConfig
|
||||
fullNetworkConfig socksProxy tcpTimeout =
|
||||
let tcpConnectTimeout = (tcpTimeout * 3) `div` 2
|
||||
in defaultNetworkConfig {socksProxy, tcpTimeout, tcpConnectTimeout}
|
||||
|
||||
parseSMPServers :: ReadM [SMPServer]
|
||||
parseSMPServers = eitherReader $ parseAll smpServersP . B.pack
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ import Simplex.Chat.Options
|
||||
import Simplex.Chat.Terminal.Input
|
||||
import Simplex.Chat.Terminal.Notification
|
||||
import Simplex.Chat.Terminal.Output
|
||||
import Simplex.Messaging.Agent.Env.SQLite (InitialAgentServers (..), NetworkConfig (..))
|
||||
import Simplex.Messaging.Agent.Env.SQLite (InitialAgentServers (..))
|
||||
import Simplex.Messaging.Client (defaultNetworkConfig)
|
||||
import Simplex.Messaging.Util (raceAny_)
|
||||
|
||||
terminalChatConfig :: ChatConfig
|
||||
@@ -30,7 +31,7 @@ terminalChatConfig =
|
||||
"smp://PQUV2eL0t7OStZOoAsPEV2QYWt4-xilbakvGUGOItUo=@smp6.simplex.im"
|
||||
],
|
||||
ntf = ["ntf://FB-Uop7RTaZZEG0ZLD2CIaTjsPh-Fw0zFAnb7QyA8Ks=@ntf2.simplex.im"],
|
||||
netCfg = NetworkConfig {socksProxy = Nothing, tcpTimeout = 5000000}
|
||||
netCfg = defaultNetworkConfig
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user