multi: registration complete MW interceptor msg

In this commit, we change the flow of the rpc middleware registration
a bit. In order to allow a client to add rpc middleware interceptors in
a deterministic order, we now make the server send a "registration
complete" message to the client after compeleting the registration
process so that the client knows when it can go ahead and register the
next client.
This commit is contained in:
Elle Mouton
2022-07-19 11:03:14 -05:00
parent 0ac421907a
commit 25acb51ba3
6 changed files with 566 additions and 485 deletions

View File

@@ -7504,8 +7504,9 @@ func (r *rpcServer) RegisterRPCMiddleware(
// middleware must be a registration message containing its name and the
// custom caveat it wants to register for.
var (
registerChan = make(chan *lnrpc.MiddlewareRegistration, 1)
errChan = make(chan error, 1)
registerChan = make(chan *lnrpc.MiddlewareRegistration, 1)
registerDoneChan = make(chan struct{})
errChan = make(chan error, 1)
)
ctxc, cancel := context.WithTimeout(
stream.Context(), r.cfg.RPCMiddleware.InterceptTimeout,
@@ -7580,6 +7581,40 @@ func (r *rpcServer) RegisterRPCMiddleware(
}
defer r.interceptorChain.RemoveMiddleware(registerMsg.MiddlewareName)
// Send a message to the client to indicate that the registration has
// successfully completed.
regCompleteMsg := &lnrpc.RPCMiddlewareRequest{
InterceptType: &lnrpc.RPCMiddlewareRequest_RegComplete{
RegComplete: true,
},
}
// Send the message in a goroutine because the Send method blocks until
// the message is read by the client.
go func() {
err := stream.Send(regCompleteMsg)
if err != nil {
errChan <- err
return
}
close(registerDoneChan)
}()
select {
case err := <-errChan:
return fmt.Errorf("error sending middleware registration "+
"complete message: %v", err)
case <-ctxc.Done():
return ctxc.Err()
case <-r.quit:
return ErrServerShuttingDown
case <-registerDoneChan:
}
return middleware.Run()
}