diff --git a/beacon/fakebeacon/server.go b/beacon/fakebeacon/server.go index d8cac1c087..f81b9ebffa 100644 --- a/beacon/fakebeacon/server.go +++ b/beacon/fakebeacon/server.go @@ -2,6 +2,7 @@ package fakebeacon import ( "net/http" + "strconv" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/gorilla/mux" @@ -9,18 +10,21 @@ import ( ) const ( - DefaultHostPort = "0.0.0.0:8686" + DefaultAddr = "localhost" + DefaultPort = 8686 ) type Config struct { - Enable bool - HostPort string + Enable bool + Addr string + Port int } func defaultConfig() *Config { return &Config{ - Enable: false, - HostPort: DefaultHostPort, + Enable: false, + Addr: DefaultAddr, + Port: DefaultPort, } } @@ -32,8 +36,11 @@ type Service struct { func NewService(cfg *Config, backend ethapi.Backend) *Service { cfgs := defaultConfig() - if cfg.HostPort != "" { - cfgs.HostPort = cfg.HostPort + if cfg.Addr != "" { + cfgs.Addr = cfg.Addr + } + if cfg.Port > 0 { + cfgs.Port = cfg.Port } s := &Service{ @@ -46,7 +53,7 @@ func NewService(cfg *Config, backend ethapi.Backend) *Service { } func (s *Service) Run() { - _ = http.ListenAndServe(s.cfg.HostPort, s.router) + _ = http.ListenAndServe(s.cfg.Addr+strconv.Itoa(s.cfg.Port), s.router) } func (s *Service) newRouter() *mux.Router { diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 9be7bab2e8..1d52092695 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -93,11 +93,11 @@ type ethstatsConfig struct { } type gethConfig struct { - Eth ethconfig.Config - Node node.Config - Ethstats ethstatsConfig - Metrics metrics.Config - FkBeacon fakebeacon.Config + Eth ethconfig.Config + Node node.Config + Ethstats ethstatsConfig + Metrics metrics.Config + FakeBeacon fakebeacon.Config } func loadConfig(file string, cfg *gethConfig) error { @@ -245,13 +245,16 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { } if ctx.IsSet(utils.FakeBeaconEnabledFlag.Name) { - cfg.FkBeacon.Enable = ctx.Bool(utils.FakeBeaconEnabledFlag.Name) + cfg.FakeBeacon.Enable = ctx.Bool(utils.FakeBeaconEnabledFlag.Name) } - if ctx.IsSet(utils.FakeBeaconHTTPHostPortFlag.Name) { - cfg.FkBeacon.HostPort = ctx.String(utils.FakeBeaconHTTPHostPortFlag.Name) + if ctx.IsSet(utils.FakeBeaconAddrFlag.Name) { + cfg.FakeBeacon.Addr = ctx.String(utils.FakeBeaconAddrFlag.Name) } - if cfg.FkBeacon.Enable { - go fakebeacon.NewService(&cfg.FkBeacon, backend).Run() + if ctx.IsSet(utils.FakeBeaconPortFlag.Name) { + cfg.FakeBeacon.Port = ctx.Int(utils.FakeBeaconPortFlag.Name) + } + if cfg.FakeBeacon.Enable { + go fakebeacon.NewService(&cfg.FakeBeacon, backend).Run() } git, _ := version.VCS() diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 0c3c1d4549..264f7cb64b 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -235,7 +235,8 @@ var ( fakeBeaconFlags = []cli.Flag{ utils.FakeBeaconEnabledFlag, - utils.FakeBeaconHTTPHostPortFlag, + utils.FakeBeaconAddrFlag, + utils.FakeBeaconPortFlag, } ) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 25c0de1e05..1a0f0a040f 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1150,14 +1150,20 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server. // Fake beacon FakeBeaconEnabledFlag = &cli.BoolFlag{ - Name: "fake-beacon.enable", + Name: "fake-beacon", Usage: "Enable the HTTP-RPC server of fake-beacon", Category: flags.APICategory, } - FakeBeaconHTTPHostPortFlag = &cli.StringFlag{ - Name: "fake-beacon.hostport", + FakeBeaconAddrFlag = &cli.StringFlag{ + Name: "fake-beacon.addr", + Usage: "HTTP-RPC server listening addr of fake-beacon", + Value: fakebeacon.DefaultAddr, + Category: flags.APICategory, + } + FakeBeaconPortFlag = &cli.IntFlag{ + Name: "fake-beacon.port", Usage: "HTTP-RPC server listening port of fake-beacon", - Value: fakebeacon.DefaultHostPort, + Value: fakebeacon.DefaultPort, Category: flags.APICategory, } )