Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9ea4845
feat(client-actor): start implement serialize/deserialize for SHReque…
elenaf9 Jan 4, 2021
a3b1aff
feat(communication): handle ask-pattern in communication actor
elenaf9 Jan 6, 2021
bc2d51d
feat(client): implement Serialize/Deserialize for ProcResult
elenaf9 Jan 7, 2021
ebfd75c
feat(clent): handle CommunicationEvent in client actor
elenaf9 Jan 15, 2021
a32fe67
feat(client): add method for writing remote vaults to interface
elenaf9 Jan 16, 2021
00f8dd8
feat(communication): enable changing the client ref that comms actor …
elenaf9 Jan 16, 2021
67f05c8
feat(client): add methods to interface to read/write remote store
elenaf9 Jan 17, 2021
72c5bd4
fix(commandline): riker dependency from github
elenaf9 Jan 18, 2021
d988e32
feat(client): add interface-test for stronghold communication
elenaf9 Jan 18, 2021
e337a67
feat(communication): refactor actor
elenaf9 Jan 25, 2021
90b782c
feat(communication): map client-actors to listening addresses
elenaf9 Jan 27, 2021
64a8efb
feat(communication): handle outgoing request sequentially
elenaf9 Jan 28, 2021
505883f
fix(client): rust fmt
elenaf9 Feb 1, 2021
36fd33c
feat(communication): implement firewall, start reimplementing tests
elenaf9 Feb 1, 2021
080afee
feat(communication): reimplement actor tests
elenaf9 Feb 2, 2021
09837fd
feat(client): integrade comms to interface
elenaf9 Feb 2, 2021
c41cb4f
fix(communication): format tests
elenaf9 Feb 3, 2021
633850b
fix(communcation): clean code
elenaf9 Feb 10, 2021
9fb4a3e
feat(communcation): use minor versions for deps
elenaf9 Feb 13, 2021
d52ad07
feat(communication): reorganize tests, reexport libp2p types
elenaf9 Feb 13, 2021
e96b8ff
fix(clippy)
elenaf9 Feb 13, 2021
1d5d6b5
fix(clippy): handle rust v1.50
elenaf9 Feb 13, 2021
1e0f14b
feat(communication): test edge cases and panics
elenaf9 Feb 14, 2021
c14cdb3
feat(p2p): enable shutdown comms
elenaf9 Feb 15, 2021
3ae348f
fix(communication): try fix test for macos
elenaf9 Feb 15, 2021
683afbb
feat(communication): wrap messages in envelopes
elenaf9 Feb 15, 2021
c8e7b23
feat(p2p): implement relay server
elenaf9 Feb 15, 2021
5dda36e
feat(communication): add test for relay
elenaf9 Feb 16, 2021
42d9f3f
fix(communication): rm panics in tasks, keep connection alive in rela…
elenaf9 Feb 17, 2021
5ae2308
fix(communication): rm tests for reusing multiaddr
elenaf9 Feb 17, 2021
3846664
feat(communication): implement connection manager
elenaf9 Feb 17, 2021
2676dbb
feat(communication): refactor & test firewall and connections
elenaf9 Feb 23, 2021
a6b9185
feat(communication): more tests, minor fixes
elenaf9 Feb 24, 2021
eed3b75
fix(communication): clean cli-relay yml
elenaf9 Feb 24, 2021
b11fa4e
feat(client): implement executing remote procs
elenaf9 Feb 25, 2021
9451537
fix(communication): avoid unwraps
elenaf9 Feb 25, 2021
d1c8547
feat(utils): mv test_utils to utils, add mod ask
elenaf9 Feb 25, 2021
d1f1ee1
fix(utils): fix changelog config
elenaf9 Feb 26, 2021
23428a2
fix(communication): add utils dep for changelog
elenaf9 Feb 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .changes/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"snapshot",
"random",
"primitives",
"test-utils"
"utils"
]
},
"stronghold-engine": {
Expand All @@ -171,7 +171,10 @@
},
"stronghold-communication": {
"path": "./communication/",
"manager": "rust"
"manager": "rust",
"dependencies": [
"utils"
]
},
"crypto": {
"path": "./engine/crypto/",
Expand All @@ -185,7 +188,7 @@
"dependencies": [
"crypto",
"random",
"test-utils"
"utils"
]
},
"snapshot": {
Expand All @@ -195,7 +198,7 @@
"dependencies": [
"crypto",
"random",
"test-utils"
"utils"
]
},
"random": {
Expand All @@ -213,8 +216,8 @@
"manager": "rust",
"publish": false
},
"test-utils": {
"path": "./test-utils/",
"utils": {
"path": "./utils/",
"manager": "rust",
"publish": false
}
Expand Down
12 changes: 12 additions & 0 deletions .changes/integrate_communication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"stronghold-communication": minor
"iota-stronghold": minor
"random": patch
"snapshot": patch
"vault": patch
"stronghold-utils": minor
---

Refactor the communication actor, enable using a relay peer, and integrate communication as feature into the stronghold interface.
Remove unecessary Option/ Result wraps in `random` and `iota-stronghold`.
Rename stronghold-test-utils to stronghold-utils and added riker ask pattern to it.
2 changes: 1 addition & 1 deletion .changes/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
| random | Engine's Random | Rust | No | No |
| primitives | Engine's Crypto Primitives | Rust | No | No |
| store | Engine's Readable Storage Interface | Rust | No | No |
| test-utils | Internal Dev Utilities for Testing | Rust | No | No |
| stronghold-utils | Reoccuring Patterns, and Utilities for Testing | Rust | No | No |

As you create PRs and make changes that require a version bump, please add a new markdown file in this folder. You do not note the version _number_, but rather the type of bump that you expect: major, minor, or patch. The filename is not important, as long as it is a `.md`, but we recommend it represents the overall change for our sanity.

Expand Down
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ updates:
open-pull-requests-limit: 3

- package-ecosystem: "cargo"
directory: "/test_utils"
directory: "/utils"
schedule:
interval: "daily"
open-pull-requests-limit: 3
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = [
"runtime",
"client",
"communication",
"test_utils",
"utils",
]
exclude = [
"products/commandline",
Expand Down
18 changes: 13 additions & 5 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ zeroize_derive = "1.0"
anyhow = "1.0"
thiserror = "1.0"
futures = "0.3"
riker = "0.4"
riker = { version = "0.4", git ="https://github.com/elenaf9/riker", branch = "master" }


[dependencies.stronghold-engine]
path = "../engine"
Expand All @@ -39,16 +40,23 @@ features = [ "random", "ed25519", "sha", "hmac", "bip39-en" ]
version = "*"
# Note: We are only adding a version so that we can publish to crates.io

[dependencies.stronghold-communication]
path = "../communication"
optional = true

[dependencies.stronghold-utils]
path = "../utils"
version = "0.1"

[features]
communication = ["stronghold-communication"]

[dev-dependencies]
hex = "0.4.2"
criterion = "0.3.3"
clap = { version = "3.0.0-beta.1", features = [ "yaml" ] }
rand = "0.8.3"

[dev-dependencies.stronghold-test-utils]
path = "../test_utils"
version = "0.1"

[[bench]]
name = "benchmark"
harness = false
83 changes: 78 additions & 5 deletions client/src/actors/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ use crate::{
};

use engine::{snapshot, vault::RecordHint};
use serde::{Deserialize, Serialize};

use riker::actors::*;

use core::{
array::TryFromSliceError,
convert::{TryFrom, TryInto},
};
use std::{path::PathBuf, time::Duration};

/// `SLIP10DeriveInput` type used to specify a Seed location or a Key location for the `SLIP10Derive` procedure.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SLIP10DeriveInput {
/// Note that BIP39 seeds are allowed to be used as SLIP10 seeds
Seed(Location),
Expand All @@ -25,7 +30,7 @@ pub enum SLIP10DeriveInput {

/// Procedure type used to call to the runtime via `Strongnhold.runtime_exec(...)`.
#[allow(dead_code)]
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Procedure {
/// Generate a raw SLIP10 seed of the specified size (in bytes, defaults to 64 bytes/512 bits) and store it in the
/// `output` location
Expand Down Expand Up @@ -76,7 +81,9 @@ pub enum Procedure {
/// A Procedure return result type. Contains the different return values for the `Procedure` type calls used with
/// `Stronghold.runtime_exec(...)`.
#[allow(dead_code)]
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(try_from = "SerdeProcResult")]
#[serde(into = "SerdeProcResult")]
pub enum ProcResult {
/// Return from generating a `SLIP10` seed.
SLIP10Generate(StatusMessage),
Expand All @@ -94,8 +101,74 @@ pub enum ProcResult {
Ed25519Sign(ResultMessage<[u8; crypto::ed25519::SIGNATURE_LENGTH]>),
}

impl TryFrom<SerdeProcResult> for ProcResult {
type Error = TryFromSliceError;

fn try_from(serde_proc_result: SerdeProcResult) -> Result<Self, Self::Error> {
match serde_proc_result {
SerdeProcResult::SLIP10Generate(msg) => Ok(ProcResult::SLIP10Generate(msg)),
SerdeProcResult::SLIP10Derive(msg) => Ok(ProcResult::SLIP10Derive(msg)),
SerdeProcResult::BIP39Recover(msg) => Ok(ProcResult::BIP39Recover(msg)),
SerdeProcResult::BIP39Generate(msg) => Ok(ProcResult::BIP39Generate(msg)),
SerdeProcResult::BIP39MnemonicSentence(msg) => Ok(ProcResult::BIP39MnemonicSentence(msg)),
SerdeProcResult::Ed25519PublicKey(msg) => {
let msg: ResultMessage<[u8; crypto::ed25519::COMPRESSED_PUBLIC_KEY_LENGTH]> = match msg {
ResultMessage::Ok(v) => ResultMessage::Ok(v.as_slice().try_into()?),
ResultMessage::Error(e) => ResultMessage::Error(e),
};
Ok(ProcResult::Ed25519PublicKey(msg))
}
SerdeProcResult::Ed25519Sign(msg) => {
let msg: ResultMessage<[u8; crypto::ed25519::SIGNATURE_LENGTH]> = match msg {
ResultMessage::Ok(v) => ResultMessage::Ok(v.as_slice().try_into()?),
ResultMessage::Error(e) => ResultMessage::Error(e),
};
Ok(ProcResult::Ed25519Sign(msg))
}
}
}
}

// Replaces arrays in ProcResult with vectors to derive Serialize/ Deserialize
#[derive(Clone, Serialize, Deserialize)]
enum SerdeProcResult {
SLIP10Generate(StatusMessage),
SLIP10Derive(ResultMessage<hd::ChainCode>),
BIP39Recover(StatusMessage),
BIP39Generate(StatusMessage),
BIP39MnemonicSentence(ResultMessage<String>),
Ed25519PublicKey(ResultMessage<Vec<u8>>),
Ed25519Sign(ResultMessage<Vec<u8>>),
}

impl From<ProcResult> for SerdeProcResult {
fn from(proc_result: ProcResult) -> Self {
match proc_result {
ProcResult::SLIP10Generate(msg) => SerdeProcResult::SLIP10Generate(msg),
ProcResult::SLIP10Derive(msg) => SerdeProcResult::SLIP10Derive(msg),
ProcResult::BIP39Recover(msg) => SerdeProcResult::BIP39Recover(msg),
ProcResult::BIP39Generate(msg) => SerdeProcResult::BIP39Generate(msg),
ProcResult::BIP39MnemonicSentence(msg) => SerdeProcResult::BIP39MnemonicSentence(msg),
ProcResult::Ed25519PublicKey(msg) => {
let msg = match msg {
ResultMessage::Ok(slice) => ResultMessage::Ok(slice.to_vec()),
ResultMessage::Error(error) => ResultMessage::Error(error),
};
SerdeProcResult::Ed25519PublicKey(msg)
}
ProcResult::Ed25519Sign(msg) => {
let msg = match msg {
ResultMessage::Ok(slice) => ResultMessage::Ok(slice.to_vec()),
ResultMessage::Error(error) => ResultMessage::Error(error),
};
SerdeProcResult::Ed25519Sign(msg)
}
}
}
}

#[allow(dead_code)]
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum SHRequest {
// check if vault exists.
CheckVault(Vec<u8>),
Expand Down Expand Up @@ -173,7 +246,7 @@ pub enum SHRequest {
}

/// Messages that come from stronghold
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum SHResults {
ReturnWriteStore(StatusMessage),
ReturnReadStore(Vec<u8>, StatusMessage),
Expand Down
19 changes: 8 additions & 11 deletions client/src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,29 +203,26 @@ impl<P: BoxProvider + Send + Sync + Clone + Ord + PartialOrd + PartialEq + Eq +

/// Exposes the `DBView` of the current vault and the cache layer to allow transactions to occur.
fn take(&mut self, key: Key<P>, f: impl FnOnce(DBView<P>, Vec<ReadResult>) -> Vec<ReadResult>) {
let mut _reads = self.get_reads(key.clone());
let reads = _reads.take().expect(line_error!());
let mut _view = self.get_view(key.clone(), reads.clone());
let view = _view.take().expect(line_error!());
let reads = self.get_reads(key.clone());
let view = self.get_view(key.clone(), reads.clone());
let res = f(view, reads);
self.insert_reads(key.clone(), res);
self.insert_view(key, _view);
self.insert_view(key, None);
}

fn get_view(&mut self, key: Key<P>, reads: Vec<ReadResult>) -> Option<DBView<P>> {
fn get_view(&mut self, key: Key<P>, reads: Vec<ReadResult>) -> DBView<P> {
self.vaults.remove(&key);

Some(DBView::load(key, reads.iter()).expect(line_error!()))
DBView::load(key, reads.iter()).expect(line_error!())
}

fn insert_view(&mut self, key: Key<P>, view: Option<DBView<P>>) {
self.vaults.insert(key, view);
}

fn get_reads(&mut self, key: Key<P>) -> Option<Vec<ReadResult>> {
fn get_reads(&mut self, key: Key<P>) -> Vec<ReadResult> {
match self.cache.remove(&key) {
Some(reads) => Some(reads),
None => Some(Vec::<ReadResult>::new()),
Some(reads) => reads,
None => Vec::<ReadResult>::new(),
}
}

Expand Down
Loading