from proposer import Proposer
from paxosmessenger import Messenger

class Acceptor():
    highest_proposal = None
    highest_promise = None
    messenger = None

    def __init__(self, messenger: Messenger):
        self.messenger = messenger

    def on_message(self, client, userdata, message):
        pass

    def prepare(self):
        pass

    def accept_request(self, fromt_uid, proposal_id, value):
        '''
        Called when an accept message is received from a proposer
        '''
        if proposal_id >= self.highest_promise:
            self.highest_promise     = proposal_id
            self.accepted_id     = proposal_id
            self.accepted_value  = value
            self.messenger.send_accepted(proposal_id, self.accepted_value)