Skip to content

Commit

Permalink
merge #24364 overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
benbaley committed Nov 23, 2023
1 parent 2e0cd39 commit 30affdb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
3 changes: 3 additions & 0 deletions cmd/platon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ var (
utils.HTTPListenAddrFlag,
utils.HTTPPortFlag,
utils.HTTPCORSDomainFlag,
utils.AuthListenFlag,
utils.AuthPortFlag,
utils.AuthVirtualHostsFlag,
utils.JWTSecretFlag,
utils.HTTPVirtualHostsFlag,
utils.GraphQLEnabledFlag,
Expand Down
28 changes: 28 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,25 @@ var (
Value: ethconfig.Defaults.RPCTxFeeCap,
Category: flags.APICategory,
}
// Authenticated RPC HTTP settings
AuthListenFlag = &cli.StringFlag{
Name: "authrpc.addr",
Usage: "Listening address for authenticated APIs",
Value: node.DefaultConfig.AuthAddr,
Category: flags.APICategory,
}
AuthVirtualHostsFlag = &cli.StringFlag{
Name: "authrpc.vhosts",
Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.",
Value: strings.Join(node.DefaultConfig.AuthVirtualHosts, ","),
Category: flags.APICategory,
}
AuthPortFlag = &cli.IntFlag{
Name: "authrpc.port",
Usage: "Listening port for authenticated APIs",
Value: node.DefaultConfig.AuthPort,
Category: flags.APICategory,
}
JWTSecretFlag = &cli.StringFlag{
Name: "authrpc.jwtsecret",
Usage: "Path to a JWT secret to use for authenticated RPC endpoints",
Expand Down Expand Up @@ -1022,6 +1041,15 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
if ctx.Bool(HTTPEnabledEthCompatibleFlag.Name) {
types2.HttpEthCompatible = true
}
if ctx.IsSet(AuthListenFlag.Name) {
cfg.AuthAddr = ctx.String(AuthListenFlag.Name)
}
if ctx.IsSet(AuthPortFlag.Name) {
cfg.AuthPort = ctx.Int(AuthPortFlag.Name)
}
if ctx.IsSet(AuthVirtualHostsFlag.Name) {
cfg.AuthVirtualHosts = SplitAndTrim(ctx.String(AuthVirtualHostsFlag.Name))
}
if ctx.IsSet(HTTPVirtualHostsFlag.Name) {
cfg.HTTPVirtualHosts = SplitAndTrim(ctx.String(HTTPVirtualHostsFlag.Name))
}
Expand Down
8 changes: 6 additions & 2 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,16 @@ type Config struct {
// HTTPPathPrefix specifies a path prefix on which http-rpc is to be served.
HTTPPathPrefix string `toml:",omitempty"`

// AuthHost is the listening address on which authenticated APIs are provided.
AuthHost string `toml:",omitempty"`
// AuthAddr is the listening address on which authenticated APIs are provided.
AuthAddr string `toml:",omitempty"`

// AuthPort is the port number on which authenticated APIs are provided.
AuthPort int `toml:",omitempty"`

// AuthVirtualHosts is the list of virtual hostnames which are allowed on incoming requests
// for the authenticated api. This is by default {'localhost'}.
AuthVirtualHosts []string `toml:",omitempty"`

// WSHost is the host interface on which to start the websocket RPC server. If
// this field is empty, no websocket API endpoint will be started.
WSHost string
Expand Down
3 changes: 2 additions & 1 deletion node/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ var (
var DefaultConfig = Config{
DataDir: DefaultDataDir(),
HTTPPort: DefaultHTTPPort,
AuthHost: DefaultAuthHost,
AuthAddr: DefaultAuthHost,
AuthPort: DefaultAuthPort,
AuthVirtualHosts: DefaultAuthVhosts,
HTTPModules: []string{"net", "web3"},
HTTPVirtualHosts: []string{"localhost"},
HTTPTimeouts: rpc.DefaultHTTPTimeouts,
Expand Down
6 changes: 3 additions & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,12 @@ func (n *Node) startRPC() error {
initAuth := func(apis []rpc.API, port int, secret []byte) error {
// Enable auth via HTTP
server := n.httpAuth
if err := server.setListenAddr(n.config.AuthHost, port); err != nil {
if err := server.setListenAddr(n.config.AuthAddr, port); err != nil {
return err
}
if err := server.enableRPC(apis, httpConfig{
CorsAllowedOrigins: DefaultAuthCors,
Vhosts: DefaultAuthVhosts,
Vhosts: n.config.AuthVirtualHosts,
Modules: DefaultAuthModules,
prefix: DefaultAuthPrefix,
jwtSecret: secret,
Expand All @@ -465,7 +465,7 @@ func (n *Node) startRPC() error {
servers = append(servers, server)
// Enable auth via WS
server = n.wsServerForPort(port, true)
if err := server.setListenAddr(n.config.AuthHost, port); err != nil {
if err := server.setListenAddr(n.config.AuthAddr, port); err != nil {
return err
}
if err := server.enableWS(apis, wsConfig{
Expand Down

0 comments on commit 30affdb

Please sign in to comment.