pub struct PeerRing {
pub did: Did,
pub finger: Arc<Mutex<FingerTable>>,
pub successor_seq: SuccessorSeq,
pub predecessor: Arc<Mutex<Option<Did>>>,
pub storage: Box<dyn KvStorageInterface<Entry> + Send + Sync>,
pub cache: Box<dyn KvStorageInterface<Entry> + Send + Sync>,
}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: DidThe did of current node.
finger: Arc<Mutex<FingerTable>>FingerTable help node to find successor quickly.
successor_seq: SuccessorSeqThe 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: Box<dyn KvStorageInterface<Entry> + Send + Sync>Local storage for ChordStorage.
cache: Box<dyn KvStorageInterface<Entry> + Send + Sync>Local cache for ChordStorage.
Implementations§
Source§impl PeerRing
impl PeerRing
Sourcepub fn new_with_storage(
did: Did,
succ_max: u8,
storage: Box<dyn KvStorageInterface<Entry> + Send + Sync>,
) -> PeerRing
pub fn new_with_storage( did: Did, succ_max: u8, storage: Box<dyn KvStorageInterface<Entry> + Send + Sync>, ) -> PeerRing
Same as new with config, but with a given storage.
Sourcepub fn new_with_storage_and_finger_table_size(
did: Did,
succ_max: u8,
storage: Box<dyn KvStorageInterface<Entry> + Send + Sync>,
finger_table_size: usize,
) -> PeerRing
pub fn new_with_storage_and_finger_table_size( did: Did, succ_max: u8, storage: Box<dyn KvStorageInterface<Entry> + Send + Sync>, finger_table_size: usize, ) -> PeerRing
Same as new with config, but with a given storage and finger table size.
Did is 160-bit. Sizes above DEFAULT_FINGER_TABLE_SIZE are clamped
by FingerTable::new; zero is allowed to disable finger maintenance.
Sourcepub fn lock_successor(&self) -> Result<SuccessorSeq, Error>
👎Deprecated
pub fn lock_successor(&self) -> Result<SuccessorSeq, Error>
Return successor sequence. This function is deprecated, please use [chord.successors] instead.
Sourcepub fn successors(&self) -> SuccessorSeq
pub fn successors(&self) -> SuccessorSeq
Return successor sequence
Sourcepub fn lock_finger(&self) -> Result<MutexGuard<'_, FingerTable>, Error>
pub fn lock_finger(&self) -> Result<MutexGuard<'_, FingerTable>, Error>
Lock and return MutexGuard of finger table.
Sourcepub fn lock_predecessor(&self) -> Result<MutexGuard<'_, Option<Did>>, Error>
pub fn lock_predecessor(&self) -> Result<MutexGuard<'_, Option<Did>>, Error>
Lock and return MutexGuard of predecessor.
Trait Implementations§
Source§impl Chord<PeerRingAction> for PeerRing
impl Chord<PeerRingAction> for PeerRing
Source§fn join(&self, did: Did) -> Result<PeerRingAction, Error>
fn join(&self, did: Did) -> Result<PeerRingAction, Error>
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, Error>
fn find_successor(&self, did: Did) -> Result<PeerRingAction, Error>
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<Did, Error>
fn notify(&self, did: Did) -> Result<Did, Error>
Handle notification from a node that thinks a did is the predecessor of current node.
The did in parameters is the Did of that predecessor.
If that node is closer to current node or current node has no predecessor, set it to the did.
This method will return current predecessor after setting.
Source§fn fix_fingers(&self) -> Result<PeerRingAction, Error>
fn fix_fingers(&self) -> Result<PeerRingAction, Error>
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
impl<const REDUNDANT: u16> ChordStorage<PeerRingAction, REDUNDANT> for PeerRing
Source§fn entry_lookup<'life0, 'async_trait>(
&'life0 self,
entry_key: Did,
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
fn entry_lookup<'life0, 'async_trait>(
&'life0 self,
entry_key: Did,
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
Look up an Entry by its ring key.
Always finds resource by finger table, ignoring the local cache.
If the entry_key is between current node and its successor, its resource should be
stored in current node.
Source§fn entry_operate<'life0, 'async_trait>(
&'life0 self,
op: EntryOperation,
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
fn entry_operate<'life0, 'async_trait>(
&'life0 self,
op: EntryOperation,
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
Handle EntryOperation if the target entry between current node and the successor of current node, otherwise find the responsible node and return as Action.
Source§impl ChordStorageCache<PeerRingAction> for PeerRing
impl ChordStorageCache<PeerRingAction> for PeerRing
Source§impl ChordStorageRepair<PeerRingAction> for PeerRing
impl ChordStorageRepair<PeerRingAction> for PeerRing
Source§fn republish_local_entries<'life0, 'async_trait>(
&'life0 self,
redundancy: u16,
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
fn republish_local_entries<'life0, 'async_trait>(
&'life0 self,
redundancy: u16,
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
Source§fn read_repair_entry<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: Entry,
misses: &'life1 [PlacementMiss],
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PeerRing: 'async_trait,
fn read_repair_entry<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: Entry,
misses: &'life1 [PlacementMiss],
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PeerRing: 'async_trait,
Source§impl ChordStorageSync<PeerRingAction> for PeerRing
impl ChordStorageSync<PeerRingAction> for PeerRing
Source§fn sync_entries_with_successor<'life0, 'async_trait>(
&'life0 self,
new_successor: Did,
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
fn sync_entries_with_successor<'life0, 'async_trait>(
&'life0 self,
new_successor: Did,
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
When the successor of a node is updated, it needs to check if there are
Entrys that are no longer between current node and new_successor,
and copy them to the new successor.
Source§fn acknowledge_synced_entries<'life0, 'life1, 'async_trait>(
&'life0 self,
acks: &'life1 [SyncedEntryAck],
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PeerRing: 'async_trait,
fn acknowledge_synced_entries<'life0, 'life1, 'async_trait>(
&'life0 self,
acks: &'life1 [SyncedEntryAck],
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PeerRing: 'async_trait,
Source§impl CorrectChord<PeerRingAction> for PeerRing
impl CorrectChord<PeerRingAction> for PeerRing
Source§fn update_successor<'life0, 'async_trait>(
&'life0 self,
did: impl LiveDid + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
fn update_successor<'life0, 'async_trait>(
&'life0 self,
did: impl LiveDid + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
When Chord have a new successor, ask the new successor for successor list
Source§fn join_then_sync<'life0, 'async_trait>(
&'life0 self,
did: impl LiveDid + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
fn join_then_sync<'life0, 'async_trait>(
&'life0 self,
did: impl LiveDid + 'async_trait,
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
Join Operation in the paper. Zave’s work differs from the original Chord paper in that it requires a newly joined node to synchronize its successors from remote nodes.
Source§fn rectify(&self, pred: Did) -> Result<(), Error>
fn rectify(&self, pred: Did) -> Result<(), Error>
HMCC/Zave Rectify operation.
Rectify is the local predecessor transition run when this node receives
a predecessor notification from pred. It has no remote action: the
message layer’s report path is handled by NotifyPredecessorSend.
Source§fn pre_stabilize(&self) -> Result<PeerRingAction, Error>
fn pre_stabilize(&self) -> Result<PeerRingAction, Error>
Pre-Stabilize Operation: Before stabilizing, the node should query its first successor for TopoInfo. If there are no successors, return PeerRingAction::None.
Source§fn stabilize(&self, info: TopoInfo) -> Result<PeerRingAction, Error>
fn stabilize(&self, info: TopoInfo) -> Result<PeerRingAction, Error>
Stabilize Operation:
Mirrors the TLA+-style CorrectStabilize operator in
tests/default/dht_convergence.rs.
The old head is captured before updating successors for the improved-successor
query check; the remote successor list contributes but_last; and notify
is emitted for the post-update head when that head is not self.
Source§fn topo_info(&self) -> Result<TopoInfo, Error>
fn topo_info(&self) -> Result<TopoInfo, Error>
A function to provide topological information about the chord.
Source§fn extend_successor<'life0, 'life1, 'async_trait>(
&'life0 self,
dids: &'life1 [impl LiveDid + 'async_trait],
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PeerRing: 'async_trait,
fn extend_successor<'life0, 'life1, 'async_trait>(
&'life0 self,
dids: &'life1 [impl LiveDid + 'async_trait],
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PeerRing: 'async_trait,
Auto Trait Implementations§
impl !RefUnwindSafe for PeerRing
impl !UnwindSafe for PeerRing
impl Freeze for PeerRing
impl Send for PeerRing
impl Sync for PeerRing
impl Unpin for PeerRing
impl UnsafeUnpin for PeerRing
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
impl<T> MaybeSend for T
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.