diff --git a/cmd/geth/js_test.go b/cmd/geth/js_test.go index 58800ed446..ed6e5b319e 100644 --- a/cmd/geth/js_test.go +++ b/cmd/geth/js_test.go @@ -96,7 +96,7 @@ func testREPL(t *testing.T, config func(*eth.Config)) (string, *testjethre, *nod t.Fatal(err) } // Create a networkless protocol stack - stack, err := node.New(&node.Config{PrivateKey: testNodeKey, Name: "test", NoDiscovery: true, IpcPath: fmt.Sprintf("geth-test-%d.ipc", rand.Int63())}) + stack, err := node.New(&node.Config{PrivateKey: testNodeKey, Name: "test", NoDiscovery: true, IPCPath: fmt.Sprintf("geth-test-%d.ipc", rand.Int63())}) if err != nil { t.Fatalf("failed to create node: %v", err) } @@ -142,7 +142,7 @@ func testREPL(t *testing.T, config func(*eth.Config)) (string, *testjethre, *nod stack.Service(ðereum) assetPath := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext") - client, err := utils.NewRemoteRPCClientFromString("ipc:" + stack.IpcEndpoint()) + client, err := utils.NewRemoteRPCClientFromString("ipc:" + stack.IPCEndpoint()) if err != nil { t.Fatalf("failed to attach to node: %v", err) } diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 61f0632db3..5c07be3f6d 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -312,7 +312,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso utils.WSListenAddrFlag, utils.WSPortFlag, utils.WSApiFlag, - utils.WSCORSDomainFlag, + utils.WSAllowedDomainsFlag, utils.IPCDisabledFlag, utils.IPCApiFlag, utils.IPCPathFlag, @@ -425,7 +425,7 @@ func console(ctx *cli.Context) { startNode(ctx, node) // Attach to the newly started node, and either execute script or become interactive - client, err := utils.NewRemoteRPCClientFromString("ipc:" + node.IpcEndpoint()) + client, err := utils.NewRemoteRPCClientFromString("ipc:" + node.IPCEndpoint()) if err != nil { utils.Fatalf("Failed to attach to the inproc geth: %v", err) } @@ -451,7 +451,7 @@ func execScripts(ctx *cli.Context) { startNode(ctx, node) // Attach to the newly started node and execute the given scripts - client, err := utils.NewRemoteRPCClientFromString("ipc:" + node.IpcEndpoint()) + client, err := utils.NewRemoteRPCClientFromString("ipc:" + node.IPCEndpoint()) if err != nil { utils.Fatalf("Failed to attach to the inproc geth: %v", err) } diff --git a/cmd/geth/monitorcmd.go b/cmd/geth/monitorcmd.go index 4d56f22893..ce3a20e8a3 100644 --- a/cmd/geth/monitorcmd.go +++ b/cmd/geth/monitorcmd.go @@ -36,7 +36,7 @@ import ( var ( monitorCommandAttachFlag = cli.StringFlag{ Name: "attach", - Value: "ipc:" + node.DefaultIpcEndpoint(), + Value: "ipc:" + node.DefaultIPCEndpoint(), Usage: "API endpoint to attach to", } monitorCommandRowsFlag = cli.IntFlag{ diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index e20c67bf85..051c518784 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -93,7 +93,7 @@ var AppHelpFlagGroups = []flagGroup{ utils.WSListenAddrFlag, utils.WSPortFlag, utils.WSApiFlag, - utils.WSCORSDomainFlag, + utils.WSAllowedDomainsFlag, utils.IPCDisabledFlag, utils.IPCApiFlag, utils.IPCPathFlag, diff --git a/cmd/gethrpctest/main.go b/cmd/gethrpctest/main.go index 8b54fa2c1f..38016fb35c 100644 --- a/cmd/gethrpctest/main.go +++ b/cmd/gethrpctest/main.go @@ -93,13 +93,13 @@ func main() { func MakeSystemNode(keydir string, privkey string, test *tests.BlockTest) (*node.Node, error) { // Create a networkless protocol stack stack, err := node.New(&node.Config{ - IpcPath: node.DefaultIpcEndpoint(), - HttpHost: common.DefaultHttpHost, - HttpPort: common.DefaultHttpPort, - HttpModules: []string{"admin", "db", "eth", "debug", "miner", "net", "shh", "txpool", "personal", "web3"}, - WsHost: common.DefaultWsHost, - WsPort: common.DefaultWsPort, - WsModules: []string{"admin", "db", "eth", "debug", "miner", "net", "shh", "txpool", "personal", "web3"}, + IPCPath: node.DefaultIPCEndpoint(), + HTTPHost: common.DefaultHTTPHost, + HTTPPort: common.DefaultHTTPPort, + HTTPModules: []string{"admin", "db", "eth", "debug", "miner", "net", "shh", "txpool", "personal", "web3"}, + WSHost: common.DefaultWSHost, + WSPort: common.DefaultWSPort, + WSModules: []string{"admin", "db", "eth", "debug", "miner", "net", "shh", "txpool", "personal", "web3"}, NoDiscovery: true, }) if err != nil { diff --git a/cmd/utils/client.go b/cmd/utils/client.go index 8595cd90b0..1144af6f65 100644 --- a/cmd/utils/client.go +++ b/cmd/utils/client.go @@ -33,7 +33,7 @@ func NewRemoteRPCClient(ctx *cli.Context) (rpc.Client, error) { return NewRemoteRPCClientFromString(endpoint) } // use IPC by default - return rpc.NewIPCClient(node.DefaultIpcEndpoint()) + return rpc.NewIPCClient(node.DefaultIPCEndpoint()) } // NewRemoteRPCClientFromString returns a RPC client which connects to the given diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 28c692689e..2fc1816afb 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -232,12 +232,12 @@ var ( RPCListenAddrFlag = cli.StringFlag{ Name: "rpcaddr", Usage: "HTTP-RPC server listening interface", - Value: common.DefaultHttpHost, + Value: common.DefaultHTTPHost, } RPCPortFlag = cli.IntFlag{ Name: "rpcport", Usage: "HTTP-RPC server listening port", - Value: common.DefaultHttpPort, + Value: common.DefaultHTTPPort, } RPCCORSDomainFlag = cli.StringFlag{ Name: "rpccorsdomain", @@ -247,7 +247,7 @@ var ( RPCApiFlag = cli.StringFlag{ Name: "rpcapi", Usage: "API's offered over the HTTP-RPC interface", - Value: rpc.DefaultHttpRpcApis, + Value: rpc.DefaultHTTPApis, } IPCDisabledFlag = cli.BoolFlag{ Name: "ipcdisable", @@ -256,12 +256,12 @@ var ( IPCApiFlag = cli.StringFlag{ Name: "ipcapi", Usage: "API's offered over the IPC-RPC interface", - Value: rpc.DefaultIpcApis, + Value: rpc.DefaultIPCApis, } IPCPathFlag = DirectoryFlag{ Name: "ipcpath", Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)", - Value: DirectoryString{common.DefaultIpcSocket}, + Value: DirectoryString{common.DefaultIPCSocket}, } WSEnabledFlag = cli.BoolFlag{ Name: "ws", @@ -270,21 +270,21 @@ var ( WSListenAddrFlag = cli.StringFlag{ Name: "wsaddr", Usage: "WS-RPC server listening interface", - Value: common.DefaultWsHost, + Value: common.DefaultWSHost, } WSPortFlag = cli.IntFlag{ Name: "wsport", Usage: "WS-RPC server listening port", - Value: common.DefaultWsPort, + Value: common.DefaultWSPort, } WSApiFlag = cli.StringFlag{ Name: "wsapi", Usage: "API's offered over the WS-RPC interface", - Value: rpc.DefaultHttpRpcApis, + Value: rpc.DefaultHTTPApis, } - WSCORSDomainFlag = cli.StringFlag{ - Name: "wscorsdomain", - Usage: "Domains from which to accept websockets requests", + WSAllowedDomainsFlag = cli.StringFlag{ + Name: "wsdomains", + Usage: "Domains from which to accept websockets requests (can be spoofed)", Value: "", } ExecFlag = cli.StringFlag{ @@ -393,9 +393,9 @@ func MustMakeDataDir(ctx *cli.Context) string { return "" } -// MakeIpcPath creates an IPC path configuration from the set command line flags, +// MakeIPCPath creates an IPC path configuration from the set command line flags, // returning an empty string if IPC was explicitly disabled, or the set path. -func MakeIpcPath(ctx *cli.Context) string { +func MakeIPCPath(ctx *cli.Context) string { if ctx.GlobalBool(IPCDisabledFlag.Name) { return "" } @@ -481,18 +481,18 @@ func MakeNAT(ctx *cli.Context) nat.Interface { return natif } -// MakeHttpRpcHost creates the HTTP RPC listener interface string from the set +// MakeHTTPRpcHost creates the HTTP RPC listener interface string from the set // command line flags, returning empty if the HTTP endpoint is disabled. -func MakeHttpRpcHost(ctx *cli.Context) string { +func MakeHTTPRpcHost(ctx *cli.Context) string { if !ctx.GlobalBool(RPCEnabledFlag.Name) { return "" } return ctx.GlobalString(RPCListenAddrFlag.Name) } -// MakeWsRpcHost creates the WebSocket RPC listener interface string from the set +// MakeWSRpcHost creates the WebSocket RPC listener interface string from the set // command line flags, returning empty if the HTTP endpoint is disabled. -func MakeWsRpcHost(ctx *cli.Context) string { +func MakeWSRpcHost(ctx *cli.Context) string { if !ctx.GlobalBool(WSEnabledFlag.Name) { return "" } @@ -616,15 +616,15 @@ func MakeSystemNode(name, version string, extra []byte, ctx *cli.Context) *node. NAT: MakeNAT(ctx), MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name), MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name), - IpcPath: MakeIpcPath(ctx), - HttpHost: MakeHttpRpcHost(ctx), - HttpPort: ctx.GlobalInt(RPCPortFlag.Name), - HttpCors: ctx.GlobalString(RPCCORSDomainFlag.Name), - HttpModules: strings.Split(ctx.GlobalString(RPCApiFlag.Name), ","), - WsHost: MakeWsRpcHost(ctx), - WsPort: ctx.GlobalInt(WSPortFlag.Name), - WsCors: ctx.GlobalString(WSCORSDomainFlag.Name), - WsModules: strings.Split(ctx.GlobalString(WSApiFlag.Name), ","), + IPCPath: MakeIPCPath(ctx), + HTTPHost: MakeHTTPRpcHost(ctx), + HTTPPort: ctx.GlobalInt(RPCPortFlag.Name), + HTTPCors: ctx.GlobalString(RPCCORSDomainFlag.Name), + HTTPModules: strings.Split(ctx.GlobalString(RPCApiFlag.Name), ","), + WSHost: MakeWSRpcHost(ctx), + WSPort: ctx.GlobalInt(WSPortFlag.Name), + WSDomains: ctx.GlobalString(WSAllowedDomainsFlag.Name), + WSModules: strings.Split(ctx.GlobalString(WSApiFlag.Name), ","), } // Configure the Ethereum service accman := MakeAccountManager(ctx) diff --git a/common/defaults.go b/common/defaults.go index c5a88d7a31..8a136fa801 100644 --- a/common/defaults.go +++ b/common/defaults.go @@ -22,11 +22,11 @@ import ( ) const ( - DefaultIpcSocket = "geth.ipc" // Default (relative) name of the IPC RPC socket - DefaultHttpHost = "localhost" // Default host interface for the HTTP RPC server - DefaultHttpPort = 8545 // Default TCP port for the HTTP RPC server - DefaultWsHost = "localhost" // Default host interface for the websocket RPC server - DefaultWsPort = 8546 // Default TCP port for the websocket RPC server + DefaultIPCSocket = "geth.ipc" // Default (relative) name of the IPC RPC socket + DefaultHTTPHost = "localhost" // Default host interface for the HTTP RPC server + DefaultHTTPPort = 8545 // Default TCP port for the HTTP RPC server + DefaultWSHost = "localhost" // Default host interface for the websocket RPC server + DefaultWSPort = 8546 // Default TCP port for the websocket RPC server ) // DefaultDataDir is the default data directory to use for the databases and other diff --git a/node/config.go b/node/config.go index f8252b63a6..301ec636ee 100644 --- a/node/config.go +++ b/node/config.go @@ -53,11 +53,11 @@ type Config struct { // in memory. DataDir string - // IpcPath is the requested location to place the IPC endpoint. If the path is + // IPCPath is the requested location to place the IPC endpoint. If the path is // a simple file name, it is placed inside the data directory (or on the root // pipe path on Windows), whereas if it's a resolvable path name (absolute or // relative), then that specific path is enforced. An empty path disables IPC. - IpcPath string + IPCPath string // This field should be a valid secp256k1 private key that will be used for both // remote peer identification as well as network traffic encryption. If no key @@ -99,104 +99,104 @@ type Config struct { // Zero defaults to preset values. MaxPendingPeers int - // HttpHost is the host interface on which to start the HTTP RPC server. If this + // HTTPHost is the host interface on which to start the HTTP RPC server. If this // field is empty, no HTTP API endpoint will be started. - HttpHost string + HTTPHost string - // HttpPort is the TCP port number on which to start the HTTP RPC server. The + // HTTPPort is the TCP port number on which to start the HTTP RPC server. The // default zero value is/ valid and will pick a port number randomly (useful // for ephemeral nodes). - HttpPort int + HTTPPort int - // HttpCors is the Cross-Origin Resource Sharing header to send to requesting + // HTTPCors is the Cross-Origin Resource Sharing header to send to requesting // clients. Please be aware that CORS is a browser enforced security, it's fully // useless for custom HTTP clients. - HttpCors string + HTTPCors string - // HttpModules is a list of API modules to expose via the HTTP RPC interface. + // HTTPModules is a list of API modules to expose via the HTTP RPC interface. // If the module list is empty, all RPC API endpoints designated public will be // exposed. - HttpModules []string + HTTPModules []string - // WsHost is the host interface on which to start the websocket RPC server. If + // WSHost is the host interface on which to start the websocket RPC server. If // this field is empty, no websocket API endpoint will be started. - WsHost string + WSHost string - // WsPort is the TCP port number on which to start the websocket RPC server. The + // WSPort is the TCP port number on which to start the websocket RPC server. The // default zero value is/ valid and will pick a port number randomly (useful for // ephemeral nodes). - WsPort int + WSPort int - // WsCors is the Cross-Origin Resource Sharing header to send to requesting clients. - // Please be aware that CORS is a browser enforced security, it's fully useless - // for custom websocket clients. - WsCors string + // WSDomains is the list of domain to accept websocket requests from. Please be + // aware that the server can only act upon the HTTP request the client sends and + // cannot verify the validity of the request header. + WSDomains string - // WsModules is a list of API modules to expose via the websocket RPC interface. + // WSModules is a list of API modules to expose via the websocket RPC interface. // If the module list is empty, all RPC API endpoints designated public will be // exposed. - WsModules []string + WSModules []string } -// IpcEndpoint resolves an IPC endpoint based on a configured value, taking into +// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into // account the set data folders as well as the designated platform we're currently // running on. -func (c *Config) IpcEndpoint() string { +func (c *Config) IPCEndpoint() string { // Short circuit if IPC has not been enabled - if c.IpcPath == "" { + if c.IPCPath == "" { return "" } // On windows we can only use plain top-level pipes if runtime.GOOS == "windows" { - if strings.HasPrefix(c.IpcPath, `\\.\pipe\`) { - return c.IpcPath + if strings.HasPrefix(c.IPCPath, `\\.\pipe\`) { + return c.IPCPath } - return `\\.\pipe\` + c.IpcPath + return `\\.\pipe\` + c.IPCPath } // Resolve names into the data directory full paths otherwise - if filepath.Base(c.IpcPath) == c.IpcPath { + if filepath.Base(c.IPCPath) == c.IPCPath { if c.DataDir == "" { - return filepath.Join(os.TempDir(), c.IpcPath) + return filepath.Join(os.TempDir(), c.IPCPath) } - return filepath.Join(c.DataDir, c.IpcPath) + return filepath.Join(c.DataDir, c.IPCPath) } - return c.IpcPath + return c.IPCPath } -// DefaultIpcEndpoint returns the IPC path used by default. -func DefaultIpcEndpoint() string { - config := &Config{DataDir: common.DefaultDataDir(), IpcPath: common.DefaultIpcSocket} - return config.IpcEndpoint() +// DefaultIPCEndpoint returns the IPC path used by default. +func DefaultIPCEndpoint() string { + config := &Config{DataDir: common.DefaultDataDir(), IPCPath: common.DefaultIPCSocket} + return config.IPCEndpoint() } -// HttpEndpoint resolves an HTTP endpoint based on the configured host interface +// HTTPEndpoint resolves an HTTP endpoint based on the configured host interface // and port parameters. -func (c *Config) HttpEndpoint() string { - if c.HttpHost == "" { +func (c *Config) HTTPEndpoint() string { + if c.HTTPHost == "" { return "" } - return fmt.Sprintf("%s:%d", c.HttpHost, c.HttpPort) + return fmt.Sprintf("%s:%d", c.HTTPHost, c.HTTPPort) } -// DefaultHttpEndpoint returns the HTTP endpoint used by default. -func DefaultHttpEndpoint() string { - config := &Config{HttpHost: common.DefaultHttpHost, HttpPort: common.DefaultHttpPort} - return config.HttpEndpoint() +// DefaultHTTPEndpoint returns the HTTP endpoint used by default. +func DefaultHTTPEndpoint() string { + config := &Config{HTTPHost: common.DefaultHTTPHost, HTTPPort: common.DefaultHTTPPort} + return config.HTTPEndpoint() } -// WsEndpoint resolves an websocket endpoint based on the configured host interface +// WSEndpoint resolves an websocket endpoint based on the configured host interface // and port parameters. -func (c *Config) WsEndpoint() string { - if c.WsHost == "" { +func (c *Config) WSEndpoint() string { + if c.WSHost == "" { return "" } - return fmt.Sprintf("%s:%d", c.WsHost, c.WsPort) + return fmt.Sprintf("%s:%d", c.WSHost, c.WSPort) } -// DefaultWsEndpoint returns the websocket endpoint used by default. -func DefaultWsEndpoint() string { - config := &Config{WsHost: common.DefaultWsHost, WsPort: common.DefaultWsPort} - return config.WsEndpoint() +// DefaultWSEndpoint returns the websocket endpoint used by default. +func DefaultWSEndpoint() string { + config := &Config{WSHost: common.DefaultWSHost, WSPort: common.DefaultWSPort} + return config.WSEndpoint() } // NodeKey retrieves the currently configured private key of the node, checking diff --git a/node/config_test.go b/node/config_test.go index efb864ce42..45a54d184a 100644 --- a/node/config_test.go +++ b/node/config_test.go @@ -63,10 +63,10 @@ func TestDatadirCreation(t *testing.T) { // Tests that IPC paths are correctly resolved to valid endpoints of different // platforms. -func TestIpcPathResolution(t *testing.T) { +func TestIPCPathResolution(t *testing.T) { var tests = []struct { DataDir string - IpcPath string + IPCPath string Windows bool Endpoint string }{ @@ -85,7 +85,7 @@ func TestIpcPathResolution(t *testing.T) { for i, test := range tests { // Only run when platform/test match if (runtime.GOOS == "windows") == test.Windows { - if endpoint := (&Config{DataDir: test.DataDir, IpcPath: test.IpcPath}).IpcEndpoint(); endpoint != test.Endpoint { + if endpoint := (&Config{DataDir: test.DataDir, IPCPath: test.IPCPath}).IPCEndpoint(); endpoint != test.Endpoint { t.Errorf("test %d: IPC endpoint mismatch: have %s, want %s", i, endpoint, test.Endpoint) } } diff --git a/node/node.go b/node/node.go index 804748b6b0..6d9290034d 100644 --- a/node/node.go +++ b/node/node.go @@ -68,7 +68,7 @@ type Node struct { wsEndpoint string // Websocket endpoint (interface + port) to listen at (empty = websocket disabled) wsWhitelist []string // Websocket RPC modules to allow through this endpoint - wsCors string // Websocket RPC Cross-Origin Resource Sharing header + wsDomains string // Websocket RPC allowed origin domains wsListener net.Listener // Websocket RPC listener socket to server API requests wsHandler *rpc.Server // Websocket RPC request handler to process the API requests @@ -107,13 +107,13 @@ func New(conf *Config) (*Node, error) { MaxPendingPeers: conf.MaxPendingPeers, }, serviceFuncs: []ServiceConstructor{}, - ipcEndpoint: conf.IpcEndpoint(), - httpEndpoint: conf.HttpEndpoint(), - httpWhitelist: conf.HttpModules, - httpCors: conf.HttpCors, - wsEndpoint: conf.WsEndpoint(), - wsWhitelist: conf.WsModules, - wsCors: conf.WsCors, + ipcEndpoint: conf.IPCEndpoint(), + httpEndpoint: conf.HTTPEndpoint(), + httpWhitelist: conf.HTTPModules, + httpCors: conf.HTTPCors, + wsEndpoint: conf.WSEndpoint(), + wsWhitelist: conf.WSModules, + wsDomains: conf.WSDomains, eventmux: new(event.TypeMux), }, nil } @@ -224,7 +224,7 @@ func (n *Node) startRPC(services map[reflect.Type]Service) error { n.stopIPC() return err } - if err := n.startWS(n.wsEndpoint, apis, n.wsWhitelist, n.wsCors); err != nil { + if err := n.startWS(n.wsEndpoint, apis, n.wsWhitelist, n.wsDomains); err != nil { n.stopHTTP() n.stopIPC() return err @@ -388,7 +388,7 @@ func (n *Node) startWS(endpoint string, apis []rpc.API, modules []string, cors s n.wsEndpoint = endpoint n.wsListener = listener n.wsHandler = handler - n.wsCors = cors + n.wsDomains = cors return nil } @@ -501,8 +501,8 @@ func (n *Node) DataDir() string { return n.datadir } -// IpcEndpoint retrieves the current IPC endpoint used by the protocol stack. -func (n *Node) IpcEndpoint() string { +// IPCEndpoint retrieves the current IPC endpoint used by the protocol stack. +func (n *Node) IPCEndpoint() string { return n.ipcEndpoint } diff --git a/node/node_test.go b/node/node_test.go index 53dcbcf74c..38bfe27e2d 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -37,7 +37,7 @@ var ( func testNodeConfig() *Config { return &Config{ - IpcPath: fmt.Sprintf("test-%d.ipc", rand.Int63()), + IPCPath: fmt.Sprintf("test-%d.ipc", rand.Int63()), PrivateKey: testNodeKey, Name: "test node", } @@ -541,7 +541,7 @@ func TestAPIGather(t *testing.T) { defer stack.Stop() // Connect to the RPC server and verify the various registered endpoints - ipcClient, err := rpc.NewIPCClient(stack.IpcEndpoint()) + ipcClient, err := rpc.NewIPCClient(stack.IPCEndpoint()) if err != nil { t.Fatalf("failed to connect to the IPC API server: %v", err) } diff --git a/rpc/server.go b/rpc/server.go index 5b88d843ae..f42ee2d37a 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -33,8 +33,8 @@ import ( const ( stopPendingRequestTimeout = 3 * time.Second // give pending requests stopPendingRequestTimeout the time to finish when the server is stopped - DefaultIpcApis = "admin,eth,debug,miner,net,shh,txpool,personal,web3" - DefaultHttpRpcApis = "eth,net,web3" + DefaultIPCApis = "admin,eth,debug,miner,net,shh,txpool,personal,web3" + DefaultHTTPApis = "eth,net,web3" ) // NewServer will create a new server instance with no registered handlers.