mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
core: access messaging servers via SOCKS5 proxy (#835)
* core: access messaging servers via SOCKS5 proxy * update option info * update simplexmq
This commit is contained in:
committed by
GitHub
parent
88d1d3448d
commit
4fd13c637c
+9
-3
@@ -87,7 +87,13 @@ defaultChatConfig =
|
||||
yesToMigrations = False
|
||||
},
|
||||
yesToMigrations = False,
|
||||
defaultServers = InitialAgentServers {smp = _defaultSMPServers, ntf = _defaultNtfServers},
|
||||
defaultServers =
|
||||
InitialAgentServers
|
||||
{ smp = _defaultSMPServers,
|
||||
ntf = _defaultNtfServers,
|
||||
socksProxy = Nothing,
|
||||
tcpTimeout = 5000000
|
||||
},
|
||||
tbqSize = 64,
|
||||
fileChunkSize = 15780,
|
||||
subscriptionConcurrency = 16,
|
||||
@@ -116,7 +122,7 @@ logCfg :: LogConfig
|
||||
logCfg = LogConfig {lc_file = Nothing, lc_stderr = True}
|
||||
|
||||
newChatController :: SQLiteStore -> Maybe User -> ChatConfig -> ChatOpts -> Maybe (Notification -> IO ()) -> IO ChatController
|
||||
newChatController chatStore user cfg@ChatConfig {agentConfig = aCfg, tbqSize, defaultServers} ChatOpts {dbFilePrefix, smpServers, logConnections} sendToast = do
|
||||
newChatController chatStore user cfg@ChatConfig {agentConfig = aCfg, tbqSize, defaultServers} ChatOpts {dbFilePrefix, smpServers, socksProxy, tcpTimeout, logConnections} sendToast = do
|
||||
let f = chatStoreFile dbFilePrefix
|
||||
config = cfg {subscriptionEvents = logConnections}
|
||||
sendNotification = fromMaybe (const $ pure ()) sendToast
|
||||
@@ -124,7 +130,7 @@ newChatController chatStore user cfg@ChatConfig {agentConfig = aCfg, tbqSize, de
|
||||
firstTime <- not <$> doesFileExist f
|
||||
currentUser <- newTVarIO user
|
||||
servers <- resolveServers defaultServers
|
||||
smpAgent <- getSMPAgentClient aCfg {dbFile = dbFilePrefix <> "_agent.db"} servers
|
||||
smpAgent <- getSMPAgentClient aCfg {dbFile = dbFilePrefix <> "_agent.db"} servers {socksProxy, tcpTimeout}
|
||||
agentAsync <- newTVarIO Nothing
|
||||
idsDrg <- newTVarIO =<< drgNew
|
||||
inputQ <- newTBQueueIO tbqSize
|
||||
|
||||
@@ -67,6 +67,8 @@ mobileChatOpts =
|
||||
ChatOpts
|
||||
{ dbFilePrefix = undefined,
|
||||
smpServers = [],
|
||||
socksProxy = Nothing,
|
||||
tcpTimeout = 5000000,
|
||||
logConnections = False,
|
||||
logAgent = False,
|
||||
chatCmd = "",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
{-# LANGUAGE ApplicativeDo #-}
|
||||
{-# LANGUAGE DuplicateRecordFields #-}
|
||||
{-# LANGUAGE NamedFieldPuns #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
|
||||
module Simplex.Chat.Options
|
||||
( ChatOpts (..),
|
||||
@@ -11,6 +13,9 @@ where
|
||||
|
||||
import qualified Data.Attoparsec.ByteString.Char8 as A
|
||||
import qualified Data.ByteString.Char8 as B
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Network.Socket (HostAddress, SockAddr (..), tupleToHostAddress)
|
||||
import Network.Socks5 (SocksConf, defaultSocksConf)
|
||||
import Options.Applicative
|
||||
import Simplex.Chat.Controller (updateStr, versionStr)
|
||||
import Simplex.Messaging.Agent.Protocol (SMPServer)
|
||||
@@ -21,6 +26,8 @@ import System.FilePath (combine)
|
||||
data ChatOpts = ChatOpts
|
||||
{ dbFilePrefix :: String,
|
||||
smpServers :: [SMPServer],
|
||||
socksProxy :: Maybe SocksConf,
|
||||
tcpTimeout :: Int,
|
||||
logConnections :: Bool,
|
||||
logAgent :: Bool,
|
||||
chatCmd :: String,
|
||||
@@ -46,10 +53,26 @@ chatOpts appDir defaultDbFileName = do
|
||||
( long "server"
|
||||
<> short 's'
|
||||
<> metavar "SERVER"
|
||||
<> help
|
||||
"Comma separated list of SMP server(s) to use"
|
||||
<> help "Comma separated list of SMP server(s) to use"
|
||||
<> value []
|
||||
)
|
||||
socksProxy <-
|
||||
flag' (Just defaultSocksProxy) (short 'x' <> help "use local SOCKS5 proxy at :9050")
|
||||
<|> option
|
||||
parseSocksConf
|
||||
( long "socks-proxy"
|
||||
<> metavar "SOCKS5"
|
||||
<> help "`ipv4:port` or `:port` of SOCKS5 proxy"
|
||||
<> value Nothing
|
||||
)
|
||||
t <-
|
||||
option
|
||||
auto
|
||||
( long "tcp-timeout"
|
||||
<> metavar "TIMEOUT"
|
||||
<> help "TCP timeout, seconds (default: 5/10 without/with SOCKS5 proxy)"
|
||||
<> value 0
|
||||
)
|
||||
logConnections <-
|
||||
switch
|
||||
( long "connections"
|
||||
@@ -95,13 +118,30 @@ chatOpts appDir defaultDbFileName = do
|
||||
<> short 'm'
|
||||
<> help "Run in maintenance mode (/_start to start chat)"
|
||||
)
|
||||
pure ChatOpts {dbFilePrefix, smpServers, logConnections, logAgent, chatCmd, chatCmdDelay, chatServerPort, maintenance}
|
||||
pure ChatOpts {dbFilePrefix, smpServers, socksProxy, tcpTimeout = 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
|
||||
|
||||
parseSMPServers :: ReadM [SMPServer]
|
||||
parseSMPServers = eitherReader $ parseAll smpServersP . B.pack
|
||||
|
||||
defaultSocksHost :: HostAddress
|
||||
defaultSocksHost = tupleToHostAddress (127, 0, 0, 1)
|
||||
|
||||
defaultSocksProxy :: SocksConf
|
||||
defaultSocksProxy = defaultSocksConf $ SockAddrInet 9050 defaultSocksHost
|
||||
|
||||
parseSocksConf :: ReadM (Maybe SocksConf)
|
||||
parseSocksConf = eitherReader $ parseAll socksConfP . B.pack
|
||||
where
|
||||
socksConfP = do
|
||||
host <- maybe defaultSocksHost tupleToHostAddress <$> optional ipv4P
|
||||
port <- fromMaybe 9050 <$> optional (A.char ':' *> (fromInteger <$> A.decimal))
|
||||
pure . Just . defaultSocksConf $ SockAddrInet port host
|
||||
ipv4P = (,,,) <$> ipNum <*> ipNum <*> ipNum <*> A.decimal
|
||||
ipNum = A.decimal <* A.char '.'
|
||||
|
||||
parseServerPort :: ReadM (Maybe String)
|
||||
parseServerPort = eitherReader $ parseAll serverPortP . B.pack
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{-# LANGUAGE DuplicateRecordFields #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE NamedFieldPuns #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
@@ -28,7 +29,9 @@ terminalChatConfig =
|
||||
"smp://hpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg=@smp5.simplex.im",
|
||||
"smp://PQUV2eL0t7OStZOoAsPEV2QYWt4-xilbakvGUGOItUo=@smp6.simplex.im"
|
||||
],
|
||||
ntf = ["ntf://FB-Uop7RTaZZEG0ZLD2CIaTjsPh-Fw0zFAnb7QyA8Ks=@ntf2.simplex.im"]
|
||||
ntf = ["ntf://FB-Uop7RTaZZEG0ZLD2CIaTjsPh-Fw0zFAnb7QyA8Ks=@ntf2.simplex.im"],
|
||||
socksProxy = Nothing,
|
||||
tcpTimeout = 5000000
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user