aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
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 /cmd/utils
parent212828963172b3921827df15abdc8602480e947d (diff)
parent188ab928c3f2a2eac5ee0f7ac42cbf2f35568bcd (diff)
downloadgo-tangerine-ba7c125153ce1be30985784a18edf38645406d03.tar
go-tangerine-ba7c125153ce1be30985784a18edf38645406d03.tar.gz
go-tangerine-ba7c125153ce1be30985784a18edf38645406d03.tar.bz2
go-tangerine-ba7c125153ce1be30985784a18edf38645406d03.tar.lz
go-tangerine-ba7c125153ce1be30985784a18edf38645406d03.tar.xz
go-tangerine-ba7c125153ce1be30985784a18edf38645406d03.tar.zst
go-tangerine-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 'cmd/utils')
-rw-r--r--cmd/utils/client.go4
-rw-r--r--cmd/utils/flags.go71
2 files changed, 13 insertions, 62 deletions
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() {