From 2e0b56a72b3eafc89938003da29c06496ac9ad4e Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Mon, 22 Jun 2015 12:47:32 +0200 Subject: added RPC start/stop support --- rpc/comms/comms.go | 9 ++++----- rpc/comms/http.go | 4 +--- rpc/comms/http_net.go | 11 +++++------ rpc/comms/inproc.go | 11 +++-------- rpc/comms/ipc.go | 4 +--- rpc/comms/ipc_unix.go | 4 ++-- rpc/comms/ipc_windows.go | 3 +-- 7 files changed, 17 insertions(+), 29 deletions(-) (limited to 'rpc/comms') diff --git a/rpc/comms/comms.go b/rpc/comms/comms.go index 29ad11b3c..bfe625758 100644 --- a/rpc/comms/comms.go +++ b/rpc/comms/comms.go @@ -11,7 +11,6 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" - "github.com/ethereum/go-ethereum/rpc/api" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/shared" ) @@ -22,14 +21,14 @@ const ( var ( // List with all API's which are offered over the in proc interface by default - DefaultInProcApis = api.AllApis + DefaultInProcApis = shared.AllApis // List with all API's which are offered over the IPC interface by default - DefaultIpcApis = api.AllApis + DefaultIpcApis = shared.AllApis // List with API's which are offered over thr HTTP/RPC interface by default DefaultHttpRpcApis = strings.Join([]string{ - api.DbApiName, api.EthApiName, api.NetApiName, api.Web3ApiName, + shared.DbApiName, shared.EthApiName, shared.NetApiName, shared.Web3ApiName, }, ",") ) @@ -44,7 +43,7 @@ type EthereumClient interface { SupportedModules() (map[string]string, error) } -func handle(conn net.Conn, api api.EthereumApi, c codec.Codec) { +func handle(conn net.Conn, api shared.EthereumApi, c codec.Codec) { codec := c.New(conn) for { diff --git a/rpc/comms/http.go b/rpc/comms/http.go index 6a543c0ed..ebee791bd 100644 --- a/rpc/comms/http.go +++ b/rpc/comms/http.go @@ -10,7 +10,6 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" - "github.com/ethereum/go-ethereum/rpc/api" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/shared" "github.com/rs/cors" @@ -28,7 +27,7 @@ type HttpConfig struct { CorsDomain string } -func StartHttp(cfg HttpConfig, codec codec.Codec, apis ...api.EthereumApi) error { +func StartHttp(cfg HttpConfig, codec codec.Codec, api shared.EthereumApi) error { if httpListener != nil { if fmt.Sprintf("%s:%d", cfg.ListenAddress, cfg.ListenPort) != httpListener.Addr().String() { return fmt.Errorf("RPC service already running on %s ", httpListener.Addr().String()) @@ -43,7 +42,6 @@ func StartHttp(cfg HttpConfig, codec codec.Codec, apis ...api.EthereumApi) error } httpListener = l - api := api.Merge(apis...) var handler http.Handler if len(cfg.CorsDomain) > 0 { var opts cors.Options diff --git a/rpc/comms/http_net.go b/rpc/comms/http_net.go index f326f1a7e..acc5f99a9 100644 --- a/rpc/comms/http_net.go +++ b/rpc/comms/http_net.go @@ -11,7 +11,6 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" - "github.com/ethereum/go-ethereum/rpc/api" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/shared" ) @@ -90,7 +89,7 @@ func newStoppableHandler(h http.Handler, stop chan struct{}) http.Handler { case <-stop: w.Header().Set("Content-Type", "application/json") err := fmt.Errorf("RPC service stopped") - response := shared.NewRpcResponse(-1, api.JsonRpcVersion, nil, err) + response := shared.NewRpcResponse(-1, shared.JsonRpcVersion, nil, err) httpSend(w, response) default: h.ServeHTTP(w, r) @@ -110,14 +109,14 @@ func httpSend(writer io.Writer, v interface{}) (n int, err error) { return writer.Write(payload) } -func gethHttpHandler(codec codec.Codec, a api.EthereumApi) http.Handler { +func gethHttpHandler(codec codec.Codec, a shared.EthereumApi) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { w.Header().Set("Content-Type", "application/json") // Limit request size to resist DoS if req.ContentLength > maxHttpSizeReqLength { err := fmt.Errorf("Request too large") - response := shared.NewRpcErrorResponse(-1, api.JsonRpcVersion, -32700, err) + response := shared.NewRpcErrorResponse(-1, shared.JsonRpcVersion, -32700, err) httpSend(w, &response) return } @@ -126,7 +125,7 @@ func gethHttpHandler(codec codec.Codec, a api.EthereumApi) http.Handler { payload, err := ioutil.ReadAll(req.Body) if err != nil { err := fmt.Errorf("Could not read request body") - response := shared.NewRpcErrorResponse(-1, api.JsonRpcVersion, -32700, err) + response := shared.NewRpcErrorResponse(-1, shared.JsonRpcVersion, -32700, err) httpSend(w, &response) return } @@ -161,7 +160,7 @@ func gethHttpHandler(codec codec.Codec, a api.EthereumApi) http.Handler { // invalid request err = fmt.Errorf("Could not decode request") - res := shared.NewRpcErrorResponse(-1, api.JsonRpcVersion, -32600, err) + res := shared.NewRpcErrorResponse(-1, shared.JsonRpcVersion, -32600, err) httpSend(w, res) }) } diff --git a/rpc/comms/inproc.go b/rpc/comms/inproc.go index b9c4e93d9..5c84b8fd8 100644 --- a/rpc/comms/inproc.go +++ b/rpc/comms/inproc.go @@ -3,15 +3,12 @@ package comms import ( "fmt" - "github.com/ethereum/go-ethereum/eth" - "github.com/ethereum/go-ethereum/rpc/api" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/shared" - "github.com/ethereum/go-ethereum/xeth" ) type InProcClient struct { - api api.EthereumApi + api shared.EthereumApi codec codec.Codec lastId interface{} lastJsonrpc string @@ -31,10 +28,8 @@ func (self *InProcClient) Close() { } // Need to setup api support -func (self *InProcClient) Initialize(xeth *xeth.XEth, eth *eth.Ethereum) { - if apis, err := api.ParseApiString(api.AllApis, self.codec, xeth, eth); err == nil { - self.api = api.Merge(apis...) - } +func (self *InProcClient) Initialize(offeredApi shared.EthereumApi) { + self.api = offeredApi } func (self *InProcClient) Send(req interface{}) error { diff --git a/rpc/comms/ipc.go b/rpc/comms/ipc.go index 7f5219300..068a1288f 100644 --- a/rpc/comms/ipc.go +++ b/rpc/comms/ipc.go @@ -6,7 +6,6 @@ import ( "encoding/json" - "github.com/ethereum/go-ethereum/rpc/api" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/shared" ) @@ -92,7 +91,6 @@ func NewIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) { } // Start IPC server -func StartIpc(cfg IpcConfig, codec codec.Codec, apis ...api.EthereumApi) error { - offeredApi := api.Merge(apis...) +func StartIpc(cfg IpcConfig, codec codec.Codec, offeredApi shared.EthereumApi) error { return startIpc(cfg, codec, offeredApi) } diff --git a/rpc/comms/ipc_unix.go b/rpc/comms/ipc_unix.go index b5eec92db..295eb916b 100644 --- a/rpc/comms/ipc_unix.go +++ b/rpc/comms/ipc_unix.go @@ -8,8 +8,8 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" - "github.com/ethereum/go-ethereum/rpc/api" "github.com/ethereum/go-ethereum/rpc/codec" + "github.com/ethereum/go-ethereum/rpc/shared" ) func newIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) { @@ -31,7 +31,7 @@ func (self *ipcClient) reconnect() error { return err } -func startIpc(cfg IpcConfig, codec codec.Codec, api api.EthereumApi) error { +func startIpc(cfg IpcConfig, codec codec.Codec, api shared.EthereumApi) error { os.Remove(cfg.Endpoint) // in case it still exists from a previous run l, err := net.ListenUnix("unix", &net.UnixAddr{Name: cfg.Endpoint, Net: "unix"}) diff --git a/rpc/comms/ipc_windows.go b/rpc/comms/ipc_windows.go index 08f79274a..44c82ef8a 100644 --- a/rpc/comms/ipc_windows.go +++ b/rpc/comms/ipc_windows.go @@ -14,7 +14,6 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" - "github.com/ethereum/go-ethereum/rpc/api" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/shared" ) @@ -652,7 +651,7 @@ func (self *ipcClient) reconnect() error { return err } -func startIpc(cfg IpcConfig, codec codec.Codec, api api.EthereumApi) error { +func startIpc(cfg IpcConfig, codec codec.Codec, api shared.EthereumApi) error { os.Remove(cfg.Endpoint) // in case it still exists from a previous run l, err := Listen(cfg.Endpoint) -- cgit v1.2.3