Merge with develop

This commit is contained in:
Jedrzej Stuczynski
2020-01-28 10:10:52 +00:00
parent 1a6226f2bf
commit 0785ad67f5
7 changed files with 222 additions and 4 deletions
Generated
+70 -1
View File
@@ -847,6 +847,20 @@ dependencies = [
"tokio-io",
]
[[package]]
name = "handlebars"
version = "3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba758d094d31274eb49d15da6f326b96bf3185239a6359bf684f3d5321148900"
dependencies = [
"log",
"pest",
"pest_derive",
"quick-error",
"serde",
"serde_json",
]
[[package]]
name = "healthcheck"
version = "0.1.0"
@@ -1135,6 +1149,12 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "maplit"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
[[package]]
name = "matches"
version = "0.1.8"
@@ -1355,6 +1375,7 @@ dependencies = [
"dirs",
"dotenv",
"futures 0.3.1",
"handlebars",
"healthcheck",
"log",
"mix-client",
@@ -1428,7 +1449,6 @@ dependencies = [
"log",
"pretty_env_logger",
"serde",
"serde_derive",
"tokio 0.2.10",
"toml",
]
@@ -1531,6 +1551,49 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pest"
version = "2.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e4fb201c5c22a55d8b24fef95f78be52738e5e1361129be1b5e862ecdb6894a"
dependencies = [
"ucd-trie",
]
[[package]]
name = "pest_derive"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0"
dependencies = [
"pest",
"pest_generator",
]
[[package]]
name = "pest_generator"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b9fcf299b5712d06ee128a556c94709aaa04512c4dffb8ead07c5c998447fc0"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "pest_meta"
version = "2.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df43fd99896fd72c485fe47542c7b500e4ac1e8700bf995544d1317a60ded547"
dependencies = [
"maplit",
"pest",
"sha-1",
]
[[package]]
name = "pin-project"
version = "0.4.7"
@@ -2474,6 +2537,12 @@ version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9"
[[package]]
name = "ucd-trie"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f00ed7be0c1ff1e24f46c3d2af4859f7e863672ba3a6e92e7cff702bf9f06c2"
[[package]]
name = "unicase"
version = "2.6.0"
+1
View File
@@ -18,6 +18,7 @@ curve25519-dalek = "1.2.3"
dirs = "2.0.2"
dotenv = "0.15.0"
futures = "0.3.1"
handlebars = "3.0.1"
log = "0.4"
pem = "0.7.0"
pretty_env_logger = "0.3"
+81
View File
@@ -1 +1,82 @@
use crate::config::persistance::pathfinder::ClientPathfinder;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
pub mod persistance;
mod template;
#[derive(Serialize, Deserialize)]
pub struct Config {
client: Client,
}
impl Default for Config {
fn default() -> Self {
unimplemented!()
}
}
#[derive(Serialize, Deserialize)]
pub struct Client {
// nym_home_directory specifies absolute path to the home nym Clients directory.
// It is expected to use default value and hence .toml file should not redefine this field.
nym_home_directory: String,
// ID specifies the human readable ID of this particular client.
// If not provided a pseudorandom id will be generated instead.
id: String,
// URL to the directory server.
directory_server: String,
// Path to file containing private identity key.
private_identity_key_file: PathBuf,
// Path to file containing public identity key.
public_identity_key_file: PathBuf,
// mix_apps_directory specifies directory for mixapps, such as a chat client,
// to store their app-specific data.
mix_apps_directory: String,
// provider_id specifies ID of the provider to which the client should send messages.
// If initially omitted, a random provider will be chosen from the available topology.
provider_id: String,
}
impl Default for Client {
fn default() -> Self {
unimplemented!()
}
}
impl Client {
fn new() -> Self {
Default::default()
}
fn with_id(mut self, id: String) -> Self {
self.id = id;
self
}
fn with_pathfinder(mut self, pathfinder: ClientPathfinder) -> Self {
// pub config_dir: PathBuf,
// pub private_mix_key: PathBuf,
// pub public_mix_key: PathBuf,
self
}
}
pub struct Logging {}
impl Default for Logging {
fn default() -> Self {
unimplemented!()
}
}
#[cfg(test)]
mod client_config {
use super::*;
}
+68
View File
@@ -0,0 +1,68 @@
use super::Config;
use handlebars::{Handlebars, TemplateRenderError};
fn config_template() -> &'static str {
// While using normal toml marshalling would have been way simpler with less overhead,
// I think it's useful to have comments attached to the saved config file to explain behaviour of
// particular fields.
// Note: any changes to the template must be reflected in the appropriate structs in mod.rs.
r#"
# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml
##### main base client config options #####
[client]
# Human readable ID of this particular client.
id = "{{ client.id }}"
# URL to the directory server.
directory_server = "{{ client.directory_server }}"
# Path to file containing private identity key.
private_identity_key_file = "{{ client.private_identity_key }}"
# Path to file containing public identity key.
public_identity_key_file = "{{ client.public_identity_key }}"
##### additional client config options #####
# ID of the provider to which the client should send messages.
provider_id = "{{ client.provider_id }}"
# directory for mixapps, such as a chat client, to store their app-specific data.
mixapps_directory = "{{ client.mix_apps_directory }}"
##### advanced configuration options #####
# Absolute path to the home Nym Clients directory.
nym_home_directory = "{{ client.home_directory }}"
"#
}
fn render_template(config: &Config) -> Result<String, TemplateRenderError> {
let reg = Handlebars::new();
reg.render_template(config_template(), &config)
}
#[cfg(test)]
mod config_template {
use super::*;
#[test]
fn it_works_for_default_config() {
render_template(&Default::default()).unwrap();
}
#[test]
fn it_works_for_dummy_config() {
let dummy_cfg = Config {
client: crate::config::Client {
id: "foomp".to_string(),
},
};
let render = render_template(&dummy_cfg).unwrap();
println!("{}", render);
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
[healthcheck]
#directory-server = "http://localhost:8080"
directory-server = "https://qa-directory.nymtech.net"
directory-server = "https://directory.nymtech.net"
interval = 10.0
test-packets-per-node = 2 # in seconds
resolution-timeout = 5 # in seconds
-1
View File
@@ -15,7 +15,6 @@ futures = "0.3.1"
log = "0.4"
pretty_env_logger = "0.3"
serde = "1.0.104"
serde_derive = "1.0.104"
tokio = { version = "0.2", features = ["full"] }
toml = "0.5.5"
+1 -1
View File
@@ -1,4 +1,4 @@
use serde_derive::Deserialize;
use serde::Deserialize;
#[derive(Deserialize, Debug)]
pub struct Config {