add --bind option and listen to both ipv4 and ipv6 by default
This commit is contained in:
parent
b7454f1eeb
commit
b7149e897b
2 changed files with 21 additions and 2 deletions
|
@ -21,11 +21,13 @@ import Utility.Env
|
|||
import Utility.MonotonicClock
|
||||
|
||||
import qualified Network.Wai.Handler.Warp as Warp
|
||||
import qualified Network.Wai.Handler.WarpTLS as Warp
|
||||
import Servant
|
||||
import Servant.Client.Streaming
|
||||
import Control.Concurrent.STM
|
||||
import Network.Socket (PortNumber)
|
||||
import qualified Data.Map as M
|
||||
import Data.String
|
||||
|
||||
cmd :: Command
|
||||
cmd = withAnnexOptions [jobsOption] $ command "p2phttp" SectionPlumbing
|
||||
|
@ -34,6 +36,7 @@ cmd = withAnnexOptions [jobsOption] $ command "p2phttp" SectionPlumbing
|
|||
|
||||
data Options = Options
|
||||
{ portOption :: Maybe PortNumber
|
||||
, bindOption :: Maybe String
|
||||
, authEnvOption :: Bool
|
||||
, authEnvHttpOption :: Bool
|
||||
, unauthReadOnlyOption :: Bool
|
||||
|
@ -47,6 +50,10 @@ optParser _ = Options
|
|||
( long "port" <> metavar paramNumber
|
||||
<> help "specify port to listen on"
|
||||
))
|
||||
<*> optional (strOption
|
||||
( long "bind" <> metavar paramAddress
|
||||
<> help "specify address to bind to"
|
||||
))
|
||||
<*> switch
|
||||
( long "authenv"
|
||||
<> help "authenticate users from environment (https only)"
|
||||
|
@ -74,11 +81,19 @@ seek o = getAnnexWorkerPool $ \workerpool ->
|
|||
authenv <- getAuthEnv
|
||||
st <- mkP2PHttpServerState acquireconn workerpool $
|
||||
mkGetServerMode authenv o
|
||||
Warp.run (fromIntegral port) (p2pHttpApp st)
|
||||
let settings = Warp.setPort port $ Warp.setHost host $
|
||||
Warp.defaultSettings
|
||||
Warp.runSettings settings (p2pHttpApp st)
|
||||
--Warp.runTLS settings (p2pHttpApp st)
|
||||
where
|
||||
port = fromMaybe
|
||||
port = maybe
|
||||
(fromIntegral defaultP2PHttpProtocolPort)
|
||||
fromIntegral
|
||||
(portOption o)
|
||||
host = maybe
|
||||
(fromString "*") -- both ipv4 and ipv6
|
||||
fromString
|
||||
(bindOption o)
|
||||
|
||||
mkGetServerMode :: M.Map Auth P2P.ServerMode -> Options -> GetServerMode
|
||||
mkGetServerMode _ o _ Nothing
|
||||
|
|
|
@ -48,6 +48,10 @@ convenient way to download the content of any key, by using the path
|
|||
use a low port like port 80. It will not drop permissions when run as
|
||||
root.
|
||||
|
||||
* `--bind=address`
|
||||
|
||||
What address to bind to. The default is to bind to all addresses.
|
||||
|
||||
* `--authenv`
|
||||
|
||||
Allows users to be authenticated with a username and password.
|
||||
|
|
Loading…
Reference in a new issue