@ -17,7 +17,6 @@
package rpc
package rpc
import (
import (
"fmt"
"net"
"net"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
@ -25,30 +24,26 @@ import (
// checkModuleAvailability check that all names given in modules are actually
// checkModuleAvailability check that all names given in modules are actually
// available API services.
// available API services.
func checkModuleAvailability ( modules [ ] string , apis [ ] API ) error {
func checkModuleAvailability ( modules [ ] string , apis [ ] API ) ( bad , available [ ] string ) {
available := make ( map [ string ] struct { } )
availableSet := make ( map [ string ] struct { } )
var availableNames string
for _ , api := range apis {
for i , api := range apis {
if _ , ok := availableSet [ api . Namespace ] ; ! ok {
if _ , ok := available [ api . Namespace ] ; ! ok {
availableSet [ api . Namespace ] = struct { } { }
available [ api . Namespace ] = struct { } { }
available = append ( available , api . Namespace )
if i > 0 {
availableNames += ", "
}
availableNames += api . Namespace
}
}
}
}
for _ , name := range modules {
for _ , name := range modules {
if _ , ok := available [ name ] ; ! ok {
if _ , ok := availableSet [ name ] ; ! ok {
return fmt . Errorf ( "invalid API %q in whitelist (available: %s)" , name , availableNames )
bad = append ( bad , name )
}
}
}
}
return nil
return bad , available
}
}
// StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules.
// StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules.
func StartHTTPEndpoint ( endpoint string , apis [ ] API , modules [ ] string , cors [ ] string , vhosts [ ] string , timeouts HTTPTimeouts ) ( net . Listener , * Server , error ) {
func StartHTTPEndpoint ( endpoint string , apis [ ] API , modules [ ] string , cors [ ] string , vhosts [ ] string , timeouts HTTPTimeouts ) ( net . Listener , * Server , error ) {
if err := checkModuleAvailability ( modules , apis ) ; err != nil {
if bad , availabl e := checkModuleAvailability ( modules , apis ) ; len ( bad ) > 0 {
return nil , nil , err
log . Error ( "Unavailable modules in HTTP API list" , "unavailable" , bad , "available" , available )
}
}
// Generate the whitelist based on the allowed modules
// Generate the whitelist based on the allowed modules
whitelist := make ( map [ string ] bool )
whitelist := make ( map [ string ] bool )
@ -79,8 +74,8 @@ func StartHTTPEndpoint(endpoint string, apis []API, modules []string, cors []str
// StartWSEndpoint starts a websocket endpoint.
// StartWSEndpoint starts a websocket endpoint.
func StartWSEndpoint ( endpoint string , apis [ ] API , modules [ ] string , wsOrigins [ ] string , exposeAll bool ) ( net . Listener , * Server , error ) {
func StartWSEndpoint ( endpoint string , apis [ ] API , modules [ ] string , wsOrigins [ ] string , exposeAll bool ) ( net . Listener , * Server , error ) {
if err := checkModuleAvailability ( modules , apis ) ; err != nil {
if bad , availabl e := checkModuleAvailability ( modules , apis ) ; len ( bad ) > 0 {
return nil , nil , err
log . Error ( "Unavailable modules in WS API list" , "unavailable" , bad , "available" , available )
}
}
// Generate the whitelist based on the allowed modules
// Generate the whitelist based on the allowed modules
whitelist := make ( map [ string ] bool )
whitelist := make ( map [ string ] bool )