|
|
|
@ -15,6 +15,7 @@ import Data.Time.Clock |
|
|
|
import ATrade.QuoteSource.Client |
|
|
|
import ATrade.QuoteSource.Client |
|
|
|
import ATrade.QuoteSource.Server |
|
|
|
import ATrade.QuoteSource.Server |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import Control.Applicative |
|
|
|
import Control.Concurrent |
|
|
|
import Control.Concurrent |
|
|
|
import Control.Monad |
|
|
|
import Control.Monad |
|
|
|
import Control.Monad.Loops |
|
|
|
import Control.Monad.Loops |
|
|
|
@ -27,6 +28,13 @@ import System.Log.Logger |
|
|
|
import System.ZMQ4 |
|
|
|
import System.ZMQ4 |
|
|
|
import System.ZMQ4.ZAP |
|
|
|
import System.ZMQ4.ZAP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import Options.Applicative |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data CommandLineConfig = CommandLineConfig |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
clConfigPath :: Maybe FilePath |
|
|
|
|
|
|
|
} deriving (Show, Eq) |
|
|
|
|
|
|
|
|
|
|
|
data UpstreamConfig = UpstreamConfig |
|
|
|
data UpstreamConfig = UpstreamConfig |
|
|
|
{ |
|
|
|
{ |
|
|
|
ucEndpoint :: T.Text, |
|
|
|
ucEndpoint :: T.Text, |
|
|
|
@ -72,14 +80,26 @@ initLogging = do |
|
|
|
updateGlobalLogger rootLoggerName (setLevel DEBUG) |
|
|
|
updateGlobalLogger rootLoggerName (setLevel DEBUG) |
|
|
|
updateGlobalLogger rootLoggerName (setHandlers [handler]) |
|
|
|
updateGlobalLogger rootLoggerName (setHandlers [handler]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parseCommandLineConfig :: Parser CommandLineConfig |
|
|
|
|
|
|
|
parseCommandLineConfig = CommandLineConfig |
|
|
|
|
|
|
|
<$> (optional $ strOption (long "config" <> short 'c' <> help "Config to use")) |
|
|
|
|
|
|
|
|
|
|
|
main :: IO () |
|
|
|
main :: IO () |
|
|
|
main = do |
|
|
|
main = do |
|
|
|
|
|
|
|
cfg <- execParser opts |
|
|
|
initLogging |
|
|
|
initLogging |
|
|
|
infoM "main" "Starting" |
|
|
|
infoM "main" "Starting" |
|
|
|
eConf <- eitherDecode . BL.fromStrict <$> B.readFile "qs-tunnel.conf" |
|
|
|
eConf <- eitherDecode . BL.fromStrict <$> B.readFile (configPath cfg) |
|
|
|
case eConf of |
|
|
|
case eConf of |
|
|
|
Left errMsg -> error errMsg |
|
|
|
Left errMsg -> error errMsg |
|
|
|
Right conf -> runWithConfig conf |
|
|
|
Right conf -> runWithConfig conf |
|
|
|
|
|
|
|
where |
|
|
|
|
|
|
|
configPath cfg = case clConfigPath cfg of |
|
|
|
|
|
|
|
Just path -> path |
|
|
|
|
|
|
|
Nothing -> "qs-tunnel.conf" |
|
|
|
|
|
|
|
opts = info (parseCommandLineConfig <**> helper) |
|
|
|
|
|
|
|
( fullDesc |
|
|
|
|
|
|
|
<> progDesc "Quotesource tunnel" ) |
|
|
|
|
|
|
|
|
|
|
|
runWithConfig conf = do |
|
|
|
runWithConfig conf = do |
|
|
|
withContext $ \ctx -> |
|
|
|
withContext $ \ctx -> |
|
|
|
@ -126,6 +146,7 @@ runWithConfig conf = do |
|
|
|
writeIORef lastHeartbeat now |
|
|
|
writeIORef lastHeartbeat now |
|
|
|
sendMulti downstream $ x :| xs |
|
|
|
sendMulti downstream $ x :| xs |
|
|
|
_ -> return () |
|
|
|
_ -> return () |
|
|
|
|
|
|
|
forever $ threadDelay 100000 |
|
|
|
where |
|
|
|
where |
|
|
|
notTimeout ref conf = do |
|
|
|
notTimeout ref conf = do |
|
|
|
now <- getCurrentTime |
|
|
|
now <- getCurrentTime |
|
|
|
|