diff --git a/.env.dist b/.env.dist deleted file mode 100644 index 027b547bd..000000000 --- a/.env.dist +++ /dev/null @@ -1,14 +0,0 @@ -# General Environment Configuration -SMPC__ENVIRONMENT=development - -# Service Configuration -SMPC__SERVICE__SERVICE_NAME=smpcv2-server - -# Database Configuration -SMPC__DATABASE__URL=postgres://user:password@localhost/dbname -SMPC__DATABASE__MIGRATE=true -SMPC__DATABASE__CREATE=false - -# AWS Configuration (if needed) -SMPC__AWS__ENDPOINT=http://localhost:4566 -SMPC__AWS__REGION=us-west-2 diff --git a/.env.mpc1.dist b/.env.mpc1.dist new file mode 100644 index 000000000..5c7f6f937 --- /dev/null +++ b/.env.mpc1.dist @@ -0,0 +1,32 @@ +# Credentials, not read in by the app, will get replaced with an IAM profile for EKS node +AWS_ACCESS_KEY_ID=x +AWS_SECRET_ACCESS_KEY=x + +# General Environment Configuration +SMPC__ENVIRONMENT=development + +# Service Configuration +SMPC__SERVICE__SERVICE_NAME=smpcv2-server + +# Database Configuration +SMPC__DATABASE__URL=postgres://user:password@localhost/dbname +SMPC__DATABASE__MIGRATE=true +SMPC__DATABASE__CREATE=false + +# AWS Configuration +SMPC__AWS__REGION=eu-north-1 + +# Servers Configuration +SMPC__SERVERS__CODES_ENGINE_PORT=4000 +SMPC__SERVERS__MASKS_ENGINE_PORT=4001 +SMPC__SERVERS__BATCH_CODES_ENGINE_PORT=4002 +SMPC__SERVERS__BATCH_MASKS_ENGINE_PORT=4003 +SMPC__SERVERS__PHASE_2_BATCH_PORT=4004 +SMPC__SERVERS__PHASE_2_PORT=4005 + +# App configuration +SMPC__PARTY_ID=0 +SMPC__REQUESTS_QUEUE_URL=https://sqs.eu-north-1.amazonaws.com/654654380399/mpc1.fifo +SMPC__RESULTS_TOPIC_ARN=arn:aws:sns:eu-north-1:654654380399:mpc-results-topic +SMPC__PATH=/opt/dlami/nvme/ +SMPC__KMS_KEY_IDS='["077788e2-9eeb-4044-859b-34496cfd500b", "896353dc-5ea5-42d4-9e4e-f65dd8169dee", "42bb01f5-8380-48b4-b1f1-929463a587fb"]' diff --git a/.env.mpc2.dist b/.env.mpc2.dist new file mode 100644 index 000000000..66c136e8a --- /dev/null +++ b/.env.mpc2.dist @@ -0,0 +1,33 @@ +# Credentials, not read in by the app, will get replaced with an IAM profile for EKS node +AWS_ACCESS_KEY_ID=x +AWS_SECRET_ACCESS_KEY=x + +# General Environment Configuration +SMPC__ENVIRONMENT=development + +# Service Configuration +SMPC__SERVICE__SERVICE_NAME=smpcv2-server + +# Database Configuration +SMPC__DATABASE__URL=postgres://user:password@localhost/dbname +SMPC__DATABASE__MIGRATE=true +SMPC__DATABASE__CREATE=false + +# AWS Configuration +SMPC__AWS__REGION=eu-north-1 + +# Servers Configuration +SMPC__SERVERS__CODES_ENGINE_PORT=4000 +SMPC__SERVERS__MASKS_ENGINE_PORT=4001 +SMPC__SERVERS__BATCH_CODES_ENGINE_PORT=4002 +SMPC__SERVERS__BATCH_MASKS_ENGINE_PORT=4003 +SMPC__SERVERS__PHASE_2_BATCH_PORT=4004 +SMPC__SERVERS__PHASE_2_PORT=4005 + +# App configuration +SMPC__PARTY_ID=1 +SMPC__REQUESTS_QUEUE_URL=https://sqs.eu-north-1.amazonaws.com/654654380399/mpc2.fifo +SMPC__RESULTS_TOPIC_ARN=arn:aws:sns:eu-north-1:654654380399:mpc-results-topic +SMPC__PATH=/opt/dlami/nvme/ +SMPC__BOOTSTRAP_URL=10.15.32.27 +SMPC__KMS_KEY_IDS='["077788e2-9eeb-4044-859b-34496cfd500b", "896353dc-5ea5-42d4-9e4e-f65dd8169dee", "42bb01f5-8380-48b4-b1f1-929463a587fb"]' diff --git a/.env.mpc3.dist b/.env.mpc3.dist new file mode 100644 index 000000000..7124fb583 --- /dev/null +++ b/.env.mpc3.dist @@ -0,0 +1,33 @@ +# Credentials, not read in by the app, will get replaced with an IAM profile for EKS node +AWS_ACCESS_KEY_ID=x +AWS_SECRET_ACCESS_KEY=x + +# General Environment Configuration +SMPC__ENVIRONMENT=development + +# Service Configuration +SMPC__SERVICE__SERVICE_NAME=smpcv2-server + +# Database Configuration +SMPC__DATABASE__URL=postgres://user:password@localhost/dbname +SMPC__DATABASE__MIGRATE=true +SMPC__DATABASE__CREATE=false + +# AWS Configuration +SMPC__AWS__REGION=eu-north-1 + +# Servers Configuration +SMPC__SERVERS__CODES_ENGINE_PORT=4000 +SMPC__SERVERS__MASKS_ENGINE_PORT=4001 +SMPC__SERVERS__BATCH_CODES_ENGINE_PORT=4002 +SMPC__SERVERS__BATCH_MASKS_ENGINE_PORT=4003 +SMPC__SERVERS__PHASE_2_BATCH_PORT=4004 +SMPC__SERVERS__PHASE_2_PORT=4005 + +# App configuration +SMPC__PARTY_ID=2 +SMPC__REQUESTS_QUEUE_URL=https://sqs.eu-north-1.amazonaws.com/654654380399/mpc3.fifo +SMPC__RESULTS_TOPIC_ARN=arn:aws:sns:eu-north-1:654654380399:mpc-results-topic +SMPC__PATH=/opt/dlami/nvme/ +SMPC__BOOTSTRAP_URL=10.15.32.27 +SMPC__KMS_KEY_IDS='["077788e2-9eeb-4044-859b-34496cfd500b", "896353dc-5ea5-42d4-9e4e-f65dd8169dee", "42bb01f5-8380-48b4-b1f1-929463a587fb"]' diff --git a/.gitignore b/.gitignore index c2de60cd3..4bb38449b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.db .vscode/ .idea/ +.env diff --git a/README.md b/README.md index e65b725d2..7c646f471 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,58 @@ - Node PoC implementation in `src/bin/server.rs` - Example client in `src/bin/client.rs` + +#### Running the server without config override +``` +AWS_REGION=eu-north-1 AWS_ACCESS_KEY_ID=xxx AWS_SECRET_ACCESS_KEY=xxx cargo run --release --bin server +``` + +#### Running the server with override ``` AWS_REGION=eu-north-1 AWS_ACCESS_KEY_ID=xxx AWS_SECRET_ACCESS_KEY=xxx cargo run --release --bin server -- --party-id {0,1,2} --queue https://sqs.eu-north-1.amazonaws.com/xxx/mpc1.fifo ``` +#### Running the client ``` AWS_ACCESS_KEY_ID=xxx AWS_SECRET_ACCESS_KEY=xxx cargo run --release --bin client -- --topic-arn arn:aws:sns:eu-north-1:xxx:mpc.fifo --db-index 2 --n-repeat 32 ``` +### Server configuration + +Please note that this mechanism does not apply to the client part. + + +#### Environment variables +Application can be completely configured via environment variables. To see the list of variables please check out contents of the `.env*` files. + +**Important!** +Please note that there is a dist file per an instance of MPC node. Before running, please make sure to rename the correct dist file to `.env`. + +For now the environment variables are read in via a `dotenvy` crate for the ease of development. + +#### CLI arguments +Not to force developers into a change of approach to work that has been established, overloading the environment variables with CLI arguments is also possible. +List of possible overrides is represented by the following `struct`: +```rust +pub struct Opt { + #[structopt(long)] + requests_queue_url: Option, + + #[structopt(long)] + results_topic_arn: Option, + + #[structopt(long)] + party_id: Option, + + #[structopt(long)] + bootstrap_url: Option, + + #[structopt(long)] + path: Option, +} +``` +Please note that due to ambiguity, all the arguments need to be provided using their full names. + ### Dependencies Requires a NVIDIA graphics card with recent drivers and CUDA libraries. @@ -42,4 +86,3 @@ If you are using `cargo test` with non-standard library paths, you might need [a ## Streams and Synchronization in V2 (`src/bin/server.rs`) > TODO: dedup between query and previous is not yet implemented ![streams](mpc-iris-streams-v2.png) - diff --git a/scripts/sync_to_hosts.sh b/scripts/sync_to_hosts.sh new file mode 100755 index 000000000..bf5230a7b --- /dev/null +++ b/scripts/sync_to_hosts.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +# Check if username is provided as a parameter +if [ -z "$1" ]; then + echo "No username provided." + echo "Usage: $0 " + exit 1 +fi + +# Assign the provided username to a variable +USER_NAME=$1 + +# Define the target directory +TARGET_DIR="/home/ubuntu/${USER_NAME}" + +# Define the hosts, order is important, indices are used to identify .env files +TARGET_HOSTS=( +"ubuntu@mpc1-c4b4574e50dcf9c1.elb.eu-north-1.amazonaws.com" +"ubuntu@mpc2-c2cf3f545a8c3ae3.elb.eu-north-1.amazonaws.com" +"ubuntu@mpc3-9aa224d36eb4357f.elb.eu-north-1.amazonaws.com" +) + +# Define the directories to exclude +EXCLUDE_DIRS=(".idea" ".git" "target") + +# Create the exclude options for rsync +EXCLUDE_OPTIONS=() +for EXCLUDE_DIR in "${EXCLUDE_DIRS[@]}"; do + EXCLUDE_OPTIONS+=("--exclude=$EXCLUDE_DIR") +done + +# Get the name of the current working directory +CURRENT_DIR_NAME=$(basename "$PWD") + +## Loop through each host using an index, starting with 1 +for i in "${!TARGET_HOSTS[@]}"; do + INDEX=$((i + 1)) + HOST=${TARGET_HOSTS[$i]} + echo "Syncing $CURRENT_DIR_NAME to $HOST:$TARGET_DIR (Target Host $INDEX)" + + ## Make sure that the correct environment file is copied to the correct host + cp .env.mpc$INDEX.dist .env + + ## Sync the current directory to the target host + rsync -avz --delete "${EXCLUDE_OPTIONS[@]}" "$PWD" "$HOST:$TARGET_DIR" + if [ $? -eq 0 ]; then + echo "Sync to $HOST completed successfully." + else + echo "Sync to $HOST failed." + fi +done diff --git a/src/bin/server.rs b/src/bin/server.rs index 9b4f2f9f6..19bf22992 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -14,8 +14,7 @@ use cudarc::driver::{ CudaDevice, CudaSlice, CudaStream, }; use gpu_iris_mpc::{ - config, - config::Config, + config::{Config, Opt, ServersConfig}, dot::{ device_manager::DeviceManager, distance_comparator::DistanceComparator, @@ -45,7 +44,6 @@ use std::{ fs::metadata, mem, ops::IndexMut, - path::PathBuf, sync::{atomic::AtomicUsize, Arc, Mutex}, time::{Duration, Instant}, }; @@ -89,13 +87,7 @@ const MAX_CONCURRENT_BATCHES: usize = 2; const DB_CODE_FILE: &str = "codes.db"; const DB_MASK_FILE: &str = "masks.db"; -const DEFAULT_PATH: &str = "/opt/dlami/nvme/"; const QUERIES: usize = ROTATIONS * N_QUERIES; -const KMS_KEY_IDS: [&str; 3] = [ - "077788e2-9eeb-4044-859b-34496cfd500b", - "896353dc-5ea5-42d4-9e4e-f65dd8169dee", - "42bb01f5-8380-48b4-b1f1-929463a587fb", -]; lazy_static! { static ref KDF_NONCE: AtomicUsize = AtomicUsize::new(0); @@ -120,27 +112,6 @@ macro_rules! forget_vec { }; } -#[derive(Debug, Parser)] -struct Opt { - #[structopt(short, long)] - queue: String, - - #[structopt(short, long)] - results_topic_arn: String, - - #[structopt(short, long)] - party_id: usize, - - #[structopt(short, long)] - bootstrap_url: Option, - - #[structopt(short, long)] - path: Option, - - #[clap(short, long, env)] - config: Option, -} - #[derive(Default)] struct BatchQueryEntries { pub code: Vec, @@ -468,17 +439,8 @@ pub fn calculate_insertion_indices( #[tokio::main] async fn main() -> eyre::Result<()> { dotenvy::dotenv().ok(); - - let Opt { - queue, - party_id, - bootstrap_url, - path, - results_topic_arn, - config, - } = Opt::parse(); - - let config: Config = config::load_config("SMPC", config.as_deref())?; + let mut config: Config = Config::load_config("SMPC").unwrap(); + config.overwrite_defaults_with_cli_args(Opt::parse()); let _tracing_shutdown_handle = if let Some(service) = &config.service { let tracing_shutdown_handle = DatadogBattery::init( @@ -508,7 +470,15 @@ async fn main() -> eyre::Result<()> { TracingShutdownHandle }; - let path = path.unwrap_or(DEFAULT_PATH.to_string()); + let Config { + path, + party_id, + results_topic_arn, + requests_queue_url, + bootstrap_url, + kms_key_ids, + .. + } = config; let code_db_path = format!("{}/{}", path, DB_CODE_FILE); let mask_db_path = format!("{}/{}", path, DB_MASK_FILE); @@ -520,7 +490,10 @@ async fn main() -> eyre::Result<()> { let store = Store::new_from_env().await?; // Init RNGs - let own_key_id = KMS_KEY_IDS[party_id]; + let own_key_id = kms_key_ids + .0 + .get(party_id) + .expect("Expected value not found in kms_key_ids"); let dh_pairs = match party_id { 0 => (1usize, 2usize), 1 => (2usize, 0usize), @@ -528,9 +501,18 @@ async fn main() -> eyre::Result<()> { _ => unimplemented!(), }; + let dh_pair_0: &str = kms_key_ids + .0 + .get(dh_pairs.0) + .expect("Expected value not found in kms_key_ids"); + let dh_pair_1: &str = kms_key_ids + .0 + .get(dh_pairs.1) + .expect("Expected value not found in kms_key_ids"); + let chacha_seeds = ( - bytemuck::cast(derive_shared_secret(own_key_id, KMS_KEY_IDS[dh_pairs.0]).await?), - bytemuck::cast(derive_shared_secret(own_key_id, KMS_KEY_IDS[dh_pairs.1]).await?), + bytemuck::cast(derive_shared_secret(own_key_id, dh_pair_0).await?), + bytemuck::cast(derive_shared_secret(own_key_id, dh_pair_1).await?), ); // Generate or load DB @@ -585,6 +567,15 @@ async fn main() -> eyre::Result<()> { let device_manager = Arc::new(DeviceManager::init()); let mut server_tasks = TaskMonitor::new(); + let ServersConfig { + codes_engine_port, + masks_engine_port, + batch_codes_engine_port, + batch_masks_engine_port, + phase_2_port, + phase_2_batch_port, + } = config.servers; + // Phase 1 Setup let mut codes_engine = ShareDB::init( party_id, @@ -594,7 +585,7 @@ async fn main() -> eyre::Result<()> { next_chacha_seeds(chacha_seeds)?, bootstrap_url.clone(), Some(true), - Some(4000), + Some(codes_engine_port), Some(&mut server_tasks), ); server_tasks.check_tasks(); @@ -607,7 +598,7 @@ async fn main() -> eyre::Result<()> { next_chacha_seeds(chacha_seeds)?, bootstrap_url.clone(), Some(true), - Some(4001), + Some(masks_engine_port), Some(&mut server_tasks), ); server_tasks.check_tasks(); @@ -624,7 +615,7 @@ async fn main() -> eyre::Result<()> { next_chacha_seeds(chacha_seeds)?, bootstrap_url.clone(), Some(true), - Some(4002), + Some(batch_codes_engine_port), Some(&mut server_tasks), ); server_tasks.check_tasks(); @@ -637,7 +628,7 @@ async fn main() -> eyre::Result<()> { next_chacha_seeds(chacha_seeds)?, bootstrap_url.clone(), Some(true), - Some(4003), + Some(batch_masks_engine_port), Some(&mut server_tasks), ); server_tasks.check_tasks(); @@ -655,7 +646,7 @@ async fn main() -> eyre::Result<()> { phase2_batch_chunk_size, next_chacha_seeds(chacha_seeds)?, bootstrap_url.clone(), - Some(4004), + Some(phase_2_batch_port), Some(&mut server_tasks), ))); server_tasks.check_tasks(); @@ -666,7 +657,7 @@ async fn main() -> eyre::Result<()> { phase2_chunk_size_max / 64, next_chacha_seeds(chacha_seeds)?, bootstrap_url.clone(), - Some(4005), + Some(phase_2_port), Some(&mut server_tasks), ))); server_tasks.check_tasks(); @@ -785,7 +776,7 @@ async fn main() -> eyre::Result<()> { // This batch can consist of N sets of iris_share + mask // It also includes a vector of request ids, mapping to the sets above - let batch = receive_batch(party_id, &sqs_client, &queue).await?; + let batch = receive_batch(party_id, &sqs_client, &requests_queue_url).await?; // Iterate over a list of tracing payloads, and create logs with mappings to // payloads Log at least a "start" event using a log with trace.id and diff --git a/src/config.rs b/src/config.rs deleted file mode 100644 index fc94ca9f2..000000000 --- a/src/config.rs +++ /dev/null @@ -1,76 +0,0 @@ -use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use std::path::Path; - -pub fn load_config(prefix: &str, config_path: Option<&Path>) -> eyre::Result -where - T: DeserializeOwned, -{ - let mut settings = config::Config::builder(); - - if let Some(path) = config_path { - settings = settings.add_source(config::File::from(path).required(true)); - } - - let settings = settings - .add_source( - config::Environment::with_prefix(prefix) - .separator("__") - .try_parsing(true), - ) - .build()?; - - let config = settings.try_deserialize::()?; - - Ok(config) -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Config { - #[serde(default)] - pub environment: Option, - - #[serde(default)] - pub service: Option, - - #[serde(default)] - pub database: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize, Default)] -pub struct DbConfig { - pub url: String, - - #[serde(default)] - pub migrate: bool, - - #[serde(default)] - pub create: bool, -} - -#[derive(Debug, Clone, Serialize, Deserialize, Default)] -pub struct AwsConfig { - /// Useful when using something like LocalStack - pub endpoint: Option, - - #[serde(default)] - pub region: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ServiceConfig { - // Service name - used for logging, metrics and tracing - pub service_name: String, - // Traces - pub traces_endpoint: Option, - // Metrics - pub metrics: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct MetricsConfig { - pub host: String, - pub port: u16, - pub queue_size: usize, - pub buffer_size: usize, - pub prefix: String, -} diff --git a/src/config/json_wrapper.rs b/src/config/json_wrapper.rs new file mode 100644 index 000000000..7b9a57297 --- /dev/null +++ b/src/config/json_wrapper.rs @@ -0,0 +1,91 @@ +use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use std::{borrow::Cow, fmt, str::FromStr}; + +#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] +pub struct JsonStrWrapper(pub T); + +impl FromStr for JsonStrWrapper +where + T: DeserializeOwned, +{ + type Err = serde_json::Error; + + fn from_str(s: &str) -> Result { + serde_json::from_str(s).map(JsonStrWrapper) + } +} + +impl fmt::Display for JsonStrWrapper +where + T: Serialize, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let s = serde_json::to_string(self).map_err(|_| fmt::Error)?; + + s.fmt(f) + } +} + +impl Serialize for JsonStrWrapper +where + T: Serialize, +{ + fn serialize(&self, serializer: S) -> Result { + serde_json::to_string(&self.0) + .map_err(serde::ser::Error::custom)? + .serialize(serializer) + } +} + +impl<'de, T> Deserialize<'de> for JsonStrWrapper +where + // TODO: Is there some way to use T: + // Deserialize<'de> here? + T: DeserializeOwned, +{ + fn deserialize>(deserializer: D) -> Result { + let s = Cow::<'static, str>::deserialize(deserializer)?; + + serde_json::from_str(&s) + .map(JsonStrWrapper) + .map_err(serde::de::Error::custom) + } +} + +impl From for JsonStrWrapper { + fn from(t: T) -> Self { + Self(t) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::Value; + + #[test] + fn json() { + let wrapper = JsonStrWrapper(vec![1, 2, 3]); + + let s = serde_json::to_string(&wrapper).unwrap(); + + assert_eq!(s, "\"[1,2,3]\""); + + let wrapper: JsonStrWrapper> = serde_json::from_str(&s).unwrap(); + + assert_eq!(wrapper.0, vec![1, 2, 3]); + } + + #[test] + fn json_value() { + let wrapper = JsonStrWrapper(vec![1, 2, 3]); + + let s = serde_json::to_value(wrapper).unwrap(); + + assert_eq!(s, Value::String("[1,2,3]".to_string())); + + let wrapper: JsonStrWrapper> = serde_json::from_value(s).unwrap(); + + assert_eq!(wrapper.0, vec![1, 2, 3]); + } +} diff --git a/src/config/mod.rs b/src/config/mod.rs new file mode 100644 index 000000000..187e6984d --- /dev/null +++ b/src/config/mod.rs @@ -0,0 +1,150 @@ +pub mod json_wrapper; + +use crate::config::json_wrapper::JsonStrWrapper; +use clap::Parser; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Parser)] +pub struct Opt { + #[structopt(long)] + requests_queue_url: Option, + + #[structopt(long)] + results_topic_arn: Option, + + #[structopt(long)] + party_id: Option, + + #[structopt(long)] + bootstrap_url: Option, + + #[structopt(long)] + path: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Config { + #[serde(default)] + pub environment: String, + + #[serde(default)] + pub party_id: usize, + + #[serde(default)] + pub requests_queue_url: String, + + #[serde(default)] + pub results_topic_arn: String, + + #[serde(default)] + pub path: String, + + #[serde(default)] + pub kms_key_ids: JsonStrWrapper>, + + #[serde(default)] + pub bootstrap_url: Option, + + #[serde(default)] + pub servers: ServersConfig, + + #[serde(default)] + pub service: Option, + + #[serde(default)] + pub database: Option, + + #[serde(default)] + pub aws: Option, +} + +impl Config { + pub fn load_config(prefix: &str) -> eyre::Result { + let settings = config::Config::builder(); + let settings = settings + .add_source( + config::Environment::with_prefix(prefix) + .separator("__") + .try_parsing(true), + ) + .build()?; + + let config: Config = settings.try_deserialize::()?; + + dbg!("Debug config"); + dbg!(&config); + + Ok(config) + } + + pub fn overwrite_defaults_with_cli_args(&mut self, opts: Opt) { + if let Some(requests_queue_url) = opts.requests_queue_url { + self.requests_queue_url = requests_queue_url; + } + + if let Some(results_topic_arn) = opts.results_topic_arn { + self.results_topic_arn = results_topic_arn; + } + + if let Some(party_id) = opts.party_id { + self.party_id = party_id; + } + + if let Some(bootstrap_url) = opts.bootstrap_url { + self.bootstrap_url = Some(bootstrap_url); + } + + if let Some(path) = opts.path { + self.path = path; + } + } +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +pub struct DbConfig { + pub url: String, + + #[serde(default)] + pub migrate: bool, + + #[serde(default)] + pub create: bool, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +pub struct AwsConfig { + /// Useful when using something like LocalStack + pub endpoint: Option, + + #[serde(default)] + pub region: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ServiceConfig { + // Service name - used for logging, metrics and tracing + pub service_name: String, + // Traces + pub traces_endpoint: Option, + // Metrics + pub metrics: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct MetricsConfig { + pub host: String, + pub port: u16, + pub queue_size: usize, + pub buffer_size: usize, + pub prefix: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +pub struct ServersConfig { + pub codes_engine_port: u16, + pub masks_engine_port: u16, + pub batch_codes_engine_port: u16, + pub batch_masks_engine_port: u16, + pub phase_2_batch_port: u16, + pub phase_2_port: u16, +} diff --git a/src/lib.rs b/src/lib.rs index ef1d0acf4..467669031 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,8 @@ #![allow(clippy::needless_range_loop)] +pub mod config; pub mod dot; pub mod helpers; pub mod rng; pub mod setup; pub mod store; pub mod threshold_ring; - -pub mod config;