bugfix with pub sub name collision with RPC method

This commit is contained in:
Bas van Kervel 2015-11-24 10:21:53 +01:00
parent 0524ea17dc
commit 8db68a8aa0
3 changed files with 21 additions and 20 deletions

View file

@ -19,7 +19,7 @@ type Progress struct {
}
type SyncingResult struct {
Syncing bool `json:"syncing"`
Syncing bool `json:"syncing"`
Status Progress `json:"status"`
}

View file

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

View file

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