Struct rings_core::dht::vnode::VirtualNode
source · Expand description
A VirtualNode is a piece of data with VNodeType and Did. You can save it to
PeerRing by ChordStorage protocol.
The Did of a Virtual Node is in the following format:
- If type value is VNodeType::Data, it’s sha1 of data field.
- If type value is VNodeType::SubRing, it’s sha1 of SubRing name.
- If type value is VNodeType::RelayMessage, it’s the destination Did of message plus 1 (to ensure that the message is sent to the successor of destination), thus while destination node going online, it will sync message from its successor.
Fields§
§did: DidThe did of VirtualNode make it unique, and can be stored and retrieved on DHT.
data: Vec<Encoded>The data entity of VirtualNode, encoded by Encoder.
kind: VNodeTypeThe type indicates how the data is encoded and how the Did is generated.
Implementations§
source§impl VirtualNode
impl VirtualNode
sourcepub fn concat(a: &Self, b: &Self) -> Result<Self>
pub fn concat(a: &Self, b: &Self) -> Result<Self>
concat data of a virtual Node We do not needs to check the type of VNode because two VNode with same did but has different Type is incapable
Examples found in repository?
src/dht/chord.rs (line 380)
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
async fn store(&self, vnode: VirtualNode) -> Result<PeerRingAction> {
let vid = vnode.did;
match self.find_successor(vid) {
// `vnode` should be stored in current node.
Ok(PeerRingAction::Some(_)) => match self.storage.get(&vid).await {
Ok(v) => {
let _ = self
.storage
.put(&vid, &VirtualNode::concat(&v, &vnode)?)
.await?;
Ok(PeerRingAction::None)
}
Err(_) => {
let _ = self.storage.put(&vid, &vnode).await?;
Ok(PeerRingAction::None)
}
},
// `vnode` should be stored in other nodes.
// Return an action to describe how to store it.
Ok(PeerRingAction::RemoteAction(n, RemoteAction::FindSuccessor(_))) => Ok(
PeerRingAction::RemoteAction(n, RemoteAction::FindAndStore(vnode)),
),
Ok(a) => Err(Error::PeerRingUnexpectedAction(a)),
Err(e) => Err(e),
}
}Trait Implementations§
source§impl Clone for VirtualNode
impl Clone for VirtualNode
source§fn clone(&self) -> VirtualNode
fn clone(&self) -> VirtualNode
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for VirtualNode
impl Debug for VirtualNode
source§impl<'de> Deserialize<'de> for VirtualNode
impl<'de> Deserialize<'de> for VirtualNode
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl PartialEq<VirtualNode> for VirtualNode
impl PartialEq<VirtualNode> for VirtualNode
source§fn eq(&self, other: &VirtualNode) -> bool
fn eq(&self, other: &VirtualNode) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl Serialize for VirtualNode
impl Serialize for VirtualNode
source§impl TryFrom<Encoded> for VirtualNode
impl TryFrom<Encoded> for VirtualNode
source§impl<T> TryFrom<MessagePayload<T>> for VirtualNodewhere
T: Serialize + DeserializeOwned,
impl<T> TryFrom<MessagePayload<T>> for VirtualNodewhere
T: Serialize + DeserializeOwned,
source§impl TryFrom<String> for VirtualNode
impl TryFrom<String> for VirtualNode
source§impl TryFrom<SubRing> for VirtualNode
impl TryFrom<SubRing> for VirtualNode
source§impl TryFrom<VirtualNode> for SubRing
impl TryFrom<VirtualNode> for SubRing
impl Eq for VirtualNode
impl StructuralEq for VirtualNode
impl StructuralPartialEq for VirtualNode
Auto Trait Implementations§
impl RefUnwindSafe for VirtualNode
impl Send for VirtualNode
impl Sync for VirtualNode
impl Unpin for VirtualNode
impl UnwindSafe for VirtualNode
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T> AsTaggedExplicit<'a> for Twhere
T: 'a,
impl<'a, T> AsTaggedExplicit<'a> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T> AsTaggedImplicit<'a> for Twhere
T: 'a,
impl<'a, T> AsTaggedImplicit<'a> for Twhere
T: 'a,
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.