From ad21a50219554754a404fd782a6ce3d1c0defe45 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Tue, 24 Nov 2015 10:21:53 +0100 Subject: [PATCH] bugfix with pub sub name collision with RPC method --- eth/downloader/downloader_rpc.go | 2 +- rpc/v2/server.go | 24 ++++++++++++++---------- rpc/v2/utils.go | 15 ++++++--------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/eth/downloader/downloader_rpc.go b/eth/downloader/downloader_rpc.go index 7eb1ae77f5..fdc47dafbb 100644 --- a/eth/downloader/downloader_rpc.go +++ b/eth/downloader/downloader_rpc.go @@ -19,7 +19,7 @@ type Progress struct { } type SyncingResult struct { - Syncing bool `json:"syncing"` + Syncing bool `json:"syncing"` Status Progress `json:"status"` } diff --git a/rpc/v2/server.go b/rpc/v2/server.go index e1e0fa3a6a..b8414acee4 100644 --- a/rpc/v2/server.go +++ b/rpc/v2/server.go @@ -130,7 +130,7 @@ func (s *Server) ServeCodec(codec ServerCodec) { const size = 64 << 10 buf := make([]byte, size) buf = buf[:runtime.Stack(buf, false)] - glog.Errorln(buf) + glog.Errorln(string(buf)) } codec.Close() }() @@ -437,16 +437,20 @@ func (s *Server) readRequest(codec ServerCodec) ([]*serverRequest, bool, RPCErro continue } - if callb, ok := svc.subscriptions[r.method]; ok { - requests[i] = &serverRequest{id: r.id, svcname: svc.name, callb: callb} - if r.params != nil && len(callb.argTypes) > 0 { - argTypes := []reflect.Type{reflect.TypeOf("")} - argTypes = append(argTypes, callb.argTypes...) - if args, err := codec.ParseRequestArguments(argTypes, r.params); err == nil { - requests[i].args = args[1:] // first one is service.method name which isn't an actual argument - } else { - requests[i].err = &invalidParamsError{err.Error()} + if r.isPubSub { // eth_subscribe + if callb, ok := svc.subscriptions[r.method]; ok { + requests[i] = &serverRequest{id: r.id, svcname: svc.name, callb: callb} + if r.params != nil && len(callb.argTypes) > 0 { + argTypes := []reflect.Type{reflect.TypeOf("")} + argTypes = append(argTypes, callb.argTypes...) + if args, err := codec.ParseRequestArguments(argTypes, r.params); err == nil { + requests[i].args = args[1:] // first one is service.method name which isn't an actual argument + } else { + requests[i].err = &invalidParamsError{err.Error()} + } } + } else { + requests[i].err = &methodNotFoundError{subscribeMethod, r.method} } continue } diff --git a/rpc/v2/utils.go b/rpc/v2/utils.go index 7b7006e8a4..b6a09bca86 100644 --- a/rpc/v2/utils.go +++ b/rpc/v2/utils.go @@ -125,13 +125,13 @@ METHODS: continue } - if isPubSub(mtype) { - var h callback - h.rcvr = rcvr - h.method = method - h.errPos = -1 - h.isSubscribe = true + var h callback + h.isSubscribe = isPubSub(mtype) + h.rcvr = rcvr + h.method = method + h.errPos = -1 + if h.isSubscribe { h.argTypes = make([]reflect.Type, mtype.NumIn()-1) // skip rcvr type for i := 1; i < mtype.NumIn(); i++ { argType := mtype.In(i) @@ -146,9 +146,6 @@ METHODS: continue METHODS } - var h callback - h.rcvr = rcvr - h.method = method numIn := mtype.NumIn() // determine method arguments, ignore first arg since it's the receiver type