Skip to content

Commit cdb77f0

Browse files
committed
Merge pull request #402 from tgerring/rpcupdates
Set RPC listening address via param
2 parents 43b5777 + ea0517b commit cdb77f0

File tree

6 files changed

+72
-66
lines changed

6 files changed

+72
-66
lines changed

cmd/ethereum/flags.go

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,41 @@ import (
3636
)
3737

3838
var (
39-
Identifier string
40-
KeyRing string
41-
DiffTool bool
42-
DiffType string
43-
KeyStore string
44-
StartRpc bool
45-
StartWebSockets bool
46-
RpcPort int
47-
WsPort int
48-
OutboundPort string
49-
ShowGenesis bool
50-
AddPeer string
51-
MaxPeer int
52-
GenAddr bool
53-
BootNodes string
54-
NodeKey *ecdsa.PrivateKey
55-
NAT nat.Interface
56-
SecretFile string
57-
ExportDir string
58-
NonInteractive bool
59-
Datadir string
60-
LogFile string
61-
ConfigFile string
62-
DebugFile string
63-
LogLevel int
64-
LogFormat string
65-
Dump bool
66-
DumpHash string
67-
DumpNumber int
68-
VmType int
69-
ImportChain string
70-
SHH bool
71-
Dial bool
72-
PrintVersion bool
39+
Identifier string
40+
KeyRing string
41+
DiffTool bool
42+
DiffType string
43+
KeyStore string
44+
StartRpc bool
45+
StartWebSockets bool
46+
RpcListenAddress string
47+
RpcPort int
48+
WsPort int
49+
OutboundPort string
50+
ShowGenesis bool
51+
AddPeer string
52+
MaxPeer int
53+
GenAddr bool
54+
BootNodes string
55+
NodeKey *ecdsa.PrivateKey
56+
NAT nat.Interface
57+
SecretFile string
58+
ExportDir string
59+
NonInteractive bool
60+
Datadir string
61+
LogFile string
62+
ConfigFile string
63+
DebugFile string
64+
LogLevel int
65+
LogFormat string
66+
Dump bool
67+
DumpHash string
68+
DumpNumber int
69+
VmType int
70+
ImportChain string
71+
SHH bool
72+
Dial bool
73+
PrintVersion bool
7374
)
7475

7576
// flags specific to cli client
@@ -93,6 +94,7 @@ func Init() {
9394
flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
9495
flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
9596

97+
flag.StringVar(&RpcListenAddress, "rpcaddr", "127.0.0.1", "address for json-rpc server to listen on")
9698
flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on")
9799
flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on")
98100
flag.BoolVar(&StartRpc, "rpc", false, "start rpc server")

cmd/ethereum/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func main() {
128128
}
129129

130130
if StartRpc {
131-
utils.StartRpc(ethereum, RpcPort)
131+
utils.StartRpc(ethereum, RpcListenAddress, RpcPort)
132132
}
133133

134134
if StartWebSockets {

cmd/mist/flags.go

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,32 @@ import (
3737
)
3838

3939
var (
40-
Identifier string
41-
KeyRing string
42-
KeyStore string
43-
StartRpc bool
44-
StartWebSockets bool
45-
RpcPort int
46-
WsPort int
47-
OutboundPort string
48-
ShowGenesis bool
49-
AddPeer string
50-
MaxPeer int
51-
GenAddr bool
52-
BootNodes string
53-
NodeKey *ecdsa.PrivateKey
54-
NAT nat.Interface
55-
SecretFile string
56-
ExportDir string
57-
NonInteractive bool
58-
Datadir string
59-
LogFile string
60-
ConfigFile string
61-
DebugFile string
62-
LogLevel int
63-
VmType int
64-
MinerThreads int
40+
Identifier string
41+
KeyRing string
42+
KeyStore string
43+
StartRpc bool
44+
StartWebSockets bool
45+
RpcListenAddress string
46+
RpcPort int
47+
WsPort int
48+
OutboundPort string
49+
ShowGenesis bool
50+
AddPeer string
51+
MaxPeer int
52+
GenAddr bool
53+
BootNodes string
54+
NodeKey *ecdsa.PrivateKey
55+
NAT nat.Interface
56+
SecretFile string
57+
ExportDir string
58+
NonInteractive bool
59+
Datadir string
60+
LogFile string
61+
ConfigFile string
62+
DebugFile string
63+
LogLevel int
64+
VmType int
65+
MinerThreads int
6566
)
6667

6768
// flags specific to gui client
@@ -79,6 +80,7 @@ func Init() {
7980
flag.StringVar(&Identifier, "id", "", "Custom client identifier")
8081
flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
8182
flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
83+
flag.StringVar(&RpcListenAddress, "rpcaddr", "127.0.0.1", "address for json-rpc server to listen on")
8284
flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on")
8385
flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on")
8486
flag.BoolVar(&StartRpc, "rpc", true, "start rpc server")

cmd/mist/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func run() error {
7373
utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
7474

7575
if StartRpc {
76-
utils.StartRpc(ethereum, RpcPort)
76+
utils.StartRpc(ethereum, RpcListenAddress, RpcPort)
7777
}
7878

7979
if StartWebSockets {

cmd/utils/cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, Secre
160160
clilogger.Infof("Main address %x\n", keyManager.Address())
161161
}
162162

163-
func StartRpc(ethereum *eth.Ethereum, RpcPort int) {
163+
func StartRpc(ethereum *eth.Ethereum, RpcListenAddress string, RpcPort int) {
164164
var err error
165-
ethereum.RpcServer, err = rpchttp.NewRpcHttpServer(xeth.New(ethereum), RpcPort)
165+
ethereum.RpcServer, err = rpchttp.NewRpcHttpServer(xeth.New(ethereum), RpcListenAddress, RpcPort)
166166
if err != nil {
167167
clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
168168
} else {

rpc/http/server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
var rpchttplogger = logger.NewLogger("RPC-HTTP")
3030
var JSON rpc.JsonWrapper
3131

32-
func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) {
33-
sport := fmt.Sprintf("127.0.0.1:%d", port)
32+
func NewRpcHttpServer(pipe *xeth.XEth, address string, port int) (*RpcHttpServer, error) {
33+
sport := fmt.Sprintf("%s:%d", address, port)
3434
l, err := net.Listen("tcp", sport)
3535
if err != nil {
3636
return nil, err
@@ -41,6 +41,7 @@ func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) {
4141
quit: make(chan bool),
4242
pipe: pipe,
4343
port: port,
44+
addr: address,
4445
}, nil
4546
}
4647

@@ -49,6 +50,7 @@ type RpcHttpServer struct {
4950
listener net.Listener
5051
pipe *xeth.XEth
5152
port int
53+
addr string
5254
}
5355

5456
func (s *RpcHttpServer) exitHandler() {
@@ -69,7 +71,7 @@ func (s *RpcHttpServer) Stop() {
6971
}
7072

7173
func (s *RpcHttpServer) Start() {
72-
rpchttplogger.Infof("Starting RPC-HTTP server on port %d", s.port)
74+
rpchttplogger.Infof("Starting RPC-HTTP server on %s:%d", s.addr, s.port)
7375
go s.exitHandler()
7476

7577
api := rpc.NewEthereumApi(s.pipe)

0 commit comments

Comments
 (0)