Skip to main content

SyncState

Struct SyncState 

Source
pub struct SyncState {
    pub node_id: Uuid,
    pub clock: VectorClock,
    pub peers: HashMap<Uuid, PeerState>,
    pub config: SyncConfig,
    /* private fields */
}
Expand description

The synchronization state for a node.

Fields§

§node_id: Uuid

This node’s ID

§clock: VectorClock

Current vector clock

§peers: HashMap<Uuid, PeerState>

Known peers

§config: SyncConfig

Configuration

Implementations§

Source§

impl SyncState

Source

pub fn new(node_id: Uuid) -> Self

Create a new sync state for a node.

Source

pub fn with_config(node_id: Uuid, config: SyncConfig) -> Self

Create with custom configuration.

Source

pub fn register_peer(&mut self, peer_id: Uuid, clock: VectorClock)

Register a new peer.

Source

pub fn register_peer_with_info(&mut self, info: PeerInfo, clock: VectorClock)

Register a peer with full info.

Source

pub fn remove_peer(&mut self, peer_id: &Uuid)

Remove a peer.

Source

pub fn get_peer(&self, peer_id: &Uuid) -> Option<&PeerState>

Get a peer’s state.

Source

pub fn get_peer_mut(&mut self, peer_id: &Uuid) -> Option<&mut PeerState>

Get a mutable reference to a peer’s state.

Source

pub fn tick(&mut self) -> u64

Update our clock and get next message ID.

Source

pub fn create_hello(&mut self, name: Option<String>) -> SyncMessage

Create a hello message.

Source

pub fn create_delta_request(&mut self, since_clock: VectorClock) -> SyncMessage

Create a delta request message.

Source

pub fn create_delta_response( &mut self, deltas: DeltaBatch, has_more: bool, ) -> SyncMessage

Create a delta response message.

Source

pub fn create_full_state(&mut self, state: GA3) -> SyncMessage

Create a full state message.

Source

pub fn create_heartbeat(&mut self) -> SyncMessage

Create a heartbeat message.

Source

pub fn create_ack(&mut self, message_id: u64) -> SyncMessage

Create an acknowledgment message.

Source

pub fn create_goodbye(&mut self) -> SyncMessage

Create a goodbye message.

Source

pub fn handle_message(&mut self, message: &SyncMessage) -> Option<SyncMessage>

Handle an incoming message from a peer.

Source

pub fn stale_peers(&self) -> Vec<Uuid>

Get list of stale peers that should be checked.

Source

pub fn peers_needing_heartbeat(&self) -> Vec<Uuid>

Get peers that need heartbeats.

Trait Implementations§

Source§

impl Debug for SyncState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.