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 417d6acb6e
commit 80fda3e8ac
3 changed files with 21 additions and 20 deletions

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,6 +437,7 @@ func (s *Server) readRequest(codec ServerCodec) ([]*serverRequest, bool, RPCErro
continue continue
} }
if r.isPubSub { // eth_subscribe
if callb, ok := svc.subscriptions[r.method]; ok { if callb, ok := svc.subscriptions[r.method]; ok {
requests[i] = &serverRequest{id: r.id, svcname: svc.name, callb: callb} requests[i] = &serverRequest{id: r.id, svcname: svc.name, callb: callb}
if r.params != nil && len(callb.argTypes) > 0 { if r.params != nil && len(callb.argTypes) > 0 {
@ -448,6 +449,9 @@ func (s *Server) readRequest(codec ServerCodec) ([]*serverRequest, bool, RPCErro
requests[i].err = &invalidParamsError{err.Error()} 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