-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compile time config with some type troubles
- Loading branch information
Showing
7 changed files
with
236 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
use nym_client_core_config_types::Config; | ||
|
||
use std::io::{BufWriter, Write}; | ||
|
||
fn main() { | ||
write_conditional_default(); | ||
|
||
println!("cargo:rerun-if-changed=build.rs"); | ||
} | ||
|
||
#[allow(unused)] | ||
const DEFAULT_CONFIG_FILE_NAME: &str = "nymvpn-config.toml"; | ||
|
||
const CONFIG_INIT_FN_PREAMBLE: &[u8] = br#" | ||
pub fn new_bootstrapped<S1, S2>(id: S1, version: S2) -> Config | ||
where | ||
S1: Into<String>, | ||
S2: Into<String>, | ||
{ | ||
use nym_sphinx_params::{PacketSize, PacketType}; | ||
let mut cfg: Config = "#; | ||
|
||
const CONFIG_INIT_FN_EPILOGUE: &[u8] = br#"; | ||
cfg.client.id = id.into(); | ||
cfg.client.version = version.into(); | ||
cfg | ||
}"#; | ||
|
||
// #[cfg(feature = "enable-cfg")] | ||
// const CUSTOM_BREAK: &[u8] = br#" | ||
// #[cfg(feature="enable-cfg")] | ||
// "#; | ||
|
||
// #[cfg(not(feature = "enable-cfg"))] | ||
// const DEFAULT_BREAK: &[u8] = br#" | ||
// #[cfg(not(feature="enable-cfg"))] | ||
// "#; | ||
|
||
// const CONFIG_INIT_FN_PREAMBLE: &[u8] = br#" | ||
// impl Default for BaseClientConfig { | ||
// fn default() -> Self { | ||
// use config_types::Keys; | ||
|
||
// Self("#; | ||
|
||
// const DEFAULT_CONFIG_EPILOGUE: &[u8] = br#" | ||
// ) | ||
// } | ||
// }"#; | ||
|
||
// #[cfg(feature = "enable-cfg")] | ||
// const CUSTOM_BREAK: &[u8] = br#" | ||
// #[cfg(feature="enable-cfg")] | ||
// "#; | ||
|
||
// #[cfg(not(feature = "enable-cfg"))] | ||
// const DEFAULT_BREAK: &[u8] = br#" | ||
// #[cfg(not(feature="enable-cfg"))] | ||
// "#; | ||
|
||
fn write_conditional_default() { | ||
// creating a string with the values from our default Config object | ||
let mut array_string = BufWriter::new(Vec::new()); | ||
array_string.write(CONFIG_INIT_FN_PREAMBLE).unwrap(); | ||
|
||
#[cfg(feature = "enable-cfg")] | ||
write_custom_config(&mut array_string); | ||
|
||
#[cfg(not(feature = "enable-cfg"))] | ||
{ | ||
let default_config = Config::new("", ""); | ||
uneval::write(default_config, &mut array_string).unwrap(); | ||
} | ||
|
||
array_string.write(CONFIG_INIT_FN_EPILOGUE).unwrap(); | ||
|
||
// write the string to a file. OUT_DIR environment variable is defined by cargo | ||
let out_dir = std::env::var("OUT_DIR").unwrap(); | ||
let dest_path = std::path::Path::new(&out_dir).join("default.rs"); | ||
|
||
let out_str = String::from_utf8(array_string.into_inner().unwrap()).unwrap(); | ||
std::fs::write(&dest_path, out_str).unwrap(); | ||
} | ||
|
||
#[cfg(feature = "enable-cfg")] | ||
pub(crate) fn write_custom_config(out: impl Write) { | ||
// allow the name of the file we draw hardcoded values from to be set by an | ||
// environment variable at compile time. | ||
let cfg_file_name = option_env!("NYMVPN_CONFIG_PATH").unwrap_or(DEFAULT_CONFIG_FILE_NAME); | ||
|
||
// set reasons to rebuild | ||
println!("cargo:rerun-if-changed={cfg_file_name}"); | ||
println!("cargo:rerun-if-env-changed=NYMVPN_CONFIG_PATH"); | ||
|
||
let path = std::path::PathBuf::from(cfg_file_name); | ||
let cfg_file_path = if path.is_absolute() { | ||
path | ||
} else { | ||
let workspace_path = std::env::var("CARGO_MANIFEST_DIR").unwrap(); | ||
std::path::Path::new(&workspace_path).join(cfg_file_name) | ||
}; | ||
|
||
let config_str: String = std::fs::read_to_string(cfg_file_path).unwrap(); | ||
let config: Config = toml::from_str(&config_str).unwrap(); | ||
|
||
uneval::write(config, out).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
[client] | ||
version = "" | ||
id = "" | ||
disabled_credentials_mode = true | ||
nyxd_urls = ["https://rpc.nymtech.net/"] | ||
nym_api_urls = ["https://validator.nymtech.net/api/"] | ||
|
||
[debug.traffic] | ||
average_packet_delay = "50ms" | ||
message_sending_average_delay = "20ms" | ||
disable_main_poisson_packet_distribution = false | ||
deterministic_route_selection = false | ||
primary_packet_size = "regular" | ||
packet_type = "mix" | ||
|
||
[debug.cover_traffic] | ||
loop_cover_traffic_average_delay = "200ms" | ||
cover_traffic_primary_size_ratio = 0.7 | ||
disable_loop_cover_traffic_stream = false | ||
|
||
[debug.gateway_connection] | ||
gateway_response_timeout = "5m" | ||
|
||
[debug.acknowledgements] | ||
average_ack_delay = "50ms" | ||
ack_wait_multiplier = 1.5 | ||
ack_wait_addition = "1s 500ms" | ||
|
||
[debug.topology] | ||
topology_refresh_rate = "5m" | ||
topology_resolution_timeout = "5s" | ||
disable_refreshing = false | ||
max_startup_gateway_waiting_period = "1h 10m" | ||
topology_structure = "NymApi" | ||
minimum_mixnode_performance = 50 | ||
minimum_gateway_performance = 50 | ||
use_extended_topology = false | ||
ignore_egress_epoch_role = false | ||
|
||
[debug.reply_surbs] | ||
minimum_reply_surb_storage_threshold = 10 | ||
maximum_reply_surb_storage_threshold = 200 | ||
minimum_reply_surb_request_size = 10 | ||
maximum_reply_surb_request_size = 100 | ||
maximum_allowed_reply_surb_request_size = 500 | ||
maximum_reply_surb_rerequest_waiting_period = "10s" | ||
maximum_reply_surb_drop_waiting_period = "5m" | ||
maximum_reply_surb_age = "12h" | ||
maximum_reply_key_age = "1day" | ||
|
||
[debug.stats_reporting] | ||
enabled = true | ||
reporting_interval = "5m" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters