Exemplo n.º 1
0
// StatusRPC implements the Election.Status rpc.
func (this *Election) StatusRPC(reqHeader *msgpb.Header,
	request *thispb.StatusRequest) error {

	if !this.InCommittee() {
		this.Errorf("this election object is not a committee member")
		return errs.ErrNotExist
	}

	lock := this.ctlr.ReadLock("election")
	round := this.CurrentRound()
	winner := this.currentWinner
	lock.Unlock()

	// Committee members always have up to date election information.
	response := thispb.StatusResponse{}
	response.ElectionRound = proto.Int64(round)
	response.ElectionWinner = proto.String(winner)
	message := thispb.ElectionMessage{}
	message.StatusResponse = &response

	clientID := reqHeader.GetMessengerId()
	if err := msg.SendResponseProto(this.msn, reqHeader, &message); err != nil {
		this.Errorf("could not send status response to %s: %v", clientID, err)
		return err
	}
	return nil
}