|
17 | 17 | package rpc |
18 | 18 |
|
19 | 19 | import ( |
20 | | - "fmt" |
21 | 20 | "net" |
22 | 21 |
|
23 | 22 | "github.com/ethereum/go-ethereum/log" |
24 | 23 | ) |
25 | 24 |
|
26 | 25 | // checkModuleAvailability check that all names given in modules are actually |
27 | 26 | // available API services. |
28 | | -func checkModuleAvailability(modules []string, apis []API) error { |
29 | | - available := make(map[string]struct{}) |
30 | | - var availableNames string |
31 | | - for i, api := range apis { |
32 | | - if _, ok := available[api.Namespace]; !ok { |
33 | | - available[api.Namespace] = struct{}{} |
34 | | - if i > 0 { |
35 | | - availableNames += ", " |
36 | | - } |
37 | | - availableNames += api.Namespace |
| 27 | +func checkModuleAvailability(modules []string, apis []API) (bad, available []string) { |
| 28 | + availableSet := make(map[string]struct{}) |
| 29 | + for _, api := range apis { |
| 30 | + if _, ok := availableSet[api.Namespace]; !ok { |
| 31 | + availableSet[api.Namespace] = struct{}{} |
| 32 | + available = append(available, api.Namespace) |
38 | 33 | } |
39 | 34 | } |
40 | 35 | for _, name := range modules { |
41 | | - if _, ok := available[name]; !ok { |
42 | | - return fmt.Errorf("invalid API %q in whitelist (available: %s)", name, availableNames) |
| 36 | + if _, ok := availableSet[name]; !ok { |
| 37 | + bad = append(bad, name) |
43 | 38 | } |
44 | 39 | } |
45 | | - return nil |
| 40 | + return bad, available |
46 | 41 | } |
47 | 42 |
|
48 | 43 | // StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules. |
49 | 44 | func StartHTTPEndpoint(endpoint string, apis []API, modules []string, cors []string, vhosts []string, timeouts HTTPTimeouts) (net.Listener, *Server, error) { |
50 | | - if err := checkModuleAvailability(modules, apis); err != nil { |
51 | | - return nil, nil, err |
| 45 | + if bad, available := checkModuleAvailability(modules, apis); len(bad) > 0 { |
| 46 | + log.Error("Unavailable modules in HTTP API list", "unavailable", bad, "available", available) |
52 | 47 | } |
53 | 48 | // Generate the whitelist based on the allowed modules |
54 | 49 | whitelist := make(map[string]bool) |
@@ -79,8 +74,8 @@ func StartHTTPEndpoint(endpoint string, apis []API, modules []string, cors []str |
79 | 74 |
|
80 | 75 | // StartWSEndpoint starts a websocket endpoint. |
81 | 76 | func StartWSEndpoint(endpoint string, apis []API, modules []string, wsOrigins []string, exposeAll bool) (net.Listener, *Server, error) { |
82 | | - if err := checkModuleAvailability(modules, apis); err != nil { |
83 | | - return nil, nil, err |
| 77 | + if bad, available := checkModuleAvailability(modules, apis); len(bad) > 0 { |
| 78 | + log.Error("Unavailable modules in WS API list", "unavailable", bad, "available", available) |
84 | 79 | } |
85 | 80 | // Generate the whitelist based on the allowed modules |
86 | 81 | whitelist := make(map[string]bool) |
|
0 commit comments