Skip to content

Commit

Permalink
Merge pull request freedomlayer#161 from freedomlayer/real/feat/integ…
Browse files Browse the repository at this point in the history
…ration-tests

Initial integration test
  • Loading branch information
realcr authored Feb 28, 2019
2 parents 57c8da7 + d73cdbc commit 80bd429
Show file tree
Hide file tree
Showing 88 changed files with 2,574 additions and 1,147 deletions.
65 changes: 57 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ members = [
"components/version",
"components/bin",
"components/app",
"components/test",
]

8 changes: 1 addition & 7 deletions components/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ crypto = { path = "../crypto", version = "0.1.0", package = "offst-crypto" }
identity = { path = "../identity", version = "0.1.0" , package = "offst-identity" }
timer = { path = "../timer", version = "0.1.0" , package = "offst-timer" }
proto = { path = "../proto", version = "0.1.0" , package = "offst-proto" }
keepalive = { path = "../keepalive", version = "0.1.0" , package = "offst-keepalive" }
secure_channel = { path = "../secure_channel", version = "0.1.0" , package = "offst-secure-channel" }
version = { path = "../version", version = "0.1.0" , package = "offst-version" }
net = { path = "../net", version = "0.1.0" , package = "offst-net" }
bin = { path = "../bin", version = "0.1.0" , package = "offst-bin" }
node = { path = "../node", version = "0.1.0" , package = "offst-node" }


log = "0.4"
simple_logger = "1.0.1"
futures-preview = "0.3.0-alpha.11"

[dev-dependencies]

tempfile = "3.0.5"

91 changes: 26 additions & 65 deletions components/app/src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,88 +3,49 @@ use std::time::Duration;
use futures::task::Spawn;

use common::int_convert::usize_to_u64;
use common::conn::FutTransform;

use proto::consts::{TICK_MS, MAX_FRAME_LENGTH};
use proto::net::messages::NetAddress;

use timer::create_timer;
use crypto::identity::PublicKey;
use crypto::crypto_rand::{CryptoRandom, system_random};
use identity::IdentityClient;
use crypto::identity::PublicKey;

use identity::IdentityClient;
use timer::create_timer;
use net::NetConnector;

use crate::node_connection::NodeConnection;

use crate::setup_conn::{setup_connection, SetupConnectionError};
pub use crate::setup_conn::NodeConnectionTuple;


use node::connect::{node_connect, NodeConnection};

#[derive(Debug)]
pub enum ConnectError {
CreateTimerError,
CreateNetConnectorError,
/// Could not open network connection
NetConnectorError,
SetupConnectionError(SetupConnectionError),
CreateNodeConnectionError,
}
pub struct ConnectError;

/// Connect to an offst-node
async fn inner_node_connect<R,S>(node_public_key: PublicKey,
net_address: NetAddress,
app_identity_client: IdentityClient,
rng: R,
spawner: S) -> Result<NodeConnectionTuple, ConnectError>
/// Connect to a remote offst-node.
pub async fn connect<S>(node_public_key: PublicKey,
node_net_address: NetAddress,
app_identity_client: IdentityClient,
spawner: S) -> Result<NodeConnection<impl CryptoRandom>, ConnectError>
where
R: CryptoRandom + Clone + 'static,
S: Spawn + Clone + Sync + Send + 'static,
S: Spawn + Clone + Send + Sync + 'static,
{
// A tcp connector, Used to connect to remote servers:
let net_connector = NetConnector::new(MAX_FRAME_LENGTH, spawner.clone())
.map_err(|_| ConnectError)?;

// Get a timer client:
let dur = Duration::from_millis(usize_to_u64(TICK_MS).unwrap());
let timer_client = create_timer(dur, spawner.clone())
.map_err(|_| ConnectError::CreateTimerError)?;

// A tcp connector, Used to connect to remote servers:
let mut net_connector = NetConnector::new(MAX_FRAME_LENGTH, spawner.clone())
.map_err(|_| ConnectError::CreateNetConnectorError)?;

let conn_pair = await!(net_connector.transform(net_address))
.ok_or(ConnectError::NetConnectorError)?;

await!(setup_connection(
conn_pair,
timer_client,
rng,
node_public_key,
app_identity_client,
spawner))
.map_err(|e| ConnectError::SetupConnectionError(e))
}
.map_err(|_| ConnectError)?;


/// Connect to an offst node
pub async fn node_connect<C,S>(node_public_key: PublicKey,
net_address: NetAddress,
app_identity_client: IdentityClient,
mut spawner: S) -> Result<NodeConnection<impl CryptoRandom>, ConnectError>
where
S: Spawn + Send + Sync + Clone + 'static,
{

// TODO: Is it ok to create a new system_random() on every call to node_connect()?
// What are the alternatives?

// TODO: Is it safe to create a new `system_random` every time?
// Obtain secure cryptographic random:
let rng = system_random();

let conn_tuple = await!(inner_node_connect(node_public_key,
net_address,
app_identity_client,
rng.clone(),
spawner.clone()))?;

NodeConnection::new(conn_tuple, rng, &mut spawner)
.map_err(|_| ConnectError::CreateNodeConnectionError)
await!(node_connect(net_connector,
node_public_key,
node_net_address,
timer_client,
app_identity_client,
rng,
spawner))
.map_err(|_| ConnectError)
}
2 changes: 1 addition & 1 deletion components/app/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use futures::task::{Spawn, SpawnExt};

use identity::{create_identity, IdentityClient};

use bin::load_identity_from_file;
use proto::file::identity::load_identity_from_file;

#[derive(Debug)]
pub enum IdentityFromFileError {
Expand Down
2 changes: 0 additions & 2 deletions components/app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@
#[macro_use]
extern crate log;

mod setup_conn;
pub mod identity;
pub mod connect;
mod node_connection;
7 changes: 0 additions & 7 deletions components/app/src/node_connection/mod.rs

This file was deleted.

5 changes: 4 additions & 1 deletion components/app_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
#[macro_use]
extern crate log;

#[macro_use]
extern crate common;

mod server;

#[cfg(test)]
mod tests;

pub use self::server::{app_server_loop,
IncomingAppConnection};
IncomingAppConnection, AppServerError};
Loading

0 comments on commit 80bd429

Please sign in to comment.