From 3085b0d6d44627db0de2a1d7607632ec44fa82c7 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 14 Oct 2021 14:33:18 -0400 Subject: [PATCH] This may belong actually in the core. --- cumberland/Cargo.toml | 7 ------ cumberland/src/hasher.rs | 6 ----- cumberland/src/lib.rs | 4 ---- cumberland/src/network.rs | 23 ------------------- cumberland/src/store.rs | 44 ------------------------------------- cumberland/src/validator.rs | 11 ---------- 6 files changed, 95 deletions(-) delete mode 100644 cumberland/Cargo.toml delete mode 100644 cumberland/src/hasher.rs delete mode 100644 cumberland/src/lib.rs delete mode 100644 cumberland/src/network.rs delete mode 100644 cumberland/src/store.rs delete mode 100644 cumberland/src/validator.rs diff --git a/cumberland/Cargo.toml b/cumberland/Cargo.toml deleted file mode 100644 index f1fc5bdac..000000000 --- a/cumberland/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "cumberland" -version = "0.1.0" -edition = "2018" - -[dependencies] -parking_lot = "^0" diff --git a/cumberland/src/hasher.rs b/cumberland/src/hasher.rs deleted file mode 100644 index 3e5f8a7e7..000000000 --- a/cumberland/src/hasher.rs +++ /dev/null @@ -1,6 +0,0 @@ -/// Hasher responsible for hashing keys. -pub trait Hasher { - const OUTPUT_SIZE: usize; - fn new() -> Self; - fn digest(&mut self, b: &[u8]) -> [u8; Self::OUTPUT_SIZE]; -} diff --git a/cumberland/src/lib.rs b/cumberland/src/lib.rs deleted file mode 100644 index 57010e333..000000000 --- a/cumberland/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod store; -mod validator; -mod network; -mod hasher; diff --git a/cumberland/src/network.rs b/cumberland/src/network.rs deleted file mode 100644 index 9e98d14bf..000000000 --- a/cumberland/src/network.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::hash::Hash; - -/// An interface to a physical network such as TCP/IP or ZeroTier. -pub trait Network { - /// An endpoint address on the network to which messages can be sent. - type Address: Hash + Clone; - - /// The maximum message size that can be handled by this Network. - /// Note that the underlying transport must be able to handle sizes of at least 4096. - const MAX_MESSAGE_SIZE: usize; - - /// Attempt to send a message to an address. - /// - /// The semantics required are similar to UDP in that delivery need not be guaranteed. - /// A return value of false indicates an obvious error such as invalid address. - fn send(&self, to: &Address, data: &[u8]) -> bool; - - /// Receive the next incoming message. - /// - /// This should block until the next message is available. A return of None indicates - /// that the instance is shutting down. - fn receive(&self) -> Option<(Address, Vec)>; -} diff --git a/cumberland/src/store.rs b/cumberland/src/store.rs deleted file mode 100644 index 05e3c8ef2..000000000 --- a/cumberland/src/store.rs +++ /dev/null @@ -1,44 +0,0 @@ -use std::collections::BTreeMap; -use std::ops::Bound::Included; -use std::sync::Arc; - -use parking_lot::Mutex; - -/// Trait to be implemented by any data store to be replicated. -pub trait Store { - fn load(&self, key: &[u8]) -> Option>; - fn store(&self, key: &[u8], value: &[u8]) -> bool; - fn for_each_range)>(&self, starting_key: &[u8], ending_key: &[u8], f: F); - fn count(&self, starting_key: &[u8], ending_key: &[u8]) -> Option; -} - -/// A simple BTreeMap backed Store, mostly for testing as it does not persist anything. -#[derive(Clone)] -pub struct BTreeStore(Mutex>>); - -impl BTreeStore { - pub fn new() -> Self { Self(Mutex::new(BTreeMap::new())) } -} - -impl Store for BTreeStore { - fn load(&self, key: &[u8]) -> Option> { - let db = self.0.lock(); - db.get(key).map(|v| v.clone()) - } - - fn store(&self, key: &[u8], value: &[u8]) -> bool { - let mut db = self.0.lock(); - let _ = db.insert(*key, Arc::from(value)); - true - } - - fn for_each_range))>(&self, starting_key: &[u8], ending_key: &[u8], f: F) { - let db = self.0.lock(); - db.range((Included(starting_key), Included(ending_key))).for_each(f) - } - - fn count(&self, starting_key: &[u8], ending_key: &[u8]) -> Option { - let db = self.0.lock(); - Some(db.range((Included(starting_key), Included(ending_key))).count() as u64) - } -} diff --git a/cumberland/src/validator.rs b/cumberland/src/validator.rs deleted file mode 100644 index 246bcdab1..000000000 --- a/cumberland/src/validator.rs +++ /dev/null @@ -1,11 +0,0 @@ -pub trait Validator { - /// Check an entry and return true if it should be stored, returned, or replicated. - fn validate(&self, key: &[u8], value: &[u8]) -> bool; -} - -/// A validator that approves everything, mostly for testing. -pub struct NilValidator; - -impl Validator for NilValidator { - fn validate(&self, _: &[u8], _: &[u8]) -> bool { true } -}