diff --git a/cmd/geth/retesteth.go b/cmd/geth/retesteth.go index c1536921a8..a7721199d1 100644 --- a/cmd/geth/retesteth.go +++ b/cmd/geth/retesteth.go @@ -887,12 +887,11 @@ func retesteth(ctx *cli.Context) error { } vhosts := splitAndTrim(ctx.GlobalString(utils.RPCVirtualHostsFlag.Name)) cors := splitAndTrim(ctx.GlobalString(utils.RPCCORSDomainFlag.Name)) - wsOrigins := splitAndTrim(ctx.GlobalString(utils.WSAllowedOriginsFlag.Value)) srv := rpc.NewServer() handler := node.NewHTTPHandlerStack(srv, cors, vhosts) - handler = node.NewWebsocketUpgradeHandler(handler, srv.WebsocketHandler(wsOrigins)) + handler = node.NewWebsocketUpgradeHandler(handler, nil) // start http server var RetestethHTTPTimeouts = rpc.HTTPTimeouts{ diff --git a/node/node.go b/node/node.go index 0748ae6be7..a8e66a3b54 100644 --- a/node/node.go +++ b/node/node.go @@ -378,7 +378,6 @@ func (n *Node) startHTTP(endpoint string, apis []rpc.API, modules []string, cors if n.httpEndpoint == n.wsEndpoint { ws = srv.WebsocketHandler(wsOrigins) } - // wrap handler in websocket handler only if websocket port is the same as http rpc handler := n.AddWebsocketHandler(NewHTTPHandlerStack(srv, cors, vhosts), ws) @@ -389,11 +388,9 @@ func (n *Node) startHTTP(endpoint string, apis []rpc.API, modules []string, cors n.log.Info("HTTP endpoint opened", "url", fmt.Sprintf("http://%v/", listener.Addr()), "cors", strings.Join(cors, ","), "vhosts", strings.Join(vhosts, ",")) - if n.httpEndpoint == n.wsEndpoint { n.log.Info("WebSocket endpoint opened", "url", fmt.Sprintf("ws://%v", listener.Addr())) } - // All listeners booted successfully n.httpEndpoint = endpoint n.httpListener = listener @@ -698,12 +695,14 @@ func (n *Node) apis() []rpc.API { } func registerApisFromWhitelist(apis []rpc.API, modules []string, srv *rpc.Server) error { + if bad, available := rpc.CheckModuleAvailability(modules, apis); len(bad) > 0 { + log.Error("Unavailable modules in HTTP API list", "unavailable", bad, "available", available) + } // Generate the whitelist based on the allowed modules whitelist := make(map[string]bool) for _, module := range modules { whitelist[module] = true } - // Register all the APIs exposed by the services for _, api := range apis { if whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) { @@ -713,6 +712,5 @@ func registerApisFromWhitelist(apis []rpc.API, modules []string, srv *rpc.Server log.Debug("HTTP registered", "namespace", api.Namespace) } } - return nil } diff --git a/rpc/endpoints.go b/rpc/endpoints.go index a749735b47..e900c4e8a9 100644 --- a/rpc/endpoints.go +++ b/rpc/endpoints.go @@ -24,10 +24,10 @@ import ( "github.com/ethereum/go-ethereum/log" ) -// checkModuleAvailability checks that all names given in modules are actually +// CheckModuleAvailability checks that all names given in modules are actually // available API services. It assumes that the MetadataApi module ("rpc") is always available; // the registration of this "rpc" module happens in NewServer() and is thus common to all endpoints. -func checkModuleAvailability(modules []string, apis []API) (bad, available []string) { +func CheckModuleAvailability(modules []string, apis []API) (bad, available []string) { availableSet := make(map[string]struct{}) for _, api := range apis { if _, ok := availableSet[api.Namespace]; !ok { @@ -45,10 +45,6 @@ func checkModuleAvailability(modules []string, apis []API) (bad, available []str // StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules. func StartHTTPEndpoint(endpoint string, apis []API, modules []string, timeouts HTTPTimeouts, handler http.Handler) (net.Listener, error) { - if bad, available := checkModuleAvailability(modules, apis); len(bad) > 0 { - log.Error("Unavailable modules in HTTP API list", "unavailable", bad, "available", available) - } - // Start the HTTP listener var ( listener net.Listener @@ -57,7 +53,6 @@ func StartHTTPEndpoint(endpoint string, apis []API, modules []string, timeouts H if listener, err = net.Listen("tcp", endpoint); err != nil { return nil, err } - // Make sure timeout values are meaningful if timeouts.ReadTimeout < time.Second { log.Warn("Sanitizing invalid HTTP read timeout", "provided", timeouts.ReadTimeout, "updated", DefaultHTTPTimeouts.ReadTimeout) @@ -71,7 +66,6 @@ func StartHTTPEndpoint(endpoint string, apis []API, modules []string, timeouts H log.Warn("Sanitizing invalid HTTP idle timeout", "provided", timeouts.IdleTimeout, "updated", DefaultHTTPTimeouts.IdleTimeout) timeouts.IdleTimeout = DefaultHTTPTimeouts.IdleTimeout } - // Bundle and start the HTTP server httpSrv := &http.Server{ Handler: handler, @@ -79,14 +73,13 @@ func StartHTTPEndpoint(endpoint string, apis []API, modules []string, timeouts H WriteTimeout: timeouts.WriteTimeout, IdleTimeout: timeouts.IdleTimeout, } - go httpSrv.Serve(listener) return listener, err } // StartWSEndpoint starts a websocket endpoint. func StartWSEndpoint(endpoint string, apis []API, modules []string, wsOrigins []string, exposeAll bool) (net.Listener, *Server, error) { - if bad, available := checkModuleAvailability(modules, apis); len(bad) > 0 { + if bad, available := CheckModuleAvailability(modules, apis); len(bad) > 0 { log.Error("Unavailable modules in WS API list", "unavailable", bad, "available", available) } // Generate the whitelist based on the allowed modules