add auth api and auth port

pull/3853/head
Lutty 3 years ago
parent 6d8ba75248
commit 1eb177f80b
  1. 7
      internal/configs/node/config.go
  2. 27
      rpc/rpc.go

@ -98,9 +98,10 @@ type ConfigType struct {
// RPCServerConfig is the config for rpc listen addresses
type RPCServerConfig struct {
HTTPEnabled bool
HTTPIp string
HTTPPort int
HTTPEnabled bool
HTTPIp string
HTTPPort int
HTTPAuthPort int
WSEnabled bool
WSIp string

@ -71,12 +71,18 @@ func (n Version) Namespace() string {
// StartServers starts the http & ws servers
func StartServers(hmy *hmy.Harmony, apis []rpc.API, config nodeconfig.RPCServerConfig) error {
apis = append(apis, getAPIs(hmy, config.DebugEnabled, config.RateLimiterEnabled, config.RequestsPerSecond)...)
authApis := getAuthAPIs(hmy, config.DebugEnabled, config.RateLimiterEnabled, config.RequestsPerSecond)
if config.HTTPEnabled {
httpEndpoint = fmt.Sprintf("%v:%v", config.HTTPIp, config.HTTPPort)
if err := startHTTP(apis); err != nil {
return err
}
httpEndpoint = fmt.Sprintf("%v:%v", config.HTTPIp, config.HTTPAuthPort)
if err := startAuthHTTP(authApis); err != nil {
return err
}
}
if config.WSEnabled {
@ -120,6 +126,10 @@ func StopServers() error {
return nil
}
func getAuthAPIs(hmy *hmy.Harmony, debugEnable bool, rateLimiterEnable bool, ratelimit int) []rpc.API {
return []rpc.API{}
}
// getAPIs returns all the API methods for the RPC interface
func getAPIs(hmy *hmy.Harmony, debugEnable bool, rateLimiterEnable bool, ratelimit int) []rpc.API {
publicAPIs := []rpc.API{
@ -179,6 +189,23 @@ func startHTTP(apis []rpc.API) (err error) {
return nil
}
func startAuthHTTP(apis []rpc.API) (err error) {
httpListener, httpHandler, err = rpc.StartHTTPEndpoint(
httpEndpoint, apis, HTTPModules, httpOrigins, httpVirtualHosts, httpTimeouts,
)
if err != nil {
return err
}
utils.Logger().Info().
Str("url", fmt.Sprintf("http://%s", httpEndpoint)).
Str("cors", strings.Join(httpOrigins, ",")).
Str("vhosts", strings.Join(httpVirtualHosts, ",")).
Msg("HTTP endpoint opened")
fmt.Printf("Started RPC server at: %v\n", httpEndpoint)
return nil
}
func startWS(apis []rpc.API) (err error) {
wsListener, wsHandler, err = rpc.StartWSEndpoint(wsEndpoint, apis, WSModules, wsOrigins, true)
if err != nil {

Loading…
Cancel
Save