From 2dc8008a5542713a2569cfb115a006dee34bbca6 Mon Sep 17 00:00:00 2001 From: Bruno Tavares Date: Mon, 3 Feb 2020 20:31:03 -0300 Subject: [PATCH 1/4] example to ensure structs are send --- Cargo.toml | 1 + examples/async.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 examples/async.rs diff --git a/Cargo.toml b/Cargo.toml index dca1280..83ba9e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,3 +41,4 @@ quickcheck = "0.8.5" data-encoding = "2.1.2" remove_dir_all = "0.5.2" tempfile = "3.1.0" +async-std = "1.5.0" diff --git a/examples/async.rs b/examples/async.rs new file mode 100644 index 0000000..9fa767d --- /dev/null +++ b/examples/async.rs @@ -0,0 +1,30 @@ +use async_std::task; +use failure::Error; +use hypercore::Feed; +use random_access_storage::RandomAccess; +use std::fmt::Debug; + +async fn append(feed: &mut Feed, content: &[u8]) +where + T: RandomAccess + Debug, +{ + feed.append(content).unwrap(); +} + +async fn print(feed: &mut Feed) +where + T: RandomAccess + Debug, +{ + println!("{:?}", feed.get(0)); + println!("{:?}", feed.get(1)); +} + +fn main() { + task::block_on(task::spawn(async { + let mut feed = Feed::default(); + + append(&mut feed, b"hello").await; + append(&mut feed, b"world").await; + print(&mut feed).await; + })); +} From 40caf92ec2c357a08ddeec03f9d4ba34a723eeaf Mon Sep 17 00:00:00 2001 From: Bruno Tavares Date: Mon, 3 Feb 2020 20:39:13 -0300 Subject: [PATCH 2/4] Replace all Rc with Arc in code. Needs to update dependencies --- src/crypto/merkle.rs | 10 +++++----- src/feed.rs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/crypto/merkle.rs b/src/crypto/merkle.rs index bba8e7a..8711e6a 100644 --- a/src/crypto/merkle.rs +++ b/src/crypto/merkle.rs @@ -1,7 +1,7 @@ use crate::crypto::Hash; use crate::storage::Node; use merkle_tree_stream::{HashMethods, MerkleTreeStream, NodeKind, PartialNode}; -use std::rc::Rc; +use std::sync::Arc; #[derive(Debug)] struct H; @@ -10,7 +10,7 @@ impl HashMethods for H { type Node = Node; type Hash = Hash; - fn leaf(&self, leaf: &PartialNode, _roots: &[Rc]) -> Self::Hash { + fn leaf(&self, leaf: &PartialNode, _roots: &[Arc]) -> Self::Hash { match leaf.data() { NodeKind::Leaf(data) => Hash::from_leaf(&data), NodeKind::Parent => unreachable!(), @@ -26,7 +26,7 @@ impl HashMethods for H { #[derive(Debug)] pub struct Merkle { stream: MerkleTreeStream, - nodes: Vec>, + nodes: Vec>, } impl Default for Merkle { @@ -52,12 +52,12 @@ impl Merkle { } /// Get the roots vector. - pub fn roots(&self) -> &Vec> { + pub fn roots(&self) -> &Vec> { self.stream.roots() } /// Get the nodes from the struct. - pub fn nodes(&self) -> &Vec> { + pub fn nodes(&self) -> &Vec> { &self.nodes } } diff --git a/src/feed.rs b/src/feed.rs index ecc2cf9..225ff98 100644 --- a/src/feed.rs +++ b/src/feed.rs @@ -23,7 +23,7 @@ use std::cmp; use std::fmt::{self, Debug, Display}; use std::ops::Range; use std::path::Path; -use std::rc::Rc; +use std::sync::Arc; /// Append-only log structure. #[derive(Debug)] @@ -398,7 +398,7 @@ where /// root nodes combined. pub fn verify(&mut self, index: usize, signature: &Signature) -> Result<()> { let roots = self.root_hashes(index)?; - let roots: Vec<_> = roots.into_iter().map(Rc::new).collect(); + let roots: Vec<_> = roots.into_iter().map(Arc::new).collect(); let message = Hash::from_roots(&roots); let message = message.as_bytes(); From d4905b11cf83871db98c118c373d52626e6b1c78 Mon Sep 17 00:00:00 2001 From: Bruno Tavares Date: Mon, 3 Feb 2020 21:37:44 -0300 Subject: [PATCH 3/4] Point to merkle-tree-stream that is Send while new version is to be released --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 83ba9e0..ff46a0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ failure = "0.1.5" flat-tree = "4.1.0" lazy_static = "1.3.0" memory-pager = "0.9.0" -merkle-tree-stream = "0.10.0" +merkle-tree-stream = { version = "0.10.0", git = "https://github.com/bltavares/merkle-tree-stream", branch = "send" } pretty-hash = "0.4.0" rand = "0.6.0" random-access-disk = "0.8.0" From 46be5197a2398e04d413ebfa65fcb6f830dedf0f Mon Sep 17 00:00:00 2001 From: Bruno Tavares Date: Tue, 18 Feb 2020 20:54:00 -0300 Subject: [PATCH 4/4] Use published version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ff46a0f..151986a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ failure = "0.1.5" flat-tree = "4.1.0" lazy_static = "1.3.0" memory-pager = "0.9.0" -merkle-tree-stream = { version = "0.10.0", git = "https://github.com/bltavares/merkle-tree-stream", branch = "send" } +merkle-tree-stream = "0.11.0" pretty-hash = "0.4.0" rand = "0.6.0" random-access-disk = "0.8.0"