Struct rings_core::dht::PeerRing

source ·
pub struct PeerRing {
    pub did: Did,
    pub finger: Arc<Mutex<FingerTable>>,
    pub successor_seq: SuccessorSeq,
    pub predecessor: Arc<Mutex<Option<Did>>>,
    pub storage: Arc<PersistenceStorage>,
    pub cache: Arc<MemStorage<Did, VirtualNode>>,
}
Expand description

PeerRing is used to help a node interact with other nodes. All nodes in rings network form a clockwise ring in the order of Did. This struct takes its name from that. PeerRing implemented Chord algorithm. PeerRing implemented ChordStorage protocol.

Fields§

§did: Did

The did of current node.

§finger: Arc<Mutex<FingerTable>>

FingerTable help node to find successor quickly.

§successor_seq: SuccessorSeq

The next node on the ring. The SuccessorSeq may contain multiple node dids for fault tolerance. The min did should be same as the first element in finger table.

§predecessor: Arc<Mutex<Option<Did>>>

The did of previous node on the ring.

§storage: Arc<PersistenceStorage>

Local storage for ChordStorage.

§cache: Arc<MemStorage<Did, VirtualNode>>

Local cache for ChordStorage.

Implementations§

source§

impl PeerRing

source

pub fn new_with_storage( did: Did, succ_max: u8, storage: PersistenceStorage ) -> Self

Same as new with config, but with a given storage.

source

pub fn lock_successor(&self) -> Result<SuccessorSeq>

👎Deprecated

Return successor sequence. This function is deprecated, please use [chord.successors] instead.

source

pub fn successors(&self) -> SuccessorSeq

Return successor sequence

source

pub fn lock_finger(&self) -> Result<MutexGuard<'_, FingerTable>>

Lock and return MutexGuard of finger table.

source

pub fn lock_predecessor(&self) -> Result<MutexGuard<'_, Option<Did>>>

Lock and return MutexGuard of predecessor.

source

pub fn remove(&self, did: Did) -> Result<()>

Remove a node from finger table. Also remove it from successor sequence. If successor_seq become empty, try setting the closest node to it.

source

pub fn bias(&self, did: Did) -> BiasId

Calculate bias of the Did on the ring.

Trait Implementations§

source§

impl Chord<PeerRingAction> for PeerRing

source§

fn join(&self, did: Did) -> Result<PeerRingAction>

Join a ring containing a node identified by did. This method is usually invoked to maintain successor sequence and finger table after connect to another node.

This method will return a RemoteAction::FindSuccessorForConnect to the caller. The caller will send it to the node identified by did, and let the node find the successor of current node and make current node connect to that successor.

source§

fn find_successor(&self, did: Did) -> Result<PeerRingAction>

Find the successor of a Did. May return a remote action for the successor is recorded in another node.

source§

fn notify(&self, did: Did) -> Result<Option<Did>>

Handle notification from a node that thinks it is the predecessor of current node. The did in parameters is the Did of that node. If that node is closer to current node or current node has no predecessor, set it to the did. This method will return that did if it is set to the predecessor.

source§

fn fix_fingers(&self) -> Result<PeerRingAction>

Fix finger table by finding the successor for each finger. According to the paper, this method should be called periodically. According to the paper, only one finger should be fixed at a time.

source§

impl<const REDUNDANT: u16> ChordStorage<PeerRingAction, REDUNDANT> for PeerRing

source§

fn vnode_lookup<'life0, 'async_trait>( &'life0 self, vid: Did ) -> Pin<Box<dyn Future<Output = Result<PeerRingAction>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Look up a VirtualNode by its Did. Always finds resource by finger table, ignoring the local cache. If the vid is between current node and its successor, its resource should be stored in current node.

source§

fn vnode_operate<'life0, 'async_trait>( &'life0 self, op: VNodeOperation ) -> Pin<Box<dyn Future<Output = Result<PeerRingAction>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Handle VNodeOperation if the target vnode between current node and the successor of current node, otherwise find the responsible node and return as Action.

source§

impl ChordStorageCache<PeerRingAction> for PeerRing

source§

fn local_cache_set(&self, vnode: VirtualNode)

Cache fetched vnode locally.

source§

fn local_cache_get(&self, vid: Did) -> Option<VirtualNode>

Get vnode from local cache.

source§

impl ChordStorageSync<PeerRingAction> for PeerRing

source§

fn sync_vnode_with_successor<'life0, 'async_trait>( &'life0 self, new_successor: Did ) -> Pin<Box<dyn Future<Output = Result<PeerRingAction>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

When the successor of a node is updated, it needs to check if there are VirtualNodes that are no longer between current node and new_successor, and sync them to the new successor.

source§

impl Clone for PeerRing

source§

fn clone(&self) -> PeerRing

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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<'a, T> AsTaggedExplicit<'a> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self>

§

impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T> AsTaggedImplicit<'a> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more