From 7139c1aff7ef9da9131598f7eb67bb0d1ed13b6c Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Mon, 2 Feb 2015 07:30:22 -0600 Subject: [PATCH 1/4] Decrease log level for Sending RPC payload --- rpc/util.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rpc/util.go b/rpc/util.go index bb4087c51c..509d9a17d3 100644 --- a/rpc/util.go +++ b/rpc/util.go @@ -18,10 +18,11 @@ package rpc import ( "encoding/json" - "github.com/ethereum/go-ethereum/logger" "io" "net/http" + "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/state" ) @@ -36,7 +37,7 @@ func (self JsonWrapper) Send(writer io.Writer, v interface{}) (n int, err error) rpclogger.Fatalln("Error marshalling JSON", err) return 0, err } - rpclogger.Infof("Sending payload: %s", payload) + rpclogger.DebugDetailf("Sending payload: %s", payload) return writer.Write(payload) } From b2b42f759c54d9d1b0ba4d9419a4c9a4bd8e4234 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Mon, 2 Feb 2015 07:37:44 -0600 Subject: [PATCH 2/4] Update signature for rpc websockets --- cmd/utils/cmd.go | 2 +- rpc/ws/server.go | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 43ad88c554..c26dab44c2 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -205,7 +205,7 @@ func StartWebSockets(eth *eth.Ethereum, wsPort int) { clilogger.Infoln("Starting WebSockets") var err error - eth.WsServer, err = rpcws.NewWebSocketServer(eth, wsPort) + eth.WsServer, err = rpcws.NewWebSocketServer(xeth.New(eth), wsPort) if err != nil { clilogger.Errorf("Could not start RPC interface (port %v): %v", wsPort, err) } else { diff --git a/rpc/ws/server.go b/rpc/ws/server.go index 2853181ecc..85cacf80bb 100644 --- a/rpc/ws/server.go +++ b/rpc/ws/server.go @@ -22,8 +22,6 @@ import ( "net/http" "code.google.com/p/go.net/websocket" - "github.com/ethereum/go-ethereum/eth" - "github.com/ethereum/go-ethereum/event/filter" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/xeth" @@ -32,25 +30,21 @@ import ( var wslogger = logger.NewLogger("RPC-WS") type WebSocketServer struct { - eth *eth.Ethereum - filterManager *filter.FilterManager - port int - doneCh chan bool - listener net.Listener + pipe *xeth.XEth + port int + doneCh chan bool + listener net.Listener } -func NewWebSocketServer(eth *eth.Ethereum, port int) (*WebSocketServer, error) { +func NewWebSocketServer(pipe *xeth.XEth, port int) (*WebSocketServer, error) { sport := fmt.Sprintf(":%d", port) l, err := net.Listen("tcp", sport) if err != nil { return nil, err } - filterManager := filter.NewFilterManager(eth.EventMux()) - go filterManager.Start() - - return &WebSocketServer{eth, - filterManager, + return &WebSocketServer{ + pipe, port, make(chan bool), l, @@ -75,7 +69,7 @@ func (self *WebSocketServer) Start() { wslogger.Infof("Starting RPC-WS server on port %d", self.port) go self.handlerLoop() - api := rpc.NewEthereumApi(xeth.New(self.eth)) + api := rpc.NewEthereumApi(self.pipe) h := self.apiHandler(api) http.Handle("/ws", h) From 55ed0ff07c6cf2dc8b422a3bf8d623a039ad6dbd Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Tue, 3 Feb 2015 17:29:29 -0600 Subject: [PATCH 3/4] Update RPC message format --- rpc/http/server.go | 11 +++++++---- rpc/message.go | 25 ++++++++++++------------- rpc/ws/server.go | 13 ++++++++----- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/rpc/http/server.go b/rpc/http/server.go index 965727a4ed..caa50d67ca 100644 --- a/rpc/http/server.go +++ b/rpc/http/server.go @@ -84,6 +84,7 @@ func (s *RpcHttpServer) Start() { } func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler { + var jsonrpcver string = "2.0" fn := func(w http.ResponseWriter, req *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") @@ -91,20 +92,22 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler { reqParsed, reqerr := JSON.ParseRequestBody(req) if reqerr != nil { - JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: rpc.ErrorParseRequest}) + jsonerr := &rpc.RpcErrorObject{-32700, rpc.ErrorParseRequest} + JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr}) return } var response interface{} reserr := api.GetRequestReply(&reqParsed, &response) if reserr != nil { - rpchttplogger.Errorln(reserr) - JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: reserr.Error()}) + rpchttplogger.Warnln(reserr) + jsonerr := &rpc.RpcErrorObject{-32603, reserr.Error()} + JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: &reqParsed.ID, Error: jsonerr}) return } rpchttplogger.Debugf("Generated response: %T %s", response, response) - JSON.Send(w, &rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response}) + JSON.Send(w, &rpc.RpcSuccessResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Result: response}) } return http.HandlerFunc(fn) diff --git a/rpc/message.go b/rpc/message.go index 26fac9d377..054b7a5789 100644 --- a/rpc/message.go +++ b/rpc/message.go @@ -33,30 +33,29 @@ const ( ErrorDecodeArgs = "Error: Could not decode arguments" ) -type ErrorResponse struct { - Error bool `json:"error"` - ErrorText string `json:"errorText"` +type RpcRequest struct { + JsonRpc string `json:"jsonrpc"` + ID int `json:"id"` + Method string `json:"method"` + Params []json.RawMessage `json:"params"` } type RpcSuccessResponse struct { ID int `json:"id"` JsonRpc string `json:"jsonrpc"` - Error bool `json:"error"` Result interface{} `json:"result"` } type RpcErrorResponse struct { - ID int `json:"id"` - JsonRpc string `json:"jsonrpc"` - Error bool `json:"error"` - ErrorText string `json:"errortext"` + ID *int `json:"id"` + JsonRpc string `json:"jsonrpc"` + Error *RpcErrorObject `json:"error"` } -type RpcRequest struct { - JsonRpc string `json:"jsonrpc"` - ID int `json:"id"` - Method string `json:"method"` - Params []json.RawMessage `json:"params"` +type RpcErrorObject struct { + Code int `json:"code"` + Message string `json:"message"` + // Data interface{} `json:"data"` } func NewErrorResponse(msg string) error { diff --git a/rpc/ws/server.go b/rpc/ws/server.go index 85cacf80bb..6be4e8ce93 100644 --- a/rpc/ws/server.go +++ b/rpc/ws/server.go @@ -28,6 +28,7 @@ import ( ) var wslogger = logger.NewLogger("RPC-WS") +var JSON rpc.JsonWrapper type WebSocketServer struct { pipe *xeth.XEth @@ -90,27 +91,29 @@ func (s *WebSocketServer) apiHandler(api *rpc.EthereumApi) http.Handler { } func sockHandler(api *rpc.EthereumApi) websocket.Handler { + var jsonrpcver string = "2.0" fn := func(conn *websocket.Conn) { for { wslogger.Debugln("Handling request") var reqParsed rpc.RpcRequest if err := websocket.JSON.Receive(conn, &reqParsed); err != nil { - wslogger.Debugln(rpc.ErrorParseRequest) - websocket.JSON.Send(conn, rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: rpc.ErrorParseRequest}) + jsonerr := &rpc.RpcErrorObject{-32700, rpc.ErrorParseRequest} + JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr}) continue } var response interface{} reserr := api.GetRequestReply(&reqParsed, &response) if reserr != nil { - wslogger.Errorln(reserr) - websocket.JSON.Send(conn, rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: reserr.Error()}) + wslogger.Warnln(reserr) + jsonerr := &rpc.RpcErrorObject{-32603, reserr.Error()} + JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: &reqParsed.ID, Error: jsonerr}) continue } wslogger.Debugf("Generated response: %T %s", response, response) - websocket.JSON.Send(conn, rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response}) + JSON.Send(conn, &rpc.RpcSuccessResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Result: response}) } } return websocket.Handler(fn) From 2656a2d0387464d6c5039f38189649533c578708 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 4 Feb 2015 10:57:47 -0600 Subject: [PATCH 4/4] Use different default RPC port per #186 --- cmd/ethereum/flags.go | 2 +- cmd/mist/flags.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/ethereum/flags.go b/cmd/ethereum/flags.go index e0fbbb0086..5bbcf3f362 100644 --- a/cmd/ethereum/flags.go +++ b/cmd/ethereum/flags.go @@ -96,7 +96,7 @@ func Init() { flag.StringVar(&NatType, "nat", "", "NAT support (UPNP|PMP) (none)") flag.StringVar(&PMPGateway, "pmp", "", "Gateway IP for PMP") flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers") - flag.IntVar(&RpcPort, "rpcport", 8080, "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.BoolVar(&StartRpc, "rpc", false, "start rpc server") flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server") diff --git a/cmd/mist/flags.go b/cmd/mist/flags.go index 9dc3ae10a7..9f91582f6e 100644 --- a/cmd/mist/flags.go +++ b/cmd/mist/flags.go @@ -111,7 +111,7 @@ func Init() { flag.StringVar(&OutboundPort, "port", "30303", "listening port") flag.BoolVar(&UseUPnP, "upnp", true, "enable UPnP support") flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers") - flag.IntVar(&RpcPort, "rpcport", 8080, "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.BoolVar(&StartRpc, "rpc", true, "start rpc server") flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")