Struct Proposer

Source
pub struct Proposer<T> {
    pub id: u64,
    pub messenger: Option<Box<dyn Messenger<T>>>,
    pub value: Option<Arc<T>>,
    pub proposal_n: u64,
    pub last_accepted_n: u64,
    pub promises_received: HashMap<u64, HashSet<PromiseData<T>>>,
    pub accepted_received: HashMap<u64, HashSet<AcceptedData<T>>>,
    pub quorum: u8,
}
Expand description

A Proposer advocates a client request, attempting to convince the Acceptors to agree on it, and acting as a coordinator to move the protocol forward when conflicts occur.

Fields§

§id: u64

Proposer’s ID

§messenger: Option<Box<dyn Messenger<T>>>

Messenger specifying communication with other nodes

§value: Option<Arc<T>>

The proposed value

§proposal_n: u64

The highest proposal number seen

§last_accepted_n: u64

The last proposal that was accepted

§promises_received: HashMap<u64, HashSet<PromiseData<T>>>

Promises received (proposal_n => data)

§accepted_received: HashMap<u64, HashSet<AcceptedData<T>>>

Accepted messages received (proposal_n => data)

§quorum: u8

The minimum number of Acceptors needed to continue

Implementations§

Source§

impl<T> Proposer<T>
where T: Eq + Hash + Clone + 'static,

Source

pub fn new(id: u64, quorum: u8) -> Self

Creates a new Proposer.

Source

pub fn prepare(&mut self, value: T)

The first phase. Creates a proposal.

Source

pub fn receive_promise(&mut self, msg: Message<T>)

Receives a Promise message from an Acceptor.

Source

pub fn accept(&mut self)

The second phase. Sets a value for the proposal, and builds an Accept request.

Source

pub fn receive_accepted(&mut self, msg: Message<T>)

Receives an Accepted message from an Acceptor.

Trait Implementations§

Source§

impl<T> Default for Proposer<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Proposer<T>

§

impl<T> !RefUnwindSafe for Proposer<T>

§

impl<T> !Send for Proposer<T>

§

impl<T> !Sync for Proposer<T>

§

impl<T> Unpin for Proposer<T>

§

impl<T> !UnwindSafe for Proposer<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.