Location: paxos/essential.py

class Proposer (object):

    messenger            = None
    proposer_uid         = None
    quorum_size          = None

    proposed_value       = None
    proposal_id          = None 
    last_accepted_id     = None
    next_proposal_number = 1
    promises_rcvd        = None

    
    def set_proposal(self, value):
        if self.proposed_value is None:
            self.proposed_value = value

    def prepare(self):
        self.promises_rcvd = set()
        self.proposal_id   = ProposalID(self.next_proposal_number, self.proposer_uid)
        
        self.next_proposal_number += 1

        self.messenger.send_prepare(self.proposal_id)

    
    def recv_promise(self, from_uid, proposal_id, prev_accepted_id, prev_accepted_value):

        if proposal_id != self.proposal_id or from_uid in self.promises_rcvd:
            return

        self.promises_rcvd.add( from_uid )
        
        if prev_accepted_id > self.last_accepted_id:
            self.last_accepted_id = prev_accepted_id
            if prev_accepted_value is not None:
                self.proposed_value = prev_accepted_value

        if len(self.promises_rcvd) == self.quorum_size:
            if self.proposed_value is not None:
                self.messenger.send_accept(self.proposal_id, self.proposed_value)