cmd, common, node, rpc: move IPC into the node itself

This commit is contained in:
Péter Szilágyi
2016-02-02 19:06:43 +02:00
parent 3274db19c7
commit 188ab928c3
14 changed files with 292 additions and 156 deletions

View File

@ -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.