pub struct VirtualNode {
    pub did: Did,
    pub data: Vec<Encoded>,
    pub kind: VNodeType,
}
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: Did

The 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: VNodeType

The type indicates how the data is encoded and how the Did is generated.

Implementations§

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

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

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more