add auth-ws port (#3932)

* add auth-ws port
pull/3934/head
LuttyYang 3 years ago committed by GitHub
parent e90e90bc5e
commit 3bce74fdbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      cmd/harmony/config_migrations.go
  2. 9
      cmd/harmony/default.go
  3. 10
      cmd/harmony/flags.go
  4. 37
      cmd/harmony/flags_test.go
  5. 1
      cmd/harmony/main.go
  6. 7
      internal/configs/harmony/harmony.go
  7. 7
      internal/configs/node/config.go
  8. 10
      internal/configs/node/network.go
  9. 19
      rpc/rpc.go

@ -212,4 +212,12 @@ func init() {
return confTree
}
migrations["2.4.0"] = func(confTree *toml.Tree) *toml.Tree {
if confTree.Get("WS.AuthPort") == nil {
confTree.Set("WS.AuthPort", defaultConfig.WS.AuthPort)
}
confTree.Set("Version", "2.5.0")
return confTree
}
}

@ -5,7 +5,7 @@ import (
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
)
const tomlConfigVersion = "2.4.0"
const tomlConfigVersion = "2.5.0"
const (
defNetworkType = nodeconfig.Mainnet
@ -39,9 +39,10 @@ var defaultConfig = harmonyconfig.HarmonyConfig{
RosettaPort: nodeconfig.DefaultRosettaPort,
},
WS: harmonyconfig.WsConfig{
Enabled: true,
IP: "127.0.0.1",
Port: nodeconfig.DefaultWSPort,
Enabled: true,
IP: "127.0.0.1",
Port: nodeconfig.DefaultWSPort,
AuthPort: nodeconfig.DefaultAuthWSPort,
},
RPCOpt: harmonyconfig.RpcOptConfig{
DebugEnabled: false,

@ -74,6 +74,7 @@ var (
wsEnabledFlag,
wsIPFlag,
wsPortFlag,
wsAuthPortFlag,
}
rpcOptFlags = []cli.Flag{
@ -653,6 +654,11 @@ var (
Usage: "port for websocket endpoint",
DefValue: defaultConfig.WS.Port,
}
wsAuthPortFlag = cli.IntFlag{
Name: "ws.auth-port",
Usage: "port for websocket auth endpoint",
DefValue: defaultConfig.WS.AuthPort,
}
)
func applyWSFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
@ -665,6 +671,9 @@ func applyWSFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, wsPortFlag) {
config.WS.Port = cli.GetIntFlagValue(cmd, wsPortFlag)
}
if cli.IsFlagChanged(cmd, wsAuthPortFlag) {
config.WS.AuthPort = cli.GetIntFlagValue(cmd, wsAuthPortFlag)
}
}
// rpc opt flags
@ -1381,6 +1390,7 @@ func applyLegacyMiscFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfi
config.HTTP.AuthPort = nodeconfig.GetRPCAuthHTTPPortFromBase(legacyPort)
config.HTTP.RosettaPort = nodeconfig.GetRosettaHTTPPortFromBase(legacyPort)
config.WS.Port = nodeconfig.GetWSPortFromBase(legacyPort)
config.WS.AuthPort = nodeconfig.GetWSAuthPortFromBase(legacyPort)
legPortStr := strconv.Itoa(legacyPort)
syncPort, _ := strconv.Atoi(legacysync.GetSyncingPort(legPortStr))

@ -78,9 +78,10 @@ func TestHarmonyFlags(t *testing.T) {
RequestsPerSecond: 1000,
},
WS: harmonyconfig.WsConfig{
Enabled: true,
IP: "127.0.0.1",
Port: 9800,
Enabled: true,
IP: "127.0.0.1",
Port: 9800,
AuthPort: 9801,
},
Consensus: &harmonyconfig.ConsensusConfig{
MinPeers: 6,
@ -529,25 +530,37 @@ func TestWSFlags(t *testing.T) {
{
args: []string{"--ws=false"},
expConfig: harmonyconfig.WsConfig{
Enabled: false,
IP: defaultConfig.WS.IP,
Port: defaultConfig.WS.Port,
Enabled: false,
IP: defaultConfig.WS.IP,
Port: defaultConfig.WS.Port,
AuthPort: defaultConfig.WS.AuthPort,
},
},
{
args: []string{"--ws", "--ws.ip", "8.8.8.8", "--ws.port", "9001"},
expConfig: harmonyconfig.WsConfig{
Enabled: true,
IP: "8.8.8.8",
Port: 9001,
Enabled: true,
IP: "8.8.8.8",
Port: 9001,
AuthPort: defaultConfig.WS.AuthPort,
},
},
{
args: []string{"--ws", "--ws.ip", "8.8.8.8", "--ws.auth-port", "9001"},
expConfig: harmonyconfig.WsConfig{
Enabled: true,
IP: "8.8.8.8",
Port: defaultConfig.WS.Port,
AuthPort: 9001,
},
},
{
args: []string{"--ip", "8.8.8.8", "--port", "9001", "--public_rpc"},
expConfig: harmonyconfig.WsConfig{
Enabled: true,
IP: nodeconfig.DefaultPublicListenIP,
Port: 9801,
Enabled: true,
IP: nodeconfig.DefaultPublicListenIP,
Port: 9801,
AuthPort: 9802,
},
},
}

@ -320,6 +320,7 @@ func setupNodeAndRun(hc harmonyconfig.HarmonyConfig) {
WSEnabled: hc.WS.Enabled,
WSIp: hc.WS.IP,
WSPort: hc.WS.Port,
WSAuthPort: hc.WS.AuthPort,
DebugEnabled: hc.RPCOpt.DebugEnabled,
RateLimiterEnabled: hc.RPCOpt.RateLimterEnabled,
RequestsPerSecond: hc.RPCOpt.RequestsPerSecond,

@ -145,9 +145,10 @@ type HttpConfig struct {
}
type WsConfig struct {
Enabled bool
IP string
Port int
Enabled bool
IP string
Port int
AuthPort int
}
type RpcOptConfig struct {

@ -103,9 +103,10 @@ type RPCServerConfig struct {
HTTPPort int
HTTPAuthPort int
WSEnabled bool
WSIp string
WSPort int
WSEnabled bool
WSIp string
WSPort int
WSAuthPort int
DebugEnabled bool

@ -54,6 +54,8 @@ const (
DefaultRosettaPort = 9700
// DefaultWSPort is the default port for web socket endpoint. The actual port used is
DefaultWSPort = 9800
// DefaultAuthWSPort is the default port for web socket auth endpoint. The actual port used is
DefaultAuthWSPort = 9801
// DefaultPrometheusPort is the default prometheus port. The actual port used is 9000+900
DefaultPrometheusPort = 9900
// DefaultP2PConcurrency is the default P2P concurrency, 0 means is set the default value of P2P Discovery, the actual value is 10
@ -79,6 +81,9 @@ const (
// rpcWSPortOffSet is the port offset for RPC websocket requests
rpcWSPortOffSet = 800
// rpcWSAuthPortOffSet is the port offset for RPC Auth websocket requests
rpcWSAuthPortOffSet = 801
// prometheusHTTPPortOffset is the port offset for prometheus HTTP requests
prometheusHTTPPortOffset = 900
)
@ -144,6 +149,11 @@ func GetWSPortFromBase(basePort int) int {
return basePort + rpcWSPortOffSet
}
// GetWSAuthPortFromBase return the Websocket port from the base auth port
func GetWSAuthPortFromBase(basePort int) int {
return basePort + rpcWSAuthPortOffSet
}
// GetPrometheusHTTPPortFromBase return the prometheus HTTP port from base port
func GetPrometheusHTTPPortFromBase(basePort int) int {
return basePort + prometheusHTTPPortOffset

@ -55,6 +55,7 @@ var (
httpEndpoint = ""
httpAuthEndpoint = ""
wsEndpoint = ""
wsAuthEndpoint = ""
httpVirtualHosts = []string{"*"}
httpTimeouts = rpc.DefaultHTTPTimeouts
httpOrigins = []string{"*"}
@ -91,6 +92,11 @@ func StartServers(hmy *hmy.Harmony, apis []rpc.API, config nodeconfig.RPCServerC
if err := startWS(apis); err != nil {
return err
}
wsAuthEndpoint = fmt.Sprintf("%v:%v", config.WSIp, config.WSAuthPort)
if err := startAuthWS(apis); err != nil {
return err
}
}
return nil
@ -220,3 +226,16 @@ func startWS(apis []rpc.API) (err error) {
fmt.Printf("Started WS server at: %v\n", wsEndpoint)
return nil
}
func startAuthWS(apis []rpc.API) (err error) {
wsListener, wsHandler, err = rpc.StartWSEndpoint(wsAuthEndpoint, apis, WSModules, wsOrigins, true)
if err != nil {
return err
}
utils.Logger().Info().
Str("url", fmt.Sprintf("ws://%s", wsListener.Addr())).
Msg("WebSocket endpoint opened")
fmt.Printf("Started Auth-WS server at: %v\n", wsAuthEndpoint)
return nil
}

Loading…
Cancel
Save