mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-16 12:16:11 +00:00
clean up
This commit is contained in:
+5
-5
@@ -24,29 +24,29 @@ func RegisterRemoteSignerMsg(cdc *amino.Codec) {
|
|||||||
// PubKeyRequest requests the consensus public key from the remote signer.
|
// PubKeyRequest requests the consensus public key from the remote signer.
|
||||||
type PubKeyRequest struct{}
|
type PubKeyRequest struct{}
|
||||||
|
|
||||||
// PubKeyResponse is a PrivValidatorSocket message containing the public key.
|
// PubKeyResponse is a response message containing the public key.
|
||||||
type PubKeyResponse struct {
|
type PubKeyResponse struct {
|
||||||
PubKey crypto.PubKey
|
PubKey crypto.PubKey
|
||||||
Error *RemoteSignerError
|
Error *RemoteSignerError
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignVoteRequest is a PrivValidatorSocket message containing a vote.
|
// SignVoteRequest is a request to sign a vote
|
||||||
type SignVoteRequest struct {
|
type SignVoteRequest struct {
|
||||||
Vote *types.Vote
|
Vote *types.Vote
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignedVoteResponse is a PrivValidatorSocket message containing a signed vote along with a potenial error message.
|
// SignedVoteResponse is a response containing a signed vote or an error
|
||||||
type SignedVoteResponse struct {
|
type SignedVoteResponse struct {
|
||||||
Vote *types.Vote
|
Vote *types.Vote
|
||||||
Error *RemoteSignerError
|
Error *RemoteSignerError
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignProposalRequest is a PrivValidatorSocket message containing a Proposal.
|
// SignProposalRequest is a request to sign a proposal
|
||||||
type SignProposalRequest struct {
|
type SignProposalRequest struct {
|
||||||
Proposal *types.Proposal
|
Proposal *types.Proposal
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignedProposalResponse is a PrivValidatorSocket message containing a proposal response
|
// SignedProposalResponse is response containing a signed proposal or an error
|
||||||
type SignedProposalResponse struct {
|
type SignedProposalResponse struct {
|
||||||
Proposal *types.Proposal
|
Proposal *types.Proposal
|
||||||
Error *RemoteSignerError
|
Error *RemoteSignerError
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// SignerClient implements PrivValidator.
|
// SignerClient implements PrivValidator.
|
||||||
// It uses a validator endpoint to request signatures from an external process.
|
// Handles remote validator connections that provide signing services
|
||||||
type SignerClient struct {
|
type SignerClient struct {
|
||||||
endpoint *SignerListenerEndpoint
|
endpoint *SignerListenerEndpoint
|
||||||
}
|
}
|
||||||
@@ -29,17 +29,17 @@ func NewSignerClient(endpoint *SignerListenerEndpoint) (*SignerClient, error) {
|
|||||||
return &SignerClient{endpoint: endpoint}, nil
|
return &SignerClient{endpoint: endpoint}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close calls Close on the underlying net.Conn.
|
// Close closes the underlying connection
|
||||||
func (sc *SignerClient) Close() error {
|
func (sc *SignerClient) Close() error {
|
||||||
return sc.endpoint.Close()
|
return sc.endpoint.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close calls Close on the underlying net.Conn.
|
// IsConnected indicates with the signer is connected to a remote signing service
|
||||||
func (sc *SignerClient) IsConnected() bool {
|
func (sc *SignerClient) IsConnected() bool {
|
||||||
return sc.endpoint.IsConnected()
|
return sc.endpoint.IsConnected()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close calls Close on the underlying net.Conn.
|
// WaitForConnection waits maxWait for a connection or returns a timeout error
|
||||||
func (sc *SignerClient) WaitForConnection(maxWait time.Duration) error {
|
func (sc *SignerClient) WaitForConnection(maxWait time.Duration) error {
|
||||||
if sc.endpoint == nil {
|
if sc.endpoint == nil {
|
||||||
return fmt.Errorf("endpoint has not been defined")
|
return fmt.Errorf("endpoint has not been defined")
|
||||||
@@ -50,7 +50,7 @@ func (sc *SignerClient) WaitForConnection(maxWait time.Duration) error {
|
|||||||
//--------------------------------------------------------
|
//--------------------------------------------------------
|
||||||
// Implement PrivValidator
|
// Implement PrivValidator
|
||||||
|
|
||||||
// GetPubKey implements PrivValidator.
|
// GetPubKey retrieves a public key from a remote signer
|
||||||
func (sc *SignerClient) GetPubKey() crypto.PubKey {
|
func (sc *SignerClient) GetPubKey() crypto.PubKey {
|
||||||
response, err := sc.endpoint.SendRequest(&PubKeyRequest{})
|
response, err := sc.endpoint.SendRequest(&PubKeyRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -72,7 +72,7 @@ func (sc *SignerClient) GetPubKey() crypto.PubKey {
|
|||||||
return pubKeyResp.PubKey
|
return pubKeyResp.PubKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignVote implements PrivValidator.
|
// SignVote requests a remote signer to sign a vote
|
||||||
func (sc *SignerClient) SignVote(chainID string, vote *types.Vote) error {
|
func (sc *SignerClient) SignVote(chainID string, vote *types.Vote) error {
|
||||||
sc.endpoint.Logger.Debug("SignerClient::SignVote")
|
sc.endpoint.Logger.Debug("SignerClient::SignVote")
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ func (sc *SignerClient) SignVote(chainID string, vote *types.Vote) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignProposal implements PrivValidator.
|
// SignProposal requests a remote signer to sign a proposal
|
||||||
func (sc *SignerClient) SignProposal(chainID string, proposal *types.Proposal) error {
|
func (sc *SignerClient) SignProposal(chainID string, proposal *types.Proposal) error {
|
||||||
response, err := sc.endpoint.SendRequest(&SignProposalRequest{Proposal: proposal})
|
response, err := sc.endpoint.SendRequest(&SignProposalRequest{Proposal: proposal})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ type SignerListenerEndpoint struct {
|
|||||||
listener net.Listener
|
listener net.Listener
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
|
|
||||||
|
timeoutAccept time.Duration
|
||||||
timeoutReadWrite time.Duration
|
timeoutReadWrite time.Duration
|
||||||
|
|
||||||
stopCh, stoppedCh chan struct{}
|
stopCh, stoppedCh chan struct{}
|
||||||
@@ -34,6 +35,7 @@ func NewSignerListenerEndpoint(logger log.Logger, listener net.Listener) *Signer
|
|||||||
|
|
||||||
sc := &SignerListenerEndpoint{
|
sc := &SignerListenerEndpoint{
|
||||||
listener: listener,
|
listener: listener,
|
||||||
|
timeoutAccept: defaultTimeoutAcceptSeconds * time.Second,
|
||||||
timeoutReadWrite: defaultTimeoutReadWriteSeconds * time.Second,
|
timeoutReadWrite: defaultTimeoutReadWriteSeconds * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +78,7 @@ func (sl *SignerListenerEndpoint) OnStop() {
|
|||||||
<-sl.stoppedCh
|
<-sl.stoppedCh
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes the underlying net.Conn.
|
// Close closes the connection
|
||||||
func (sl *SignerListenerEndpoint) Close() error {
|
func (sl *SignerListenerEndpoint) Close() error {
|
||||||
sl.mtx.Lock()
|
sl.mtx.Lock()
|
||||||
defer sl.mtx.Unlock()
|
defer sl.mtx.Unlock()
|
||||||
@@ -100,28 +102,24 @@ func (sl *SignerListenerEndpoint) WaitForConnection(maxWait time.Duration) error
|
|||||||
return sl.ensureConnection(maxWait)
|
return sl.ensureConnection(maxWait)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendRequest sends a request and waits for a response
|
// SendRequest ensures there is a connection, sends a request and waits for a response
|
||||||
func (sl *SignerListenerEndpoint) SendRequest(request RemoteSignerMsg) (RemoteSignerMsg, error) {
|
func (sl *SignerListenerEndpoint) SendRequest(request RemoteSignerMsg) (RemoteSignerMsg, error) {
|
||||||
sl.mtx.Lock()
|
sl.mtx.Lock()
|
||||||
defer sl.mtx.Unlock()
|
defer sl.mtx.Unlock()
|
||||||
|
|
||||||
// TODO: Add retries.. that include dropping the connection and
|
|
||||||
|
|
||||||
sl.Logger.Debug("SignerListenerEndpoint: Send request", "connected", sl.isConnected())
|
sl.Logger.Debug("SignerListenerEndpoint: Send request", "connected", sl.isConnected())
|
||||||
err := sl.ensureConnection(sl.timeoutReadWrite)
|
err := sl.ensureConnection(sl.timeoutAccept)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sl.Logger.Debug("Send request. Write")
|
sl.Logger.Debug("Send request. Write")
|
||||||
|
|
||||||
err = sl.writeMessage(request)
|
err = sl.writeMessage(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sl.Logger.Debug("Send request. Read")
|
sl.Logger.Debug("Send request. Read")
|
||||||
|
|
||||||
res, err := sl.readMessage()
|
res, err := sl.readMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sl.Logger.Debug("Read Error", "err", err)
|
sl.Logger.Debug("Read Error", "err", err)
|
||||||
@@ -131,7 +129,6 @@ func (sl *SignerListenerEndpoint) SendRequest(request RemoteSignerMsg) (RemoteSi
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsConnected indicates if there is an active connection
|
|
||||||
func (sl *SignerListenerEndpoint) isConnected() bool {
|
func (sl *SignerListenerEndpoint) isConnected() bool {
|
||||||
return sl.IsRunning() && sl.conn != nil
|
return sl.IsRunning() && sl.conn != nil
|
||||||
}
|
}
|
||||||
@@ -231,7 +228,6 @@ func (sl *SignerListenerEndpoint) ensureConnection(maxWait time.Duration) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// dropConnection closes the current connection but does not touch the listening socket
|
|
||||||
func (sl *SignerListenerEndpoint) dropConnection() {
|
func (sl *SignerListenerEndpoint) dropConnection() {
|
||||||
if sl.conn != nil {
|
if sl.conn != nil {
|
||||||
if err := sl.conn.Close(); err != nil {
|
if err := sl.conn.Close(); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user