aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-02-05 19:45:36 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-02-05 19:45:36 +0800
commita13bc9d7a1bc96fab93ace40045c0f0fea4da836 (patch)
treec6bd5be2e3e1ce06450a8611b2f1253b2ac18351 /cmd
parentba7c125153ce1be30985784a18edf38645406d03 (diff)
downloadgo-tangerine-a13bc9d7a1bc96fab93ace40045c0f0fea4da836.tar.gz
go-tangerine-a13bc9d7a1bc96fab93ace40045c0f0fea4da836.tar.zst
go-tangerine-a13bc9d7a1bc96fab93ace40045c0f0fea4da836.zip
cmd, common, node, rpc: move HTTP RPC into node, drop singletone aspect
Diffstat (limited to 'cmd')
-rw-r--r--cmd/geth/main.go5
-rw-r--r--cmd/gethrpctest/main.go37
-rw-r--r--cmd/utils/flags.go48
3 files changed, 28 insertions, 62 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index fa456a7ac..a321181a1 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -503,11 +503,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)
diff --git a/cmd/gethrpctest/main.go b/cmd/gethrpctest/main.go
index becd09f5a..b0907f8c5 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,13 @@ 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"},
+ NoDiscovery: true,
+ })
if err != nil {
return nil, err
}
@@ -164,23 +163,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/flags.go b/cmd/utils/flags.go
index 5d56ba7d0..40ea29d78 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -233,12 +233,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",
@@ -262,7 +262,7 @@ var (
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,12 +271,12 @@ 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",
@@ -284,7 +284,7 @@ var (
Value: rpc.DefaultHttpRpcApis,
}
WSAllowedDomainsFlag = cli.StringFlag{
- Name: "wsdomains",
+ Name: "wscors",
Usage: "Domains from which to accept websockets requests",
Value: "",
}
@@ -482,6 +482,15 @@ 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)
+}
+
// 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 +600,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 +608,11 @@ 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), ","),
}
// Configure the Ethereum service
accman := MakeAccountManager(ctx)
@@ -744,27 +757,6 @@ func MakeChain(ctx *cli.Context) (chain *core.BlockChain, chainDb ethdb.Database
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() {