cmd, common, node, rpc: rework naming convention to canonical one

This commit is contained in:
Péter Szilágyi 2016-02-09 13:24:42 +02:00
parent 7486904b92
commit 900e124bee
13 changed files with 115 additions and 115 deletions

@ -96,7 +96,7 @@ func testREPL(t *testing.T, config func(*eth.Config)) (string, *testjethre, *nod
t.Fatal(err) t.Fatal(err)
} }
// Create a networkless protocol stack // 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 { if err != nil {
t.Fatalf("failed to create node: %v", err) 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(&ethereum) stack.Service(&ethereum)
assetPath := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext") 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 { if err != nil {
t.Fatalf("failed to attach to node: %v", err) t.Fatalf("failed to attach to node: %v", err)
} }

@ -312,7 +312,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils.WSListenAddrFlag, utils.WSListenAddrFlag,
utils.WSPortFlag, utils.WSPortFlag,
utils.WSApiFlag, utils.WSApiFlag,
utils.WSCORSDomainFlag, utils.WSAllowedDomainsFlag,
utils.IPCDisabledFlag, utils.IPCDisabledFlag,
utils.IPCApiFlag, utils.IPCApiFlag,
utils.IPCPathFlag, utils.IPCPathFlag,
@ -425,7 +425,7 @@ func console(ctx *cli.Context) {
startNode(ctx, node) startNode(ctx, node)
// Attach to the newly started node, and either execute script or become interactive // 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 { if err != nil {
utils.Fatalf("Failed to attach to the inproc geth: %v", err) utils.Fatalf("Failed to attach to the inproc geth: %v", err)
} }
@ -451,7 +451,7 @@ func execScripts(ctx *cli.Context) {
startNode(ctx, node) startNode(ctx, node)
// Attach to the newly started node and execute the given scripts // 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 { if err != nil {
utils.Fatalf("Failed to attach to the inproc geth: %v", err) utils.Fatalf("Failed to attach to the inproc geth: %v", err)
} }

@ -36,7 +36,7 @@ import (
var ( var (
monitorCommandAttachFlag = cli.StringFlag{ monitorCommandAttachFlag = cli.StringFlag{
Name: "attach", Name: "attach",
Value: "ipc:" + node.DefaultIpcEndpoint(), Value: "ipc:" + node.DefaultIPCEndpoint(),
Usage: "API endpoint to attach to", Usage: "API endpoint to attach to",
} }
monitorCommandRowsFlag = cli.IntFlag{ monitorCommandRowsFlag = cli.IntFlag{

@ -93,7 +93,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.WSListenAddrFlag, utils.WSListenAddrFlag,
utils.WSPortFlag, utils.WSPortFlag,
utils.WSApiFlag, utils.WSApiFlag,
utils.WSCORSDomainFlag, utils.WSAllowedDomainsFlag,
utils.IPCDisabledFlag, utils.IPCDisabledFlag,
utils.IPCApiFlag, utils.IPCApiFlag,
utils.IPCPathFlag, utils.IPCPathFlag,

@ -93,13 +93,13 @@ func main() {
func MakeSystemNode(keydir string, privkey string, test *tests.BlockTest) (*node.Node, error) { func MakeSystemNode(keydir string, privkey string, test *tests.BlockTest) (*node.Node, error) {
// Create a networkless protocol stack // Create a networkless protocol stack
stack, err := node.New(&node.Config{ stack, err := node.New(&node.Config{
IpcPath: node.DefaultIpcEndpoint(), IPCPath: node.DefaultIPCEndpoint(),
HttpHost: common.DefaultHttpHost, HTTPHost: common.DefaultHTTPHost,
HttpPort: common.DefaultHttpPort, HTTPPort: common.DefaultHTTPPort,
HttpModules: []string{"admin", "db", "eth", "debug", "miner", "net", "shh", "txpool", "personal", "web3"}, HTTPModules: []string{"admin", "db", "eth", "debug", "miner", "net", "shh", "txpool", "personal", "web3"},
WsHost: common.DefaultWsHost, WSHost: common.DefaultWSHost,
WsPort: common.DefaultWsPort, WSPort: common.DefaultWSPort,
WsModules: []string{"admin", "db", "eth", "debug", "miner", "net", "shh", "txpool", "personal", "web3"}, WSModules: []string{"admin", "db", "eth", "debug", "miner", "net", "shh", "txpool", "personal", "web3"},
NoDiscovery: true, NoDiscovery: true,
}) })
if err != nil { if err != nil {

@ -33,7 +33,7 @@ func NewRemoteRPCClient(ctx *cli.Context) (rpc.Client, error) {
return NewRemoteRPCClientFromString(endpoint) return NewRemoteRPCClientFromString(endpoint)
} }
// use IPC by default // use IPC by default
return rpc.NewIPCClient(node.DefaultIpcEndpoint()) return rpc.NewIPCClient(node.DefaultIPCEndpoint())
} }
// NewRemoteRPCClientFromString returns a RPC client which connects to the given // NewRemoteRPCClientFromString returns a RPC client which connects to the given

@ -232,12 +232,12 @@ var (
RPCListenAddrFlag = cli.StringFlag{ RPCListenAddrFlag = cli.StringFlag{
Name: "rpcaddr", Name: "rpcaddr",
Usage: "HTTP-RPC server listening interface", Usage: "HTTP-RPC server listening interface",
Value: common.DefaultHttpHost, Value: common.DefaultHTTPHost,
} }
RPCPortFlag = cli.IntFlag{ RPCPortFlag = cli.IntFlag{
Name: "rpcport", Name: "rpcport",
Usage: "HTTP-RPC server listening port", Usage: "HTTP-RPC server listening port",
Value: common.DefaultHttpPort, Value: common.DefaultHTTPPort,
} }
RPCCORSDomainFlag = cli.StringFlag{ RPCCORSDomainFlag = cli.StringFlag{
Name: "rpccorsdomain", Name: "rpccorsdomain",
@ -247,7 +247,7 @@ var (
RPCApiFlag = cli.StringFlag{ RPCApiFlag = cli.StringFlag{
Name: "rpcapi", Name: "rpcapi",
Usage: "API's offered over the HTTP-RPC interface", Usage: "API's offered over the HTTP-RPC interface",
Value: rpc.DefaultHttpRpcApis, Value: rpc.DefaultHTTPApis,
} }
IPCDisabledFlag = cli.BoolFlag{ IPCDisabledFlag = cli.BoolFlag{
Name: "ipcdisable", Name: "ipcdisable",
@ -256,12 +256,12 @@ var (
IPCApiFlag = cli.StringFlag{ IPCApiFlag = cli.StringFlag{
Name: "ipcapi", Name: "ipcapi",
Usage: "API's offered over the IPC-RPC interface", Usage: "API's offered over the IPC-RPC interface",
Value: rpc.DefaultIpcApis, Value: rpc.DefaultIPCApis,
} }
IPCPathFlag = DirectoryFlag{ IPCPathFlag = DirectoryFlag{
Name: "ipcpath", Name: "ipcpath",
Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)", Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)",
Value: DirectoryString{common.DefaultIpcSocket}, Value: DirectoryString{common.DefaultIPCSocket},
} }
WSEnabledFlag = cli.BoolFlag{ WSEnabledFlag = cli.BoolFlag{
Name: "ws", Name: "ws",
@ -270,21 +270,21 @@ var (
WSListenAddrFlag = cli.StringFlag{ WSListenAddrFlag = cli.StringFlag{
Name: "wsaddr", Name: "wsaddr",
Usage: "WS-RPC server listening interface", Usage: "WS-RPC server listening interface",
Value: common.DefaultWsHost, Value: common.DefaultWSHost,
} }
WSPortFlag = cli.IntFlag{ WSPortFlag = cli.IntFlag{
Name: "wsport", Name: "wsport",
Usage: "WS-RPC server listening port", Usage: "WS-RPC server listening port",
Value: common.DefaultWsPort, Value: common.DefaultWSPort,
} }
WSApiFlag = cli.StringFlag{ WSApiFlag = cli.StringFlag{
Name: "wsapi", Name: "wsapi",
Usage: "API's offered over the WS-RPC interface", Usage: "API's offered over the WS-RPC interface",
Value: rpc.DefaultHttpRpcApis, Value: rpc.DefaultHTTPApis,
} }
WSCORSDomainFlag = cli.StringFlag{ WSAllowedDomainsFlag = cli.StringFlag{
Name: "wscorsdomain", Name: "wsdomains",
Usage: "Domains from which to accept websockets requests", Usage: "Domains from which to accept websockets requests (can be spoofed)",
Value: "", Value: "",
} }
ExecFlag = cli.StringFlag{ ExecFlag = cli.StringFlag{
@ -393,9 +393,9 @@ func MustMakeDataDir(ctx *cli.Context) string {
return "" 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. // 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) { if ctx.GlobalBool(IPCDisabledFlag.Name) {
return "" return ""
} }
@ -481,18 +481,18 @@ func MakeNAT(ctx *cli.Context) nat.Interface {
return natif 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. // 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) { if !ctx.GlobalBool(RPCEnabledFlag.Name) {
return "" return ""
} }
return ctx.GlobalString(RPCListenAddrFlag.Name) 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. // 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) { if !ctx.GlobalBool(WSEnabledFlag.Name) {
return "" return ""
} }
@ -616,15 +616,15 @@ func MakeSystemNode(name, version string, extra []byte, ctx *cli.Context) *node.
NAT: MakeNAT(ctx), NAT: MakeNAT(ctx),
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name), MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name), MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name),
IpcPath: MakeIpcPath(ctx), IPCPath: MakeIPCPath(ctx),
HttpHost: MakeHttpRpcHost(ctx), HTTPHost: MakeHTTPRpcHost(ctx),
HttpPort: ctx.GlobalInt(RPCPortFlag.Name), HTTPPort: ctx.GlobalInt(RPCPortFlag.Name),
HttpCors: ctx.GlobalString(RPCCORSDomainFlag.Name), HTTPCors: ctx.GlobalString(RPCCORSDomainFlag.Name),
HttpModules: strings.Split(ctx.GlobalString(RPCApiFlag.Name), ","), HTTPModules: strings.Split(ctx.GlobalString(RPCApiFlag.Name), ","),
WsHost: MakeWsRpcHost(ctx), WSHost: MakeWSRpcHost(ctx),
WsPort: ctx.GlobalInt(WSPortFlag.Name), WSPort: ctx.GlobalInt(WSPortFlag.Name),
WsCors: ctx.GlobalString(WSCORSDomainFlag.Name), WSDomains: ctx.GlobalString(WSAllowedDomainsFlag.Name),
WsModules: strings.Split(ctx.GlobalString(WSApiFlag.Name), ","), WSModules: strings.Split(ctx.GlobalString(WSApiFlag.Name), ","),
} }
// Configure the Ethereum service // Configure the Ethereum service
accman := MakeAccountManager(ctx) accman := MakeAccountManager(ctx)

@ -22,11 +22,11 @@ import (
) )
const ( const (
DefaultIpcSocket = "geth.ipc" // Default (relative) name of the IPC RPC socket DefaultIPCSocket = "geth.ipc" // Default (relative) name of the IPC RPC socket
DefaultHttpHost = "localhost" // Default host interface for the HTTP RPC server DefaultHTTPHost = "localhost" // Default host interface for the HTTP RPC server
DefaultHttpPort = 8545 // Default TCP port 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 DefaultWSHost = "localhost" // Default host interface for the websocket RPC server
DefaultWsPort = 8546 // Default TCP port 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 // DefaultDataDir is the default data directory to use for the databases and other

@ -53,11 +53,11 @@ type Config struct {
// in memory. // in memory.
DataDir string 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 // 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 // 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. // 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 // 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 // remote peer identification as well as network traffic encryption. If no key
@ -99,104 +99,104 @@ type Config struct {
// Zero defaults to preset values. // Zero defaults to preset values.
MaxPendingPeers int 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. // 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 // default zero value is/ valid and will pick a port number randomly (useful
// for ephemeral nodes). // 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 // clients. Please be aware that CORS is a browser enforced security, it's fully
// useless for custom HTTP clients. // 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 // If the module list is empty, all RPC API endpoints designated public will be
// exposed. // 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. // 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 // default zero value is/ valid and will pick a port number randomly (useful for
// ephemeral nodes). // ephemeral nodes).
WsPort int WSPort int
// WsCors is the Cross-Origin Resource Sharing header to send to requesting clients. // WSDomains is the list of domain to accept websocket requests from. Please be
// Please be aware that CORS is a browser enforced security, it's fully useless // aware that the server can only act upon the HTTP request the client sends and
// for custom websocket clients. // cannot verify the validity of the request header.
WsCors string 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 // If the module list is empty, all RPC API endpoints designated public will be
// exposed. // 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 // account the set data folders as well as the designated platform we're currently
// running on. // running on.
func (c *Config) IpcEndpoint() string { func (c *Config) IPCEndpoint() string {
// Short circuit if IPC has not been enabled // Short circuit if IPC has not been enabled
if c.IpcPath == "" { if c.IPCPath == "" {
return "" return ""
} }
// On windows we can only use plain top-level pipes // On windows we can only use plain top-level pipes
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
if strings.HasPrefix(c.IpcPath, `\\.\pipe\`) { if strings.HasPrefix(c.IPCPath, `\\.\pipe\`) {
return c.IpcPath return c.IPCPath
} }
return `\\.\pipe\` + c.IpcPath return `\\.\pipe\` + c.IPCPath
} }
// Resolve names into the data directory full paths otherwise // 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 == "" { 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. // DefaultIPCEndpoint returns the IPC path used by default.
func DefaultIpcEndpoint() string { func DefaultIPCEndpoint() string {
config := &Config{DataDir: common.DefaultDataDir(), IpcPath: common.DefaultIpcSocket} config := &Config{DataDir: common.DefaultDataDir(), IPCPath: common.DefaultIPCSocket}
return config.IpcEndpoint() 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. // and port parameters.
func (c *Config) HttpEndpoint() string { func (c *Config) HTTPEndpoint() string {
if c.HttpHost == "" { if c.HTTPHost == "" {
return "" 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. // DefaultHTTPEndpoint returns the HTTP endpoint used by default.
func DefaultHttpEndpoint() string { func DefaultHTTPEndpoint() string {
config := &Config{HttpHost: common.DefaultHttpHost, HttpPort: common.DefaultHttpPort} config := &Config{HTTPHost: common.DefaultHTTPHost, HTTPPort: common.DefaultHTTPPort}
return config.HttpEndpoint() 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. // and port parameters.
func (c *Config) WsEndpoint() string { func (c *Config) WSEndpoint() string {
if c.WsHost == "" { if c.WSHost == "" {
return "" 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. // DefaultWSEndpoint returns the websocket endpoint used by default.
func DefaultWsEndpoint() string { func DefaultWSEndpoint() string {
config := &Config{WsHost: common.DefaultWsHost, WsPort: common.DefaultWsPort} config := &Config{WSHost: common.DefaultWSHost, WSPort: common.DefaultWSPort}
return config.WsEndpoint() return config.WSEndpoint()
} }
// NodeKey retrieves the currently configured private key of the node, checking // NodeKey retrieves the currently configured private key of the node, checking

@ -63,10 +63,10 @@ func TestDatadirCreation(t *testing.T) {
// Tests that IPC paths are correctly resolved to valid endpoints of different // Tests that IPC paths are correctly resolved to valid endpoints of different
// platforms. // platforms.
func TestIpcPathResolution(t *testing.T) { func TestIPCPathResolution(t *testing.T) {
var tests = []struct { var tests = []struct {
DataDir string DataDir string
IpcPath string IPCPath string
Windows bool Windows bool
Endpoint string Endpoint string
}{ }{
@ -85,7 +85,7 @@ func TestIpcPathResolution(t *testing.T) {
for i, test := range tests { for i, test := range tests {
// Only run when platform/test match // Only run when platform/test match
if (runtime.GOOS == "windows") == test.Windows { 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) t.Errorf("test %d: IPC endpoint mismatch: have %s, want %s", i, endpoint, test.Endpoint)
} }
} }

@ -68,7 +68,7 @@ type Node struct {
wsEndpoint string // Websocket endpoint (interface + port) to listen at (empty = websocket disabled) wsEndpoint string // Websocket endpoint (interface + port) to listen at (empty = websocket disabled)
wsWhitelist []string // Websocket RPC modules to allow through this endpoint 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 wsListener net.Listener // Websocket RPC listener socket to server API requests
wsHandler *rpc.Server // Websocket RPC request handler to process the 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, MaxPendingPeers: conf.MaxPendingPeers,
}, },
serviceFuncs: []ServiceConstructor{}, serviceFuncs: []ServiceConstructor{},
ipcEndpoint: conf.IpcEndpoint(), ipcEndpoint: conf.IPCEndpoint(),
httpEndpoint: conf.HttpEndpoint(), httpEndpoint: conf.HTTPEndpoint(),
httpWhitelist: conf.HttpModules, httpWhitelist: conf.HTTPModules,
httpCors: conf.HttpCors, httpCors: conf.HTTPCors,
wsEndpoint: conf.WsEndpoint(), wsEndpoint: conf.WSEndpoint(),
wsWhitelist: conf.WsModules, wsWhitelist: conf.WSModules,
wsCors: conf.WsCors, wsDomains: conf.WSDomains,
eventmux: new(event.TypeMux), eventmux: new(event.TypeMux),
}, nil }, nil
} }
@ -224,7 +224,7 @@ func (n *Node) startRPC(services map[reflect.Type]Service) error {
n.stopIPC() n.stopIPC()
return err 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.stopHTTP()
n.stopIPC() n.stopIPC()
return err return err
@ -388,7 +388,7 @@ func (n *Node) startWS(endpoint string, apis []rpc.API, modules []string, cors s
n.wsEndpoint = endpoint n.wsEndpoint = endpoint
n.wsListener = listener n.wsListener = listener
n.wsHandler = handler n.wsHandler = handler
n.wsCors = cors n.wsDomains = cors
return nil return nil
} }
@ -501,8 +501,8 @@ func (n *Node) DataDir() string {
return n.datadir return n.datadir
} }
// IpcEndpoint retrieves the current IPC endpoint used by the protocol stack. // IPCEndpoint retrieves the current IPC endpoint used by the protocol stack.
func (n *Node) IpcEndpoint() string { func (n *Node) IPCEndpoint() string {
return n.ipcEndpoint return n.ipcEndpoint
} }

@ -37,7 +37,7 @@ var (
func testNodeConfig() *Config { func testNodeConfig() *Config {
return &Config{ return &Config{
IpcPath: fmt.Sprintf("test-%d.ipc", rand.Int63()), IPCPath: fmt.Sprintf("test-%d.ipc", rand.Int63()),
PrivateKey: testNodeKey, PrivateKey: testNodeKey,
Name: "test node", Name: "test node",
} }
@ -541,7 +541,7 @@ func TestAPIGather(t *testing.T) {
defer stack.Stop() defer stack.Stop()
// Connect to the RPC server and verify the various registered endpoints // 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 { if err != nil {
t.Fatalf("failed to connect to the IPC API server: %v", err) t.Fatalf("failed to connect to the IPC API server: %v", err)
} }

@ -33,8 +33,8 @@ import (
const ( const (
stopPendingRequestTimeout = 3 * time.Second // give pending requests stopPendingRequestTimeout the time to finish when the server is stopped 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" DefaultIPCApis = "admin,eth,debug,miner,net,shh,txpool,personal,web3"
DefaultHttpRpcApis = "eth,net,web3" DefaultHTTPApis = "eth,net,web3"
) )
// NewServer will create a new server instance with no registered handlers. // NewServer will create a new server instance with no registered handlers.