aboutsummaryrefslogtreecommitdiffstats
path: root/node
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-02-09 19:24:42 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-02-09 19:24:42 +0800
commit900e124beea551ded290f61e7bf85ff6b2e4a29e (patch)
treef4447602e77956699a8df44a1edc9932688d48fd /node
parent7486904b92449c5955bb682f4ff98752906912b8 (diff)
downloaddexon-900e124beea551ded290f61e7bf85ff6b2e4a29e.tar
dexon-900e124beea551ded290f61e7bf85ff6b2e4a29e.tar.gz
dexon-900e124beea551ded290f61e7bf85ff6b2e4a29e.tar.bz2
dexon-900e124beea551ded290f61e7bf85ff6b2e4a29e.tar.lz
dexon-900e124beea551ded290f61e7bf85ff6b2e4a29e.tar.xz
dexon-900e124beea551ded290f61e7bf85ff6b2e4a29e.tar.zst
dexon-900e124beea551ded290f61e7bf85ff6b2e4a29e.zip
cmd, common, node, rpc: rework naming convention to canonical one
Diffstat (limited to 'node')
-rw-r--r--node/config.go100
-rw-r--r--node/config_test.go6
-rw-r--r--node/node.go24
-rw-r--r--node/node_test.go4
4 files changed, 67 insertions, 67 deletions
diff --git a/node/config.go b/node/config.go
index f8252b63a..301ec636e 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 efb864ce4..45a54d184 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 804748b6b..6d9290034 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 53dcbcf74..38bfe27e2 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)
}