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 committed by Péter Szilágyi
parent 2d608d99f8
commit ad21a50219
3 changed files with 21 additions and 20 deletions

View file

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

View file

@ -130,7 +130,7 @@ func (s *Server) ServeCodec(codec ServerCodec) {
const size = 64 << 10 const size = 64 << 10
buf := make([]byte, size) buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)] buf = buf[:runtime.Stack(buf, false)]
glog.Errorln(buf) glog.Errorln(string(buf))
} }
codec.Close() codec.Close()
}() }()
@ -437,16 +437,20 @@ func (s *Server) readRequest(codec ServerCodec) ([]*serverRequest, bool, RPCErro
continue continue
} }
if callb, ok := svc.subscriptions[r.method]; ok { if r.isPubSub { // eth_subscribe
requests[i] = &serverRequest{id: r.id, svcname: svc.name, callb: callb} if callb, ok := svc.subscriptions[r.method]; ok {
if r.params != nil && len(callb.argTypes) > 0 { requests[i] = &serverRequest{id: r.id, svcname: svc.name, callb: callb}
argTypes := []reflect.Type{reflect.TypeOf("")} if r.params != nil && len(callb.argTypes) > 0 {
argTypes = append(argTypes, callb.argTypes...) argTypes := []reflect.Type{reflect.TypeOf("")}
if args, err := codec.ParseRequestArguments(argTypes, r.params); err == nil { argTypes = append(argTypes, callb.argTypes...)
requests[i].args = args[1:] // first one is service.method name which isn't an actual argument if args, err := codec.ParseRequestArguments(argTypes, r.params); err == nil {
} else { requests[i].args = args[1:] // first one is service.method name which isn't an actual argument
requests[i].err = &invalidParamsError{err.Error()} } else {
requests[i].err = &invalidParamsError{err.Error()}
}
} }
} else {
requests[i].err = &methodNotFoundError{subscribeMethod, r.method}
} }
continue continue
} }

View file

@ -125,13 +125,13 @@ METHODS:
continue continue
} }
if isPubSub(mtype) { var h callback
var h callback h.isSubscribe = isPubSub(mtype)
h.rcvr = rcvr h.rcvr = rcvr
h.method = method h.method = method
h.errPos = -1 h.errPos = -1
h.isSubscribe = true
if h.isSubscribe {
h.argTypes = make([]reflect.Type, mtype.NumIn()-1) // skip rcvr type h.argTypes = make([]reflect.Type, mtype.NumIn()-1) // skip rcvr type
for i := 1; i < mtype.NumIn(); i++ { for i := 1; i < mtype.NumIn(); i++ {
argType := mtype.In(i) argType := mtype.In(i)
@ -146,9 +146,6 @@ METHODS:
continue METHODS continue METHODS
} }
var h callback
h.rcvr = rcvr
h.method = method
numIn := mtype.NumIn() numIn := mtype.NumIn()
// determine method arguments, ignore first arg since it's the receiver type // determine method arguments, ignore first arg since it's the receiver type