Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop' into signals-internal
Browse files Browse the repository at this point in the history
  • Loading branch information
maackle committed Dec 14, 2018
2 parents c48cc35 + 0f18797 commit d9e24d7
Show file tree
Hide file tree
Showing 19 changed files with 354 additions and 191 deletions.
1 change: 1 addition & 0 deletions cmd/Cargo.toml
Expand Up @@ -4,6 +4,7 @@ version = "0.0.2"
authors = ["Holochain Core Dev Team <devcore@holochain.org>"]

[dependencies]
holochain_net = { path = "../net" }
holochain_core_types = { path = "../core_types" }
holochain_core = { path = "../core" }
holochain_cas_implementations = { path = "../cas_implementations" }
Expand Down
3 changes: 2 additions & 1 deletion cmd/src/cli/run.rs
Expand Up @@ -2,6 +2,7 @@ use cli::{self, package};
use colored::*;
use error::DefaultResult;
use holochain_container_api::{config::*, container::Container};
use holochain_net::p2p_config::P2pConfig;
use std::fs;

const LOCAL_STORAGE_PATH: &str = ".hc";
Expand Down Expand Up @@ -44,7 +45,7 @@ pub fn run(package: bool, port: u16, persist: bool) -> DefaultResult<()> {
agent: AGENT_CONFIG_ID.into(),
logger: Default::default(),
storage,
network: Some("{\"backend\": \"mock\"}".to_string()),
network: Some(P2pConfig::default_mock().as_str()),
};

let interface_config = InterfaceConfiguration {
Expand Down
1 change: 1 addition & 0 deletions cmd/src/main.rs
Expand Up @@ -2,6 +2,7 @@ extern crate holochain_cas_implementations;
extern crate holochain_container_api;
extern crate holochain_core;
extern crate holochain_core_types;
extern crate holochain_net;
extern crate structopt;
#[macro_use]
extern crate failure;
Expand Down
29 changes: 13 additions & 16 deletions container_api/src/config.rs
Expand Up @@ -231,9 +231,10 @@ where
#[cfg(test)]
pub mod tests {
use crate::config::{load_configuration, Configuration};
use holochain_core::context::mock_network_config;

pub fn example_serialized_network_config() -> String {
String::from("{\\\"backend\\\":\\\"mock\\\"}")
String::from(mock_network_config())
}

#[test]
Expand Down Expand Up @@ -329,7 +330,7 @@ pub mod tests {
[[interfaces.instances]]
id = "app spec instance"
"#,
"{\\\"backend\\\":\\\"special\\\"}"
"{\\\"backend_kind\\\":\\\"special\\\"}"
);

let config = load_configuration::<Configuration>(toml).unwrap();
Expand All @@ -345,7 +346,7 @@ pub mod tests {
let instance_config = instances.get(0).unwrap();
assert_eq!(
instance_config.network,
Some("{\"backend\":\"special\"}".to_string())
Some("{\"backend_kind\":\"special\"}".to_string())
);
}

Expand Down Expand Up @@ -409,8 +410,7 @@ pub mod tests {

#[test]
fn test_inconsistent_config() {
let toml = &format!(
r#"
let toml = r#"
[[agents]]
id = "test agent"
name = "Holo Tester"
Expand All @@ -425,25 +425,24 @@ pub mod tests {
id = "app spec instance"
dna = "WRONG DNA ID"
agent = "test agent"
network = "{}"
[instances.logger]
type = "simple"
file = "app_spec.log"
[instances.storage]
type = "file"
path = "app_spec_storage"
"#,
example_serialized_network_config()
);
let config: Configuration = load_configuration(toml).unwrap();
"#;

let config: Configuration =
load_configuration(toml).expect("Failed to load config from toml string");

assert_eq!(config.check_consistency(), Err("DNA configuration \"WRONG DNA ID\" not found, mentioned in instance \"app spec instance\"".to_string()));
}

#[test]
fn test_inconsistent_config_interface_1() {
let toml = &format!(
r#"
let toml = r#"
[[agents]]
id = "test agent"
name = "Holo Tester"
Expand All @@ -458,7 +457,6 @@ pub mod tests {
id = "app spec instance"
dna = "app spec rust"
agent = "test agent"
network = "{}"
[instances.logger]
type = "simple"
file = "app_spec.log"
Expand All @@ -473,9 +471,8 @@ pub mod tests {
port = 8888
[[interfaces.instances]]
id = "WRONG INSTANCE ID"
"#,
example_serialized_network_config()
);
"#;

let config = load_configuration::<Configuration>(toml).unwrap();

assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions container_api/src/container.rs
Expand Up @@ -29,9 +29,9 @@ use std::{
thread,
};

use holochain_net::p2p_config::P2pConfig;
use interface::{ContainerApiDispatcher, InstanceMap, Interface};
use interface_impls;

/// Main representation of the container.
/// Holds a `HashMap` of Holochain instances referenced by ID.

Expand All @@ -54,7 +54,7 @@ type SignalSender = SyncSender<Signal>;
type InterfaceThreadHandle = thread::JoinHandle<Result<(), String>>;
type DnaLoader = Arc<Box<FnMut(&String) -> Result<Dna, HolochainError> + Send>>;

pub static DEFAULT_NETWORK_CONFIG: &'static str = "{\"backend\":\"mock\"}";
pub static DEFAULT_NETWORK_CONFIG: &'static str = P2pConfig::DEFAULT_MOCK_CONFIG;

impl Container {
/// Creates a new instance with the default DnaLoader that actually loads files.
Expand Down
3 changes: 2 additions & 1 deletion container_api/src/holochain.rs
Expand Up @@ -21,6 +21,7 @@
//! cas::file::FilesystemStorage, eav::file::EavFileStorage,
//! };
//! use tempfile::tempdir;
//! use holochain_core::context::mock_network_config;
//!
//! // instantiate a new holochain instance
//!
Expand All @@ -37,7 +38,7 @@
//! Arc::new(Mutex::new(SimplePersister::new(file_storage.clone()))),
//! file_storage.clone(),
//! Arc::new(RwLock::new(EavFileStorage::new(tempdir().unwrap().path().to_str().unwrap().to_string()).unwrap())),
//! JsonString::from("{\"backend\": \"mock\"}"),
//! mock_network_config(),
//! ).unwrap();
//! let mut hc = Holochain::new(dna,Arc::new(context)).unwrap();
//!
Expand Down
3 changes: 2 additions & 1 deletion core/src/context.rs
Expand Up @@ -10,6 +10,7 @@ use holochain_core_types::{
error::{HcResult, HolochainError},
json::JsonString,
};
use holochain_net::p2p_config::P2pConfig;
use std::{
sync::{mpsc::SyncSender, Arc, Mutex, RwLock, RwLockReadGuard},
thread::sleep,
Expand Down Expand Up @@ -188,7 +189,7 @@ pub async fn get_dna_and_agent(context: &Arc<Context>) -> HcResult<(String, Stri
/// create a test network
#[cfg_attr(tarpaulin, skip)]
pub fn mock_network_config() -> JsonString {
json!({"backend": "mock"}).into()
JsonString::from(P2pConfig::DEFAULT_MOCK_CONFIG)
}

#[cfg(test)]
Expand Down
11 changes: 8 additions & 3 deletions core/src/network/reducers/init.rs
Expand Up @@ -3,12 +3,15 @@ use crate::{
context::Context,
network::{handler::create_handler, state::NetworkState},
};
use holochain_net::p2p_network::P2pNetwork;
use holochain_net::{p2p_config::P2pConfig, p2p_network::P2pNetwork};
use holochain_net_connection::{
net_connection::NetConnection,
protocol_wrapper::{ProtocolWrapper, TrackAppData},
};
use std::sync::{Arc, Mutex};
use std::{
str::FromStr,
sync::{Arc, Mutex},
};

pub fn reduce_init(
context: Arc<Context>,
Expand All @@ -17,7 +20,9 @@ pub fn reduce_init(
) {
let action = action_wrapper.action();
let network_settings = unwrap_to!(action => Action::InitNetwork);
let mut network = P2pNetwork::new(create_handler(&context), &network_settings.config).unwrap();
let p2p_config = P2pConfig::from_str(&network_settings.config.to_string())
.expect("network settings failed to deserialize");
let mut network = P2pNetwork::new(create_handler(&context), &p2p_config).unwrap();

let _ = network
.send(
Expand Down
3 changes: 3 additions & 0 deletions net/Cargo.toml
Expand Up @@ -7,8 +7,11 @@ authors = ["Holochain Core Dev Team <devcore@holochain.org>"]
base64 = "0.9.3"
failure = "0.1.1"
holochain_core_types = { path = "../core_types" }
holochain_core_types_derive = { path = "../core_types_derive" }
holochain_net_connection = { path = "../net_connection" }
holochain_net_ipc = { path = "../net_ipc" }
lazy_static = "1.2"
regex = "1"
serde = "1.0"
serde_derive = "1.0"
serde_json = { version = "1", features = ["preserve_order"] }
7 changes: 1 addition & 6 deletions net/src/ipc_net_worker.rs
Expand Up @@ -17,9 +17,7 @@ use holochain_net_connection::{
NetResult,
};

use std::{convert::TryFrom, sync::mpsc};

use std::{collections::HashMap, io::Read};
use std::{collections::HashMap, convert::TryFrom, io::Read, sync::mpsc};

use serde_json;

Expand All @@ -28,11 +26,8 @@ pub struct IpcNetWorker {
handler: NetHandler,
ipc_relay: NetConnectionRelay,
ipc_relay_receiver: mpsc::Receiver<Protocol>,

is_ready: bool,

state: String,

last_state_millis: f64,
}

Expand Down
6 changes: 6 additions & 0 deletions net/src/lib.rs
Expand Up @@ -17,8 +17,14 @@ extern crate regex;
#[allow(unused_imports)]
#[macro_use]
extern crate serde_json;
#[allow(unused_imports)]
#[macro_use]
extern crate serde_derive;
#[macro_use]
pub extern crate holochain_core_types_derive;

pub mod error;
pub mod ipc_net_worker;
pub mod mock_worker;
pub mod p2p_config;
pub mod p2p_network;

0 comments on commit d9e24d7

Please sign in to comment.