aboutsummaryrefslogtreecommitdiffstats
path: root/node/config.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-02-03 01:06:43 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-02-04 17:23:15 +0800
commit188ab928c3f2a2eac5ee0f7ac42cbf2f35568bcd (patch)
treeeaeebfbe371a9ae8e801bd934d7dd850c7354765 /node/config.go
parent3274db19c7563e31f79418b63f6c10233cbaa32a (diff)
downloaddexon-188ab928c3f2a2eac5ee0f7ac42cbf2f35568bcd.tar.gz
dexon-188ab928c3f2a2eac5ee0f7ac42cbf2f35568bcd.tar.zst
dexon-188ab928c3f2a2eac5ee0f7ac42cbf2f35568bcd.zip
cmd, common, node, rpc: move IPC into the node itself
Diffstat (limited to 'node/config.go')
-rw-r--r--node/config.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/node/config.go b/node/config.go
index 93f0ba79d..d3eb1c78b 100644
--- a/node/config.go
+++ b/node/config.go
@@ -23,7 +23,10 @@ import (
"net"
"os"
"path/filepath"
+ "runtime"
+ "strings"
+ "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
@@ -49,6 +52,12 @@ type Config struct {
// in memory.
DataDir string
+ // 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
+
// 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
// is configured, the preset one is loaded from the data dir, generating it if
@@ -90,6 +99,37 @@ type Config struct {
MaxPendingPeers int
}
+// 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 {
+ // Short circuit if IPC has not been enabled
+ 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
+ }
+ return `\\.\pipe\` + c.IpcPath
+ }
+ // Resolve names into the data directory full paths otherwise
+ if filepath.Base(c.IpcPath) == c.IpcPath {
+ if c.DataDir == "" {
+ return filepath.Join(os.TempDir(), c.IpcPath)
+ }
+ return filepath.Join(c.DataDir, 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()
+}
+
// NodeKey retrieves the currently configured private key of the node, checking
// first any manually set key, falling back to the one found in the configured
// data folder. If no key can be found, a new one is generated.