Struct chord_rs_core::NodeService
source · pub struct NodeService<C: Client> { /* private fields */ }Implementations§
source§impl<C: Client + Clone + Sync + Send + 'static> NodeService<C>
impl<C: Client + Clone + Sync + Send + 'static> NodeService<C>
sourcepub fn new(socket_addr: SocketAddr, replication_factor: usize) -> Self
pub fn new(socket_addr: SocketAddr, replication_factor: usize) -> Self
Create a new node service
Arguments
socket_addr- The address of the nodereplication_factor- The number of successors to keep track of
pub fn id(&self) -> NodeId
sourcepub async fn find_successor(&self, id: NodeId) -> Result<Node, ServiceError>
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
pub async fn get_predecessor(&self) -> Result<Option<Node>, ServiceError>
pub async fn get_successor(&self) -> Result<Node, ServiceError>
pub async fn get_successor_list(&self) -> Result<Vec<Node>, ServiceError>
sourcepub async fn join(&self, node: Node) -> Result<(), ServiceError>
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.
sourcepub fn notify(&self, node: Node)
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
sourcepub async fn stabilize(&self) -> Result<(), ServiceError>
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.
pub async fn reconcile_successors(&self)
sourcepub async fn check_predecessor(&self) -> Result<(), ServiceError>
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.
sourcepub async fn fix_fingers(&self)
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.
sourcepub fn finger_table(&self) -> Vec<Finger>
pub fn finger_table(&self) -> Vec<Finger>
Get finger table
This method is used to get the finger table of the node.