Browse Source

check for request ID after receiving it

pull/521/head
Anton Kaliaev 7 years ago
committed by Ethan Buchman
parent
commit
7fadde0b37
3 changed files with 14 additions and 3 deletions
  1. +1
    -1
      rpc/lib/client/http_client.go
  2. +2
    -2
      rpc/lib/client/ws_client.go
  3. +11
    -0
      rpc/lib/server/handlers.go

+ 1
- 1
rpc/lib/client/http_client.go View File

@ -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
}


+ 2
- 2
rpc/lib/client/ws_client.go View File

@ -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
}


+ 11
- 0
rpc/lib/server/handlers.go View File

@ -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]


Loading…
Cancel
Save