pub struct NodeService<C: Client> { /* private fields */ }

Implementations§

source§

impl<C: Client + Clone + Sync + Send + 'static> NodeService<C>

source

pub fn new(socket_addr: SocketAddr, replication_factor: usize) -> Self

Create a new node service

Arguments
  • socket_addr - The address of the node
  • replication_factor - The number of successors to keep track of
source

pub fn id(&self) -> NodeId

source

pub async fn find_successor(&self, id: NodeId) -> Result<Node, ServiceError>

Find the successor of the given id.

If the given id is in the range of the current node and its successor, the successor is returned. Otherwise, the successor of the closest preceding node is returned.

Arguments
  • id - The id to find the successor for
source

pub async fn get_predecessor(&self) -> Result<Option<Node>, ServiceError>

source

pub async fn get_successor(&self) -> Result<Node, ServiceError>

source

pub async fn get_successor_list(&self) -> Result<Vec<Node>, ServiceError>

source

pub async fn join(&self, node: Node) -> Result<(), ServiceError>

Join the chord ring.

This method is used to join the chord ring. It will find the successor of its own id and set it as the successor.

Arguments
  • node - The node to join the ring with. It’s an existing node in the ring.
source

pub fn notify(&self, node: Node)

Notify the node about a potential new predecessor.

If the predecessor is not set or the given node is in the range of the current node and the predecessor, the predecessor is set to the given node.

Arguments
  • node - The node which might be the new predecessor
source

pub async fn stabilize(&self) -> Result<(), ServiceError>

Stabilize the node

This method is used to stabilize the node. It will check if a predecessor of the successor is in the range of the current node and its successor. If so, the successor will be set to the retrieved predecessor.

It will also notify the successor about the current node.

Note

This method should be called periodically.

source

pub async fn reconcile_successors(&self)

source

pub async fn check_predecessor(&self) -> Result<(), ServiceError>

Check predecessor

This method is used to check if the predecessor is still alive. If not, the predecessor is set to None.

Note

This method should be called periodically.

source

pub async fn fix_fingers(&self)

Fix fingers

This method is used to fix the fingers. It iterates over all fingers and re-requests the successor of the finger’s id. Then sets the successor of the finger to the retrieved node.

Note

This method should be called periodically.

source

pub fn finger_table(&self) -> Vec<Finger>

Get finger table

This method is used to get the finger table of the node.

Trait Implementations§

source§

impl<C: Debug + Client> Debug for NodeService<C>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C> RefUnwindSafe for NodeService<C>

§

impl<C> Send for NodeService<C>where C: Send + Sync,

§

impl<C> Sync for NodeService<C>where C: Send + Sync,

§

impl<C> Unpin for NodeService<C>

§

impl<C> UnwindSafe for NodeService<C>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for Twhere T: Any,

§

fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for Twhere T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync + 'static>

source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.