aboutsummaryrefslogtreecommitdiffstats
path: root/node/config.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-02-05 17:33:24 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-02-05 17:33:24 +0800
commitba7c125153ce1be30985784a18edf38645406d03 (patch)
tree92c1e2b8ec6ef0d4b39381148b3497e311e80b95 /node/config.go
parent212828963172b3921827df15abdc8602480e947d (diff)
parent188ab928c3f2a2eac5ee0f7ac42cbf2f35568bcd (diff)
downloaddexon-ba7c125153ce1be30985784a18edf38645406d03.tar
dexon-ba7c125153ce1be30985784a18edf38645406d03.tar.gz
dexon-ba7c125153ce1be30985784a18edf38645406d03.tar.bz2
dexon-ba7c125153ce1be30985784a18edf38645406d03.tar.lz
dexon-ba7c125153ce1be30985784a18edf38645406d03.tar.xz
dexon-ba7c125153ce1be30985784a18edf38645406d03.tar.zst
dexon-ba7c125153ce1be30985784a18edf38645406d03.zip
Merge pull request #2168 from karalabe/move-rpc-into-node
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.