king: Flags to disable HTTP/HTTPS/UDP per-ship.

This commit is contained in:
Benjamin Summers 2020-05-12 16:55:49 -07:00
parent ba705694bd
commit 4ebf276430
7 changed files with 68 additions and 11 deletions

View File

@ -29,6 +29,9 @@ data Opts = Opts
, oDryFrom :: Maybe Word64 , oDryFrom :: Maybe Word64
, oVerbose :: Bool , oVerbose :: Bool
, oAmesPort :: Maybe Word16 , oAmesPort :: Maybe Word16
, oNoAmes :: Bool
, oNoHttp :: Bool
, oNoHttps :: Bool
, oTrace :: Bool , oTrace :: Bool
, oCollectFx :: Bool , oCollectFx :: Bool
, oLocalhost :: Bool , oLocalhost :: Bool
@ -227,6 +230,24 @@ opts = do
<> help "Ames port" <> help "Ames port"
<> hidden <> hidden
oNoAmes <-
switch
$ long "no-ames"
<> help "Run with Ames disabled."
<> hidden
oNoHttp <-
switch
$ long "no-http"
<> help "Run with HTTP disabled."
<> hidden
oNoHttps <-
switch
$ long "no-https"
<> help "Run with HTTPS disabled."
<> hidden
oHttpPort <- oHttpPort <-
optional optional
$ option auto $ option auto

View File

@ -36,6 +36,9 @@ data NetMode
data NetworkConfig = NetworkConfig data NetworkConfig = NetworkConfig
{ _ncNetMode :: NetMode { _ncNetMode :: NetMode
, _ncAmesPort :: Maybe Word16 , _ncAmesPort :: Maybe Word16
, _ncNoAmes :: Bool
, _ncNoHttp :: Bool
, _ncNoHttps :: Bool
, _ncHttpPort :: Maybe Word16 , _ncHttpPort :: Maybe Word16
, _ncHttpsPort :: Maybe Word16 , _ncHttpsPort :: Maybe Word16
, _ncLocalPort :: Maybe Word16 , _ncLocalPort :: Maybe Word16

View File

@ -165,6 +165,9 @@ toNetworkConfig CLI.Opts {..} = NetworkConfig { .. }
_ncHttpPort = oHttpPort _ncHttpPort = oHttpPort
_ncHttpsPort = oHttpsPort _ncHttpsPort = oHttpsPort
_ncLocalPort = oLoopbackPort _ncLocalPort = oLoopbackPort
_ncNoAmes = oNoAmes
_ncNoHttp = oNoHttp
_ncNoHttps = oNoHttps
tryBootFromPill :: ( HasLogFunc e, HasNetworkConfig e, HasPierConfig e tryBootFromPill :: ( HasLogFunc e, HasNetworkConfig e, HasPierConfig e
, HasConfigDir e, HasStderrLogFunc e , HasConfigDir e, HasStderrLogFunc e

View File

@ -70,14 +70,15 @@ hearEv p a bs =
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
netMode :: HasNetworkConfig e => Bool -> RIO e NetworkMode netMode :: HasNetworkConfig e => Bool -> RIO e NetworkMode
netMode True = pure Fake netMode isFake = do
netMode False = view (networkConfigL . ncNetMode . to cvt) netMode <- view (networkConfigL . ncNetMode)
where noAmes <- view (networkConfigL . ncNoAmes)
cvt :: NetMode -> NetworkMode pure $ case (noAmes, isFake, netMode) of
cvt = \case (True, _ , _ ) -> NoNetwork
NMNormal -> Real (_ , _ , NMNone ) -> NoNetwork
NMLocalhost -> Localhost (_ , True, _ ) -> Fake
NMNone -> NoNetwork (_ , _ , NMNormal ) -> Real
(_ , _ , NMLocalhost) -> Localhost
udpPort :: Bool -> Ship -> HasNetworkConfig e => RIO e PortNumber udpPort :: Bool -> Ship -> HasNetworkConfig e => RIO e PortNumber
udpPort isFake who = do udpPort isFake who = do

View File

@ -201,6 +201,9 @@ startServ multi who isFake conf plan = do
let soHost :: SockOpts -> ServHost let soHost :: SockOpts -> ServHost
soHost so = if soLocalhost so then SHLocalhost else SHAnyHostOk soHost so = if soLocalhost so then SHLocalhost else SHAnyHostOk
noHttp <- view (networkConfigL . ncNoHttp)
noHttps <- view (networkConfigL . ncNoHttps)
let onReq :: WhichServer -> Ship -> Word64 -> ReqInfo -> STM () let onReq :: WhichServer -> Ship -> Word64 -> ReqInfo -> STM ()
onReq which _ship reqId reqInfo = onReq which _ship reqId reqInfo =
plan (requestEvent srvId which reqId reqInfo) plan (requestEvent srvId which reqId reqInfo)
@ -217,6 +220,7 @@ startServ multi who isFake conf plan = do
{ scHost = soHost (pttLop ptt) { scHost = soHost (pttLop ptt)
, scPort = soWhich (pttLop ptt) , scPort = soWhich (pttLop ptt)
, scRedi = Nothing , scRedi = Nothing
, scFake = False
, scType = STHttp who $ ReqApi , scType = STHttp who $ ReqApi
{ rcReq = onReq Loopback { rcReq = onReq Loopback
, rcKil = onKilReq , rcKil = onKilReq
@ -228,6 +232,7 @@ startServ multi who isFake conf plan = do
{ scHost = soHost (pttIns ptt) { scHost = soHost (pttIns ptt)
, scPort = soWhich (pttIns ptt) , scPort = soWhich (pttIns ptt)
, scRedi = secRedi , scRedi = secRedi
, scFake = noHttp
, scType = STHttp who $ ReqApi , scType = STHttp who $ ReqApi
{ rcReq = onReq Insecure { rcReq = onReq Insecure
, rcKil = onKilReq , rcKil = onKilReq
@ -240,6 +245,7 @@ startServ multi who isFake conf plan = do
{ scHost = soHost (pttSec ptt) { scHost = soHost (pttSec ptt)
, scPort = soWhich (pttSec ptt) , scPort = soWhich (pttSec ptt)
, scRedi = Nothing , scRedi = Nothing
, scFake = noHttps
, scType = STHttps who tls $ ReqApi , scType = STHttps who tls $ ReqApi
{ rcReq = onReq Secure { rcReq = onReq Secure
, rcKil = onKilReq , rcKil = onKilReq

View File

@ -101,6 +101,7 @@ multiEyre conf@MultiEyreConf {..} = do
{ scHost = host { scHost = host
, scPort = SPChoices $ singleton $ fromIntegral por , scPort = SPChoices $ singleton $ fromIntegral por
, scRedi = Nothing -- TODO , scRedi = Nothing -- TODO
, scFake = False
, scType = STMultiHttp $ ReqApi , scType = STMultiHttp $ ReqApi
{ rcReq = onReq Insecure { rcReq = onReq Insecure
, rcKil = onKil , rcKil = onKil
@ -113,6 +114,7 @@ multiEyre conf@MultiEyreConf {..} = do
{ scHost = host { scHost = host
, scPort = SPChoices $ singleton $ fromIntegral por , scPort = SPChoices $ singleton $ fromIntegral por
, scRedi = Nothing , scRedi = Nothing
, scFake = False
, scType = STMultiHttps (MTC vTlsC) $ ReqApi , scType = STMultiHttps (MTC vTlsC) $ ReqApi
{ rcReq = onReq Secure { rcReq = onReq Secure
, rcKil = onKil , rcKil = onKil

View File

@ -29,6 +29,7 @@ module Urbit.Vere.Eyre.Serv
, ServConf(..) , ServConf(..)
, configCreds , configCreds
, serv , serv
, fakeServ
) )
where where
@ -98,6 +99,7 @@ data ServConf = ServConf
, scHost :: ServHost , scHost :: ServHost
, scPort :: ServPort , scPort :: ServPort
, scRedi :: Maybe W.Port , scRedi :: Maybe W.Port
, scFake :: Bool
} }
deriving (Show) deriving (Show)
@ -282,9 +284,22 @@ configCreds TlsConfig {..} =
Left str -> Left (pack str) Left str -> Left (pack str)
Right rs -> Right rs Right rs -> Right rs
serv :: HasLogFunc e => TVar E.LiveReqs -> ServConf -> RIO e ServApi fakeServ :: HasLogFunc e => ServConf -> RIO e ServApi
serv vLive conf@ServConf {..} = do fakeServ conf = do
logTrace (displayShow ("EYRE", "SERV", "Start", conf)) let por = fakePort (scPort conf)
logTrace (displayShow ("EYRE", "SERV", "Running Fake Server", por))
pure $ ServApi
{ saKil = pure ()
, saPor = pure por
}
where
fakePort :: ServPort -> W.Port
fakePort SPAnyPort = 55555
fakePort (SPChoices (x :| _)) = x
realServ :: HasLogFunc e => TVar E.LiveReqs -> ServConf -> RIO e ServApi
realServ vLive conf@ServConf {..} = do
logTrace (displayShow ("EYRE", "SERV", "Running Real Server"))
kil <- newEmptyTMVarIO kil <- newEmptyTMVarIO
por <- newEmptyTMVarIO por <- newEmptyTMVarIO
@ -301,3 +316,9 @@ serv vLive conf@ServConf {..} = do
rwith (forceOpenSocket scHost scPort) $ \(por, sok) -> do rwith (forceOpenSocket scHost scPort) $ \(por, sok) -> do
atomically (putTMVar vPort por) atomically (putTMVar vPort por)
startServer scType scHost por sok scRedi vLive startServer scType scHost por sok scRedi vLive
serv :: HasLogFunc e => TVar E.LiveReqs -> ServConf -> RIO e ServApi
serv vLive conf = do
if scFake conf
then fakeServ conf
else realServ vLive conf