aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
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 /cmd
parent3274db19c7563e31f79418b63f6c10233cbaa32a (diff)
downloadgo-tangerine-188ab928c3f2a2eac5ee0f7ac42cbf2f35568bcd.tar
go-tangerine-188ab928c3f2a2eac5ee0f7ac42cbf2f35568bcd.tar.gz
go-tangerine-188ab928c3f2a2eac5ee0f7ac42cbf2f35568bcd.tar.bz2
go-tangerine-188ab928c3f2a2eac5ee0f7ac42cbf2f35568bcd.tar.lz
go-tangerine-188ab928c3f2a2eac5ee0f7ac42cbf2f35568bcd.tar.xz
go-tangerine-188ab928c3f2a2eac5ee0f7ac42cbf2f35568bcd.tar.zst
go-tangerine-188ab928c3f2a2eac5ee0f7ac42cbf2f35568bcd.zip
cmd, common, node, rpc: move IPC into the node itself
Diffstat (limited to 'cmd')
-rw-r--r--cmd/geth/main.go7
-rw-r--r--cmd/geth/monitorcmd.go4
-rw-r--r--cmd/gethrpctest/main.go61
-rw-r--r--cmd/utils/client.go4
-rw-r--r--cmd/utils/flags.go71
5 files changed, 18 insertions, 129 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 09c7eee05..fa456a7ac 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -502,12 +502,7 @@ func startNode(ctx *cli.Context, stack *node.Node) {
unlockAccount(ctx, accman, trimmed, i, passwords)
}
}
- // Start auxiliary services if enabled.
- if !ctx.GlobalBool(utils.IPCDisabledFlag.Name) {
- if err := utils.StartIPC(stack, ctx); err != nil {
- utils.Fatalf("Failed to start IPC: %v", err)
- }
- }
+ // Start auxiliary services if enabled
if ctx.GlobalBool(utils.RPCEnabledFlag.Name) {
if err := utils.StartRPC(stack, ctx); err != nil {
utils.Fatalf("Failed to start RPC: %v", err)
diff --git a/cmd/geth/monitorcmd.go b/cmd/geth/monitorcmd.go
index 1d7bf3f6a..4d56f2289 100644
--- a/cmd/geth/monitorcmd.go
+++ b/cmd/geth/monitorcmd.go
@@ -28,7 +28,7 @@ import (
"github.com/codegangsta/cli"
"github.com/ethereum/go-ethereum/cmd/utils"
- "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rpc"
"github.com/gizak/termui"
)
@@ -36,7 +36,7 @@ import (
var (
monitorCommandAttachFlag = cli.StringFlag{
Name: "attach",
- Value: "ipc:" + common.DefaultIpcPath(),
+ Value: "ipc:" + node.DefaultIpcEndpoint(),
Usage: "API endpoint to attach to",
}
monitorCommandRowsFlag = cli.IntFlag{
diff --git a/cmd/gethrpctest/main.go b/cmd/gethrpctest/main.go
index 8522258a9..becd09f5a 100644
--- a/cmd/gethrpctest/main.go
+++ b/cmd/gethrpctest/main.go
@@ -18,25 +18,20 @@
package main
import (
+ "errors"
"flag"
"io/ioutil"
"log"
"os"
"os/signal"
- "path/filepath"
- "runtime"
-
- "errors"
"github.com/ethereum/go-ethereum/accounts"
- "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/node"
- "github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/tests"
"github.com/ethereum/go-ethereum/whisper"
)
@@ -89,11 +84,6 @@ func main() {
}
log.Println("Initial test suite passed...")
- if err := StartIPC(stack); err != nil {
- log.Fatalf("Failed to start IPC interface: %v\n", err)
- }
- log.Println("IPC Interface started, accepting requests...")
-
// Start the RPC interface and wait until terminated
if err := StartRPC(stack); err != nil {
log.Fatalf("Failed to start RPC interface: %v", err)
@@ -109,7 +99,7 @@ func main() {
// keystore path and initial pre-state.
func MakeSystemNode(keydir string, privkey string, test *tests.BlockTest) (*node.Node, error) {
// Create a networkless protocol stack
- stack, err := node.New(&node.Config{NoDiscovery: true})
+ stack, err := node.New(&node.Config{IpcPath: node.DefaultIpcEndpoint(), NoDiscovery: true})
if err != nil {
return nil, err
}
@@ -194,50 +184,3 @@ func StartRPC(stack *node.Node) error {
glog.V(logger.Error).Infof("Unable to start RPC-HTTP interface, could not find admin API")
return errors.New("Unable to start RPC-HTTP interface")
}
-
-// StartIPC initializes an IPC interface to the given protocol stack.
-func StartIPC(stack *node.Node) error {
- var ethereum *eth.Ethereum
- if err := stack.Service(&ethereum); err != nil {
- return err
- }
-
- endpoint := `\\.\pipe\geth.ipc`
- if runtime.GOOS != "windows" {
- endpoint = filepath.Join(common.DefaultDataDir(), "geth.ipc")
- }
-
- listener, err := rpc.CreateIPCListener(endpoint)
- if err != nil {
- return err
- }
-
- server := rpc.NewServer()
-
- // register package API's this node provides
- offered := stack.APIs()
- for _, api := range offered {
- server.RegisterName(api.Namespace, api.Service)
- glog.V(logger.Debug).Infof("Register %T under namespace '%s' for IPC service\n", api.Service, api.Namespace)
- }
-
- //var ethereum *eth.Ethereum
- //if err := stack.Service(&ethereum); err != nil {
- // return err
- //}
-
- go func() {
- glog.V(logger.Info).Infof("Start IPC server on %s\n", endpoint)
- for {
- conn, err := listener.Accept()
- if err != nil {
- glog.V(logger.Error).Infof("Unable to accept connection - %v\n", err)
- }
-
- codec := rpc.NewJSONCodec(conn)
- go server.ServeCodec(codec)
- }
- }()
-
- return nil
-}
diff --git a/cmd/utils/client.go b/cmd/utils/client.go
index bac456491..40ebcd729 100644
--- a/cmd/utils/client.go
+++ b/cmd/utils/client.go
@@ -150,10 +150,8 @@ func NewRemoteRPCClient(ctx *cli.Context) (rpc.Client, error) {
endpoint := ctx.Args().First()
return NewRemoteRPCClientFromString(endpoint)
}
-
// use IPC by default
- endpoint := IPCSocketPath(ctx)
- return rpc.NewIPCClient(endpoint)
+ return rpc.NewIPCClient(node.DefaultIpcEndpoint())
}
// NewRemoteRPCClientFromString returns a RPC client which connects to the given
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 1e3e58e51..5d56ba7d0 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -261,8 +261,8 @@ var (
}
IPCPathFlag = DirectoryFlag{
Name: "ipcpath",
- Usage: "Filename for IPC socket/pipe",
- Value: DirectoryString{common.DefaultIpcPath()},
+ Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)",
+ Value: DirectoryString{common.DefaultIpcSocket()},
}
WSEnabledFlag = cli.BoolFlag{
Name: "ws",
@@ -394,6 +394,15 @@ func MustMakeDataDir(ctx *cli.Context) string {
return ""
}
+// 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.
+func MakeIpcPath(ctx *cli.Context) string {
+ if ctx.GlobalBool(IPCDisabledFlag.Name) {
+ return ""
+ }
+ return ctx.GlobalString(IPCPathFlag.Name)
+}
+
// MakeNodeKey creates a node key from set command line flags, either loading it
// from a file or as a specified hex value. If neither flags were provided, this
// method returns nil and an emphemeral key is to be generated.
@@ -582,6 +591,7 @@ func MakeSystemNode(name, version string, extra []byte, ctx *cli.Context) *node.
// Configure the node's service container
stackConf := &node.Config{
DataDir: MustMakeDataDir(ctx),
+ IpcPath: MakeIpcPath(ctx),
PrivateKey: MakeNodeKey(ctx),
Name: MakeNodeName(name, version, ctx),
NoDiscovery: ctx.GlobalBool(NoDiscoverFlag.Name),
@@ -734,63 +744,6 @@ func MakeChain(ctx *cli.Context) (chain *core.BlockChain, chainDb ethdb.Database
return chain, chainDb
}
-func IPCSocketPath(ctx *cli.Context) (ipcpath string) {
- if runtime.GOOS == "windows" {
- ipcpath = common.DefaultIpcPath()
- if ctx.GlobalIsSet(IPCPathFlag.Name) {
- ipcpath = ctx.GlobalString(IPCPathFlag.Name)
- }
- } else {
- ipcpath = common.DefaultIpcPath()
- if ctx.GlobalIsSet(DataDirFlag.Name) {
- ipcpath = filepath.Join(ctx.GlobalString(DataDirFlag.Name), "geth.ipc")
- }
- if ctx.GlobalIsSet(IPCPathFlag.Name) {
- ipcpath = ctx.GlobalString(IPCPathFlag.Name)
- }
- }
-
- return
-}
-
-func StartIPC(stack *node.Node, ctx *cli.Context) error {
- var ethereum *eth.Ethereum
- if err := stack.Service(&ethereum); err != nil {
- return err
- }
-
- endpoint := IPCSocketPath(ctx)
- listener, err := rpc.CreateIPCListener(endpoint)
- if err != nil {
- return err
- }
-
- server := rpc.NewServer()
-
- // register package API's this node provides
- offered := stack.APIs()
- for _, api := range offered {
- server.RegisterName(api.Namespace, api.Service)
- glog.V(logger.Debug).Infof("Register %T under namespace '%s' for IPC service\n", api.Service, api.Namespace)
- }
-
- go func() {
- glog.V(logger.Info).Infof("Start IPC server on %s\n", endpoint)
- for {
- conn, err := listener.Accept()
- if err != nil {
- glog.V(logger.Error).Infof("Unable to accept connection - %v\n", err)
- }
-
- codec := rpc.NewJSONCodec(conn)
- go server.ServeCodec(codec)
- }
- }()
-
- return nil
-
-}
-
// StartRPC starts a HTTP JSON-RPC API server.
func StartRPC(stack *node.Node, ctx *cli.Context) error {
for _, api := range stack.APIs() {