mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-19 14:54:22 +01:00
lsps0: check service impl satisfies handler type.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -139,17 +140,17 @@ func (s *Server) Serve(lis lightning.CustomMsgClient) error {
|
|||||||
defer func() { <-guard }()
|
defer func() { <-guard }()
|
||||||
|
|
||||||
// Call the method handler for the requested method.
|
// Call the method handler for the requested method.
|
||||||
r, err := m.method.Handler(m.service.serviceImpl, context.TODO(), df)
|
r, err := m.method.Handler(m.service.serviceImpl, context.TODO(), df)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s, ok := status.FromError(err)
|
s, ok := status.FromError(err)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Printf("Internal error when processing custom message '%s' from peer '%s': %v", string(msg.Data), msg.PeerId, err)
|
log.Printf("Internal error when processing custom message '%s' from peer '%s': %v", string(msg.Data), msg.PeerId, err)
|
||||||
s = status.New(codes.InternalError, InternalError)
|
s = status.New(codes.InternalError, InternalError)
|
||||||
}
|
}
|
||||||
|
|
||||||
sendError(lis, msg, req, s)
|
sendError(lis, msg, req, s)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sendResponse(lis, msg, req, r)
|
sendResponse(lis, msg, req, r)
|
||||||
}()
|
}()
|
||||||
@@ -234,6 +235,16 @@ func sendError(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) RegisterService(desc *ServiceDesc, impl interface{}) {
|
func (s *Server) RegisterService(desc *ServiceDesc, impl interface{}) {
|
||||||
|
if impl == nil {
|
||||||
|
log.Fatalf("lsps0: Server.RegisterService got nil service implementation")
|
||||||
|
}
|
||||||
|
|
||||||
|
ht := reflect.TypeOf(desc.HandlerType).Elem()
|
||||||
|
st := reflect.TypeOf(impl)
|
||||||
|
if !st.Implements(ht) {
|
||||||
|
log.Fatalf("lsps0: Server.RegisterService found the handler of type %v that does not satisfy %v", st, ht)
|
||||||
|
}
|
||||||
|
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
log.Printf("RegisterService(%q)", desc.ServiceName)
|
log.Printf("RegisterService(%q)", desc.ServiceName)
|
||||||
|
|||||||
Reference in New Issue
Block a user