From 7fadde0b373a82b7698f455fb8843c00b31295d7 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Mon, 18 Sep 2017 12:02:15 -0700 Subject: [PATCH] check for request ID after receiving it --- rpc/lib/client/http_client.go | 2 +- rpc/lib/client/ws_client.go | 4 ++-- rpc/lib/server/handlers.go | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/rpc/lib/client/http_client.go b/rpc/lib/client/http_client.go index b64aea30a..1fbaedfae 100644 --- a/rpc/lib/client/http_client.go +++ b/rpc/lib/client/http_client.go @@ -75,7 +75,7 @@ func NewJSONRPCClient(remote string) *JSONRPCClient { } func (c *JSONRPCClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) { - request, err := types.MapToRequest("", method, params) + request, err := types.MapToRequest("jsonrpc-client", method, params) if err != nil { return nil, err } diff --git a/rpc/lib/client/ws_client.go b/rpc/lib/client/ws_client.go index 7bf3fc2a9..1407073ae 100644 --- a/rpc/lib/client/ws_client.go +++ b/rpc/lib/client/ws_client.go @@ -195,7 +195,7 @@ func (c *WSClient) Send(ctx context.Context, request types.RPCRequest) error { // Call the given method. See Send description. func (c *WSClient) Call(ctx context.Context, method string, params map[string]interface{}) error { - request, err := types.MapToRequest("", method, params) + request, err := types.MapToRequest("ws-client", method, params) if err != nil { return err } @@ -205,7 +205,7 @@ func (c *WSClient) Call(ctx context.Context, method string, params map[string]in // CallWithArrayParams the given method with params in a form of array. See // Send description. func (c *WSClient) CallWithArrayParams(ctx context.Context, method string, params []interface{}) error { - request, err := types.ArrayToRequest("", method, params) + request, err := types.ArrayToRequest("ws-client", method, params) if err != nil { return err } diff --git a/rpc/lib/server/handlers.go b/rpc/lib/server/handlers.go index 070072d8f..5cb3baddd 100644 --- a/rpc/lib/server/handlers.go +++ b/rpc/lib/server/handlers.go @@ -113,6 +113,11 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han WriteRPCResponseHTTP(w, types.RPCParseError("", errors.Wrap(err, "Error unmarshalling request"))) return } + // A Notification is a Request object without an "id" member. + // The Server MUST NOT reply to a Notification, including those that are within a batch request. + if request.ID == "" { + return + } if len(r.URL.Path) > 1 { WriteRPCResponseHTTP(w, types.RPCInvalidRequestError(request.ID, errors.Errorf("Path %s is invalid", r.URL.Path))) return @@ -513,6 +518,12 @@ func (wsc *wsConnection) readRoutine() { continue } + // A Notification is a Request object without an "id" member. + // The Server MUST NOT reply to a Notification, including those that are within a batch request. + if request.ID == "" { + continue + } + // Now, fetch the RPCFunc and execute it. rpcFunc := wsc.funcMap[request.Method]