From f9cbd16f27e393d4937354ee31435e0a2f689484 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Fri, 7 Aug 2015 09:56:49 +0200 Subject: support for user agents --- cmd/geth/js.go | 10 +++------- cmd/geth/main.go | 2 +- cmd/utils/flags.go | 25 ++++++++++++++++--------- 3 files changed, 20 insertions(+), 17 deletions(-) (limited to 'cmd') diff --git a/cmd/geth/js.go b/cmd/geth/js.go index bf56423ec..ff319ab6b 100644 --- a/cmd/geth/js.go +++ b/cmd/geth/js.go @@ -145,19 +145,15 @@ func apiWordCompleter(line string, pos int) (head string, completions []string, return begin, completionWords, end } -func newLightweightJSRE(libPath string, client comms.EthereumClient, interactive bool, f xeth.Frontend) *jsre { +func newLightweightJSRE(libPath string, client comms.EthereumClient, interactive bool) *jsre { js := &jsre{ps1: "> "} js.wait = make(chan *big.Int) js.client = client js.ds = docserver.New("/") - if f == nil { - f = js - } - // update state in separare forever blocks js.re = re.New(libPath) - if err := js.apiBindings(f); err != nil { + if err := js.apiBindings(js); err != nil { utils.Fatalf("Unable to initialize console - %v", err) } @@ -291,7 +287,7 @@ func (js *jsre) apiBindings(f xeth.Frontend) error { utils.Fatalf("Unable to determine supported api's: %v", err) } - jeth := rpc.NewJeth(api.Merge(apiImpl...), js.re, js.client) + jeth := rpc.NewJeth(api.Merge(apiImpl...), js.re, js.client, f) js.re.Set("jeth", struct{}{}) t, _ := js.re.Get("jeth") jethObj := t.Object() diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 895e55b44..b0dcf4e50 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -425,7 +425,7 @@ func attach(ctx *cli.Context) { ctx.GlobalString(utils.JSpathFlag.Name), client, true, - nil) + ) if ctx.GlobalString(utils.ExecFlag.Name) != "" { repl.batch(ctx.GlobalString(utils.ExecFlag.Name)) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 462da9305..9e15d4a40 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -21,30 +21,32 @@ import ( "fmt" "log" "math/big" + "net" "net/http" "os" "path/filepath" "runtime" "strconv" - "github.com/ethereum/go-ethereum/core/vm" - "github.com/ethereum/go-ethereum/metrics" - "github.com/codegangsta/cli" "github.com/ethereum/ethash" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/p2p/nat" "github.com/ethereum/go-ethereum/rpc/api" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/comms" + "github.com/ethereum/go-ethereum/rpc/shared" + "github.com/ethereum/go-ethereum/rpc/useragent" "github.com/ethereum/go-ethereum/xeth" ) @@ -518,15 +520,20 @@ func StartIPC(eth *eth.Ethereum, ctx *cli.Context) error { Endpoint: IpcSocketPath(ctx), } - xeth := xeth.New(eth, nil) - codec := codec.JSON + initializer := func(conn net.Conn) (shared.EthereumApi, error) { + fe := useragent.NewRemoteFrontend(conn, eth.AccountManager()) + xeth := xeth.New(eth, fe) + codec := codec.JSON - apis, err := api.ParseApiString(ctx.GlobalString(IPCApiFlag.Name), codec, xeth, eth) - if err != nil { - return err + apis, err := api.ParseApiString(ctx.GlobalString(IPCApiFlag.Name), codec, xeth, eth) + if err != nil { + return nil, err + } + + return api.Merge(apis...), nil } - return comms.StartIpc(config, codec, api.Merge(apis...)) + return comms.StartIpc(config, codec.JSON, initializer) } func StartRPC(eth *eth.Ethereum, ctx *cli.Context) error { -- cgit v1.2.3