|
|
|
@ -18,6 +18,7 @@ limitations under the License.
|
|
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
@ -39,7 +40,7 @@ type SignerClientHandler struct {
|
|
|
|
|
clientCallback chan interface{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *SignerClientHandler) Send(command *protocol.Command, out chan []byte) error {
|
|
|
|
|
func (s *SignerClientHandler) Send(ctx context.Context, command *protocol.Command, out chan []byte) error {
|
|
|
|
|
var (
|
|
|
|
|
frame []byte
|
|
|
|
|
err error
|
|
|
|
@ -54,7 +55,12 @@ func (s *SignerClientHandler) Send(command *protocol.Command, out chan []byte) e
|
|
|
|
|
|
|
|
|
|
s.logger.Trace("writing command announcement")
|
|
|
|
|
|
|
|
|
|
out <- frame
|
|
|
|
|
select {
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
return nil
|
|
|
|
|
case out <- frame:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
frame, err = msgpack.Marshal(command.Command)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -63,17 +69,22 @@ func (s *SignerClientHandler) Send(command *protocol.Command, out chan []byte) e
|
|
|
|
|
|
|
|
|
|
s.logger.WithField("command", command.Command).Debug("write command data")
|
|
|
|
|
|
|
|
|
|
out <- frame
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
select {
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
return nil
|
|
|
|
|
case out <- frame:
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *SignerClientHandler) ResponseAnnounce(in chan []byte) (*protocol.Response, error) {
|
|
|
|
|
func (s *SignerClientHandler) ResponseAnnounce(ctx context.Context, in chan []byte) (*protocol.Response, error) {
|
|
|
|
|
response := &protocol.Response{}
|
|
|
|
|
|
|
|
|
|
var announce messages.ResponseAnnounce
|
|
|
|
|
|
|
|
|
|
select {
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
return nil, nil
|
|
|
|
|
case frame := <-in:
|
|
|
|
|
if err := msgpack.Unmarshal(frame, &announce); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("could not unmarshal response announcement: %w", err)
|
|
|
|
@ -89,8 +100,10 @@ func (s *SignerClientHandler) ResponseAnnounce(in chan []byte) (*protocol.Respon
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *SignerClientHandler) ResponseData(in chan []byte, response *protocol.Response) error {
|
|
|
|
|
func (s *SignerClientHandler) ResponseData(ctx context.Context, in chan []byte, response *protocol.Response) error {
|
|
|
|
|
select {
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
return nil
|
|
|
|
|
case frame := <-in:
|
|
|
|
|
switch response.Announce.Code {
|
|
|
|
|
case messages.RespHealth:
|
|
|
|
@ -124,7 +137,7 @@ func (s *SignerClientHandler) ResponseData(in chan []byte, response *protocol.Re
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *SignerClientHandler) HandleResponse(response *protocol.Response) error {
|
|
|
|
|
func (s *SignerClientHandler) HandleResponse(ctx context.Context, response *protocol.Response) error {
|
|
|
|
|
s.logger.WithField("response", response.Announce).Info("handled response")
|
|
|
|
|
s.logger.WithField("response", response).Debug("full response")
|
|
|
|
|
|
|
|
|
@ -132,9 +145,9 @@ func (s *SignerClientHandler) HandleResponse(response *protocol.Response) error
|
|
|
|
|
case *messages.ErrorResponse:
|
|
|
|
|
s.logger.WithField("message", r.Message).Error("error from signer")
|
|
|
|
|
case *messages.HealthResponse:
|
|
|
|
|
s.handleHealthResponse(r)
|
|
|
|
|
s.handleHealthResponse(ctx, r)
|
|
|
|
|
case *messages.FetchCRLResponse:
|
|
|
|
|
s.handleFetchCRLResponse(r)
|
|
|
|
|
s.handleFetchCRLResponse(ctx, r)
|
|
|
|
|
default:
|
|
|
|
|
s.logger.WithField("response", response).Warnf("unhandled response of type %T", response.Response)
|
|
|
|
|
}
|
|
|
|
@ -142,7 +155,7 @@ func (s *SignerClientHandler) HandleResponse(response *protocol.Response) error
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *SignerClientHandler) handleHealthResponse(r *messages.HealthResponse) {
|
|
|
|
|
func (s *SignerClientHandler) handleHealthResponse(ctx context.Context, r *messages.HealthResponse) {
|
|
|
|
|
signerInfo := client.SignerInfo{}
|
|
|
|
|
|
|
|
|
|
signerInfo.SignerHealth = r.Healthy
|
|
|
|
@ -198,11 +211,21 @@ func (s *SignerClientHandler) handleHealthResponse(r *messages.HealthResponse) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.clientCallback <- signerInfo
|
|
|
|
|
select {
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
return
|
|
|
|
|
case s.clientCallback <- signerInfo:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *SignerClientHandler) handleFetchCRLResponse(r *messages.FetchCRLResponse) {
|
|
|
|
|
s.clientCallback <- r
|
|
|
|
|
func (s *SignerClientHandler) handleFetchCRLResponse(ctx context.Context, r *messages.FetchCRLResponse) {
|
|
|
|
|
select {
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
return
|
|
|
|
|
case s.clientCallback <- r:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func New(
|
|
|
|
|