aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/geth/js.go74
-rw-r--r--cmd/geth/js_test.go48
-rw-r--r--cmd/geth/main.go24
-rw-r--r--cmd/geth/monitorcmd.go49
-rw-r--r--cmd/gethrpctest/main.go40
-rw-r--r--cmd/utils/client.go121
-rw-r--r--cmd/utils/flags.go94
7 files changed, 113 insertions, 337 deletions
diff --git a/cmd/geth/js.go b/cmd/geth/js.go
index 3d0251f08..e7e28b24b 100644
--- a/cmd/geth/js.go
+++ b/cmd/geth/js.go
@@ -80,73 +80,25 @@ type jsre struct {
prompter
}
-var (
- loadedModulesMethods map[string][]string
- autoCompleteStatement = "function _autocomplete(obj) {var results = []; for (var e in obj) { results.push(e); }; return results; }; _autocomplete(%s)"
-)
-
-func keywordCompleter(jsre *jsre, line string) []string {
- var results []string
- parts := strings.Split(line, ".")
- objRef := "this"
- prefix := line
- if len(parts) > 1 {
- objRef = strings.Join(parts[0:len(parts) - 1], ".")
- prefix = parts[len(parts) - 1]
- }
-
- result, _ := jsre.re.Run(fmt.Sprintf(autoCompleteStatement, objRef))
- raw, _ := result.Export()
- if keys, ok := raw.([]interface{}); ok {
- for _, k := range keys {
- if strings.HasPrefix(fmt.Sprintf("%s", k), prefix) {
- if objRef == "this" {
- results = append(results, fmt.Sprintf("%s", k))
- } else {
- results = append(results, fmt.Sprintf("%s.%s", strings.Join(parts[:len(parts) - 1], "."), k))
- }
- }
- }
- }
-
- // e.g. web3<tab><tab> append dot since its an object
- isObj, _ := jsre.re.Run(fmt.Sprintf("typeof(%s) === 'object'", line))
- if isObject, _ := isObj.ToBoolean(); isObject {
- results = append(results, line + ".")
- }
-
- sort.Strings(results)
- return results
-}
-
-func apiWordCompleterWithContext(jsre *jsre) liner.WordCompleter {
- completer := func(line string, pos int) (head string, completions []string, tail string) {
+func makeCompleter(re *jsre) liner.WordCompleter {
+ return func(line string, pos int) (head string, completions []string, tail string) {
if len(line) == 0 || pos == 0 {
return "", nil, ""
}
-
// chuck data to relevant part for autocompletion, e.g. in case of nested lines eth.getBalance(eth.coinb<tab><tab>
i := 0
for i = pos - 1; i > 0; i-- {
if line[i] == '.' || (line[i] >= 'a' && line[i] <= 'z') || (line[i] >= 'A' && line[i] <= 'Z') {
continue
}
- if i >= 3 && line[i] == '3' && line[i - 3] == 'w' && line[i - 2] == 'e' && line[i - 1] == 'b' {
+ if i >= 3 && line[i] == '3' && line[i-3] == 'w' && line[i-2] == 'e' && line[i-1] == 'b' {
continue
}
i += 1
break
}
-
- begin := line[:i]
- keyword := line[i:pos]
- end := line[pos:]
-
- completionWords := keywordCompleter(jsre, keyword)
- return begin, completionWords, end
+ return line[:i], re.re.CompleteKeywords(line[i:pos]), line[pos:]
}
-
- return completer
}
func newLightweightJSRE(docRoot string, client rpc.Client, datadir string, interactive bool) *jsre {
@@ -165,9 +117,9 @@ func newLightweightJSRE(docRoot string, client rpc.Client, datadir string, inter
lr := liner.NewLiner()
js.withHistory(datadir, func(hist *os.File) { lr.ReadHistory(hist) })
lr.SetCtrlCAborts(true)
- js.loadAutoCompletion()
- lr.SetWordCompleter(apiWordCompleterWithContext(js))
+ lr.SetWordCompleter(makeCompleter(js))
lr.SetTabCompletionStyle(liner.TabPrints)
+ lr.SetMultiLineMode(true)
js.prompter = lr
js.atexit = func() {
js.withHistory(datadir, func(hist *os.File) { hist.Truncate(0); lr.WriteHistory(hist) })
@@ -196,8 +148,7 @@ func newJSRE(stack *node.Node, docRoot, corsDomain string, client rpc.Client, in
lr := liner.NewLiner()
js.withHistory(stack.DataDir(), func(hist *os.File) { lr.ReadHistory(hist) })
lr.SetCtrlCAborts(true)
- js.loadAutoCompletion()
- lr.SetWordCompleter(apiWordCompleterWithContext(js))
+ lr.SetWordCompleter(makeCompleter(js))
lr.SetTabCompletionStyle(liner.TabPrints)
js.prompter = lr
js.atexit = func() {
@@ -209,15 +160,6 @@ func newJSRE(stack *node.Node, docRoot, corsDomain string, client rpc.Client, in
return js
}
-func (self *jsre) loadAutoCompletion() {
- if modules, err := self.supportedApis(); err == nil {
- loadedModulesMethods = make(map[string][]string)
- for module, _ := range modules {
- loadedModulesMethods[module] = rpc.AutoCompletion[module]
- }
- }
-}
-
func (self *jsre) batch(statement string) {
err := self.re.EvalAndPrettyPrint(statement)
@@ -280,7 +222,7 @@ func (js *jsre) apiBindings() error {
utils.Fatalf("Error loading bignumber.js: %v", err)
}
- err = js.re.Compile("ethereum.js", re.Web3_JS)
+ err = js.re.Compile("web3.js", re.Web3_JS)
if err != nil {
utils.Fatalf("Error loading web3.js: %v", err)
}
diff --git a/cmd/geth/js_test.go b/cmd/geth/js_test.go
index 19583c5ef..4330b484c 100644
--- a/cmd/geth/js_test.go
+++ b/cmd/geth/js_test.go
@@ -37,22 +37,21 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/node"
- "github.com/ethereum/go-ethereum/cmd/utils"
)
const (
testSolcPath = ""
- solcVersion = "0.9.23"
+ solcVersion = "0.9.23"
- testKey = "e6fab74a43941f82d89cb7faa408e227cdad3153c4720e540e855c19b15e6674"
+ testKey = "e6fab74a43941f82d89cb7faa408e227cdad3153c4720e540e855c19b15e6674"
testAddress = "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
testBalance = "10000000000000000000"
-// of empty string
+ // of empty string
testHash = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
)
var (
- versionRE = regexp.MustCompile(strconv.Quote(`"compilerVersion":"` + solcVersion + `"`))
+ versionRE = regexp.MustCompile(strconv.Quote(`"compilerVersion":"` + solcVersion + `"`))
testNodeKey = crypto.ToECDSA(common.Hex2Bytes("4b50fa71f5c3eeb8fdc452224b2395af2fcc3d125e06c32c82e048c0559db03f"))
testGenesis = `{"` + testAddress[2:] + `": {"balance": "` + testBalance + `"}}`
)
@@ -141,8 +140,10 @@ func testREPL(t *testing.T, config func(*eth.Config)) (string, *testjethre, *nod
stack.Service(&ethereum)
assetPath := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext")
- //client := comms.NewInProcClient(codec.JSON)
- client := utils.NewInProcRPCClient(stack)
+ client, err := stack.Attach()
+ if err != nil {
+ t.Fatalf("failed to attach to node: %v", err)
+ }
tf := &testjethre{client: ethereum.HTTPClient()}
repl := newJSRE(stack, assetPath, "", client, false)
tf.jsre = repl
@@ -152,9 +153,6 @@ func testREPL(t *testing.T, config func(*eth.Config)) (string, *testjethre, *nod
func TestNodeInfo(t *testing.T) {
t.Skip("broken after p2p update")
tmp, repl, ethereum := testJEthRE(t)
- if err := ethereum.Start(); err != nil {
- t.Fatalf("error starting ethereum: %v", err)
- }
defer ethereum.Stop()
defer os.RemoveAll(tmp)
@@ -167,8 +165,8 @@ func TestAccounts(t *testing.T) {
defer node.Stop()
defer os.RemoveAll(tmp)
- checkEvalJSON(t, repl, `eth.accounts`, `["` + testAddress + `"]`)
- checkEvalJSON(t, repl, `eth.coinbase`, `"` + testAddress + `"`)
+ checkEvalJSON(t, repl, `eth.accounts`, `["`+testAddress+`"]`)
+ checkEvalJSON(t, repl, `eth.coinbase`, `"`+testAddress+`"`)
val, err := repl.re.Run(`jeth.newAccount("password")`)
if err != nil {
t.Errorf("expected no error, got %v", err)
@@ -178,7 +176,7 @@ func TestAccounts(t *testing.T) {
t.Errorf("address not hex: %q", addr)
}
- checkEvalJSON(t, repl, `eth.accounts`, `["` + testAddress + `","` + addr + `"]`)
+ checkEvalJSON(t, repl, `eth.accounts`, `["`+testAddress+`","`+addr+`"]`)
}
@@ -206,13 +204,13 @@ func TestBlockChain(t *testing.T) {
node.Service(&ethereum)
ethereum.BlockChain().Reset()
- checkEvalJSON(t, repl, `admin.exportChain(` + tmpfileq + `)`, `true`)
+ checkEvalJSON(t, repl, `admin.exportChain(`+tmpfileq+`)`, `true`)
if _, err := os.Stat(tmpfile); err != nil {
t.Fatal(err)
}
// check import, verify that dumpBlock gives the same result.
- checkEvalJSON(t, repl, `admin.importChain(` + tmpfileq + `)`, `true`)
+ checkEvalJSON(t, repl, `admin.importChain(`+tmpfileq+`)`, `true`)
checkEvalJSON(t, repl, `debug.dumpBlock(eth.blockNumber)`, beforeExport)
}
@@ -240,7 +238,7 @@ func TestCheckTestAccountBalance(t *testing.T) {
defer os.RemoveAll(tmp)
repl.re.Run(`primary = "` + testAddress + `"`)
- checkEvalJSON(t, repl, `eth.getBalance(primary)`, `"` + testBalance + `"`)
+ checkEvalJSON(t, repl, `eth.getBalance(primary)`, `"`+testBalance+`"`)
}
func TestSignature(t *testing.T) {
@@ -301,11 +299,11 @@ func TestContract(t *testing.T) {
*/
source := `contract test {\n` +
- " /// @notice Will multiply `a` by 7." + `\n` +
- ` function multiply(uint a) returns(uint d) {\n` +
- ` return a * 7;\n` +
- ` }\n` +
- `}\n`
+ " /// @notice Will multiply `a` by 7." + `\n` +
+ ` function multiply(uint a) returns(uint d) {\n` +
+ ` return a * 7;\n` +
+ ` }\n` +
+ `}\n`
if checkEvalJSON(t, repl, `admin.stopNatSpec()`, `true`) != nil {
return
@@ -315,10 +313,10 @@ func TestContract(t *testing.T) {
if err != nil {
t.Fatalf("%v", err)
}
- if checkEvalJSON(t, repl, `primary = eth.accounts[0]`, `"` + testAddress + `"`) != nil {
+ if checkEvalJSON(t, repl, `primary = eth.accounts[0]`, `"`+testAddress+`"`) != nil {
return
}
- if checkEvalJSON(t, repl, `source = "` + source + `"`, `"` + source + `"`) != nil {
+ if checkEvalJSON(t, repl, `source = "`+source+`"`, `"`+source+`"`) != nil {
return
}
@@ -396,7 +394,7 @@ multiply7 = Multiply7.at(contractaddress);
var contentHash = `"0x86d2b7cf1e72e9a7a3f8d96601f0151742a2f780f1526414304fbe413dc7f9bd"`
if sol != nil && solcVersion != sol.Version() {
- modContractInfo := versionRE.ReplaceAll(contractInfo, []byte(`"compilerVersion":"` + sol.Version() + `"`))
+ modContractInfo := versionRE.ReplaceAll(contractInfo, []byte(`"compilerVersion":"`+sol.Version()+`"`))
fmt.Printf("modified contractinfo:\n%s\n", modContractInfo)
contentHash = `"` + common.ToHex(crypto.Sha3([]byte(modContractInfo))) + `"`
}
@@ -481,7 +479,7 @@ func processTxs(repl *testjethre, t *testing.T, expTxc int) bool {
repl.wait <- height
select {
case <-timer.C:
- // if times out make sure the xeth loop does not block
+ // if times out make sure the xeth loop does not block
go func() {
select {
case repl.wait <- nil:
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index fa456a7ac..8594d18c5 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -399,7 +399,7 @@ func attach(ctx *cli.Context) {
// attach to a running geth instance
client, err := utils.NewRemoteRPCClient(ctx)
if err != nil {
- utils.Fatalf("Unable to attach to geth - %v", err)
+ utils.Fatalf("Unable to attach to geth: %v", err)
}
repl := newLightweightJSRE(
@@ -425,8 +425,10 @@ func console(ctx *cli.Context) {
startNode(ctx, node)
// Attach to the newly started node, and either execute script or become interactive
- client := utils.NewInProcRPCClient(node)
-
+ client, err := node.Attach()
+ if err != nil {
+ utils.Fatalf("Failed to attach to the inproc geth: %v", err)
+ }
repl := newJSRE(node,
ctx.GlobalString(utils.JSpathFlag.Name),
ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
@@ -449,8 +451,10 @@ func execScripts(ctx *cli.Context) {
startNode(ctx, node)
// Attach to the newly started node and execute the given scripts
- client := utils.NewInProcRPCClient(node)
-
+ client, err := node.Attach()
+ if err != nil {
+ utils.Fatalf("Failed to attach to the inproc geth: %v", err)
+ }
repl := newJSRE(node,
ctx.GlobalString(utils.JSpathFlag.Name),
ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
@@ -503,16 +507,6 @@ func startNode(ctx *cli.Context, stack *node.Node) {
}
}
// 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)
- }
- }
- if ctx.GlobalBool(utils.WSEnabledFlag.Name) {
- if err := utils.StartWS(stack, ctx); err != nil {
- utils.Fatalf("Failed to start WS: %v", err)
- }
- }
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) {
if err := ethereum.StartMining(ctx.GlobalInt(utils.MinerThreadsFlag.Name), ctx.GlobalString(utils.MiningGPUFlag.Name)); err != nil {
utils.Fatalf("Failed to start mining: %v", err)
diff --git a/cmd/geth/monitorcmd.go b/cmd/geth/monitorcmd.go
index 4d56f2289..5d839b5a3 100644
--- a/cmd/geth/monitorcmd.go
+++ b/cmd/geth/monitorcmd.go
@@ -36,7 +36,7 @@ import (
var (
monitorCommandAttachFlag = cli.StringFlag{
Name: "attach",
- Value: "ipc:" + node.DefaultIpcEndpoint(),
+ Value: "ipc:" + node.DefaultIPCEndpoint(),
Usage: "API endpoint to attach to",
}
monitorCommandRowsFlag = cli.IntFlag{
@@ -105,8 +105,6 @@ func monitor(ctx *cli.Context) {
}
defer termui.Close()
- termui.UseTheme("helloworld")
-
rows := len(monitored)
if max := ctx.Int(monitorCommandRowsFlag.Name); rows > max {
rows = max
@@ -117,7 +115,7 @@ func monitor(ctx *cli.Context) {
}
// Create each individual data chart
footer := termui.NewPar("")
- footer.HasBorder = true
+ footer.Block.Border = true
footer.Height = 3
charts := make([]*termui.LineChart, len(monitored))
@@ -135,28 +133,27 @@ func monitor(ctx *cli.Context) {
termui.Render(termui.Body)
// Watch for various system events, and periodically refresh the charts
- refresh := time.Tick(time.Duration(ctx.Int(monitorCommandRefreshFlag.Name)) * time.Second)
- for {
- select {
- case event := <-termui.EventCh():
- if event.Type == termui.EventKey && event.Key == termui.KeyCtrlC {
- return
- }
- if event.Type == termui.EventResize {
- termui.Body.Width = termui.TermWidth()
- for _, chart := range charts {
- chart.Height = (termui.TermHeight() - footer.Height) / rows
- }
- termui.Body.Align()
- termui.Render(termui.Body)
- }
- case <-refresh:
+ termui.Handle("/sys/kbd/C-c", func(termui.Event) {
+ termui.StopLoop()
+ })
+ termui.Handle("/sys/wnd/resize", func(termui.Event) {
+ termui.Body.Width = termui.TermWidth()
+ for _, chart := range charts {
+ chart.Height = (termui.TermHeight() - footer.Height) / rows
+ }
+ termui.Body.Align()
+ termui.Render(termui.Body)
+ })
+ go func() {
+ tick := time.NewTicker(time.Duration(ctx.Int(monitorCommandRefreshFlag.Name)) * time.Second)
+ for range tick.C {
if refreshCharts(client, monitored, data, units, charts, ctx, footer) {
termui.Body.Align()
}
termui.Render(termui.Body)
}
- }
+ }()
+ termui.Loop()
}
// retrieveMetrics contacts the attached geth node and retrieves the entire set
@@ -328,9 +325,9 @@ func updateChart(metric string, data []float64, base *int, chart *termui.LineCha
if strings.Contains(metric, "/Percentiles/") || strings.Contains(metric, "/pauses/") || strings.Contains(metric, "/time/") {
units = timeUnits
}
- chart.Border.Label = metric
+ chart.BorderLabel = metric
if len(units[unit]) > 0 {
- chart.Border.Label += " [" + units[unit] + "]"
+ chart.BorderLabel += " [" + units[unit] + "]"
}
chart.LineColor = colors[unit] | termui.AttrBold
if err != nil {
@@ -350,8 +347,8 @@ func createChart(height int) *termui.LineChart {
chart.AxesColor = termui.ColorWhite
chart.PaddingBottom = -2
- chart.Border.LabelFgColor = chart.Border.FgColor | termui.AttrBold
- chart.Border.FgColor = chart.Border.BgColor
+ chart.BorderLabelFg = chart.BorderFg | termui.AttrBold
+ chart.BorderFg = chart.BorderBg
return chart
}
@@ -361,7 +358,7 @@ func updateFooter(ctx *cli.Context, err error, footer *termui.Par) {
// Generate the basic footer
refresh := time.Duration(ctx.Int(monitorCommandRefreshFlag.Name)) * time.Second
footer.Text = fmt.Sprintf("Press Ctrl+C to quit. Refresh interval: %v.", refresh)
- footer.TextFgColor = termui.Theme().ParTextFg | termui.AttrBold
+ footer.TextFgColor = termui.ThemeAttr("par.fg") | termui.AttrBold
// Append any encountered errors
if err != nil {
diff --git a/cmd/gethrpctest/main.go b/cmd/gethrpctest/main.go
index becd09f5a..38016fb35 100644
--- a/cmd/gethrpctest/main.go
+++ b/cmd/gethrpctest/main.go
@@ -18,7 +18,6 @@
package main
import (
- "errors"
"flag"
"io/ioutil"
"log"
@@ -26,10 +25,10 @@ import (
"os/signal"
"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/tests"
@@ -84,12 +83,6 @@ func main() {
}
log.Println("Initial test suite passed...")
- // Start the RPC interface and wait until terminated
- if err := StartRPC(stack); err != nil {
- log.Fatalf("Failed to start RPC interface: %v", err)
- }
- log.Println("RPC Interface started, accepting requests...")
-
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit
@@ -99,7 +92,16 @@ 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{IpcPath: node.DefaultIpcEndpoint(), NoDiscovery: true})
+ stack, err := node.New(&node.Config{
+ IPCPath: node.DefaultIPCEndpoint(),
+ HTTPHost: common.DefaultHTTPHost,
+ HTTPPort: common.DefaultHTTPPort,
+ HTTPModules: []string{"admin", "db", "eth", "debug", "miner", "net", "shh", "txpool", "personal", "web3"},
+ WSHost: common.DefaultWSHost,
+ WSPort: common.DefaultWSPort,
+ WSModules: []string{"admin", "db", "eth", "debug", "miner", "net", "shh", "txpool", "personal", "web3"},
+ NoDiscovery: true,
+ })
if err != nil {
return nil, err
}
@@ -164,23 +166,3 @@ func RunTest(stack *node.Node, test *tests.BlockTest) error {
}
return nil
}
-
-// StartRPC initializes an RPC interface to the given protocol stack.
-func StartRPC(stack *node.Node) error {
- /*
- web3 := NewPublicWeb3API(stack)
- server.RegisterName("web3", web3)
- net := NewPublicNetAPI(stack.Server(), ethereum.NetVersion())
- server.RegisterName("net", net)
- */
-
- for _, api := range stack.APIs() {
- if adminApi, ok := api.Service.(*node.PrivateAdminAPI); ok {
- _, err := adminApi.StartRPC("127.0.0.1", 8545, "", "admin,db,eth,debug,miner,net,shh,txpool,personal,web3")
- return err
- }
- }
-
- 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")
-}
diff --git a/cmd/utils/client.go b/cmd/utils/client.go
index 40ebcd729..3913d007b 100644
--- a/cmd/utils/client.go
+++ b/cmd/utils/client.go
@@ -17,132 +17,14 @@
package utils
import (
- "encoding/json"
"fmt"
-
"strings"
"github.com/codegangsta/cli"
- "github.com/ethereum/go-ethereum/eth"
- "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"
)
-// NewInProcRPCClient will start a new RPC server for the given node and returns a client to interact with it.
-func NewInProcRPCClient(stack *node.Node) *inProcClient {
- server := rpc.NewServer()
-
- offered := stack.APIs()
- for _, api := range offered {
- server.RegisterName(api.Namespace, api.Service)
- }
-
- web3 := node.NewPublicWeb3API(stack)
- server.RegisterName("web3", web3)
-
- var ethereum *eth.Ethereum
- if err := stack.Service(&ethereum); err == nil {
- net := eth.NewPublicNetAPI(stack.Server(), ethereum.NetVersion())
- server.RegisterName("net", net)
- } else {
- glog.V(logger.Warn).Infof("%v\n", err)
- }
-
- buf := &buf{
- requests: make(chan []byte),
- responses: make(chan []byte),
- }
- client := &inProcClient{
- server: server,
- buf: buf,
- }
-
- go func() {
- server.ServeCodec(rpc.NewJSONCodec(client.buf))
- }()
-
- return client
-}
-
-// buf represents the connection between the RPC server and console
-type buf struct {
- readBuf []byte // store remaining request bytes after a partial read
- requests chan []byte // list with raw serialized requests
- responses chan []byte // list with raw serialized responses
-}
-
-// will read the next request in json format
-func (b *buf) Read(p []byte) (int, error) {
- // last read didn't read entire request, return remaining bytes
- if len(b.readBuf) > 0 {
- n := copy(p, b.readBuf)
- if n < len(b.readBuf) {
- b.readBuf = b.readBuf[:n]
- } else {
- b.readBuf = b.readBuf[:0]
- }
- return n, nil
- }
-
- // read next request
- req := <-b.requests
- n := copy(p, req)
- if n < len(req) {
- // buf too small, store remaining chunk for next read
- b.readBuf = req[n:]
- }
-
- return n, nil
-}
-
-// Write send the given buffer to the backend
-func (b *buf) Write(p []byte) (n int, err error) {
- b.responses <- p
- return len(p), nil
-}
-
-// Close cleans up obtained resources.
-func (b *buf) Close() error {
- close(b.requests)
- close(b.responses)
-
- return nil
-}
-
-// inProcClient starts a RPC server and uses buf to communicate with it.
-type inProcClient struct {
- server *rpc.Server
- buf *buf
-}
-
-// Close will stop the RPC server
-func (c *inProcClient) Close() {
- c.server.Stop()
-}
-
-// Send a msg to the endpoint
-func (c *inProcClient) Send(msg interface{}) error {
- d, err := json.Marshal(msg)
- if err != nil {
- return err
- }
- c.buf.requests <- d
- return nil
-}
-
-// Recv reads a message and tries to parse it into the given msg
-func (c *inProcClient) Recv(msg interface{}) error {
- data := <-c.buf.responses
- return json.Unmarshal(data, &msg)
-}
-
-// Returns the collection of modules the RPC server offers.
-func (c *inProcClient) SupportedModules() (map[string]string, error) {
- return rpc.SupportedModules(c)
-}
-
// NewRemoteRPCClient returns a RPC client which connects to a running geth instance.
// Depending on the given context this can either be a IPC or a HTTP client.
func NewRemoteRPCClient(ctx *cli.Context) (rpc.Client, error) {
@@ -151,7 +33,7 @@ func NewRemoteRPCClient(ctx *cli.Context) (rpc.Client, error) {
return NewRemoteRPCClientFromString(endpoint)
}
// use IPC by default
- return rpc.NewIPCClient(node.DefaultIpcEndpoint())
+ return rpc.NewIPCClient(node.DefaultIPCEndpoint())
}
// NewRemoteRPCClientFromString returns a RPC client which connects to the given
@@ -169,6 +51,5 @@ func NewRemoteRPCClientFromString(endpoint string) (rpc.Client, error) {
if strings.HasPrefix(endpoint, "ws:") {
return rpc.NewWSClient(endpoint)
}
-
return nil, fmt.Errorf("invalid endpoint")
}
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index ca9fd74ba..8e89b9fb1 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -18,7 +18,6 @@ package utils
import (
"crypto/ecdsa"
- "errors"
"fmt"
"io/ioutil"
"math"
@@ -233,12 +232,12 @@ var (
RPCListenAddrFlag = cli.StringFlag{
Name: "rpcaddr",
Usage: "HTTP-RPC server listening interface",
- Value: "127.0.0.1",
+ Value: common.DefaultHTTPHost,
}
RPCPortFlag = cli.IntFlag{
Name: "rpcport",
Usage: "HTTP-RPC server listening port",
- Value: 8545,
+ Value: common.DefaultHTTPPort,
}
RPCCORSDomainFlag = cli.StringFlag{
Name: "rpccorsdomain",
@@ -248,7 +247,7 @@ var (
RPCApiFlag = cli.StringFlag{
Name: "rpcapi",
Usage: "API's offered over the HTTP-RPC interface",
- Value: rpc.DefaultHttpRpcApis,
+ Value: rpc.DefaultHTTPApis,
}
IPCDisabledFlag = cli.BoolFlag{
Name: "ipcdisable",
@@ -257,12 +256,12 @@ var (
IPCApiFlag = cli.StringFlag{
Name: "ipcapi",
Usage: "API's offered over the IPC-RPC interface",
- Value: rpc.DefaultIpcApis,
+ Value: rpc.DefaultIPCApis,
}
IPCPathFlag = DirectoryFlag{
Name: "ipcpath",
Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)",
- Value: DirectoryString{common.DefaultIpcSocket()},
+ Value: DirectoryString{common.DefaultIPCSocket},
}
WSEnabledFlag = cli.BoolFlag{
Name: "ws",
@@ -271,21 +270,21 @@ var (
WSListenAddrFlag = cli.StringFlag{
Name: "wsaddr",
Usage: "WS-RPC server listening interface",
- Value: "127.0.0.1",
+ Value: common.DefaultWSHost,
}
WSPortFlag = cli.IntFlag{
Name: "wsport",
Usage: "WS-RPC server listening port",
- Value: 8546,
+ Value: common.DefaultWSPort,
}
WSApiFlag = cli.StringFlag{
Name: "wsapi",
Usage: "API's offered over the WS-RPC interface",
- Value: rpc.DefaultHttpRpcApis,
+ Value: rpc.DefaultHTTPApis,
}
WSAllowedDomainsFlag = cli.StringFlag{
Name: "wsdomains",
- Usage: "Domains from which to accept websockets requests",
+ Usage: "Domains from which to accept websockets requests (can be spoofed)",
Value: "",
}
ExecFlag = cli.StringFlag{
@@ -394,9 +393,9 @@ func MustMakeDataDir(ctx *cli.Context) string {
return ""
}
-// MakeIpcPath creates an IPC path configuration from the set command line flags,
+// 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 {
+func MakeIPCPath(ctx *cli.Context) string {
if ctx.GlobalBool(IPCDisabledFlag.Name) {
return ""
}
@@ -482,6 +481,24 @@ func MakeNAT(ctx *cli.Context) nat.Interface {
return natif
}
+// MakeHTTPRpcHost creates the HTTP RPC listener interface string from the set
+// command line flags, returning empty if the HTTP endpoint is disabled.
+func MakeHTTPRpcHost(ctx *cli.Context) string {
+ if !ctx.GlobalBool(RPCEnabledFlag.Name) {
+ return ""
+ }
+ return ctx.GlobalString(RPCListenAddrFlag.Name)
+}
+
+// MakeWSRpcHost creates the WebSocket RPC listener interface string from the set
+// command line flags, returning empty if the HTTP endpoint is disabled.
+func MakeWSRpcHost(ctx *cli.Context) string {
+ if !ctx.GlobalBool(WSEnabledFlag.Name) {
+ return ""
+ }
+ return ctx.GlobalString(WSListenAddrFlag.Name)
+}
+
// MakeGenesisBlock loads up a genesis block from an input file specified in the
// command line, or returns the empty string if none set.
func MakeGenesisBlock(ctx *cli.Context) string {
@@ -591,7 +608,6 @@ 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),
@@ -600,6 +616,15 @@ func MakeSystemNode(name, version string, extra []byte, ctx *cli.Context) *node.
NAT: MakeNAT(ctx),
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name),
+ IPCPath: MakeIPCPath(ctx),
+ HTTPHost: MakeHTTPRpcHost(ctx),
+ HTTPPort: ctx.GlobalInt(RPCPortFlag.Name),
+ HTTPCors: ctx.GlobalString(RPCCORSDomainFlag.Name),
+ HTTPModules: strings.Split(ctx.GlobalString(RPCApiFlag.Name), ","),
+ WSHost: MakeWSRpcHost(ctx),
+ WSPort: ctx.GlobalInt(WSPortFlag.Name),
+ WSDomains: ctx.GlobalString(WSAllowedDomainsFlag.Name),
+ WSModules: strings.Split(ctx.GlobalString(WSApiFlag.Name), ","),
}
// Configure the Ethereum service
accman := MakeAccountManager(ctx)
@@ -740,48 +765,5 @@ func MakeChain(ctx *cli.Context) (chain *core.BlockChain, chainDb ethdb.Database
if err != nil {
Fatalf("Could not start chainmanager: %v", err)
}
-
return chain, chainDb
}
-
-// StartRPC starts a HTTP JSON-RPC API server.
-func StartRPC(stack *node.Node, ctx *cli.Context) error {
- for _, api := range stack.APIs() {
- if adminApi, ok := api.Service.(*node.PrivateAdminAPI); ok {
- address := ctx.GlobalString(RPCListenAddrFlag.Name)
- port := ctx.GlobalInt(RPCPortFlag.Name)
- cors := ctx.GlobalString(RPCCORSDomainFlag.Name)
- apiStr := ""
- if ctx.GlobalIsSet(RPCApiFlag.Name) {
- apiStr = ctx.GlobalString(RPCApiFlag.Name)
- }
-
- _, err := adminApi.StartRPC(address, port, cors, apiStr)
- return err
- }
- }
-
- 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")
-}
-
-// StartWS starts a websocket JSON-RPC API server.
-func StartWS(stack *node.Node, ctx *cli.Context) error {
- for _, api := range stack.APIs() {
- if adminApi, ok := api.Service.(*node.PrivateAdminAPI); ok {
- address := ctx.GlobalString(WSListenAddrFlag.Name)
- port := ctx.GlobalInt(WSAllowedDomainsFlag.Name)
- allowedDomains := ctx.GlobalString(WSAllowedDomainsFlag.Name)
- apiStr := ""
- if ctx.GlobalIsSet(WSApiFlag.Name) {
- apiStr = ctx.GlobalString(WSApiFlag.Name)
- }
-
- _, err := adminApi.StartWS(address, port, allowedDomains, apiStr)
- return err
- }
- }
-
- glog.V(logger.Error).Infof("Unable to start RPC-WS interface, could not find admin API")
- return errors.New("Unable to start RPC-WS interface")
-}