From 2b595018690fe57f190bda1b1390f6203ab64a08 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Mon, 21 Oct 2024 12:38:52 -0400 Subject: [PATCH] Fix TODO's in docs Also fix some small lints --- src/common/node.rs | 7 ++++++- src/common/peer.rs | 11 ++++++----- src/storage/mod.rs | 6 +----- src/tree/merkle_tree_changeset.rs | 4 ++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/common/node.rs b/src/common/node.rs index 7e339d3..1c78144 100644 --- a/src/common/node.rs +++ b/src/common/node.rs @@ -14,16 +14,21 @@ pub(crate) struct NodeByteRange { pub(crate) length: u64, } -/// Nodes that are persisted to disk. +/// Nodes of the Merkle Tree that are persisted to disk. // TODO: replace `hash: Vec` with `hash: Hash`. This requires patching / // rewriting the Blake2b crate to support `.from_bytes()` to serialize from // disk. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Node { + /// This node's index in the Merkle tree pub(crate) index: u64, + /// Hash of the data in this node pub(crate) hash: Vec, + /// Number of bytes in this [`Node::data`] pub(crate) length: u64, + /// Index of this nodes parent pub(crate) parent: u64, + /// Hypercore's data. Can be receieved after the rest of the node, so it's optional. pub(crate) data: Option>, pub(crate) blank: bool, } diff --git a/src/common/peer.rs b/src/common/peer.rs index c71b981..b420317 100644 --- a/src/common/peer.rs +++ b/src/common/peer.rs @@ -1,6 +1,7 @@ //! Types needed for passing information with with peers. //! hypercore-protocol-rs uses these types and wraps them //! into wire messages. + use crate::Node; #[derive(Debug, Clone, PartialEq)] @@ -20,7 +21,7 @@ pub struct RequestSeek { } #[derive(Debug, Clone, PartialEq)] -/// Request of a DataUpgrade from peer +/// Request for a DataUpgrade from peer pub struct RequestUpgrade { /// Hypercore start index pub start: u64, @@ -79,7 +80,7 @@ pub struct DataBlock { pub index: u64, /// Data block value in bytes pub value: Vec, - /// TODO: document + /// Nodes of the merkle tree pub nodes: Vec, } @@ -104,11 +105,11 @@ pub struct DataSeek { #[derive(Debug, Clone, PartialEq)] /// TODO: Document pub struct DataUpgrade { - /// TODO: Document + /// Starting block of this upgrade response pub start: u64, - /// TODO: Document + /// Number of blocks in this upgrade response pub length: u64, - /// TODO: Document + /// The nodes of the merkle tree pub nodes: Vec, /// TODO: Document pub additional_nodes: Vec, diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 333da2b..ad4b68a 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -147,11 +147,7 @@ impl Storage { instruction.index, &buf, )), - Err(RandomAccessError::OutOfBounds { - offset: _, - end: _, - length, - }) => { + Err(RandomAccessError::OutOfBounds { length, .. }) => { if instruction.allow_miss { Ok(StoreInfo::new_content_miss( instruction.store.clone(), diff --git a/src/tree/merkle_tree_changeset.rs b/src/tree/merkle_tree_changeset.rs index be28873..9305302 100644 --- a/src/tree/merkle_tree_changeset.rs +++ b/src/tree/merkle_tree_changeset.rs @@ -10,8 +10,8 @@ use crate::{ /// first create the changes to this changeset, get out information from this to put to the oplog, /// and the commit the changeset to the tree. /// -/// This is called "MerkleTreeBatch" in Javascript, see: -/// https://github.com/hypercore-protocol/hypercore/blob/master/lib/merkle-tree.js +/// This is called "MerkleTreeBatch" in Javascript, source +/// [here](https://github.com/holepunchto/hypercore/blob/88a1a2f1ebe6e33102688225516c4e882873f710/lib/merkle-tree.js#L44). #[derive(Debug)] pub(crate) struct MerkleTreeChangeset { pub(crate) length: u64,