add IPC commandline options

This commit is contained in:
Bas van Kervel 2015-06-02 09:37:35 +02:00
parent 0eca879627
commit 8c736d1319
7 changed files with 93 additions and 24 deletions

View file

@ -67,14 +67,14 @@ type jsre struct {
prompter
}
func newJSRE(datadir, libPath string) *jsre {
func newJSRE(datadir, libPath, ipcpath string) *jsre {
js := &jsre{ps1: "> "}
js.wait = make(chan *big.Int)
// update state in separare forever blocks
js.re = re.New(libPath)
js.apiBindings()
// js.adminBindings()
js.apiBindings(ipcpath)
// TODO js.adminBindings()
if !liner.TerminalSupported() {
js.prompter = dumbterm{bufio.NewReader(os.Stdin)}
@ -92,9 +92,9 @@ func newJSRE(datadir, libPath string) *jsre {
return js
}
func (js *jsre) apiBindings() {
func (js *jsre) apiBindings(ipcpath string) {
ethApi := rpc.NewEthereumApi(nil)
jeth := rpc.NewJeth(ethApi, js.re)
jeth := rpc.NewJeth(ethApi, js.re, ipcpath)
js.re.Set("jeth", struct{}{})
t, _ := js.re.Get("jeth")

View file

@ -21,11 +21,15 @@
package main
import (
"fmt"
"io"
"os"
"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
"github.com/codegangsta/cli"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/logger"
)
const (
@ -33,6 +37,34 @@ const (
Version = "0.9.26"
)
var (
gitCommit string // set via linker flag
nodeNameVersion string
app = utils.NewApp(Version, "the ether console")
)
func init() {
if gitCommit == "" {
nodeNameVersion = Version
} else {
nodeNameVersion = Version + "-" + gitCommit[:8]
}
app.Action = run
app.Flags = []cli.Flag{
utils.DataDirFlag,
utils.IPCDisabledFlag,
utils.IPCPathFlag,
utils.VerbosityFlag,
utils.JSpathFlag,
}
app.Before = func(ctx *cli.Context) error {
utils.SetupLogger(ctx)
return nil
}
}
func main() {
// Wrap the standard output with a colorified stream (windows)
if isatty.IsTerminal(os.Stdout.Fd()) {
@ -42,7 +74,32 @@ func main() {
}
}
// TODO, datadir + jspath
repl := newJSRE("/home/bas/.ethereum", ".")
var interrupted = false
utils.RegisterInterrupt(func(os.Signal) {
interrupted = true
})
utils.HandleInterrupt()
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, "Error: ", err)
}
// we need to run the interrupt callbacks in case gui is closed
// this skips if we got here by actual interrupt stopping the GUI
if !interrupted {
utils.RunInterruptCallbacks(os.Interrupt)
}
logger.Flush()
}
func run(ctx *cli.Context) {
//start := time.Now()
datadir := ctx.GlobalString(utils.DataDirFlag.Name)
jspath := ctx.GlobalString(utils.JSpathFlag.Name)
ipcpath := ctx.GlobalString(utils.IPCPathFlag.Name)
repl := newJSRE(datadir, jspath, ipcpath)
repl.interactive()
}

View file

@ -73,7 +73,7 @@ type jsre struct {
prompter
}
func newJSRE(ethereum *eth.Ethereum, libPath, corsDomain string, interactive bool, f xeth.Frontend) *jsre {
func newJSRE(ethereum *eth.Ethereum, libPath, ipcpath, corsDomain string, interactive bool, f xeth.Frontend) *jsre {
js := &jsre{ethereum: ethereum, ps1: "> "}
// set default cors domain used by startRpc from CLI flag
js.corsDomain = corsDomain
@ -84,7 +84,7 @@ func newJSRE(ethereum *eth.Ethereum, libPath, corsDomain string, interactive boo
js.wait = js.xeth.UpdateState()
// update state in separare forever blocks
js.re = re.New(libPath)
js.apiBindings(f)
js.apiBindings(f, ipcpath)
js.adminBindings()
if !liner.TerminalSupported() || !interactive {
@ -103,10 +103,10 @@ func newJSRE(ethereum *eth.Ethereum, libPath, corsDomain string, interactive boo
return js
}
func (js *jsre) apiBindings(f xeth.Frontend) {
func (js *jsre) apiBindings(f xeth.Frontend, ipcpath string) {
xe := xeth.New(js.ethereum, f)
ethApi := rpc.NewEthereumApi(xe)
jeth := rpc.NewJeth(ethApi, js.re)
jeth := rpc.NewJeth(ethApi, js.re, ipcpath)
js.re.Set("jeth", struct{}{})
t, _ := js.re.Get("jeth")

View file

@ -238,7 +238,8 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils.RPCEnabledFlag,
utils.RPCListenAddrFlag,
utils.RPCPortFlag,
utils.IPCEnabledFlag,
utils.IPCDisabledFlag,
utils.IPCPathFlag,
utils.WhisperEnabledFlag,
utils.VMDebugFlag,
utils.ProtocolVersionFlag,
@ -304,6 +305,7 @@ func console(ctx *cli.Context) {
repl := newJSRE(
ethereum,
ctx.String(utils.JSpathFlag.Name),
ctx.String(utils.IPCPathFlag.Name),
ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
true,
nil,
@ -325,6 +327,7 @@ func execJSFiles(ctx *cli.Context) {
repl := newJSRE(
ethereum,
ctx.String(utils.JSpathFlag.Name),
ctx.String(utils.IPCPathFlag.Name),
ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
false,
nil,
@ -387,7 +390,7 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
utils.Fatalf("Error starting RPC: %v", err)
}
}
if ctx.GlobalBool(utils.IPCEnabledFlag.Name) {
if !ctx.GlobalBool(utils.IPCDisabledFlag.Name) {
if err := utils.StartIPC(eth, ctx); err != nil {
utils.Fatalf("Error starting IPC: %v", err)
}

View file

@ -204,9 +204,14 @@ var (
Usage: "Domain on which to send Access-Control-Allow-Origin header",
Value: "",
}
IPCEnabledFlag = cli.BoolFlag{
Name: "ipc",
Usage: "Enable the IPC-RPC server",
IPCDisabledFlag = cli.BoolFlag{
Name: "ipcdisable",
Usage: "Disable the IPC-RPC server",
}
IPCPathFlag = cli.StringFlag{
Name: "ipcpath",
Usage: "Filename for IPC socket/pipe",
Value: common.DefaultIpcPath(),
}
// Network Settings
MaxPeersFlag = cli.IntFlag{
@ -378,7 +383,7 @@ func StartRPC(eth *eth.Ethereum, ctx *cli.Context) error {
func StartIPC(eth *eth.Ethereum, ctx *cli.Context) error {
config := comms.IpcConfig{
Endpoint: ctx.GlobalString(DataDirFlag.Name) + "/geth.sock",
Endpoint: ctx.GlobalString(IPCPathFlag.Name),
}
xeth := xeth.New(eth, nil)

View file

@ -94,6 +94,10 @@ func DefaultDataDir() string {
}
}
func DefaultIpcPath() string {
return filepath.Join(DefaultDataDir(), "geth.ipc")
}
func IsWindows() bool {
return runtime.GOOS == "windows"
}

View file

@ -15,10 +15,11 @@ import (
type Jeth struct {
ethApi *EthereumApi
re *jsre.JSRE
ipcpath string
}
func NewJeth(ethApi *EthereumApi, re *jsre.JSRE) *Jeth {
return &Jeth{ethApi, re}
func NewJeth(ethApi *EthereumApi, re *jsre.JSRE, ipcpath string) *Jeth {
return &Jeth{ethApi, re, ipcpath}
}
func (self *Jeth) err(call otto.FunctionCall, code int, msg string, id interface{}) (response otto.Value) {
@ -40,8 +41,7 @@ func (self *Jeth) Send(call otto.FunctionCall) (response otto.Value) {
return self.err(call, -32700, err.Error(), nil)
}
// TODO
client, err := comms.NewIpcClient(comms.IpcConfig{"/home/bas/.ethereum/geth.sock"}, codec.JSON)
client, err := comms.NewIpcClient(comms.IpcConfig{self.ipcpath}, codec.JSON)
if err != nil {
fmt.Println("Error response:", err)
return self.err(call, -32603, err.Error(), -1)