wip: Comment types

* add comments to all public types
* fix comments to adhere to comment standards
This commit is contained in:
Alexander Simmerl 2018-01-17 17:12:04 +01:00 committed by Ethan Buchman
parent 23eb84db35
commit c27fda09dd

View File

@ -34,7 +34,8 @@ const (
dialRetryIntervalSeconds = 1 dialRetryIntervalSeconds = 1
) )
// NewPrivValidatorSocket returns an instance of PrivValidatorSocket. // NewPrivValidatorSocketClient returns an instance of
// PrivValidatorSocketClient.
func NewPrivValidatorSocketClient(logger log.Logger, socketAddr string) *PrivValidatorSocketClient { func NewPrivValidatorSocketClient(logger log.Logger, socketAddr string) *PrivValidatorSocketClient {
pvsc := &PrivValidatorSocketClient{ pvsc := &PrivValidatorSocketClient{
SocketAddress: socketAddr, SocketAddress: socketAddr,
@ -43,6 +44,7 @@ func NewPrivValidatorSocketClient(logger log.Logger, socketAddr string) *PrivVal
return pvsc return pvsc
} }
// OnStart implements cmn.Service.
func (pvsc *PrivValidatorSocketClient) OnStart() error { func (pvsc *PrivValidatorSocketClient) OnStart() error {
if err := pvsc.BaseService.OnStart(); err != nil { if err := pvsc.BaseService.OnStart(); err != nil {
return err return err
@ -63,6 +65,7 @@ RETRY_LOOP:
} }
} }
// OnStop implements cmn.Service.
func (pvsc *PrivValidatorSocketClient) OnStop() { func (pvsc *PrivValidatorSocketClient) OnStop() {
pvsc.BaseService.OnStop() pvsc.BaseService.OnStop()
@ -71,11 +74,13 @@ func (pvsc *PrivValidatorSocketClient) OnStop() {
} }
} }
// Address is an alias for PubKey().Address().
func (pvsc *PrivValidatorSocketClient) Address() data.Bytes { func (pvsc *PrivValidatorSocketClient) Address() data.Bytes {
pubKey := pvsc.PubKey() pubKey := pvsc.PubKey()
return pubKey.Address() return pubKey.Address()
} }
// PubKey implements PrivValidator.
func (pvsc *PrivValidatorSocketClient) PubKey() crypto.PubKey { func (pvsc *PrivValidatorSocketClient) PubKey() crypto.PubKey {
res, err := readWrite(pvsc.conn, PubKeyMsg{}) res, err := readWrite(pvsc.conn, PubKeyMsg{})
if err != nil { if err != nil {
@ -84,6 +89,7 @@ func (pvsc *PrivValidatorSocketClient) PubKey() crypto.PubKey {
return res.(PubKeyMsg).PubKey return res.(PubKeyMsg).PubKey
} }
// SignVote implements PrivValidator.
func (pvsc *PrivValidatorSocketClient) SignVote(chainID string, vote *types.Vote) error { func (pvsc *PrivValidatorSocketClient) SignVote(chainID string, vote *types.Vote) error {
res, err := readWrite(pvsc.conn, SignVoteMsg{Vote: vote}) res, err := readWrite(pvsc.conn, SignVoteMsg{Vote: vote})
if err != nil { if err != nil {
@ -93,6 +99,7 @@ func (pvsc *PrivValidatorSocketClient) SignVote(chainID string, vote *types.Vote
return nil return nil
} }
// SignProposal implements PrivValidator.
func (pvsc *PrivValidatorSocketClient) SignProposal(chainID string, proposal *types.Proposal) error { func (pvsc *PrivValidatorSocketClient) SignProposal(chainID string, proposal *types.Proposal) error {
res, err := readWrite(pvsc.conn, SignProposalMsg{Proposal: proposal}) res, err := readWrite(pvsc.conn, SignProposalMsg{Proposal: proposal})
if err != nil { if err != nil {
@ -102,6 +109,7 @@ func (pvsc *PrivValidatorSocketClient) SignProposal(chainID string, proposal *ty
return nil return nil
} }
// SignHeartbeat implements PrivValidator.
func (pvsc *PrivValidatorSocketClient) SignHeartbeat(chainID string, heartbeat *types.Heartbeat) error { func (pvsc *PrivValidatorSocketClient) SignHeartbeat(chainID string, heartbeat *types.Heartbeat) error {
res, err := readWrite(pvsc.conn, SignHeartbeatMsg{Heartbeat: heartbeat}) res, err := readWrite(pvsc.conn, SignHeartbeatMsg{Heartbeat: heartbeat})
if err != nil { if err != nil {
@ -126,6 +134,8 @@ type PrivValidatorSocketServer struct {
chainID string chainID string
} }
// NewPrivValidatorSocketServer returns an instance of
// PrivValidatorSocketServer.
func NewPrivValidatorSocketServer(logger log.Logger, socketAddr, chainID string, privVal PrivValidator) *PrivValidatorSocketServer { func NewPrivValidatorSocketServer(logger log.Logger, socketAddr, chainID string, privVal PrivValidator) *PrivValidatorSocketServer {
proto, addr := cmn.ProtocolAndAddress(socketAddr) proto, addr := cmn.ProtocolAndAddress(socketAddr)
pvss := &PrivValidatorSocketServer{ pvss := &PrivValidatorSocketServer{
@ -138,6 +148,7 @@ func NewPrivValidatorSocketServer(logger log.Logger, socketAddr, chainID string,
return pvss return pvss
} }
// OnStart implements cmn.Service.
func (pvss *PrivValidatorSocketServer) OnStart() error { func (pvss *PrivValidatorSocketServer) OnStart() error {
if err := pvss.BaseService.OnStart(); err != nil { if err := pvss.BaseService.OnStart(); err != nil {
return err return err
@ -151,6 +162,7 @@ func (pvss *PrivValidatorSocketServer) OnStart() error {
return nil return nil
} }
// OnStop implements cmn.Service.
func (pvss *PrivValidatorSocketServer) OnStop() { func (pvss *PrivValidatorSocketServer) OnStop() {
pvss.BaseService.OnStop() pvss.BaseService.OnStop()
if err := pvss.listener.Close(); err != nil { if err := pvss.listener.Close(); err != nil {
@ -226,6 +238,8 @@ const (
msgTypeSignHeartbeat = byte(0x12) msgTypeSignHeartbeat = byte(0x12)
) )
// PrivValidatorSocketMsg is a message sent between PrivValidatorSocket client
// and server.
type PrivValidatorSocketMsg interface{} type PrivValidatorSocketMsg interface{}
var _ = wire.RegisterInterface( var _ = wire.RegisterInterface(
@ -256,18 +270,22 @@ func decodeMsg(bz []byte) (msg PrivValidatorSocketMsg, err error) {
return msg, err return msg, err
} }
// PubKeyMsg is a PrivValidatorSocket message containing the public key.
type PubKeyMsg struct { type PubKeyMsg struct {
PubKey crypto.PubKey PubKey crypto.PubKey
} }
// SignVoteMsg is a PrivValidatorSocket message containing a vote.
type SignVoteMsg struct { type SignVoteMsg struct {
Vote *types.Vote Vote *types.Vote
} }
// SignProposalMsg is a PrivValidatorSocket message containing a Proposal.
type SignProposalMsg struct { type SignProposalMsg struct {
Proposal *types.Proposal Proposal *types.Proposal
} }
// SignHeartbeatMsg is a PrivValidatorSocket message containing a Heartbeat.
type SignHeartbeatMsg struct { type SignHeartbeatMsg struct {
Heartbeat *types.Heartbeat Heartbeat *types.Heartbeat
} }