Merge pull request #402 from tgerring/rpcupdates

Set RPC listening address via param
This commit is contained in:
Jeffrey Wilcke 2015-02-28 21:07:46 +01:00
commit cdb77f0ecd
6 changed files with 72 additions and 66 deletions

View File

@ -36,40 +36,41 @@ import (
) )
var ( var (
Identifier string Identifier string
KeyRing string KeyRing string
DiffTool bool DiffTool bool
DiffType string DiffType string
KeyStore string KeyStore string
StartRpc bool StartRpc bool
StartWebSockets bool StartWebSockets bool
RpcPort int RpcListenAddress string
WsPort int RpcPort int
OutboundPort string WsPort int
ShowGenesis bool OutboundPort string
AddPeer string ShowGenesis bool
MaxPeer int AddPeer string
GenAddr bool MaxPeer int
BootNodes string GenAddr bool
NodeKey *ecdsa.PrivateKey BootNodes string
NAT nat.Interface NodeKey *ecdsa.PrivateKey
SecretFile string NAT nat.Interface
ExportDir string SecretFile string
NonInteractive bool ExportDir string
Datadir string NonInteractive bool
LogFile string Datadir string
ConfigFile string LogFile string
DebugFile string ConfigFile string
LogLevel int DebugFile string
LogFormat string LogLevel int
Dump bool LogFormat string
DumpHash string Dump bool
DumpNumber int DumpHash string
VmType int DumpNumber int
ImportChain string VmType int
SHH bool ImportChain string
Dial bool SHH bool
PrintVersion bool Dial bool
PrintVersion bool
) )
// flags specific to cli client // flags specific to cli client
@ -93,6 +94,7 @@ func Init() {
flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use") flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)") flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
flag.StringVar(&RpcListenAddress, "rpcaddr", "127.0.0.1", "address for json-rpc server to listen on")
flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on") flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on")
flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on") flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on")
flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") flag.BoolVar(&StartRpc, "rpc", false, "start rpc server")

View File

@ -128,7 +128,7 @@ func main() {
} }
if StartRpc { if StartRpc {
utils.StartRpc(ethereum, RpcPort) utils.StartRpc(ethereum, RpcListenAddress, RpcPort)
} }
if StartWebSockets { if StartWebSockets {

View File

@ -37,31 +37,32 @@ import (
) )
var ( var (
Identifier string Identifier string
KeyRing string KeyRing string
KeyStore string KeyStore string
StartRpc bool StartRpc bool
StartWebSockets bool StartWebSockets bool
RpcPort int RpcListenAddress string
WsPort int RpcPort int
OutboundPort string WsPort int
ShowGenesis bool OutboundPort string
AddPeer string ShowGenesis bool
MaxPeer int AddPeer string
GenAddr bool MaxPeer int
BootNodes string GenAddr bool
NodeKey *ecdsa.PrivateKey BootNodes string
NAT nat.Interface NodeKey *ecdsa.PrivateKey
SecretFile string NAT nat.Interface
ExportDir string SecretFile string
NonInteractive bool ExportDir string
Datadir string NonInteractive bool
LogFile string Datadir string
ConfigFile string LogFile string
DebugFile string ConfigFile string
LogLevel int DebugFile string
VmType int LogLevel int
MinerThreads int VmType int
MinerThreads int
) )
// flags specific to gui client // flags specific to gui client
@ -79,6 +80,7 @@ func Init() {
flag.StringVar(&Identifier, "id", "", "Custom client identifier") flag.StringVar(&Identifier, "id", "", "Custom client identifier")
flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use") flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)") flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
flag.StringVar(&RpcListenAddress, "rpcaddr", "127.0.0.1", "address for json-rpc server to listen on")
flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on") flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on")
flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on") flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on")
flag.BoolVar(&StartRpc, "rpc", true, "start rpc server") flag.BoolVar(&StartRpc, "rpc", true, "start rpc server")

View File

@ -73,7 +73,7 @@ func run() error {
utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive) utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
if StartRpc { if StartRpc {
utils.StartRpc(ethereum, RpcPort) utils.StartRpc(ethereum, RpcListenAddress, RpcPort)
} }
if StartWebSockets { if StartWebSockets {

View File

@ -160,9 +160,9 @@ func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, Secre
clilogger.Infof("Main address %x\n", keyManager.Address()) clilogger.Infof("Main address %x\n", keyManager.Address())
} }
func StartRpc(ethereum *eth.Ethereum, RpcPort int) { func StartRpc(ethereum *eth.Ethereum, RpcListenAddress string, RpcPort int) {
var err error var err error
ethereum.RpcServer, err = rpchttp.NewRpcHttpServer(xeth.New(ethereum), RpcPort) ethereum.RpcServer, err = rpchttp.NewRpcHttpServer(xeth.New(ethereum), RpcListenAddress, RpcPort)
if err != nil { if err != nil {
clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err) clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
} else { } else {

View File

@ -29,8 +29,8 @@ import (
var rpchttplogger = logger.NewLogger("RPC-HTTP") var rpchttplogger = logger.NewLogger("RPC-HTTP")
var JSON rpc.JsonWrapper var JSON rpc.JsonWrapper
func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) { func NewRpcHttpServer(pipe *xeth.XEth, address string, port int) (*RpcHttpServer, error) {
sport := fmt.Sprintf("127.0.0.1:%d", port) sport := fmt.Sprintf("%s:%d", address, port)
l, err := net.Listen("tcp", sport) l, err := net.Listen("tcp", sport)
if err != nil { if err != nil {
return nil, err return nil, err
@ -41,6 +41,7 @@ func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) {
quit: make(chan bool), quit: make(chan bool),
pipe: pipe, pipe: pipe,
port: port, port: port,
addr: address,
}, nil }, nil
} }
@ -49,6 +50,7 @@ type RpcHttpServer struct {
listener net.Listener listener net.Listener
pipe *xeth.XEth pipe *xeth.XEth
port int port int
addr string
} }
func (s *RpcHttpServer) exitHandler() { func (s *RpcHttpServer) exitHandler() {
@ -69,7 +71,7 @@ func (s *RpcHttpServer) Stop() {
} }
func (s *RpcHttpServer) Start() { func (s *RpcHttpServer) Start() {
rpchttplogger.Infof("Starting RPC-HTTP server on port %d", s.port) rpchttplogger.Infof("Starting RPC-HTTP server on %s:%d", s.addr, s.port)
go s.exitHandler() go s.exitHandler()
api := rpc.NewEthereumApi(s.pipe) api := rpc.NewEthereumApi(s.pipe)