# Path: src/lifeRaft/states/voter.py
# class Voter(State):
# 
#     def __init__(self, timeout=1.0):
#         super(Voter, self).__init__(timeout=timeout)
#         self._last_vote = None
# 
#     def on_vote_request(self, message):
#         if(self._last_vote is None and
#            message.data["lastLogIndex"] >= self._server._lastLogIndex):
#             self._last_vote = message.sender
#             self._send_vote_response_message(message)
#         else:
#             self._send_vote_response_message(message, yes=False)
# 
#         return self, None
# 
#     def _send_vote_response_message(self, msg, yes=True):
#         voteResponse = RequestVoteResponseMessage(
#             self._server._name,
#             msg.sender,
#             msg.term,
#             {"response": yes})
#         self._server.send_message_response(voteResponse)
#     
#     def on_client_message(self, message):
#         ''' return the message response for the client '''
#         return ClientFollowerResponse(message.sender, self._last_vote)


from .voter import Voter
        from .candidate import Candidate
import time
            self._send_response_message(message, yes=False)
            return self, None

        if(message.data != {}):
            log = self._server._log
            data = message.data

            # Check if the leader is too far ahead in the log.
            if(data["leaderCommit"] != self._server._commitIndex):
                # If the leader is too far ahead then we
                #   use the length of the log - 1
                self._server._commitIndex = min(data["leaderCommit"],
                                                len(log) - 1)

            # Can't possibly be up-to-date with the log
            # If the log is smaller than the preLogIndex
            if(len(log) < data["prevLogIndex"]):
                self._send_response_message(message, yes=False)
                return self, None

            # We need to hold the induction proof of the algorithm here.
            #   So, we make sure that the prevLogIndex term is always
            #   equal to the server.
            if(len(log) > 0 and
               log[data["prevLogIndex"]]["term"] != data["prevLogTerm"]):

                # There is a conflict we need to resync so delete everything
                #   from this prevLogIndex and forward and send a failure
                #   to the server.
                log = log[:data["prevLogIndex"]]

# Path: src/lifeRaft/states/voter.py
# class Voter(State):
# 
#     def __init__(self, timeout=1.0):
#         super(Voter, self).__init__(timeout=timeout)
#         self._last_vote = None
# 
#     def on_vote_request(self, message):
#         if(self._last_vote is None and
#            message.data["lastLogIndex"] >= self._server._lastLogIndex):
#             self._last_vote = message.sender
#             self._send_vote_response_message(message)
#         else:
#             self._send_vote_response_message(message, yes=False)
# 
#         return self, None
# 
#     def _send_vote_response_message(self, msg, yes=True):
#         voteResponse = RequestVoteResponseMessage(
#             self._server._name,
#             msg.sender,
#             msg.term,
#             {"response": yes})
#         self._server.send_message_response(voteResponse)
#     
#     def on_client_message(self, message):
#         ''' return the message response for the client '''
#         return ClientFollowerResponse(message.sender, self._last_vote)


# Path: src/lifeRaft/states/follower.py
from .voter import Voter
        from .candidate import Candidate
import time

            self._send_response_message(message, yes=False)
            return self, None

        if(message.data != {}):
            log = self._server._log
            data = message.data

            # Check if the leader is too far ahead in the log.
            if(data["leaderCommit"] != self._server._commitIndex):
                # If the leader is too far ahead then we
                #   use the length of the log - 1
                self._server._commitIndex = min(data["leaderCommit"],
                                                len(log) - 1)

            # Can't possibly be up-to-date with the log
            # If the log is smaller than the preLogIndex
            if(len(log) < data["prevLogIndex"]):
                self._send_response_message(message, yes=False)
                return self, None

            # We need to hold the induction proof of the algorithm here.
            #   So, we make sure that the prevLogIndex term is always
            #   equal to the server.
            if(len(log) > 0 and
               log[data["prevLogIndex"]]["term"] != data["prevLogTerm"]):

                # There is a conflict we need to resync so delete everything
                #   from this prevLogIndex and forward and send a failure
                #   to the server.
                log = log[:data["prevLogIndex"]]

                self._send_response_message(message, yes=False)