diff --git a/src/blake2.rs b/src/blake2.rs index 063b176..9c70094 100644 --- a/src/blake2.rs +++ b/src/blake2.rs @@ -11,6 +11,9 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +//! Implements the HashWriter interface for the Blake2 hash function. +//! Requires the `blake2` feature to be set. + use crate::hash::*; use blake2::digest::Digest; pub use blake2::{Blake2b512, Blake2s256}; diff --git a/src/dag.rs b/src/dag.rs index 93115e4..acb5883 100644 --- a/src/dag.rs +++ b/src/dag.rs @@ -11,6 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +//! Implementation of the MerkleDag based off of the merkle-crdt whitepaper. use std::{collections::BTreeSet, marker::PhantomData}; @@ -68,8 +69,8 @@ where /// and add it to the DAG with the given payload item and dependency id set. It is idempotent for any /// given set of inputs. /// - /// One result of not constructing/adding nodes in this way is that we ensure that we always satisfy - /// the implementation rule in the merkel-crdt's whitepaper. + /// One result of not constructing and then adding nodes in this way is that we ensure that we always + /// satisfy the implementation rule in the merkel-crdt's whitepaper. pub fn add_node<'a, N: Into>>( &'a mut self, item: N, diff --git a/src/hash.rs b/src/hash.rs index 7f073de..c6f0405 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -11,6 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +//! HashWriter trait specification and default implementations. + use std::collections::hash_map::DefaultHasher; use std::hash::Hasher; diff --git a/src/leveldb/mod.rs b/src/leveldb/mod.rs index b4656b3..0894e68 100644 --- a/src/leveldb/mod.rs +++ b/src/leveldb/mod.rs @@ -11,6 +11,9 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +//! Module implementing a store interface using LevelDB for a MerkleDag. +//! Requires the `rusty-leveldb` interface. + use std::cell::RefCell; use std::path::Path; @@ -23,8 +26,9 @@ use crate::blake2::*; use ciborium; use rusty_leveldb; -// TODO(jwall): Add leveldb backing store for a Merkle-DAG - +/// A `Store` implementation using the rusty-leveldb port of leveldb. +/// The Default implementation of this `Default::default()` is an in-memory +/// implementation of the store. pub struct LevelStore { store: RefCell, } @@ -37,6 +41,7 @@ impl LevelStore { }) } } + impl Store for LevelStore { fn contains(&self, id: &[u8]) -> Result { Ok(self.store.borrow_mut().get(id).is_some()) diff --git a/src/lib.rs b/src/lib.rs index 8d48008..0833a7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +//! A merkle dag along the lines of the merkle-crdt whitepaper. + #[cfg(feature = "blake2")] pub mod blake2; pub mod dag; diff --git a/src/node.rs b/src/node.rs index 837be1b..fb3f44a 100644 --- a/src/node.rs +++ b/src/node.rs @@ -11,6 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +//! `Node` types for satisfying the properties necessary for a MerkleDag. + use std::{collections::BTreeSet, marker::PhantomData}; use serde::{Deserialize, Serialize}; diff --git a/src/prelude.rs b/src/prelude.rs index eb546d4..8afa7f2 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - +//! Exports the most common set of types for this crate. pub use crate::dag::*; pub use crate::hash::*; pub use crate::node::*; diff --git a/src/store.rs b/src/store.rs index df841ba..43a0660 100644 --- a/src/store.rs +++ b/src/store.rs @@ -11,6 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +//! The MerkleDag backing store trait. + use std::collections::BTreeMap; use crate::{hash::HashWriter, node::Node}; @@ -23,12 +25,16 @@ pub enum StoreError { NoSuchDependents, } +/// Trait representing the backing storage interface for a `DAG`. pub trait Store: Default where HW: HashWriter, { + /// Checks if the `Store` contains a node with this id. fn contains(&self, id: &[u8]) -> Result; + /// Fetches a node from the `Store` by id if it exists. fn get(&self, id: &[u8]) -> Result>>; + /// Stores a given node. fn store(&mut self, node: Node) -> Result<()>; }